summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/libvirt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/libvirt')
-rw-r--r--src/main/java/org/openslx/libvirt/capabilities/Capabilities.java155
-rw-r--r--src/main/java/org/openslx/libvirt/capabilities/cpu/Cpu.java165
-rw-r--r--src/main/java/org/openslx/libvirt/capabilities/cpu/Feature.java51
-rw-r--r--src/main/java/org/openslx/libvirt/capabilities/cpu/Pages.java60
-rw-r--r--src/main/java/org/openslx/libvirt/capabilities/guest/Domain.java53
-rw-r--r--src/main/java/org/openslx/libvirt/capabilities/guest/Guest.java127
-rw-r--r--src/main/java/org/openslx/libvirt/capabilities/guest/Machine.java72
-rw-r--r--src/main/java/org/openslx/libvirt/domain/Domain.java232
-rw-r--r--src/main/java/org/openslx/libvirt/domain/device/ControllerUsb.java2
-rw-r--r--src/main/java/org/openslx/libvirt/domain/device/Device.java21
-rw-r--r--src/main/java/org/openslx/libvirt/domain/device/Disk.java6
-rw-r--r--src/main/java/org/openslx/libvirt/domain/device/FileSystem.java292
-rw-r--r--src/main/java/org/openslx/libvirt/domain/device/HostdevPci.java2
-rw-r--r--src/main/java/org/openslx/libvirt/domain/device/Interface.java40
-rw-r--r--src/main/java/org/openslx/libvirt/domain/device/Parallel.java158
-rw-r--r--src/main/java/org/openslx/libvirt/domain/device/Serial.java156
-rw-r--r--src/main/java/org/openslx/libvirt/domain/device/Sound.java2
-rw-r--r--src/main/java/org/openslx/libvirt/domain/device/Video.java2
-rw-r--r--src/main/java/org/openslx/libvirt/libosinfo/LibOsInfo.java158
-rw-r--r--src/main/java/org/openslx/libvirt/libosinfo/os/Os.java93
-rw-r--r--src/main/java/org/openslx/libvirt/xml/LibvirtXmlDocument.java12
-rw-r--r--src/main/java/org/openslx/libvirt/xml/LibvirtXmlEditable.java72
-rw-r--r--src/main/java/org/openslx/libvirt/xml/LibvirtXmlNode.java22
-rw-r--r--src/main/java/org/openslx/libvirt/xml/LibvirtXmlResources.java59
-rw-r--r--src/main/java/org/openslx/libvirt/xml/LibvirtXmlSchemaValidator.java5
-rw-r--r--src/main/java/org/openslx/libvirt/xml/LibvirtXmlSerializable.java12
26 files changed, 1943 insertions, 86 deletions
diff --git a/src/main/java/org/openslx/libvirt/capabilities/Capabilities.java b/src/main/java/org/openslx/libvirt/capabilities/Capabilities.java
new file mode 100644
index 0000000..7987371
--- /dev/null
+++ b/src/main/java/org/openslx/libvirt/capabilities/Capabilities.java
@@ -0,0 +1,155 @@
+package org.openslx.libvirt.capabilities;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openslx.libvirt.capabilities.cpu.Cpu;
+import org.openslx.libvirt.capabilities.guest.Guest;
+import org.openslx.libvirt.xml.LibvirtXmlDocument;
+import org.openslx.libvirt.xml.LibvirtXmlDocumentException;
+import org.openslx.libvirt.xml.LibvirtXmlNode;
+import org.openslx.libvirt.xml.LibvirtXmlResources;
+import org.openslx.libvirt.xml.LibvirtXmlSerializationException;
+import org.openslx.libvirt.xml.LibvirtXmlValidationException;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+/**
+ * Implementation of the Libvirt capabilities XML document.
+ *
+ * The Libvirt capabilities XML document is used to describe the configuration and capabilities of
+ * the hypervisor's host.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+public class Capabilities extends LibvirtXmlDocument
+{
+ /**
+ * Creates Libvirt capabilities XML document from {@link String} providing Libvirt capabilities
+ * XML content.
+ *
+ * @param xml {@link String} with Libvirt capabilities XML content.
+ *
+ * @throws LibvirtXmlDocumentException creation of XML context failed.
+ * @throws LibvirtXmlSerializationException serialization of the capabilities XML content failed.
+ * @throws LibvirtXmlValidationException XML content is not a valid capabilities XML document.
+ */
+ public Capabilities( String xml )
+ throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException
+ {
+ super( xml, LibvirtXmlResources.getLibvirtRng( "capabilities.rng" ) );
+ }
+
+ /**
+ * Creates Libvirt capabilities XML document from {@link File} containing Libvirt capabilities
+ * XML content.
+ *
+ * @param xml existing {@link File} containing Libvirt capabilities XML content.
+ *
+ * @throws LibvirtXmlDocumentException creation of XML context failed.
+ * @throws LibvirtXmlSerializationException serialization of the capabilities XML content failed.
+ * @throws LibvirtXmlValidationException XML content is not a valid capabilities XML document.
+ */
+ public Capabilities( File xml )
+ throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException
+ {
+ super( xml, LibvirtXmlResources.getLibvirtRng( "capabilities.rng" ) );
+ }
+
+ /**
+ * Creates Libvirt capabilities XML document from {@link InputStream} providing Libvirt
+ * capabilities XML content.
+ *
+ * @param xml {@link InputStream} providing Libvirt capabilities XML content.
+ *
+ * @throws LibvirtXmlDocumentException creation of XML context failed.
+ * @throws LibvirtXmlSerializationException serialization of the capabilities XML content failed.
+ * @throws LibvirtXmlValidationException XML content is not a valid capabilities XML document.
+ */
+ public Capabilities( InputStream xml )
+ throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException
+ {
+ super( xml, LibvirtXmlResources.getLibvirtRng( "capabilities.rng" ) );
+ }
+
+ /**
+ * Creates Libvirt capabilities XML document from {@link InputSource} providing Libvirt
+ * capabilities XML content.
+ *
+ * @param xml {@link InputSource} providing Libvirt capabilities XML content.
+ *
+ * @throws LibvirtXmlDocumentException creation of XML context failed.
+ * @throws LibvirtXmlSerializationException serialization of the capabilities XML content failed.
+ * @throws LibvirtXmlValidationException XML content is not a valid capabilities XML document.
+ */
+ public Capabilities( InputSource xml )
+ throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException
+ {
+ super( xml, LibvirtXmlResources.getLibvirtRng( "capabilities.rng" ) );
+ }
+
+ /**
+ * Returns UUID of the Libvirt host machine.
+ *
+ * @return UUID of the host machine.
+ */
+ public String getHostUuid()
+ {
+ return this.getRootXmlNode().getXmlElementValue( "host/uuid" );
+ }
+
+ /**
+ * Returns CPU capabilities of the host machine.
+ *
+ * @return CPU capabilities of the host machine.
+ */
+ public Cpu getHostCpu()
+ {
+ final Node hostCpuNode = this.getRootXmlNode().getXmlElement( "host/cpu" );
+
+ if ( hostCpuNode == null ) {
+ return null;
+ } else {
+ final LibvirtXmlNode hostCpuXmlNode = new LibvirtXmlNode( this.getRootXmlNode().getXmlDocument(),
+ hostCpuNode );
+ return Cpu.newInstance( hostCpuXmlNode );
+ }
+ }
+
+ /**
+ * Checks whether the Libvirt host machine has IOMMU support.
+ *
+ * @return State of the IOMMU support.
+ */
+ public boolean hasHostIommuSupport()
+ {
+ return this.getRootXmlNode().getXmlElementAttributeValueAsBool( "host/iommu", "support" );
+ }
+
+ /**
+ * Returns capabilities of all possible guest machines.
+ *
+ * @return capabilities of all possible guest machines.
+ */
+ public List<Guest> getGuests()
+ {
+ final List<Guest> guestList = new ArrayList<Guest>();
+ final NodeList guestNodes = this.getRootXmlNode().getXmlNodes( "guest" );
+
+ for ( int i = 0; i < guestNodes.getLength(); i++ ) {
+ final LibvirtXmlNode guestNode = new LibvirtXmlNode( this.getRootXmlNode().getXmlDocument(),
+ guestNodes.item( i ) );
+ final Guest guest = Guest.newInstance( guestNode );
+
+ if ( guest != null ) {
+ guestList.add( guest );
+ }
+ }
+
+ return guestList;
+ }
+}
diff --git a/src/main/java/org/openslx/libvirt/capabilities/cpu/Cpu.java b/src/main/java/org/openslx/libvirt/capabilities/cpu/Cpu.java
new file mode 100644
index 0000000..dc5fbd0
--- /dev/null
+++ b/src/main/java/org/openslx/libvirt/capabilities/cpu/Cpu.java
@@ -0,0 +1,165 @@
+package org.openslx.libvirt.capabilities.cpu;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openslx.libvirt.xml.LibvirtXmlNode;
+import org.w3c.dom.NodeList;
+
+/**
+ * Implementation of the host CPU capabilities as part of the Libvirt capabilities XML document.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+public class Cpu extends LibvirtXmlNode
+{
+ /**
+ * Creates an empty host CPU capabilities instance.
+ */
+ public Cpu()
+ {
+ super();
+ }
+
+ /**
+ * Creates a host CPU capabilities instance representing an existing Libvirt XML host CPU
+ * capabilities element.
+ *
+ * @param xmlNode existing Libvirt XML host CPU capabilities element.
+ */
+ public Cpu( LibvirtXmlNode xmlNode )
+ {
+ super( xmlNode );
+ }
+
+ /**
+ * Returns the architecture name of the host CPU.
+ *
+ * @return architecture name of the host CPU.
+ */
+ public String getArch()
+ {
+ return this.getXmlElementValue( "arch" );
+ }
+
+ /**
+ * Returns the model name of the host CPU.
+ *
+ * @return model name of the host CPU.
+ */
+ public String getModel()
+ {
+ return this.getXmlElementValue( "model" );
+ }
+
+ /**
+ * Returns the vendor name of the host CPU.
+ *
+ * @return vendor name of the host CPU.
+ */
+ public String getVendor()
+ {
+ return this.getXmlElementValue( "vendor" );
+ }
+
+ /**
+ * Returns the number of sockets of the host CPU.
+ *
+ * @return number of sockets of the host CPU.
+ */
+ public int getTopologySockets()
+ {
+ final String numSockets = this.getXmlElementAttributeValue( "topology", "sockets" );
+ return Integer.parseInt( numSockets );
+ }
+
+ /**
+ * Returns the number of dies of the host CPU.
+ *
+ * @return number of dies of the host CPU.
+ */
+ public int getTopologyDies()
+ {
+ final String numDies = this.getXmlElementAttributeValue( "topology", "dies" );
+ return Integer.parseInt( numDies );
+ }
+
+ /**
+ * Returns the number of cores of the host CPU.
+ *
+ * @return number of cores of the host CPU.
+ */
+ public int getTopologyCores()
+ {
+ final String numCores = this.getXmlElementAttributeValue( "topology", "cores" );
+ return Integer.parseInt( numCores );
+ }
+
+ /**
+ * Returns the number of threads of the host CPU.
+ *
+ * @return number of threads of the host CPU.
+ */
+ public int getTopologyThreads()
+ {
+ final String numThreads = this.getXmlElementAttributeValue( "topology", "threads" );
+ return Integer.parseInt( numThreads );
+ }
+
+ /**
+ * Returns the supported features of the host CPU.
+ *
+ * @return supported features of the host CPU.
+ */
+ public List<Feature> getFeatures()
+ {
+ final List<Feature> featureList = new ArrayList<Feature>();
+ final NodeList featureNodes = this.getXmlNodes( "feature" );
+
+ for ( int i = 0; i < featureNodes.getLength(); i++ ) {
+ final LibvirtXmlNode featureNode = new LibvirtXmlNode( this.getXmlDocument(), featureNodes.item( i ) );
+ final Feature feature = Feature.newInstance( featureNode );
+
+ if ( feature != null ) {
+ featureList.add( feature );
+ }
+ }
+
+ return featureList;
+ }
+
+ /**
+ * Returns the supported memory pages of the host CPU.
+ *
+ * @return supported memory pages of the host CPU.
+ */
+ public List<Pages> getPages()
+ {
+ final List<Pages> pagesList = new ArrayList<Pages>();
+ final NodeList pagesNodes = this.getXmlNodes( "pages" );
+
+ for ( int i = 0; i < pagesNodes.getLength(); i++ ) {
+ final LibvirtXmlNode pagesNode = new LibvirtXmlNode( this.getXmlDocument(), pagesNodes.item( i ) );
+ final Pages pages = Pages.newInstance( pagesNode );
+
+ if ( pages != null ) {
+ pagesList.add( pages );
+ }
+ }
+
+ return pagesList;
+ }
+
+ /**
+ * Creates a host CPU capabilities instance representing an existing Libvirt XML host CPU
+ * capabilities element.
+ *
+ * @param xmlNode existing Libvirt XML host CPU capabilities element.
+ * @return host CPU capabilities instance.
+ */
+ public static Cpu newInstance( LibvirtXmlNode xmlNode )
+ {
+ return new Cpu( xmlNode );
+ }
+}
diff --git a/src/main/java/org/openslx/libvirt/capabilities/cpu/Feature.java b/src/main/java/org/openslx/libvirt/capabilities/cpu/Feature.java
new file mode 100644
index 0000000..96c77d5
--- /dev/null
+++ b/src/main/java/org/openslx/libvirt/capabilities/cpu/Feature.java
@@ -0,0 +1,51 @@
+package org.openslx.libvirt.capabilities.cpu;
+
+import org.openslx.libvirt.xml.LibvirtXmlNode;
+
+/**
+ * Implementation of a host CPU feature as part of the Libvirt capabilities XML document.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+public class Feature extends LibvirtXmlNode
+{
+ /**
+ * Creates an empty host CPU feature instance.
+ */
+ public Feature()
+ {
+ super();
+ }
+
+ /**
+ * Creates an host CPU feature representing an existing Libvirt XML host CPU feature element.
+ *
+ * @param xmlNode existing Libvirt XML host CPU feature element.
+ */
+ public Feature( LibvirtXmlNode xmlNode )
+ {
+ super( xmlNode );
+ }
+
+ /**
+ * Returns the name of the host CPU feature.
+ *
+ * @return name of the host CPU feature.
+ */
+ public String getName()
+ {
+ return this.getXmlElementAttributeValue( "name" );
+ }
+
+ /**
+ * Creates an host CPU feature representing an existing Libvirt XML host CPU feature element.
+ *
+ * @param xmlNode existing Libvirt XML host CPU feature element.
+ * @return host CPU feature instance.
+ */
+ public static Feature newInstance( LibvirtXmlNode xmlNode )
+ {
+ return new Feature( xmlNode );
+ }
+}
diff --git a/src/main/java/org/openslx/libvirt/capabilities/cpu/Pages.java b/src/main/java/org/openslx/libvirt/capabilities/cpu/Pages.java
new file mode 100644
index 0000000..eea5a36
--- /dev/null
+++ b/src/main/java/org/openslx/libvirt/capabilities/cpu/Pages.java
@@ -0,0 +1,60 @@
+package org.openslx.libvirt.capabilities.cpu;
+
+import java.math.BigInteger;
+
+import org.openslx.libvirt.domain.DomainUtils;
+import org.openslx.libvirt.xml.LibvirtXmlNode;
+
+/**
+ * Implementation of a host CPU memory pages instance as part of the Libvirt capabilities XML
+ * document.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+public class Pages extends LibvirtXmlNode
+{
+ /**
+ * Creates an empty host CPU memory pages instance.
+ */
+ public Pages()
+ {
+ super();
+ }
+
+ /**
+ * Creates a host CPU memory pages instance representing an existing Libvirt XML host CPU pages
+ * element.
+ *
+ * @param xmlNode existing Libvirt XML host CPU pages element.
+ */
+ public Pages( LibvirtXmlNode xmlNode )
+ {
+ super( xmlNode );
+ }
+
+ /**
+ * Returns size of the memory pages instance.
+ *
+ * @return size of the memory pages instance.
+ */
+ public BigInteger getSize()
+ {
+ final String pagesValue = this.getXmlElementAttributeValue( "size" );
+ final String pagesUnit = this.getXmlElementAttributeValue( "unit" );
+
+ return DomainUtils.decodeMemory( pagesValue, pagesUnit );
+ }
+
+ /**
+ * Creates a host CPU memory pages instance representing an existing Libvirt XML host CPU pages
+ * element.
+ *
+ * @param xmlNode existing Libvirt XML host CPU pages element.
+ * @return host CPU memory pages instance.
+ */
+ public static Pages newInstance( LibvirtXmlNode xmlNode )
+ {
+ return new Pages( xmlNode );
+ }
+}
diff --git a/src/main/java/org/openslx/libvirt/capabilities/guest/Domain.java b/src/main/java/org/openslx/libvirt/capabilities/guest/Domain.java
new file mode 100644
index 0000000..8716064
--- /dev/null
+++ b/src/main/java/org/openslx/libvirt/capabilities/guest/Domain.java
@@ -0,0 +1,53 @@
+package org.openslx.libvirt.capabilities.guest;
+
+import org.openslx.libvirt.domain.Domain.Type;
+import org.openslx.libvirt.xml.LibvirtXmlNode;
+
+/**
+ * Implementation of a guest domain as part of the Libvirt capabilities XML capabilities document.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+public class Domain extends LibvirtXmlNode
+{
+ /**
+ * Creates an empty guest domain instance.
+ */
+ public Domain()
+ {
+ super();
+ }
+
+ /**
+ * Creates a guest domain representing an existing Libvirt XML guest domain element.
+ *
+ * @param xmlNode existing Libvirt XML guest domain element.
+ */
+ public Domain( LibvirtXmlNode xmlNode )
+ {
+ super( xmlNode );
+ }
+
+ /**
+ * Returns the domain type of the guest domain.
+ *
+ * @return type of the guest domain.
+ */
+ public Type getType()
+ {
+ final String type = this.getXmlElementAttributeValue( "type" );
+ return Type.fromString( type );
+ }
+
+ /**
+ * Creates a guest domain representing an existing Libvirt XML guest domain element.
+ *
+ * @param xmlNode existing Libvirt XML guest domain element.
+ * @return guest domain instance.
+ */
+ public static Domain newInstance( LibvirtXmlNode xmlNode )
+ {
+ return new Domain( xmlNode );
+ }
+}
diff --git a/src/main/java/org/openslx/libvirt/capabilities/guest/Guest.java b/src/main/java/org/openslx/libvirt/capabilities/guest/Guest.java
new file mode 100644
index 0000000..2471180
--- /dev/null
+++ b/src/main/java/org/openslx/libvirt/capabilities/guest/Guest.java
@@ -0,0 +1,127 @@
+package org.openslx.libvirt.capabilities.guest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openslx.libvirt.domain.Domain.OsType;
+import org.openslx.libvirt.xml.LibvirtXmlNode;
+import org.w3c.dom.NodeList;
+
+/**
+ * Implementation of the guest capabilities as part of the Libvirt capabilities XML document.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+public class Guest extends LibvirtXmlNode
+{
+ /**
+ * Creates an empty guest instance.
+ */
+ public Guest()
+ {
+ super();
+ }
+
+ /**
+ * Creates a guest representing an existing Libvirt XML guest capabilities element.
+ *
+ * @param xmlNode existing Libvirt XML guest capabilities element.
+ */
+ public Guest( LibvirtXmlNode xmlNode )
+ {
+ super( xmlNode );
+ }
+
+ /**
+ * Return OS type of the guest.
+ *
+ * @return OS type of the guest.
+ */
+ public OsType getOsType()
+ {
+ final String osType = this.getXmlElementValue( "os_type" );
+ return OsType.fromString( osType );
+ }
+
+ /**
+ * Returns the architecture name of the guest.
+ *
+ * @return architecture name of the guest.
+ */
+ public String getArchName()
+ {
+ return this.getXmlElementAttributeValue( "arch", "name" );
+ }
+
+ /**
+ * Return word size of the guest's architecture.
+ *
+ * @return word size of the guest's architecture.
+ */
+ public int getArchWordSize()
+ {
+ final String archWordSize = this.getXmlElementValue( "arch/wordsize" );
+ return Integer.parseInt( archWordSize );
+ }
+
+ public String getArchEmulator()
+ {
+ return this.getXmlElementValue( "arch/emulator" );
+ }
+
+ /**
+ * Returns the available machines of the guest's architecture.
+ *
+ * @return available machines of the guest's architecture.
+ */
+ public List<Machine> getArchMachines()
+ {
+ final List<Machine> machinesList = new ArrayList<Machine>();
+ final NodeList machineNodes = this.getXmlNodes( "arch/machine" );
+
+ for ( int i = 0; i < machineNodes.getLength(); i++ ) {
+ final LibvirtXmlNode machineNode = new LibvirtXmlNode( this.getXmlDocument(), machineNodes.item( i ) );
+ final Machine machine = Machine.newInstance( machineNode );
+
+ if ( machine != null ) {
+ machinesList.add( machine );
+ }
+ }
+
+ return machinesList;
+ }
+
+ /**
+ * Returns the supported domains of the guest.
+ *
+ * @return supported domains of the guest.
+ */
+ public List<Domain> getArchDomains()
+ {
+ final List<Domain> domainList = new ArrayList<Domain>();
+ final NodeList domainNodes = this.getXmlNodes( "arch/domain" );
+
+ for ( int i = 0; i < domainNodes.getLength(); i++ ) {
+ final LibvirtXmlNode domainNode = new LibvirtXmlNode( this.getXmlDocument(), domainNodes.item( i ) );
+ final Domain domain = Domain.newInstance( domainNode );
+
+ if ( domain != null ) {
+ domainList.add( domain );
+ }
+ }
+
+ return domainList;
+ }
+
+ /**
+ * Creates a guest representing an existing Libvirt XML guest capabilities element.
+ *
+ * @param xmlNode existing Libvirt XML guest capabilities element.
+ * @return guest capabilities instance.
+ */
+ public static Guest newInstance( LibvirtXmlNode xmlNode )
+ {
+ return new Guest( xmlNode );
+ }
+}
diff --git a/src/main/java/org/openslx/libvirt/capabilities/guest/Machine.java b/src/main/java/org/openslx/libvirt/capabilities/guest/Machine.java
new file mode 100644
index 0000000..dfe6362
--- /dev/null
+++ b/src/main/java/org/openslx/libvirt/capabilities/guest/Machine.java
@@ -0,0 +1,72 @@
+package org.openslx.libvirt.capabilities.guest;
+
+import org.openslx.libvirt.xml.LibvirtXmlNode;
+
+/**
+ * Implementation of a guest machine as part of the Libvirt XML capabilities document.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+public class Machine extends LibvirtXmlNode
+{
+ /**
+ * Creates an empty guest machine instance.
+ */
+ public Machine()
+ {
+ super();
+ }
+
+ /**
+ * Creates an guest machine representing an existing Libvirt XML guest machine element.
+ *
+ * @param xmlNode existing Libvirt XML guest machine element.
+ */
+ public Machine( LibvirtXmlNode xmlNode )
+ {
+ super( xmlNode );
+ }
+
+ /**
+ * Returns the canonical machine name.
+ *
+ * @return canonical machine name.
+ */
+ public String getCanonicalMachine()
+ {
+ return this.getXmlElementAttributeValue( "canonical" );
+ }
+
+ /**
+ * Returns the maximum number of CPUs supported by the guest machine.
+ *
+ * @return maximum number of CPUs supported by the guest machine.
+ */
+ public int getMaxCpus()
+ {
+ final String numMaxCpus = this.getXmlElementAttributeValue( "maxCpus" );
+ return Integer.parseUnsignedInt( numMaxCpus );
+ }
+
+ /**
+ * Returns the name of the guest machine.
+ *
+ * @return name of the guest machine.
+ */
+ public String getName()
+ {
+ return this.getXmlElementValue( null );
+ }
+
+ /**
+ * Creates an guest machine representing an existing Libvirt XML guest machine element.
+ *
+ * @param xmlNode existing Libvirt XML guest machine element.
+ * @return guest machine instance.
+ */
+ public static Machine newInstance( LibvirtXmlNode xmlNode )
+ {
+ return new Machine( xmlNode );
+ }
+}
diff --git a/src/main/java/org/openslx/libvirt/domain/Domain.java b/src/main/java/org/openslx/libvirt/domain/Domain.java
index 4e15ec1..50d0811 100644
--- a/src/main/java/org/openslx/libvirt/domain/Domain.java
+++ b/src/main/java/org/openslx/libvirt/domain/Domain.java
@@ -20,6 +20,7 @@ import org.openslx.libvirt.domain.device.Disk;
import org.openslx.libvirt.domain.device.DiskCdrom;
import org.openslx.libvirt.domain.device.DiskFloppy;
import org.openslx.libvirt.domain.device.DiskStorage;
+import org.openslx.libvirt.domain.device.FileSystem;
import org.openslx.libvirt.domain.device.Graphics;
import org.openslx.libvirt.domain.device.GraphicsSdl;
import org.openslx.libvirt.domain.device.GraphicsSpice;
@@ -28,6 +29,8 @@ import org.openslx.libvirt.domain.device.Hostdev;
import org.openslx.libvirt.domain.device.Interface;
import org.openslx.libvirt.domain.device.InterfaceBridge;
import org.openslx.libvirt.domain.device.InterfaceNetwork;
+import org.openslx.libvirt.domain.device.Parallel;
+import org.openslx.libvirt.domain.device.Serial;
import org.openslx.libvirt.domain.device.Sound;
import org.openslx.libvirt.domain.device.Video;
import org.openslx.libvirt.xml.LibvirtXmlDocument;
@@ -258,6 +261,17 @@ public class Domain extends LibvirtXmlDocument
}
/**
+ * Returns the libosinfo operating system identifier.
+ *
+ * @return libosinfo operating system identifier.
+ */
+ public String getLibOsInfoOsId()
+ {
+ return this.getRootXmlNode()
+ .getXmlElementAttributeValue( "metadata/*[local-name()='libosinfo']/*[local-name()='os']", "id" );
+ }
+
+ /**
* Returns virtual machine UUID defined in the Libvirt domain XML document.
*
* @return UUID of virtual machine.
@@ -353,6 +367,122 @@ public class Domain extends LibvirtXmlDocument
}
/**
+ * Returns OS type defined in the Libvirt domain XML document.
+ *
+ * @return OS type of the virtual machine.
+ */
+ public OsType getOsType()
+ {
+ final String osType = this.getRootXmlNode().getXmlElementValue( "os/type" );
+ return OsType.fromString( osType );
+ }
+
+ /**
+ * Set OS type in the Libvirt domain XML document.
+ *
+ * @param type OS type for the virtual machine.
+ */
+ public void setOsType( OsType type )
+ {
+ this.getRootXmlNode().setXmlElementValue( "os/type", type.toString() );
+ }
+
+ /**
+ * Returns OS architecture defined in the Libvirt domain XML document.
+ *
+ * @return OS architecture of the virtual machine.
+ */
+ public String getOsArch()
+ {
+ return this.getRootXmlNode().getXmlElementAttributeValue( "os/type", "arch" );
+ }
+
+ /**
+ * Set OS architecture in the Libvirt domain XML document.
+ *
+ * @param arch OS architecture for the virtual machine.
+ */
+ public void setOsArch( String arch )
+ {
+ this.getRootXmlNode().setXmlElementAttributeValue( "os/type", "arch", arch );
+ }
+
+ /**
+ * Returns OS machine defined in the Libvirt domain XML document.
+ *
+ * @return OS machine of the virtual machine.
+ */
+ public String getOsMachine()
+ {
+ return this.getRootXmlNode().getXmlElementAttributeValue( "os/type", "machine" );
+ }
+
+ /**
+ * Set OS machine in the Libvirt domain XML document.
+ *
+ * @param machine OS machine for the virtual machine.
+ */
+ public void setOsMachine( String machine )
+ {
+ this.getRootXmlNode().setXmlElementAttributeValue( "os/type", "machine", machine );
+ }
+
+ /**
+ * Operating system types specifiable for a virtual machine in the Libvirt domain XML document.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+ public enum OsType
+ {
+ // @formatter:off
+ XEN ( "xen" ),
+ LINUX( "linux" ),
+ HVM ( "hvm" ),
+ EXE ( "exe" ),
+ UML ( "uml" );
+ // @formatter:on
+
+ /**
+ * Name of the OS type in a Libvirt domain XML document.
+ */
+ private final String osType;
+
+ /**
+ * Creates an OS type.
+ *
+ * @param osType valid name of the OS type in the Libvirt domain XML document.
+ */
+ OsType( String osType )
+ {
+ this.osType = osType;
+ }
+
+ @Override
+ public String toString()
+ {
+ return this.osType;
+ }
+
+ /**
+ * Creates an OS type from its name with error check.
+ *
+ * @param osType name of the OS type in the Libvirt domain XML document.
+ * @return valid OS type.
+ */
+ public static OsType fromString( String osType )
+ {
+ for ( OsType t : OsType.values() ) {
+ if ( t.osType.equalsIgnoreCase( osType ) ) {
+ return t;
+ }
+ }
+
+ return null;
+ }
+ }
+
+ /**
* Returns virtual machine CPU model defined in the Libvirt domain XML document.
*
* @return CPU model of virtual machine.
@@ -484,7 +614,7 @@ public class Domain extends LibvirtXmlDocument
/**
* Creates a CPU check from its name with error check.
*
- * @param mode name of the CPU check in the Libvirt domain XML document.
+ * @param check name of the CPU check in the Libvirt domain XML document.
* @return valid CPU check.
*/
public static CpuCheck fromString( String check )
@@ -521,6 +651,26 @@ public class Domain extends LibvirtXmlDocument
}
/**
+ * Returns the file name of the emulator binary defined in the Libvirt domain XML document.
+ *
+ * @return file name of the emulator binary.
+ */
+ public String getDevicesEmulator()
+ {
+ return this.getRootXmlNode().getXmlElementValue( "devices/emulator" );
+ }
+
+ /**
+ * Sets the file name of the emulator binary in the Libvirt domain XML document.
+ *
+ * @param emulator file name of the emulator binary.
+ */
+ public void setDevicesEmulator( String emulator )
+ {
+ this.getRootXmlNode().setXmlElementValue( "devices/emulator", emulator );
+ }
+
+ /**
* Returns virtual machine devices defined in the Libvirt domain XML document.
*
* @return devices of the virtual machine.
@@ -535,12 +685,14 @@ public class Domain extends LibvirtXmlDocument
NodeList devicesElements = devicesNode.getChildNodes();
for ( int i = 0; i < devicesElements.getLength(); i++ ) {
- LibvirtXmlNode deviceNode = null;
- deviceNode = new LibvirtXmlNode( this.getRootXmlNode().getXmlDocument(), devicesElements.item( i ) );
- Device device = Device.newInstance( deviceNode );
-
- if ( device != null ) {
- devices.add( device );
+ final Node childNode = devicesElements.item( i );
+ if ( childNode.getNodeType() == Node.ELEMENT_NODE ) {
+ LibvirtXmlNode deviceNode = new LibvirtXmlNode( this.getRootXmlNode().getXmlDocument(), childNode );
+ Device device = Device.newInstance( deviceNode );
+
+ if ( device != null ) {
+ devices.add( device );
+ }
}
}
}
@@ -687,6 +839,17 @@ public class Domain extends LibvirtXmlDocument
}
/**
+ * Returns list of virtual machine file system devices specified in the Libvirt domain XML
+ * document.
+ *
+ * @return list of virtual machine file system devices.
+ */
+ public ArrayList<FileSystem> getFileSystemDevices()
+ {
+ return Domain.filterDevices( FileSystem.class, this.getDevices() );
+ }
+
+ /**
* Returns list of virtual machine hostdev devices specified in the Libvirt domain XML document.
*
* @return list of virtual machine hostdev devices.
@@ -718,6 +881,28 @@ public class Domain extends LibvirtXmlDocument
}
/**
+ * Returns list of virtual machine parallel port devices specified in the Libvirt domain XML
+ * document.
+ *
+ * @return list of virtual machine parallel port devices.
+ */
+ public ArrayList<Parallel> getParallelDevices()
+ {
+ return Domain.filterDevices( Parallel.class, this.getDevices() );
+ }
+
+ /**
+ * Returns list of virtual machine serial port devices specified in the Libvirt domain XML
+ * document.
+ *
+ * @return list of virtual machine serial port devices.
+ */
+ public ArrayList<Serial> getSerialDevices()
+ {
+ return Domain.filterDevices( Serial.class, this.getDevices() );
+ }
+
+ /**
* Returns list of virtual machine sound devices specified in the Libvirt domain XML document.
*
* @return list of virtual machine sound devices.
@@ -871,6 +1056,16 @@ public class Domain extends LibvirtXmlDocument
}
/**
+ * Adds a virtual machine file system device to the Libvirt domain XML document.
+ *
+ * @return reference to the added file system device if creation was successful.
+ */
+ public FileSystem addFileSystemDevice()
+ {
+ return FileSystem.class.cast( this.addDevice( new FileSystem() ) );
+ }
+
+ /**
* Adds a virtual machine disk device to the Libvirt domain XML document.
*
* @return reference to the added disk device if creation was successful.
@@ -951,6 +1146,26 @@ public class Domain extends LibvirtXmlDocument
}
/**
+ * Adds a virtual machine parallel port device to the Libvirt domain XML document.
+ *
+ * @return reference to the added parallel port device if creation was successful.
+ */
+ public Parallel addParallelDevice()
+ {
+ return Parallel.class.cast( this.addDevice( new Parallel() ) );
+ }
+
+ /**
+ * Adds a virtual machine serial port device to the Libvirt domain XML document.
+ *
+ * @return reference to the added serial port device if creation was successful.
+ */
+ public Serial addSerialDevice()
+ {
+ return Serial.class.cast( this.addDevice( new Serial() ) );
+ }
+
+ /**
* Adds a virtual machine sound device to the Libvirt domain XML document.
*
* @return reference to the added sound device if creation was successful.
@@ -1012,7 +1227,8 @@ public class Domain extends LibvirtXmlDocument
public void removeInterfaceDevicesSource()
{
for ( Interface interfaceDevice : this.getInterfaceDevices() ) {
- interfaceDevice.removeSource();
+ // set empty source to preserve the XML attribute (to prevent XML validation errors)
+ interfaceDevice.setSource( "" );
}
}
}
diff --git a/src/main/java/org/openslx/libvirt/domain/device/ControllerUsb.java b/src/main/java/org/openslx/libvirt/domain/device/ControllerUsb.java
index 695167c..1798027 100644
--- a/src/main/java/org/openslx/libvirt/domain/device/ControllerUsb.java
+++ b/src/main/java/org/openslx/libvirt/domain/device/ControllerUsb.java
@@ -122,7 +122,7 @@ public class ControllerUsb extends Controller
/**
* Creates USB controller device model from its name with error check.
*
- * @param type name of the USB controller device model in a Libvirt domain XML document.
+ * @param model name of the USB controller device model in a Libvirt domain XML document.
* @return valid USB controller device model.
*/
public static Model fromString( String model )
diff --git a/src/main/java/org/openslx/libvirt/domain/device/Device.java b/src/main/java/org/openslx/libvirt/domain/device/Device.java
index 5c26c55..151592a 100644
--- a/src/main/java/org/openslx/libvirt/domain/device/Device.java
+++ b/src/main/java/org/openslx/libvirt/domain/device/Device.java
@@ -77,6 +77,9 @@ public class Device extends LibvirtXmlNode
} else if ( device instanceof Disk ) {
LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.DISK );
createdDevice = Disk.createInstance( Disk.class.cast( device ), xmlNode );
+ } else if ( device instanceof FileSystem ) {
+ LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.FILESYSTEM );
+ createdDevice = FileSystem.createInstance( FileSystem.class.cast( device ), xmlNode );
} else if ( device instanceof Hostdev ) {
LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.HOSTDEV );
createdDevice = Hostdev.createInstance( Hostdev.class.cast( device ), xmlNode );
@@ -86,6 +89,12 @@ public class Device extends LibvirtXmlNode
} else if ( device instanceof Graphics ) {
LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.GRAPHICS );
createdDevice = Graphics.createInstance( Graphics.class.cast( device ), xmlNode );
+ } else if ( device instanceof Parallel ) {
+ LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.PARALLEL );
+ createdDevice = Parallel.createInstance( xmlNode );
+ } else if ( device instanceof Serial ) {
+ LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.SERIAL );
+ createdDevice = Serial.createInstance( xmlNode );
} else if ( device instanceof Sound ) {
LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.SOUND );
createdDevice = Sound.createInstance( xmlNode );
@@ -125,6 +134,9 @@ public class Device extends LibvirtXmlNode
case DISK:
device = Disk.newInstance( xmlNode );
break;
+ case FILESYSTEM:
+ device = FileSystem.newInstance( xmlNode );
+ break;
case HOSTDEV:
device = Hostdev.newInstance( xmlNode );
break;
@@ -134,6 +146,12 @@ public class Device extends LibvirtXmlNode
case GRAPHICS:
device = Graphics.newInstance( xmlNode );
break;
+ case PARALLEL:
+ device = Parallel.newInstance( xmlNode );
+ break;
+ case SERIAL:
+ device = Serial.newInstance( xmlNode );
+ break;
case SOUND:
device = Sound.newInstance( xmlNode );
break;
@@ -157,9 +175,12 @@ public class Device extends LibvirtXmlNode
// @formatter:off
CONTROLLER( "controller" ),
DISK ( "disk" ),
+ FILESYSTEM( "filesystem" ),
HOSTDEV ( "hostdev" ),
INTERFACE ( "interface" ),
GRAPHICS ( "graphics" ),
+ PARALLEL ( "parallel" ),
+ SERIAL ( "serial" ),
SOUND ( "sound" ),
VIDEO ( "video" );
// @formatter:on
diff --git a/src/main/java/org/openslx/libvirt/domain/device/Disk.java b/src/main/java/org/openslx/libvirt/domain/device/Disk.java
index 464e7b6..7694538 100644
--- a/src/main/java/org/openslx/libvirt/domain/device/Disk.java
+++ b/src/main/java/org/openslx/libvirt/domain/device/Disk.java
@@ -68,7 +68,7 @@ public class Disk extends Device
storageSource = this.getXmlElementAttributeValue( "source", "file" );
break;
case BLOCK:
- storageSource = this.getXmlElementAttributeValue( "source", "bdev" );
+ storageSource = this.getXmlElementAttributeValue( "source", "dev" );
break;
}
@@ -96,7 +96,7 @@ public class Disk extends Device
this.setXmlElementAttributeValue( "source", "file", source );
break;
case BLOCK:
- this.setXmlElementAttributeValue( "source", "bdev", source );
+ this.setXmlElementAttributeValue( "source", "dev", source );
break;
}
}
@@ -195,7 +195,7 @@ public class Disk extends Device
/**
* Sets target device for the disk device.
*
- * @param target device for the disk device.
+ * @param targetDevice target device for the disk device.
*/
public void setTargetDevice( String targetDevice )
{
diff --git a/src/main/java/org/openslx/libvirt/domain/device/FileSystem.java b/src/main/java/org/openslx/libvirt/domain/device/FileSystem.java
new file mode 100644
index 0000000..9ec8caf
--- /dev/null
+++ b/src/main/java/org/openslx/libvirt/domain/device/FileSystem.java
@@ -0,0 +1,292 @@
+package org.openslx.libvirt.domain.device;
+
+import org.openslx.libvirt.xml.LibvirtXmlNode;
+
+/**
+ * A file system device node in a Libvirt domain XML document.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+public class FileSystem extends Device
+{
+ /**
+ * Creates an empty file system device.
+ */
+ public FileSystem()
+ {
+ super();
+ }
+
+ /**
+ * Creates a file system device representing an existing Libvirt XML file system device element.
+ *
+ * @param xmlNode existing Libvirt XML file system device element.
+ */
+ public FileSystem( LibvirtXmlNode xmlNode )
+ {
+ super( xmlNode );
+ }
+
+ /**
+ * Returns access mode of the file system device.
+ *
+ * @return access mode of the file system device.
+ */
+ public AccessMode getAccessMode()
+ {
+ final String mode = this.getXmlElementAttributeValue( "accessmode" );
+ return AccessMode.fromString( mode );
+ }
+
+ /**
+ * Sets access mode for the file system device.
+ *
+ * @param mode access mode for the file system device.
+ */
+ public void setAccessMode( AccessMode mode )
+ {
+ this.setXmlElementAttributeValue( "accessmode", mode.toString() );
+ }
+
+ /**
+ * Returns type of the file system device.
+ *
+ * @return type of the file system device.
+ */
+ public Type getType()
+ {
+ final String type = this.getXmlElementAttributeValue( "type" );
+ return Type.fromString( type );
+ }
+
+ /**
+ * Sets type for the file system device.
+ *
+ * @param type type for the file system device.
+ */
+ public void setType( Type type )
+ {
+ this.setXmlElementAttributeValue( "type", type.toString() );
+ }
+
+ /**
+ * Returns source of the file system device.
+ *
+ * @return source of the file system device.
+ */
+ public String getSource()
+ {
+ final Type type = this.getType();
+ String source = null;
+
+ switch ( type ) {
+ case BIND:
+ source = this.getXmlElementAttributeValue( "source", "dir" );
+ break;
+ case BLOCK:
+ source = this.getXmlElementAttributeValue( "source", "dev" );
+ break;
+ case FILE:
+ source = this.getXmlElementAttributeValue( "source", "file" );
+ break;
+ case MOUNT:
+ source = this.getXmlElementAttributeValue( "source", "dir" );
+ break;
+ case RAM:
+ source = this.getXmlElementAttributeValue( "source", "usage" );
+ break;
+ case TEMPLATE:
+ source = this.getXmlElementAttributeValue( "source", "name" );
+ break;
+ }
+
+ return source;
+ }
+
+ /**
+ * Sets source for the file system device.
+ *
+ * @param source source for the file system device.
+ */
+ public void setSource( String source )
+ {
+ Type type = this.getType();
+
+ // remove all attributes from sub-element 'source'
+ this.removeXmlElementAttributes( "source" );
+
+ switch ( type ) {
+ case BIND:
+ this.setXmlElementAttributeValue( "source", "dir", source );
+ break;
+ case BLOCK:
+ this.setXmlElementAttributeValue( "source", "dev", source );
+ break;
+ case FILE:
+ this.setXmlElementAttributeValue( "source", "file", source );
+ break;
+ case MOUNT:
+ this.setXmlElementAttributeValue( "source", "dir", source );
+ break;
+ case RAM:
+ this.setXmlElementAttributeValue( "source", "usage", source );
+ break;
+ case TEMPLATE:
+ this.setXmlElementAttributeValue( "source", "name", source );
+ break;
+ }
+ }
+
+ /**
+ * Returns target of the file system device.
+ *
+ * @return target of the file system device.
+ */
+ public String getTarget()
+ {
+ return this.getXmlElementAttributeValue( "target", "dir" );
+ }
+
+ /**
+ * Sets target for the file system device.
+ *
+ * @param target target for the file system device.
+ */
+ public void setTarget( String target )
+ {
+ this.setXmlElementAttributeValue( "target", "dir", target );
+ }
+
+ /**
+ * Creates a non-existent file system device as Libvirt XML device element.
+ *
+ * @param xmlNode Libvirt XML node of the Libvirt XML device that is created.
+ * @return created file system device instance.
+ */
+ public static FileSystem createInstance( LibvirtXmlNode xmlNode )
+ {
+ return FileSystem.newInstance( xmlNode );
+ }
+
+ /**
+ * Creates a file system device representing an existing Libvirt XML file system device element.
+ *
+ * @param xmlNode existing Libvirt XML file system device element.
+ * @return file system device instance.
+ */
+ public static FileSystem newInstance( LibvirtXmlNode xmlNode )
+ {
+ return new FileSystem( xmlNode );
+ }
+
+ /**
+ * Access mode for the file system device.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+ public enum AccessMode
+ {
+ // @formatter:off
+ PASSTHROUGH( "passthrough" ),
+ MAPPED ( "mapped" ),
+ SQUASH ( "squash" );
+ // @formatter:on
+
+ /**
+ * Name of the file system device access mode.
+ */
+ private String mode;
+
+ /**
+ * Creates file system device access mode.
+ *
+ * @param mode valid name of the file system device access mode in a Libvirt domain XML
+ * document.
+ */
+ AccessMode( String mode )
+ {
+ this.mode = mode;
+ }
+
+ @Override
+ public String toString()
+ {
+ return this.mode;
+ }
+
+ /**
+ * Creates file system device access mode from its name with error check.
+ *
+ * @param mode name of the file system device access mode in a Libvirt domain XML document.
+ * @return valid file system device access mode.
+ */
+ public static AccessMode fromString( String mode )
+ {
+ for ( AccessMode a : AccessMode.values() ) {
+ if ( a.mode.equalsIgnoreCase( mode ) ) {
+ return a;
+ }
+ }
+
+ return null;
+ }
+ }
+
+ /**
+ * Type of file system device.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+ public enum Type
+ {
+ // @formatter:off
+ MOUNT ( "mount" ),
+ TEMPLATE( "template" ),
+ FILE ( "file" ),
+ BLOCK ( "block" ),
+ RAM ( "ram" ),
+ BIND ( "bind" );
+ // @formatter:on
+
+ /**
+ * Name of the file system device type.
+ */
+ private String type;
+
+ /**
+ * Creates file system device type.
+ *
+ * @param type valid name of the file system device type in a Libvirt domain XML document.
+ */
+ Type( String type )
+ {
+ this.type = type;
+ }
+
+ @Override
+ public String toString()
+ {
+ return this.type;
+ }
+
+ /**
+ * Creates file system device type from its name with error check.
+ *
+ * @param type name of the file system device type in a Libvirt domain XML document.
+ * @return valid file system device type.
+ */
+ public static Type fromString( String type )
+ {
+ for ( Type t : Type.values() ) {
+ if ( t.type.equalsIgnoreCase( type ) ) {
+ return t;
+ }
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/src/main/java/org/openslx/libvirt/domain/device/HostdevPci.java b/src/main/java/org/openslx/libvirt/domain/device/HostdevPci.java
index 3b26fb0..a0563f2 100644
--- a/src/main/java/org/openslx/libvirt/domain/device/HostdevPci.java
+++ b/src/main/java/org/openslx/libvirt/domain/device/HostdevPci.java
@@ -48,7 +48,7 @@ public class HostdevPci extends Hostdev
* detached from the host before being passed on to the guest and reattached to the host after
* the guest exits.
*
- * @return state whether PCI hostdev device is managed.
+ * @param managed state whether PCI hostdev device is managed or not.
*/
public void setManaged( boolean managed )
{
diff --git a/src/main/java/org/openslx/libvirt/domain/device/Interface.java b/src/main/java/org/openslx/libvirt/domain/device/Interface.java
index b09c7da..44b8e4c 100644
--- a/src/main/java/org/openslx/libvirt/domain/device/Interface.java
+++ b/src/main/java/org/openslx/libvirt/domain/device/Interface.java
@@ -59,16 +59,16 @@ public class Interface extends Device
{
return Type.fromString( this.getXmlElementAttributeValue( "type" ) );
}
-
+
/**
* Sets type of the network device.
- *
- * @return type of the network device.
+ *
+ * @param type network device type.
*/
- public void setType(Type type)
+ public void setType( Type type )
{
String source = this.getSource();
-
+
// change type and set source again
this.setXmlElementAttributeValue( "type", type.toString() );
this.setSource( source );
@@ -119,6 +119,26 @@ public class Interface extends Device
}
/**
+ * Returns MAC address of the network device.
+ *
+ * @return MAC address of the network device.
+ */
+ public String getMacAddress()
+ {
+ return this.getXmlElementAttributeValue( "mac", "address" );
+ }
+
+ /**
+ * Sets MAC address of the network device.
+ *
+ * @param macAddress MAC address for the network device.
+ */
+ public void setMacAddress( String macAddress )
+ {
+ this.setXmlElementAttributeValue( "mac", "address", macAddress );
+ }
+
+ /**
* Removes boot oder entry of the network interface device.
*/
public void removeBootOrder()
@@ -135,6 +155,14 @@ public class Interface extends Device
}
/**
+ * Removes MAC address of the network interface device.
+ */
+ public void removeMacAddress()
+ {
+ this.removeXmlElement( "mac" );
+ }
+
+ /**
* Creates a non-existent network interface device as Libvirt XML device element.
*
* @param iface network device that is created.
@@ -299,7 +327,7 @@ public class Interface extends Device
/**
* Creates network interface device model from its name with error check.
*
- * @param type name of the network interface device model in a Libvirt domain XML document.
+ * @param model name of the network interface device model in a Libvirt domain XML document.
* @return valid network interface device model.
*/
public static Model fromString( String model )
diff --git a/src/main/java/org/openslx/libvirt/domain/device/Parallel.java b/src/main/java/org/openslx/libvirt/domain/device/Parallel.java
new file mode 100644
index 0000000..7db60ca
--- /dev/null
+++ b/src/main/java/org/openslx/libvirt/domain/device/Parallel.java
@@ -0,0 +1,158 @@
+package org.openslx.libvirt.domain.device;
+
+import org.openslx.libvirt.xml.LibvirtXmlNode;
+
+/**
+ * A parallel port device node in a Libvirt domain XML document.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+public class Parallel extends Device
+{
+ /**
+ * Creates an empty parallel port device.
+ */
+ public Parallel()
+ {
+ super();
+ }
+
+ /**
+ * Creates a parallel port device representing an existing Libvirt XML parallel port device
+ * element.
+ *
+ * @param xmlNode existing Libvirt XML parallel port device element.
+ */
+ public Parallel( LibvirtXmlNode xmlNode )
+ {
+ super( xmlNode );
+ }
+
+ /**
+ * Returns the type of the parallel port device.
+ *
+ * @return type of the parallel port device.
+ */
+ public Type getType()
+ {
+ final String type = this.getXmlElementAttributeValue( "type" );
+ return Type.fromString( type );
+ }
+
+ /**
+ * Sets the type for the parallel port device.
+ *
+ * @param type type for the parallel port device.
+ */
+ public void setType( Type type )
+ {
+ this.setXmlElementAttributeValue( "type", type.toString() );
+ }
+
+ /**
+ * Returns the source of the parallel port device.
+ *
+ * @return source of the parallel port device.
+ */
+ public String getSource()
+ {
+ return this.getXmlElementAttributeValue( "source", "path" );
+ }
+
+ /**
+ * Sets the source for the parallel port device.
+ *
+ * @param source source for the parallel port device.
+ */
+ public void setSource( String source )
+ {
+ this.setXmlElementAttributeValue( "source", "path", source );
+ }
+
+ /**
+ * Creates a non-existent parallel port device as Libvirt XML parallel port device element.
+ *
+ * @param xmlNode Libvirt XML node of the Libvirt XML parallel port device that is created.
+ * @return created parallel port device instance.
+ */
+ public static Parallel createInstance( LibvirtXmlNode xmlNode )
+ {
+ return Parallel.newInstance( xmlNode );
+ }
+
+ /**
+ * Creates a parallel port device representing an existing Libvirt XML parallel port device
+ * element.
+ *
+ * @param xmlNode existing Libvirt XML parallel port device element.
+ * @return parallel port device instance.
+ */
+ public static Parallel newInstance( LibvirtXmlNode xmlNode )
+ {
+ return new Parallel( xmlNode );
+ }
+
+ /**
+ * Type of parallel port device.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+ public enum Type
+ {
+ // @formatter:off
+ DEV ( "dev" ),
+ FILE ( "file" ),
+ PIPE ( "pipe" ),
+ UNIX ( "unix" ),
+ TCP ( "tcp" ),
+ UDP ( "udp" ),
+ NULL ( "null" ),
+ STDIO ( "stdio" ),
+ VC ( "vc" ),
+ PTY ( "pty" ),
+ SPICEVMC ( "spicevmc" ),
+ SPICEPORT( "spiceport" ),
+ NMDM ( "nmdm" );
+ // @formatter:on
+
+ /**
+ * Name of the parallel port device type.
+ */
+ private String type;
+
+ /**
+ * Creates parallel port device type.
+ *
+ * @param type valid name of the parallel port device type in a Libvirt domain XML document.
+ */
+ Type( String type )
+ {
+ this.type = type;
+ }
+
+ @Override
+ public String toString()
+ {
+ return this.type;
+ }
+
+ /**
+ * Creates parallel port device type from its name with error check.
+ *
+ * @param type name of the parallel port device type in a Libvirt domain XML document.
+ * @return valid parallel port device type.
+ */
+ public static Type fromString( String type )
+ {
+ for ( Type t : Type.values() ) {
+ if ( t.type.equalsIgnoreCase( type ) ) {
+ return t;
+ }
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/src/main/java/org/openslx/libvirt/domain/device/Serial.java b/src/main/java/org/openslx/libvirt/domain/device/Serial.java
new file mode 100644
index 0000000..54be26e
--- /dev/null
+++ b/src/main/java/org/openslx/libvirt/domain/device/Serial.java
@@ -0,0 +1,156 @@
+package org.openslx.libvirt.domain.device;
+
+import org.openslx.libvirt.xml.LibvirtXmlNode;
+
+/**
+ * A serial port device node in a Libvirt domain XML document.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+public class Serial extends Device
+{
+ /**
+ * Creates an empty serial port device.
+ */
+ public Serial()
+ {
+ super();
+ }
+
+ /**
+ * Creates a serial port device representing an existing Libvirt XML serial port device element.
+ *
+ * @param xmlNode existing Libvirt XML serial port device element.
+ */
+ public Serial( LibvirtXmlNode xmlNode )
+ {
+ super( xmlNode );
+ }
+
+ /**
+ * Returns the type of the serial port device.
+ *
+ * @return type of the serial port device.
+ */
+ public Type getType()
+ {
+ final String type = this.getXmlElementAttributeValue( "type" );
+ return Type.fromString( type );
+ }
+
+ /**
+ * Sets the type for the serial port device.
+ *
+ * @param type type for the serial port device.
+ */
+ public void setType( Type type )
+ {
+ this.setXmlElementAttributeValue( "type", type.toString() );
+ }
+
+ /**
+ * Returns the source of the serial port device.
+ *
+ * @return source of the serial port device.
+ */
+ public String getSource()
+ {
+ return this.getXmlElementAttributeValue( "source", "path" );
+ }
+
+ /**
+ * Sets the source for the serial port device.
+ *
+ * @param source source for the serial port device.
+ */
+ public void setSource( String source )
+ {
+ this.setXmlElementAttributeValue( "source", "path", source );
+ }
+
+ /**
+ * Creates a non-existent serial port device as Libvirt XML serial port device element.
+ *
+ * @param xmlNode Libvirt XML node of the Libvirt XML serial port device that is created.
+ * @return created serial port device instance.
+ */
+ public static Serial createInstance( LibvirtXmlNode xmlNode )
+ {
+ return Serial.newInstance( xmlNode );
+ }
+
+ /**
+ * Creates a serial port device representing an existing Libvirt XML serial port device element.
+ *
+ * @param xmlNode existing Libvirt XML serial port device element.
+ * @return serial port device instance.
+ */
+ public static Serial newInstance( LibvirtXmlNode xmlNode )
+ {
+ return new Serial( xmlNode );
+ }
+
+ /**
+ * Type of serial port device.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+ public enum Type
+ {
+ // @formatter:off
+ DEV ( "dev" ),
+ FILE ( "file" ),
+ PIPE ( "pipe" ),
+ UNIX ( "unix" ),
+ TCP ( "tcp" ),
+ UDP ( "udp" ),
+ NULL ( "null" ),
+ STDIO ( "stdio" ),
+ VC ( "vc" ),
+ PTY ( "pty" ),
+ SPICEVMC ( "spicevmc" ),
+ SPICEPORT( "spiceport" ),
+ NMDM ( "nmdm" );
+ // @formatter:on
+
+ /**
+ * Name of the serial port device type.
+ */
+ private String type;
+
+ /**
+ * Creates serial port device type.
+ *
+ * @param type valid name of the serial port device type in a Libvirt domain XML document.
+ */
+ Type( String type )
+ {
+ this.type = type;
+ }
+
+ @Override
+ public String toString()
+ {
+ return this.type;
+ }
+
+ /**
+ * Creates serial port device type from its name with error check.
+ *
+ * @param type name of the serial port device type in a Libvirt domain XML document.
+ * @return valid serial port device type.
+ */
+ public static Type fromString( String type )
+ {
+ for ( Type t : Type.values() ) {
+ if ( t.type.equalsIgnoreCase( type ) ) {
+ return t;
+ }
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/src/main/java/org/openslx/libvirt/domain/device/Sound.java b/src/main/java/org/openslx/libvirt/domain/device/Sound.java
index e424ed4..dfeeffd 100644
--- a/src/main/java/org/openslx/libvirt/domain/device/Sound.java
+++ b/src/main/java/org/openslx/libvirt/domain/device/Sound.java
@@ -111,7 +111,7 @@ public class Sound extends Device
/**
* Creates sound device model from its name with error check.
*
- * @param type name of the sound device model in a Libvirt domain XML document.
+ * @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 )
diff --git a/src/main/java/org/openslx/libvirt/domain/device/Video.java b/src/main/java/org/openslx/libvirt/domain/device/Video.java
index e901b85..0f8861f 100644
--- a/src/main/java/org/openslx/libvirt/domain/device/Video.java
+++ b/src/main/java/org/openslx/libvirt/domain/device/Video.java
@@ -171,7 +171,7 @@ public class Video extends Device
/**
* Creates video device model from its name with error check.
*
- * @param type name of the video device model in a Libvirt domain XML document.
+ * @param model name of the video device model in a Libvirt domain XML document.
* @return valid video device model.
*/
public static Model fromString( String model )
diff --git a/src/main/java/org/openslx/libvirt/libosinfo/LibOsInfo.java b/src/main/java/org/openslx/libvirt/libosinfo/LibOsInfo.java
new file mode 100644
index 0000000..f506d74
--- /dev/null
+++ b/src/main/java/org/openslx/libvirt/libosinfo/LibOsInfo.java
@@ -0,0 +1,158 @@
+package org.openslx.libvirt.libosinfo;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.function.Predicate;
+
+import org.openslx.libvirt.libosinfo.os.Os;
+import org.openslx.libvirt.xml.LibvirtXmlDocument;
+import org.openslx.libvirt.xml.LibvirtXmlDocumentException;
+import org.openslx.libvirt.xml.LibvirtXmlNode;
+import org.openslx.libvirt.xml.LibvirtXmlResources;
+import org.openslx.libvirt.xml.LibvirtXmlSerializationException;
+import org.openslx.libvirt.xml.LibvirtXmlValidationException;
+import org.openslx.virtualization.Version;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+/**
+ * Implementation of a libosinfo XML document.
+ *
+ * The libosinfo XML document is used to describe existing operating systems, devices and their
+ * configuration possibilities.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+public class LibOsInfo extends LibvirtXmlDocument
+{
+ /**
+ * Creates a libosinfo XML document from a {@link String} providing libosinfo XML content.
+ *
+ * @param xml {@link String} with libosinfo XML content.
+ *
+ * @throws LibvirtXmlDocumentException creation of XML context failed.
+ * @throws LibvirtXmlSerializationException serialization of the libosinfo XML content failed.
+ * @throws LibvirtXmlValidationException XML content is not a valid libosinfo XML document.
+ */
+ public LibOsInfo( String xml )
+ throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException
+ {
+ super( xml, LibvirtXmlResources.getLibOsInfoRng( "osinfo.rng" ) );
+ }
+
+ /**
+ * Creates a libosinfo XML document from a {@link File} containing libosinfo XML content.
+ *
+ * @param xml existing {@link File} containing libosinfo XML content.
+ *
+ * @throws LibvirtXmlDocumentException creation of XML context failed.
+ * @throws LibvirtXmlSerializationException serialization of the libosinfo XML content failed.
+ * @throws LibvirtXmlValidationException XML content is not a valid libosinfo XML document.
+ */
+ public LibOsInfo( File xml )
+ throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException
+ {
+ super( xml, LibvirtXmlResources.getLibOsInfoRng( "osinfo.rng" ) );
+ }
+
+ /**
+ * Creates a libosinfo XML document from an {@link InputStream} providing libosinfo XML content.
+ *
+ * @param xml {@link InputStream} providing libosinfo XML content.
+ *
+ * @throws LibvirtXmlDocumentException creation of XML context failed.
+ * @throws LibvirtXmlSerializationException serialization of the libosinfo XML content failed.
+ * @throws LibvirtXmlValidationException XML content is not a valid libosinfo XML document.
+ */
+ public LibOsInfo( InputStream xml )
+ throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException
+ {
+ super( xml, LibvirtXmlResources.getLibOsInfoRng( "osinfo.rng" ) );
+ }
+
+ /**
+ * Creates libosinfo XML document from {@link InputSource} providing libosinfo XML content.
+ *
+ * @param xml {@link InputSource} providing libosinfo XML content.
+ *
+ * @throws LibvirtXmlDocumentException creation of XML context failed.
+ * @throws LibvirtXmlSerializationException serialization of the libosinfo XML content failed.
+ * @throws LibvirtXmlValidationException XML content is not a valid libosinfo XML document.
+ */
+ public LibOsInfo( InputSource xml )
+ throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException
+ {
+ super( xml, LibvirtXmlResources.getLibOsInfoRng( "osinfo.rng" ) );
+ }
+
+ /**
+ * Returns the version of the libosinfo database.
+ *
+ * @return version of the libosinfo database.
+ */
+ public Version getVersion()
+ {
+ final String version = this.getRootXmlNode().getXmlElementAttributeValue( "version" );
+ return Version.valueOf( version );
+ }
+
+ /**
+ * Returns a list of all defined operating systems.
+ *
+ * @return list of all defined operating systems.
+ */
+ public ArrayList<Os> getOses()
+ {
+ final ArrayList<Os> oses = new ArrayList<Os>();
+ final NodeList osNodes = this.getRootXmlNode().getXmlNodes( "os" );
+
+ if ( osNodes != null ) {
+ for ( int i = 0; i < osNodes.getLength(); i++ ) {
+ final Node childNode = osNodes.item( i );
+ if ( childNode.getNodeType() == Node.ELEMENT_NODE ) {
+ final LibvirtXmlNode osNode = new LibvirtXmlNode( this.getRootXmlNode().getXmlDocument(), childNode );
+ final Os os = Os.newInstance( osNode );
+
+ if ( os != null ) {
+ oses.add( os );
+ }
+ }
+ }
+ }
+
+ return oses;
+ }
+
+ /**
+ * Lookups an operating system in the libosinfo database specified by the operating system
+ * identifier.
+ *
+ * @param osId identifier of the operating system to lookup in the libosinfo database.
+ * @return found operating system from the libosinfo database.
+ */
+ public static Os lookupOs( String osId )
+ {
+ Os os = null;
+
+ if ( osId != null && !osId.isEmpty() ) {
+ ArrayList<Os> oses = null;
+
+ try {
+ final LibOsInfo osInfo = new LibOsInfo( LibvirtXmlResources.getLibOsInfoXml( "osinfo.xml" ) );
+ oses = osInfo.getOses();
+ } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) {
+ oses = null;
+ }
+
+ if ( oses != null ) {
+ final Predicate<Os> byOsId = osCandidate -> osId.equals( osCandidate.getId() );
+ os = oses.stream().filter( byOsId ).findFirst().orElse( null );
+ }
+ }
+
+ return os;
+ }
+}
diff --git a/src/main/java/org/openslx/libvirt/libosinfo/os/Os.java b/src/main/java/org/openslx/libvirt/libosinfo/os/Os.java
new file mode 100644
index 0000000..37a0a2e
--- /dev/null
+++ b/src/main/java/org/openslx/libvirt/libosinfo/os/Os.java
@@ -0,0 +1,93 @@
+package org.openslx.libvirt.libosinfo.os;
+
+import org.openslx.libvirt.xml.LibvirtXmlNode;
+import org.openslx.virtualization.Version;
+
+/**
+ * A operating system node in a libosinfo XML document.
+ *
+ * @author Manuel Bentele
+ * @version 1.0
+ */
+public class Os extends LibvirtXmlNode
+{
+ /**
+ * Creates an empty operating system.
+ */
+ public Os()
+ {
+ super();
+ }
+
+ /**
+ * Creates a operating system representing an existing libosinfo XML operating system element.
+ *
+ * @param xmlNode existing libosinfo XML operating system element.
+ */
+ public Os( LibvirtXmlNode xmlNode )
+ {
+ super( xmlNode );
+ }
+
+ /**
+ * Returns the identifier of the operating system.
+ *
+ * @return identifier of the operating system.
+ */
+ public String getId()
+ {
+ return this.getXmlElementAttributeValue( "id" );
+ }
+
+ /**
+ * Returns the name of the operating system.
+ *
+ * @return name of the operating system.
+ */
+ public String getName()
+ {
+ return this.getXmlElementValue( "name" );
+ }
+
+ /**
+ * Returns the version of the operating system.
+ *
+ * @return version of the operating system.
+ */
+ public Version getVersion()
+ {
+ final String version = this.getXmlElementValue( "version" );
+ return Version.valueOf( version );
+ }
+
+ /**
+ * Returns the system family of the operating system.
+ *
+ * @return system family of the operating system.
+ */
+ public String getFamily()
+ {
+ return this.getXmlElementValue( "family" );
+ }
+
+ /**
+ * Returns the distribution name of the operating system.
+ *
+ * @return distribution name of the operating system.
+ */
+ public String getDistro()
+ {
+ return this.getXmlElementValue( "distro" );
+ }
+
+ /**
+ * Creates a operating system representing an existing libosinfo XML operating system element.
+ *
+ * @param xmlNode existing libosinfo XML operating system element.
+ * @return libosinfo XML operating system instance.
+ */
+ public static Os newInstance( LibvirtXmlNode node )
+ {
+ return new Os( node );
+ }
+}
diff --git a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlDocument.java b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlDocument.java
index 9382ced..f24ba4f 100644
--- a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlDocument.java
+++ b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlDocument.java
@@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
@@ -252,16 +253,7 @@ public abstract class LibvirtXmlDocument implements LibvirtXmlSerializable, Libv
@Override
public void fromXml( String xml ) throws LibvirtXmlSerializationException
{
- try {
- this.xmlDocument = this.domBuilder.parse( xml );
- this.xmlDocument.getDocumentElement().normalize();
- } catch ( SAXException e ) {
- e.printStackTrace();
- } catch ( IOException e ) {
- e.printStackTrace();
- }
-
- this.rootXmlNode = new LibvirtXmlNode( this.xmlDocument, this.xmlDocument.getDocumentElement() );
+ this.fromXml( new InputSource( new StringReader( xml ) ) );
}
@Override
diff --git a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlEditable.java b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlEditable.java
index 1ddddce..40d7b86 100644
--- a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlEditable.java
+++ b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlEditable.java
@@ -4,7 +4,7 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
- * Editability of XML nodes based on {@link XPath} expressions.
+ * Editability of XML nodes based on XPath expressions.
*
* @author Manuel Bentele
* @version 1.0
@@ -12,17 +12,17 @@ import org.w3c.dom.NodeList;
public interface LibvirtXmlEditable
{
/**
- * Returns XML node selected by a {@link XPath} expression
+ * Returns XML node selected by a XPath expression
*
- * @param expression {@link XPath} expression to select XML node.
+ * @param expression XPath expression to select XML node.
* @return selected XML node.
*/
public Node getXmlNode( String expression );
/**
- * Returns XML nodes selected by a {@link XPath} expression
+ * Returns XML nodes selected by a XPath expression
*
- * @param expression {@link XPath} expression to select XML nodes.
+ * @param expression XPath expression to select XML nodes.
* @return selected XML nodes.
*/
public NodeList getXmlNodes( String expression );
@@ -38,20 +38,20 @@ public interface LibvirtXmlEditable
}
/**
- * Returns XML element from selection by a {@link XPath} expression.
+ * Returns XML element from selection by a XPath expression.
*
- * @param expression {@link XPath} expression to select XML element.
+ * @param expression XPath expression to select XML element.
* @return selected XML element.
*/
public Node getXmlElement( String expression );
/**
- * Sets an XML element selected by a {@link XPath} expression.
+ * Sets an XML element selected by a XPath expression.
*
- * If the XML element selected by the given {@link XPath} expression does not exists, the XML
+ * If the XML element selected by the given XPath expression does not exists, the XML
* element will be created.
*
- * @param expression {@link XPath} expression to select XML element.
+ * @param expression XPath expression to select XML element.
*/
public default void setXmlElement( String expression )
{
@@ -59,43 +59,43 @@ public interface LibvirtXmlEditable
}
/**
- * Sets a XML element selected by a {@link XPath} expression and appends child XML node.
+ * Sets a XML element selected by a XPath expression and appends child XML node.
*
- * If the XML element selected by the given {@link XPath} expression does not exists, the XML
+ * If the XML element selected by the given XPath expression does not exists, the XML
* element will be created and the given XML child node is appended.
*
- * @param expression {@link XPath} expression to select XML element.
+ * @param expression XPath expression to select XML element.
* @param child XML node that will be appended to the selected XML element.
*/
public void setXmlElement( String expression, Node child );
/**
- * Returns the text value of a XML element selected by a {@link XPath} expression.
+ * Returns the text value of a XML element selected by a XPath expression.
*
- * @param expression {@link XPath} expression to select XML element.
+ * @param expression XPath expression to select XML element.
* @return Text value of the selected XML element.
*/
public String getXmlElementValue( String expression );
/**
- * Sets the text value of a XML element selected by a {@link XPath} expression.
+ * Sets the text value of a XML element selected by a XPath expression.
*
- * @param expression {@link XPath} expression to select XML element.
+ * @param expression XPath expression to select XML element.
* @param value text value to set selected XML element's text.
*/
public void setXmlElementValue( String expression, String value );
/**
- * Removes a XML element and all its childs selected by a {@link XPath} expression.
+ * Removes a XML element and all its childs selected by a XPath expression.
*
- * @param expression {@link XPath} expression to select XML element.
+ * @param expression XPath expression to select XML element.
*/
public void removeXmlElement( String expression );
/**
- * Removes all child elements of a XML element selected by a {@link XPath} expression.
+ * Removes all child elements of a XML element selected by a XPath expression.
*
- * @param expression {@link XPath} expression to select XML element.
+ * @param expression XPath expression to select XML element.
*/
public void removeXmlElementChilds( String expression );
@@ -128,14 +128,14 @@ public interface LibvirtXmlEditable
}
/**
- * Returns the binary choice of a XML attribute from a XML element selected by a
- * {@link XPath}expression.
+ * Returns the binary choice of a XML attribute from a XML element selected by a XPath
+ * expression.
*
* If the text value of the XML attribute equals to <i>yes</i>, the returned {@link boolean}
* value is set to <i>true</i>. Otherwise, if the text value of the XML attribute equals to
* <i>no</i>, the returned {@link boolean} value is set to <i>false</i>.
*
- * @param expression {@link XPath} expression to select XML element.
+ * @param expression XPath expression to select XML element.
* @param attributeName name to select XML attribute of the current XML root element.
* @return attribute value of the XML attribute from the current XML root element as
* {@link boolean}.
@@ -146,10 +146,9 @@ public interface LibvirtXmlEditable
}
/**
- * Returns the text value of a XML attribute from a XML element selected by a
- * {@link XPath}expression.
+ * Returns the text value of a XML attribute from a XML element selected by a XPath expression.
*
- * @param expression {@link XPath} expression to select XML element.
+ * @param expression XPath expression to select XML element.
* @param attributeName name to select XML attribute of the selected XML element.
* @return attribute text of the XML attribute from the selected XML element.
*/
@@ -185,15 +184,15 @@ public interface LibvirtXmlEditable
}
/**
- * Sets the binary choice value of a XML attribute from a XML element selected by a
- * {@link XPath} expression.
+ * Sets the binary choice value of a XML attribute from a XML element selected by a XPath
+ * expression.
*
* If the binary choice value for the XML attribute equals to <i>true</i>, the text value of the
* selected XML attribute is set to <i>yes</i>. Otherwise, if the binary choice value for the
* selected XML attribute equals to <i>false</i>, the text value of the selected XML attribute is
* set to <i>no</i>.
*
- * @param expression {@link XPath} expression to select XML element.
+ * @param expression XPath expression to select XML element.
* @param attributeName name to select XML attribute of the selected XML element.
* @param value binary choice value for the selected XML attribute from the selected XML element.
*/
@@ -204,10 +203,9 @@ public interface LibvirtXmlEditable
}
/**
- * Sets the text value of a XML attribute from a XML element selected by a
- * {@link XPath} expression.
+ * Sets the text value of a XML attribute from a XML element selected by a XPath expression.
*
- * @param expression {@link XPath} expression to select XML element.
+ * @param expression XPath expression to select XML element.
* @param attributeName name to select XML attribute of the selected XML element.
* @param value XML attribute value for the selected XML attribute from the selected XML element.
*/
@@ -224,17 +222,17 @@ public interface LibvirtXmlEditable
}
/**
- * Removes an XML attribute from a XML element selected by a {@link XPath} expression.
+ * Removes an XML attribute from a XML element selected by a XPath expression.
*
- * @param expression {@link XPath} expression to select XML element.
+ * @param expression XPath expression to select XML element.
* @param attributeName name of the attribute which should be deleted.
*/
public void removeXmlElementAttribute( String expression, String attributeName );
/**
- * Removes all XML attributes from a XML element selected by a {@link XPath} expression.
+ * Removes all XML attributes from a XML element selected by a XPath expression.
*
- * @param expression {@link XPath} expression to select XML element.
+ * @param expression XPath expression to select XML element.
*/
public void removeXmlElementAttributes( String expression );
diff --git a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlNode.java b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlNode.java
index 93e28de..6d00271 100644
--- a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlNode.java
+++ b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlNode.java
@@ -12,7 +12,7 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
- * A representation of a XML node as part of a {@link LibvirtXMLDocument}.
+ * A representation of a XML node as part of a {@link LibvirtXmlDocument}.
*
* @author Manuel Bentele
* @version 1.0
@@ -20,17 +20,17 @@ import org.w3c.dom.NodeList;
public class LibvirtXmlNode implements LibvirtXmlCreatable, LibvirtXmlEditable
{
/**
- * Separation character for internal {@link XPath} expressions.
+ * Separation character for internal XPath expressions.
*/
private static final String XPATH_EXPRESSION_SEPARATOR = "/";
/**
- * Current XML node selection character for internal {@link XPath} expressions.
+ * Current XML node selection character for internal XPath expressions.
*/
private static final String XPATH_EXPRESSION_CURRENT_NODE = ".";
/**
- * Factory to create {@link XPath} objects.
+ * Factory to create XPath objects.
*/
private XPathFactory xPathFactory = null;
@@ -40,13 +40,12 @@ public class LibvirtXmlNode implements LibvirtXmlCreatable, LibvirtXmlEditable
private Document xmlDocument = null;
/**
- * Current XML base node as XML root anchor for relative internal {@link XPath} expressions.
+ * Current XML base node as XML root anchor for relative internal XPath expressions.
*/
private Node xmlBaseNode = null;
/**
- * Create and initialize {@link XPath} context to define and compile custom {@link XPath}
- * expressions.
+ * Create and initialize XPath context to define and compile custom XPath expressions.
*/
private void createXPathContext()
{
@@ -139,8 +138,7 @@ public class LibvirtXmlNode implements LibvirtXmlCreatable, LibvirtXmlEditable
/**
* Returns current XML base node.
*
- * @return current XML base node as XML root anchor of relative internal {@link XPath}
- * expressions.
+ * @return current XML base node as XML root anchor of relative internal XPath expressions.
*/
public Node getXmlBaseNode()
{
@@ -150,8 +148,8 @@ public class LibvirtXmlNode implements LibvirtXmlCreatable, LibvirtXmlEditable
/**
* Sets existing XML base node for Libvirt XML node.
*
- * @param xmlBaseNode existing XML base node as XML root anchor for relative internal
- * {@link XPath} expressions.
+ * @param xmlBaseNode existing XML base node as XML root anchor for relative internal XPath
+ * expressions.
*/
public void setXmlBaseNode( Node xmlBaseNode )
{
@@ -317,7 +315,7 @@ public class LibvirtXmlNode implements LibvirtXmlCreatable, LibvirtXmlEditable
attribute.setNodeValue( value );
}
}
-
+
@Override
public void removeXmlElementAttribute( String expression, String attributeName )
{
diff --git a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlResources.java b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlResources.java
index 38c818b..a6b3e39 100644
--- a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlResources.java
+++ b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlResources.java
@@ -17,6 +17,11 @@ public final class LibvirtXmlResources
private static final String LIBVIRT_PREFIX_PATH = File.separator + "libvirt";
/**
+ * File path prefix of the absolute path to the libosinfo resource folder in a *.jar file.
+ */
+ private static final String LIBOSINFO_PREFIX_PATH = File.separator + "libvirt" + File.separator + "libosinfo";
+
+ /**
* File path prefix of the absolute path to the libvirt XSL resource folder in a *.jar file.
*/
private static final String LIBVIRT_PREFIX_PATH_XSL = LIBVIRT_PREFIX_PATH + File.separator + "xsl";
@@ -27,6 +32,29 @@ public final class LibvirtXmlResources
private static final String LIBVIRT_PREFIX_PATH_RNG = LIBVIRT_PREFIX_PATH + File.separator + "rng";
/**
+ * File path prefix of the absolute path to the libosinfo RNG resource folder in a *.jar file.
+ */
+ private static final String LIBOSINFO_PREFIX_PATH_RNG = LIBOSINFO_PREFIX_PATH + File.separator + "rng";
+
+ /**
+ * File path prefix of the absolute path to the libosinfo XML resource folder in a *.jar file.
+ */
+ private static final String LIBOSINFO_PREFIX_PATH_XML = LIBOSINFO_PREFIX_PATH + File.separator + "xml";
+
+ /**
+ * Returns a Libvirt resource as stream.
+ *
+ * @param prefix file path of the Libvirt resource in the resources *.jar folder.
+ * @param fileName file name of the Libvirt resource in the resources *.jar folder.
+ * @return Libvirt resource as stream.
+ */
+ private static InputStream getLibvirtResource( String prefix, String fileName )
+ {
+ final String path = prefix + File.separator + fileName;
+ return LibvirtXmlResources.class.getResourceAsStream( path );
+ }
+
+ /**
* Returns a Libvirt XSL resource as stream.
*
* @param libvirtXslFileName file name of the XSL resource in the resources *.jar folder.
@@ -34,8 +62,7 @@ public final class LibvirtXmlResources
*/
public static InputStream getLibvirtXsl( String libvirtXslFileName )
{
- String libvirtXslPath = LibvirtXmlResources.LIBVIRT_PREFIX_PATH_XSL + File.separator + libvirtXslFileName;
- return LibvirtXmlResources.class.getResourceAsStream( libvirtXslPath );
+ return LibvirtXmlResources.getLibvirtResource( LibvirtXmlResources.LIBVIRT_PREFIX_PATH_XSL, libvirtXslFileName );
}
/**
@@ -46,7 +73,31 @@ public final class LibvirtXmlResources
*/
public static InputStream getLibvirtRng( String libvirtRngFileName )
{
- String libvirtRngPath = LibvirtXmlResources.LIBVIRT_PREFIX_PATH_RNG + File.separator + libvirtRngFileName;
- return LibvirtXmlResources.class.getResourceAsStream( libvirtRngPath );
+ return LibvirtXmlResources.getLibvirtResource( LibvirtXmlResources.LIBVIRT_PREFIX_PATH_RNG, libvirtRngFileName );
+ }
+
+ /**
+ * Returns a libosinfo RNG schema resource as stream.
+ *
+ * @param libosInfoRngFileName file name of the RNG schema resource in the resources *.jar
+ * folder.
+ * @return libosinfo RNG schema resource as stream.
+ */
+ public static InputStream getLibOsInfoRng( String libosInfoRngFileName )
+ {
+ return LibvirtXmlResources.getLibvirtResource( LibvirtXmlResources.LIBOSINFO_PREFIX_PATH_RNG,
+ libosInfoRngFileName );
+ }
+
+ /**
+ * Returns a libosinfo XML resource as stream.
+ *
+ * @param libosInfoXmlFileName file name of the XML resource in the resources *.jar folder.
+ * @return libosinfo XML resource as stream.
+ */
+ public static InputStream getLibOsInfoXml( String libosInfoXmlFileName )
+ {
+ return LibvirtXmlResources.getLibvirtResource( LibvirtXmlResources.LIBOSINFO_PREFIX_PATH_XML,
+ libosInfoXmlFileName );
}
}
diff --git a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlSchemaValidator.java b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlSchemaValidator.java
index e074948..bc8f90f 100644
--- a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlSchemaValidator.java
+++ b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlSchemaValidator.java
@@ -196,8 +196,9 @@ public class LibvirtXmlSchemaValidator
/**
* Creates a validator for validation of Libvirt XML documents with RelaxNG schemas.
*
- * @param rngSchema
- * @throws SAXException
+ * @param rngSchema RelaxNG schema used for validation with {@link #validate(Document)}.
+ *
+ * @throws SAXException creation of a Libvirt XML validator failed.
*/
public LibvirtXmlSchemaValidator( InputStream rngSchema ) throws SAXException
{
diff --git a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlSerializable.java b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlSerializable.java
index 6f11ce5..4cd0a32 100644
--- a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlSerializable.java
+++ b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlSerializable.java
@@ -17,6 +17,8 @@ public abstract interface LibvirtXmlSerializable
* Serialize Libvirt XML document from {@link String}.
*
* @param xml {@link String} containing XML content.
+ *
+ * @throws LibvirtXmlSerializationException serialization of Libvirt XML document failed.
*/
public void fromXml( String xml ) throws LibvirtXmlSerializationException;
@@ -24,6 +26,8 @@ public abstract interface LibvirtXmlSerializable
* Serialize Libvirt XML document from {@link File}.
*
* @param xml {@link File} containing XML content.
+ *
+ * @throws LibvirtXmlSerializationException serialization of Libvirt XML document failed.
*/
public void fromXml( File xml ) throws LibvirtXmlSerializationException;
@@ -31,6 +35,8 @@ public abstract interface LibvirtXmlSerializable
* Serialize Libvirt XML document from {@link InputStream}.
*
* @param xml {@link InputStream} providing XML content.
+ *
+ * @throws LibvirtXmlSerializationException serialization of Libvirt XML document failed.
*/
void fromXml( InputStream xml ) throws LibvirtXmlSerializationException;
@@ -38,6 +44,8 @@ public abstract interface LibvirtXmlSerializable
* Serialize Libvirt XML document from {@link InputSource}.
*
* @param xml {@link InputSource} providing XML content.
+ *
+ * @throws LibvirtXmlSerializationException serialization of Libvirt XML document failed.
*/
public void fromXml( InputSource xml ) throws LibvirtXmlSerializationException;
@@ -45,6 +53,8 @@ public abstract interface LibvirtXmlSerializable
* Serialize Libvirt XML document to {@link String}.
*
* @return XML {@link String} containing Libvirt XML document content.
+ *
+ * @throws LibvirtXmlSerializationException serialization of Libvirt XML document failed.
*/
public String toXml() throws LibvirtXmlSerializationException;
@@ -52,6 +62,8 @@ public abstract interface LibvirtXmlSerializable
* Serialize Libvirt XML document to {@link File}.
*
* @param xml XML {@link File} containing Libvirt XML document content.
+ *
+ * @throws LibvirtXmlSerializationException serialization of Libvirt XML document failed.
*/
public void toXml( File xml ) throws LibvirtXmlSerializationException;
}