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 DAVBooleanValue extends BooleanValue { 42 43 48 public DAVBooleanValue(boolean bValue) { 49 super(bValue); 50 } 51 52 public DAVBooleanValue() { 53 super(); 54 } 55 56 63 public static void toXML(Document xmlDoc, Element propEl, List aValues) { 64 if(aValues.size()==1) { 65 if( ((DAVBooleanValue)aValues.get(0)).getValue() ) { 66 Text txt = xmlDoc.createTextNode("true"); 67 propEl.appendChild(txt); 68 } else { 69 Text txt = xmlDoc.createTextNode("false"); 70 propEl.appendChild(txt); 71 } 72 } else if(aValues.size()>1) { 73 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "type", "Array" ); 74 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "arraySize", Integer.toString(aValues.size()) ); 75 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "itemType", NamespaceType.XML_SCHEMA.getPrefix()+":boolean"); 76 Iterator itor = aValues.iterator(); 77 while (itor.hasNext()) { 78 DAVBooleanValue val = (DAVBooleanValue) itor.next(); 79 Element arrayEl = xmlDoc.createElementNS(NamespaceType.XML_SCHEMA.getURI(), "boolean"); 80 if( val.getValue() ) { 81 Text txt = xmlDoc.createTextNode("true"); 82 arrayEl.appendChild(txt); 83 } else { 84 Text txt = xmlDoc.createTextNode("false"); 85 arrayEl.appendChild(txt); 86 } 87 propEl.appendChild(arrayEl); 88 } 89 } 90 } 91 92 99 public static void fromXML(PropertyInstance propInst, Element propEl) { 100 if(propEl.getChildNodes().getLength()==1) { 101 Text txt = (Text ) propEl.getFirstChild(); 102 if(txt!=null) { 103 DAVBooleanValue val = (DAVBooleanValue) propInst.getNewValueInstance(); 104 val.setValue( Boolean.valueOf(txt.getData()).booleanValue() ); 105 propInst.addValueWithoutFiringVirtualFileEvent(val); 106 } 107 } else if(propEl.getChildNodes().getLength()>1) { 108 NodeList nl = propEl.getChildNodes(); 109 for (int i = 0; i < nl.getLength(); i++) { 110 Node node = nl.item(i); 111 if(node.getNodeType()==Node.ELEMENT_NODE) { 112 Text txt = (Text ) node.getFirstChild(); 113 if(txt!=null) { 114 DAVBooleanValue val = (DAVBooleanValue) propInst.getNewValueInstance(); 115 val.setValue( Boolean.valueOf(txt.getData()).booleanValue() ); 116 propInst.addValueWithoutFiringVirtualFileEvent(val); 117 } 118 } 119 } 120 } 121 } 122 123 } 124 | Popular Tags |