summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/libvirt/domain/device/Sound.java
blob: dfeeffd2a0ca7420cb4dcbf4c17c855085790013 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package org.openslx.libvirt.domain.device;

import org.openslx.libvirt.xml.LibvirtXmlNode;

/**
 * A sound device node in a Libvirt domain XML document.
 * 
 * @author Manuel Bentele
 * @version 1.0
 */
public class Sound extends Device
{
	/**
	 * Creates an empty sound device.
	 */
	public Sound()
	{
		super();
	}

	/**
	 * Creates a sound device representing an existing Libvirt XML sound device element.
	 * 
	 * @param xmlNode existing Libvirt XML sound device element.
	 */
	public Sound( LibvirtXmlNode xmlNode )
	{
		super( xmlNode );
	}

	/**
	 * Returns hardware model of the sound device.
	 * 
	 * @return hardware model of the sound device.
	 */
	public Model getModel()
	{
		String model = this.getXmlElementAttributeValue( "model" );
		return Model.fromString( model );
	}

	/**
	 * Sets hardware model for the sound device.
	 * 
	 * @param model hardware model for the sound device.
	 */
	public void setModel( Model model )
	{
		this.setXmlElementAttributeValue( "model", model.toString() );
	}

	/**
	 * Creates a non-existent sound device as Libvirt XML device element.
	 * 
	 * @param xmlNode Libvirt XML node of the Libvirt XML device that is created.
	 * @return created sound device instance.
	 */
	public static Sound createInstance( LibvirtXmlNode xmlNode )
	{
		return Sound.newInstance( xmlNode );
	}

	/**
	 * Creates a sound device representing an existing Libvirt XML sound device element.
	 * 
	 * @param xmlNode existing Libvirt XML sound device element.
	 * @return sound device instance.
	 */
	public static Sound newInstance( LibvirtXmlNode xmlNode )
	{
		return new Sound( xmlNode );
	}

	/**
	 * Model of sound device.
	 * 
	 * @author Manuel Bentele
	 * @version 1.0
	 */
	public enum Model
	{
		// @formatter:off
		AC97  ( "ac97" ),
		ES1370( "es1370" ),
		ICH6  ( "ich6" ),
		ICH9  ( "ich9" ),
		SB16  ( "sb16" );
		// @formatter:on

		/**
		 * Name of the sound device model.
		 */
		private String model;

		/**
		 * Creates sound device model.
		 * 
		 * @param type valid name of the sound device model in a Libvirt domain XML document.
		 */
		Model( String model )
		{
			this.model = model;
		}

		@Override
		public String toString()
		{
			return this.model;
		}

		/**
		 * Creates sound device model from its name with error check.
		 * 
		 * @param model name of the sound device model in a Libvirt domain XML document.
		 * @return valid sound device model.
		 */
		public static Model fromString( String model )
		{
			for ( Model m : Model.values() ) {
				if ( m.model.equalsIgnoreCase( model ) ) {
					return m;
				}
			}

			return null;
		}
	}
}