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.CategoryBag;
21 import org.apache.juddi.datatype.KeyedReference;
22 import org.apache.juddi.datatype.RegistryObject;
23 import org.apache.juddi.datatype.TModelBag;
24 import org.apache.juddi.datatype.TModelKey;
25 import org.apache.juddi.datatype.request.FindBinding;
26 import org.apache.juddi.datatype.request.FindQualifier;
27 import org.apache.juddi.datatype.request.FindQualifiers;
28 import org.apache.juddi.util.xml.XMLUtils;
29 import org.w3c.dom.Element;
30
31
32 /***
33 * FindBindingHandler
34 *
35 * "Knows about the creation and populating of FindBinding objects.
36 * Returns FindBinding."
37 *
38 * @author Steve Viens (sviens@apache.org)
39 * @author Anou Mana (anou_mana@users.sourceforge.net)
40 */
41 public class FindBindingHandler extends AbstractHandler
42 {
43 public static final String TAG_NAME = "find_binding";
44
45 private HandlerMaker maker = null;
46
47 protected FindBindingHandler(HandlerMaker maker)
48 {
49 this.maker = maker;
50 }
51
52 public RegistryObject unmarshal(Element element)
53 {
54 FindBinding obj = new FindBinding();
55 Vector nodeList = null;
56 AbstractHandler handler = null;
57
58
59 String serviceKey = element.getAttribute("serviceKey");
60 if ((serviceKey != null && (serviceKey.trim().length() > 0)))
61 obj.setServiceKey(serviceKey);
62
63 String generic = element.getAttribute("generic");
64 if ((generic != null && (generic.trim().length() > 0)))
65 obj.setGeneric(generic);
66
67 String maxRows = element.getAttribute("maxRows");
68 if ((maxRows != null) && (maxRows.trim().length() > 0))
69 obj.setMaxRows(maxRows);
70
71
72
73
74
75 nodeList = XMLUtils.getChildElementsByTagName(element,FindQualifiersHandler.TAG_NAME);
76 if (nodeList.size() > 0)
77 {
78 handler = maker.lookup(FindQualifiersHandler.TAG_NAME);
79 obj.setFindQualifiers((FindQualifiers)handler.unmarshal((Element)nodeList.elementAt(0)));
80 }
81
82 nodeList = XMLUtils.getChildElementsByTagName(element,TModelBagHandler.TAG_NAME);
83 if (nodeList.size() > 0)
84 {
85 handler = maker.lookup(TModelBagHandler.TAG_NAME);
86 obj.setTModelBag((TModelBag)handler.unmarshal((Element)nodeList.elementAt(0)));
87 }
88
89 nodeList = XMLUtils.getChildElementsByTagName(element,CategoryBagHandler.TAG_NAME);
90 if (nodeList.size() > 0)
91 {
92 handler = maker.lookup(CategoryBagHandler.TAG_NAME);
93 obj.setCategoryBag((CategoryBag)handler.unmarshal((Element)nodeList.elementAt(0)));
94 }
95
96 return obj;
97 }
98
99 public void marshal(RegistryObject object,Element parent)
100 {
101 FindBinding request = (FindBinding)object;
102 String generic = request.getGeneric();
103 generic = getGeneric(generic);
104 String namespace = getUDDINamespace(generic);
105 Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
106 AbstractHandler handler = null;
107
108 String key = request.getServiceKey();
109 if (key != null)
110 element.setAttribute("serviceKey",key);
111
112 element.setAttribute("generic",generic);
113
114 int maxRows = request.getMaxRows();
115 if (maxRows > 0)
116 element.setAttribute("maxRows",String.valueOf(maxRows));
117
118 FindQualifiers qualifiers = request.getFindQualifiers();
119 if ((qualifiers != null) && (qualifiers.size() > 0))
120 {
121 handler = maker.lookup(FindQualifiersHandler.TAG_NAME);
122 handler.marshal(qualifiers,element);
123 }
124
125 CategoryBag catBag = request.getCategoryBag();
126 if (catBag != null)
127 {
128 handler = maker.lookup(CategoryBagHandler.TAG_NAME);
129 handler.marshal(catBag,element);
130 }
131
132 TModelBag bag = request.getTModelBag();
133 if (bag != null)
134 {
135 handler = maker.lookup(TModelBagHandler.TAG_NAME);
136 handler.marshal(bag,element);
137 }
138
139 parent.appendChild(element);
140 }
141
142
143 /****************************************************************************/
144 /****************************** TEST DRIVER *********************************/
145 /****************************************************************************/
146
147
148 public static void main(String args[])
149 throws Exception
150 {
151 HandlerMaker maker = HandlerMaker.getInstance();
152 AbstractHandler handler = maker.lookup(FindBindingHandler.TAG_NAME);
153
154 Element parent = XMLUtils.newRootElement();
155 Element child = null;
156
157 CategoryBag catBag = new CategoryBag();
158 catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue"));
159 catBag.addKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","catBagKeyName2","catBagKeyValue2"));
160
161 TModelBag bag = new TModelBag();
162 bag.addTModelKey("uuid:35d9793b-9911-4b85-9f0e-5d4c65b4f253");
163 bag.addTModelKey(new TModelKey("uuid:c5ab113f-0d6b-4247-b3c4-8c012726acd8"));
164
165 FindBinding request = new FindBinding();
166 request.addFindQualifier(new FindQualifier(FindQualifier.SORT_BY_DATE_ASC));
167 request.addFindQualifier(new FindQualifier(FindQualifier.AND_ALL_KEYS));
168 request.setMaxRows(50);
169 request.setServiceKey("fd36dbce-bc3e-468b-8346-5374975a0843");
170 request.setTModelBag(bag);
171 request.setCategoryBag(catBag);
172
173 System.out.println();
174
175 RegistryObject regObject = request;
176 handler.marshal(regObject,parent);
177 child = (Element)parent.getFirstChild();
178 parent.removeChild(child);
179 XMLUtils.writeXML(child,System.out);
180
181 System.out.println();
182
183 regObject = handler.unmarshal(child);
184 handler.marshal(regObject,parent);
185 child = (Element)parent.getFirstChild();
186 parent.removeChild(child);
187 XMLUtils.writeXML(child,System.out);
188 }
189 }