1 19 package org.openharmonise.webdav.client.value; 20 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import org.openharmonise.commons.xml.namespace.*; 25 import org.openharmonise.vfs.metadata.*; 26 import org.openharmonise.vfs.metadata.value.*; 27 import org.w3c.dom.Document ; 28 import org.w3c.dom.Element ; 29 import org.w3c.dom.Node ; 30 import org.w3c.dom.NodeList ; 31 import org.w3c.dom.Text ; 32 33 34 41 public class DAVIntegerValue extends IntegerValue { 42 43 48 public DAVIntegerValue(int nValue) { 49 super(nValue); 50 } 51 52 55 public DAVIntegerValue() { 56 super(); 57 } 58 59 66 public static void toXML(Document xmlDoc, Element propEl, List aValues) { 67 if(aValues.size()==1) { 68 Text txt = xmlDoc.createTextNode( Integer.toString( ((DAVIntegerValue)aValues.get(0)).getValue() ) ); 69 propEl.appendChild(txt); 70 } else if(aValues.size()>1) { 71 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "type", "Array" ); 72 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "arraySize", Integer.toString(aValues.size()) ); 73 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "itemType", NamespaceType.XML_SCHEMA.getPrefix()+":integer"); 74 Iterator itor = aValues.iterator(); 75 while (itor.hasNext()) { 76 DAVIntegerValue val = (DAVIntegerValue) itor.next(); 77 Element arrayEl = xmlDoc.createElementNS(NamespaceType.XML_SCHEMA.getURI(), "integer"); 78 Text txt = xmlDoc.createTextNode( Integer.toString( val.getValue() ) ); 79 arrayEl.appendChild(txt); 80 propEl.appendChild(arrayEl); 81 } 82 } 83 } 84 85 92 public static void fromXML(PropertyInstance propInst, Element propEl) { 93 if(propEl.getChildNodes().getLength()==1) { 94 Text txt = (Text ) propEl.getFirstChild(); 95 if(txt!=null) { 96 DAVIntegerValue val = (DAVIntegerValue) propInst.getNewValueInstance(); 97 val.setValue( Integer.parseInt(txt.getData()) ); 98 propInst.addValueWithoutFiringVirtualFileEvent(val); 99 } 100 } else if(propEl.getChildNodes().getLength()>1) { 101 NodeList nl = propEl.getChildNodes(); 102 for (int i = 0; i < nl.getLength(); i++) { 103 Node node = nl.item(i); 104 if(node.getNodeType()==Node.ELEMENT_NODE) { 105 Text txt = (Text ) node.getFirstChild(); 106 if(txt!=null) { 107 DAVIntegerValue val = (DAVIntegerValue) propInst.getNewValueInstance(); 108 val.setValue( Integer.parseInt(txt.getData()) ); 109 propInst.addValueWithoutFiringVirtualFileEvent(val); 110 } 111 } 112 } 113 } 114 } 115 116 } 117 | Popular Tags |