summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/util/vm/VboxConfig.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/util/vm/VboxConfig.java')
-rw-r--r--src/main/java/org/openslx/util/vm/VboxConfig.java65
1 files changed, 38 insertions, 27 deletions
diff --git a/src/main/java/org/openslx/util/vm/VboxConfig.java b/src/main/java/org/openslx/util/vm/VboxConfig.java
index 70af022..a244497 100644
--- a/src/main/java/org/openslx/util/vm/VboxConfig.java
+++ b/src/main/java/org/openslx/util/vm/VboxConfig.java
@@ -23,6 +23,7 @@ import javax.xml.xpath.XPathFactory;
import org.apache.log4j.Logger;
import org.openslx.util.vm.VmMetaData.DriveBusType;
import org.openslx.util.vm.VmMetaData.HardDisk;
+import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -293,8 +294,6 @@ public class VboxConfig
* @param targetTag
* @param targetAttr0
* @param value0
- * @param targetAttr1
- * @param value1
* @return
*/
public Node findANode( String targetTag, String targetAttr0, String value0 )
@@ -357,13 +356,19 @@ public class VboxConfig
}
}
- public void addAttributeToNode( Node targetNode, String attrName, String value )
+ public boolean addAttributeToNode( Node targetNode, String attrName, String value )
{
if ( targetNode == null ) {
LOGGER.warn( "Node is null; stopped!" );
- return;
+ return false;
+ }
+ try {
+ ( (Element)targetNode ).setAttribute( attrName, value );
+ } catch (DOMException e) {
+ LOGGER.error("Failed set '" + attrName + "' to '" + value + "' of xml node '" + targetNode.getNodeName() + "': ", e);
+ return false;
}
- ( (Element)targetNode ).setAttribute( attrName, value );
+ return true;
}
public Node addNewNode( String nameOfParent, String nameOfnewNode, boolean oneLiner )
@@ -375,33 +380,39 @@ public class VboxConfig
{
Node parent = null;
NodeList posibleParents = findANode( nameOfParent );
- if ( posibleParents.getLength() > 1 ) {
- // if we have more then 1 parent we need to have an sanityArg s.t. we insert our new attribute in the right tag
- if ( refAttr == null ) {
- LOGGER.warn( "Action would change values of more than one node; stopped!" );
- return null;
- }
- for ( int i = 1; i < posibleParents.getLength(); i++ ) {
- if ( ( (Element)posibleParents.item( i ) ).getAttribute( refAttr ).equals( refVal ) ) {
- parent = posibleParents.item( i );
- break;
+ Element newNode;
+ try {
+ if ( posibleParents.getLength() > 1 ) {
+ // if we have more then 1 parent we need to have an sanityArg s.t. we insert our new attribute in the right tag
+ if ( refAttr == null ) {
+ LOGGER.warn( "Action would change values of more than one node; stopped!" );
+ return null;
+ }
+ for ( int i = 1; i < posibleParents.getLength(); i++ ) {
+ if ( ( (Element)posibleParents.item( i ) ).getAttribute( refAttr ).equals( refVal ) ) {
+ parent = posibleParents.item( i );
+ break;
+ }
}
+ } else {
+ parent = posibleParents.item( 0 );
}
- } else {
- parent = posibleParents.item( 0 );
- }
- if ( parent == null ) {
- LOGGER.warn( "Node: '" + nameOfParent + "' could not be found" );
- return null;
- }
- Element newNode = doc.createElement( nameOfnewNode );
+ if ( parent == null ) {
+ LOGGER.warn( "Node: '" + nameOfParent + "' could not be found" );
+ return null;
+ }
+ newNode = doc.createElement( nameOfnewNode );
- if ( !oneLiner ) {
- org.w3c.dom.Text a = doc.createTextNode( "\n" );
- newNode.appendChild( a );
+ if ( !oneLiner ) {
+ org.w3c.dom.Text a = doc.createTextNode( "\n" );
+ newNode.appendChild( a );
+ }
+ parent.appendChild( newNode );
+ } catch (DOMException e) {
+ LOGGER.error("Something went wrong: ", e);
+ return null;
}
- parent.appendChild( newNode );
return newNode;
}