1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 /***
24 * Knows about the creation and populating of Property objects.
25 *
26 * @author Steve Viens (sviens@apache.org)
27 */
28 public class PropertyHandler extends AbstractHandler
29 {
30 public static final String TAG_NAME = "property";
31
32 protected PropertyHandler(HandlerMaker maker)
33 {
34 }
35
36 public RegistryObject unmarshal(Element element)
37 {
38 Property obj = new Property();
39
40
41 String name = element.getAttribute("name");
42 if ((name != null) && (name.trim().length() > 0))
43 obj.setName(name);
44
45 String value = element.getAttribute("value");
46 if ((value != null) && (value.trim().length() > 0))
47 obj.setValue(value);
48
49
50
51
52
53
54
55 return obj;
56 }
57
58 public void marshal(RegistryObject object,Element parent)
59 {
60 Property property = (Property)object;
61 String generic = getGeneric(null);
62 String namespace = getUDDINamespace(generic);
63 Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
64
65 String name = property.getName();
66 if ((name != null) && (name.trim().length() > 0))
67 element.setAttribute("name",name);
68
69 String value = property.getValue();
70 if ((value != null) && (value.trim().length() > 0))
71 element.setAttribute("value",value);
72
73 parent.appendChild(element);
74 }
75
76
77 /****************************************************************************/
78 /****************************** TEST DRIVER *********************************/
79 /****************************************************************************/
80
81
82 public static void main(String args[])
83 throws Exception
84 {
85
86 Property inprop = new Property("nameAttr","valueAttr");
87
88
89 HandlerMaker maker = HandlerMaker.getInstance();
90 AbstractHandler handler = maker.lookup(PropertyHandler.TAG_NAME);
91 Element element = null;
92 handler.marshal(inprop,element);
93 AddressLine outprop = (AddressLine)handler.unmarshal(element);
94
95
96 if (outprop.equals(inprop))
97 System.out.println("Input and output are the same.");
98 else
99 System.out.println("Input and output are NOT the same!");
100 }
101 }