1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.handler;
17
18 import java.util.Vector;
19
20 import org.apache.juddi.datatype.RegistryObject;
21 import org.apache.juddi.datatype.request.FindQualifier;
22 import org.apache.juddi.datatype.request.FindQualifiers;
23 import org.apache.juddi.util.xml.XMLUtils;
24 import org.w3c.dom.Element;
25
26 /***
27 * "Knows about the creation and populating of FindQualifiers objects.
28 * Returns FindQualifiers."
29 *
30 * @author Steve Viens (sviens@apache.org)
31 */
32 public class FindQualifiersHandler extends AbstractHandler
33 {
34 public static final String TAG_NAME = "findQualifiers";
35
36 private HandlerMaker maker = null;
37
38 protected FindQualifiersHandler(HandlerMaker maker)
39 {
40 this.maker = maker;
41 }
42
43 public RegistryObject unmarshal(Element element)
44 {
45 FindQualifiers obj = new FindQualifiers();
46 Vector nodeList = null;
47 AbstractHandler handler = null;
48
49
50
51
52
53
54
55
56 nodeList = XMLUtils.getChildElementsByTagName(element,FindQualifierHandler.TAG_NAME);
57 for (int i=0; i<nodeList.size(); i++)
58 {
59 handler = maker.lookup(FindQualifierHandler.TAG_NAME);
60 obj.addFindQualifier((FindQualifier)handler.unmarshal((Element)nodeList.elementAt(i)));
61 }
62
63 return obj;
64 }
65
66 public void marshal(RegistryObject object,Element parent)
67 {
68 FindQualifiers qualifiers = (FindQualifiers)object;
69 String generic = getGeneric(null);
70 String namespace = getUDDINamespace(generic);
71 Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
72 AbstractHandler handler = null;
73
74 Vector qVector = qualifiers.getFindQualifierVector();
75 if ((qVector!=null) && (qVector.size() > 0))
76 {
77 handler = maker.lookup(FindQualifierHandler.TAG_NAME);
78 for (int i=0; i < qVector.size(); i++)
79 handler.marshal((FindQualifier)qVector.elementAt(i),element);
80 }
81
82 parent.appendChild(element);
83 }
84
85
86 /****************************************************************************/
87 /****************************** TEST DRIVER *********************************/
88 /****************************************************************************/
89
90
91 public static void main(String args[])
92 throws Exception
93 {
94 HandlerMaker maker = HandlerMaker.getInstance();
95 AbstractHandler handler = maker.lookup(FindQualifiersHandler.TAG_NAME);
96
97 Element parent = XMLUtils.newRootElement();
98 Element child = null;
99
100 FindQualifiers qualifiers = new FindQualifiers();
101 qualifiers.addFindQualifier(new FindQualifier(FindQualifier.SORT_BY_DATE_ASC));
102 qualifiers.addFindQualifier(new FindQualifier(FindQualifier.AND_ALL_KEYS));
103
104 System.out.println();
105
106 RegistryObject regObject = qualifiers;
107 handler.marshal(regObject,parent);
108 child = (Element)parent.getFirstChild();
109 parent.removeChild(child);
110 XMLUtils.writeXML(child,System.out);
111
112 System.out.println();
113
114 regObject = handler.unmarshal(child);
115 handler.marshal(regObject,parent);
116 child = (Element)parent.getFirstChild();
117 parent.removeChild(child);
118 XMLUtils.writeXML(child,System.out);
119 }
120 }