1 16 package org.apache.juddi.handler; 17 18 import org.apache.juddi.datatype.AddressLine; 19 import org.apache.juddi.datatype.RegistryObject; 20 import org.apache.juddi.datatype.response.Property; 21 import org.w3c.dom.Element ; 22 23 28 public class PropertyHandler extends AbstractHandler 29 { 30 public static final String TAG_NAME = "property"; 31 32 private HandlerMaker maker = null; 33 34 protected PropertyHandler(HandlerMaker maker) 35 { 36 this.maker = maker; 37 } 38 39 public RegistryObject unmarshal(Element element) 40 { 41 Property obj = new Property(); 42 43 String name = element.getAttribute("name"); 45 if ((name != null) && (name.trim().length() > 0)) 46 obj.setName(name); 47 48 String value = element.getAttribute("value"); 49 if ((value != null) && (value.trim().length() > 0)) 50 obj.setValue(value); 51 52 55 58 return obj; 59 } 60 61 public void marshal(RegistryObject object,Element parent) 62 { 63 Property property = (Property)object; 64 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 65 66 String name = property.getName(); 67 if ((name != null) && (name.trim().length() > 0)) 68 element.setAttribute("name",name); 69 70 String value = property.getValue(); 71 if ((value != null) && (value.trim().length() > 0)) 72 element.setAttribute("value",value); 73 74 parent.appendChild(element); 75 } 76 77 78 79 80 81 82 83 public static void main(String args[]) 84 throws Exception 85 { 86 Property inprop = new Property("nameAttr","valueAttr"); 88 89 HandlerMaker maker = HandlerMaker.getInstance(); 91 AbstractHandler handler = maker.lookup(PropertyHandler.TAG_NAME); 92 Element element = null; 93 handler.marshal(inprop,element); 94 AddressLine outprop = (AddressLine)handler.unmarshal(element); 95 96 if (outprop.equals(inprop)) 98 System.out.println("Input and output are the same."); 99 else 100 System.out.println("Input and output are NOT the same!"); 101 } 102 } | Popular Tags |