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.Address;
21 import org.apache.juddi.datatype.AddressLine;
22 import org.apache.juddi.datatype.CategoryBag;
23 import org.apache.juddi.datatype.Description;
24 import org.apache.juddi.datatype.DiscoveryURL;
25 import org.apache.juddi.datatype.DiscoveryURLs;
26 import org.apache.juddi.datatype.Email;
27 import org.apache.juddi.datatype.IdentifierBag;
28 import org.apache.juddi.datatype.KeyedReference;
29 import org.apache.juddi.datatype.Name;
30 import org.apache.juddi.datatype.OverviewDoc;
31 import org.apache.juddi.datatype.Phone;
32 import org.apache.juddi.datatype.RegistryObject;
33 import org.apache.juddi.datatype.binding.AccessPoint;
34 import org.apache.juddi.datatype.binding.BindingTemplate;
35 import org.apache.juddi.datatype.binding.BindingTemplates;
36 import org.apache.juddi.datatype.binding.HostingRedirector;
37 import org.apache.juddi.datatype.binding.InstanceDetails;
38 import org.apache.juddi.datatype.binding.TModelInstanceDetails;
39 import org.apache.juddi.datatype.binding.TModelInstanceInfo;
40 import org.apache.juddi.datatype.business.BusinessEntity;
41 import org.apache.juddi.datatype.business.Contact;
42 import org.apache.juddi.datatype.business.Contacts;
43 import org.apache.juddi.datatype.service.BusinessService;
44 import org.apache.juddi.datatype.service.BusinessServices;
45 import org.apache.juddi.util.xml.XMLUtils;
46 import org.w3c.dom.Element;
47
48 /***
49 * "Knows about the creation and populating of BusinessEntity objects.
50 * Returns BusinessEntity."
51 *
52 * @author Steve Viens (sviens@apache.org)
53 * @author Anou Mana (anou_mana@users.sourceforge.net)
54 */
55 public class BusinessEntityHandler extends AbstractHandler
56 {
57 public static final String TAG_NAME = "businessEntity";
58
59 private HandlerMaker maker = null;
60
61 protected BusinessEntityHandler(HandlerMaker maker)
62 {
63 this.maker = maker;
64 }
65
66 public RegistryObject unmarshal(Element element)
67 {
68 BusinessEntity obj = new BusinessEntity();
69 Vector nodeList = null;
70 AbstractHandler handler = null;
71
72
73 obj.setBusinessKey(element.getAttribute("businessKey"));
74 obj.setOperator(element.getAttribute("operator"));
75 obj.setAuthorizedName(element.getAttribute("authorizedName"));
76
77
78
79
80
81 nodeList = XMLUtils.getChildElementsByTagName(element,NameHandler.TAG_NAME);
82 for (int i=0; i<nodeList.size(); i++)
83 {
84 handler = maker.lookup(NameHandler.TAG_NAME);
85 Name name = (Name )handler.unmarshal((Element)nodeList.elementAt(i));
86 if (name != null)
87 obj.addName(name);
88 }
89
90 nodeList = XMLUtils.getChildElementsByTagName(element,DescriptionHandler.TAG_NAME);
91 for (int i=0; i<nodeList.size(); i++)
92 {
93 handler = maker.lookup(DescriptionHandler.TAG_NAME);
94 Description descr = (Description)handler.unmarshal((Element)nodeList.elementAt(i));
95 if (descr != null)
96 obj.addDescription(descr);
97 }
98
99 nodeList = XMLUtils.getChildElementsByTagName(element,DiscoveryURLsHandler.TAG_NAME);
100 if (nodeList.size() > 0)
101 {
102 handler = maker.lookup(DiscoveryURLsHandler.TAG_NAME);
103 obj.setDiscoveryURLs((DiscoveryURLs)handler.unmarshal((Element)nodeList.elementAt(0)));
104 }
105
106 nodeList = XMLUtils.getChildElementsByTagName(element,ContactsHandler.TAG_NAME);
107 if (nodeList.size() > 0)
108 {
109 handler = maker.lookup(ContactsHandler.TAG_NAME);
110 obj.setContacts((Contacts)handler.unmarshal((Element)nodeList.elementAt(0)));
111 }
112
113 nodeList = XMLUtils.getChildElementsByTagName(element,BusinessServicesHandler.TAG_NAME);
114 if (nodeList.size() > 0)
115 {
116 handler = maker.lookup(BusinessServicesHandler.TAG_NAME);
117 obj.setBusinessServices((BusinessServices)handler.unmarshal((Element)nodeList.elementAt(0)));
118 }
119
120 nodeList = XMLUtils.getChildElementsByTagName(element,IdentifierBagHandler.TAG_NAME);
121 if (nodeList.size() > 0)
122 {
123 handler = maker.lookup(IdentifierBagHandler.TAG_NAME);
124 obj.setIdentifierBag((IdentifierBag)handler.unmarshal((Element)nodeList.elementAt(0)));
125 }
126
127 nodeList = XMLUtils.getChildElementsByTagName(element,CategoryBagHandler.TAG_NAME);
128 if (nodeList.size() > 0)
129 {
130 handler = maker.lookup(CategoryBagHandler.TAG_NAME);
131 obj.setCategoryBag((CategoryBag)handler.unmarshal((Element)nodeList.elementAt(0)));
132 }
133
134 return obj;
135 }
136
137 public void marshal(RegistryObject object,Element parent)
138 {
139 BusinessEntity business = (BusinessEntity)object;
140 String generic = getGeneric(null);
141 String namespace = getUDDINamespace(generic);
142 Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
143 AbstractHandler handler = null;
144
145 String businessKey = business.getBusinessKey();
146 if (businessKey != null)
147 element.setAttribute("businessKey",businessKey);
148 else
149 element.setAttribute("businessKey","");
150
151 String operator = business.getOperator();
152 if (operator != null)
153 element.setAttribute("operator",operator);
154
155 String authName = business.getAuthorizedName();
156 if (authName != null)
157 element.setAttribute("authorizedName",authName);
158
159 DiscoveryURLs discURLs = business.getDiscoveryURLs();
160 if (discURLs != null)
161 {
162 handler = maker.lookup(DiscoveryURLsHandler.TAG_NAME);
163 handler.marshal(discURLs,element);
164 }
165
166 Vector nameVector = business.getNameVector();
167 if ((nameVector!=null) && (nameVector.size() > 0))
168 {
169 handler = maker.lookup(NameHandler.TAG_NAME);
170 for (int i=0; i < nameVector.size(); i++)
171 handler.marshal((Name)nameVector.elementAt(i),element);
172 }
173
174 Vector descrVector = business.getDescriptionVector();
175 if ((descrVector!=null) && (descrVector.size() > 0))
176 {
177 handler = maker.lookup(DescriptionHandler.TAG_NAME);
178 for (int i=0; i < descrVector.size(); i++)
179 handler.marshal((Description)descrVector.elementAt(i),element);
180 }
181
182 Contacts contacts = business.getContacts();
183 if (contacts != null)
184 {
185 handler = maker.lookup(ContactsHandler.TAG_NAME);
186 handler.marshal(contacts,element);
187 }
188
189 BusinessServices services = business.getBusinessServices();
190 if (services != null)
191 {
192 handler = maker.lookup(BusinessServicesHandler.TAG_NAME);
193 handler.marshal(services,element);
194 }
195
196 IdentifierBag identifierBag = business.getIdentifierBag();
197 if ((identifierBag != null) && (identifierBag.getKeyedReferenceVector() != null) && (!identifierBag.getKeyedReferenceVector().isEmpty()))
198 {
199 handler = maker.lookup(IdentifierBagHandler.TAG_NAME);
200 handler.marshal(identifierBag,element);
201 }
202
203 CategoryBag categoryBag = business.getCategoryBag();
204 if ((categoryBag != null) && (categoryBag.getKeyedReferenceVector() != null) && (!categoryBag.getKeyedReferenceVector().isEmpty()))
205 {
206 handler = maker.lookup(CategoryBagHandler.TAG_NAME);
207 handler.marshal(categoryBag,element);
208 }
209
210 parent.appendChild(element);
211 }
212
213
214 /****************************************************************************/
215 /****************************** TEST DRIVER *********************************/
216 /****************************************************************************/
217
218
219 public static void main(String args[])
220 throws Exception
221 {
222 HandlerMaker maker = HandlerMaker.getInstance();
223 AbstractHandler handler = maker.lookup(BusinessEntityHandler.TAG_NAME);
224 Element parent = XMLUtils.newRootElement();
225 Element child = null;
226
227 OverviewDoc overDoc = new OverviewDoc();
228 overDoc.setOverviewURL("http://www.sviens.com/service.html");
229 overDoc.addDescription(new Description("over-doc Descr"));
230 overDoc.addDescription(new Description("over-doc Descr Two","en"));
231
232 InstanceDetails instDetails = new InstanceDetails();
233 instDetails.addDescription(new Description("body-isa-wunder"));
234 instDetails.addDescription(new Description("sweetchild-o-mine","it"));
235 instDetails.setInstanceParms("inst-det parameters");
236 instDetails.setOverviewDoc(overDoc);
237
238 TModelInstanceInfo tModInstInfo = new TModelInstanceInfo();
239 tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9");
240 tModInstInfo.addDescription(new Description("tMod-Inst-Info"));
241 tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es"));
242 tModInstInfo.setInstanceDetails(instDetails);
243
244 TModelInstanceDetails tModInstDet = new TModelInstanceDetails();
245 tModInstDet.addTModelInstanceInfo(tModInstInfo);
246
247 BindingTemplate binding = new BindingTemplate();
248 binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a");
249 binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31");
250 binding.addDescription(new Description("whatever"));
251 binding.addDescription(new Description("whatever too","fr"));
252 binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0"));
253 binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.sviens.com/service.wsdl"));
254 binding.setTModelInstanceDetails(tModInstDet);
255
256 BindingTemplates bindings = new BindingTemplates();
257 bindings.addBindingTemplate(binding);
258
259 CategoryBag catBag = new CategoryBag();
260 catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue"));
261 catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","catBagKeyName2","catBagKeyValue2"));
262
263 IdentifierBag idBag = new IdentifierBag();
264 idBag.addKeyedReference(new KeyedReference("idBagKeyName","idBagkeyValue"));
265 idBag.addKeyedReference(new KeyedReference("uuid:f78a135a-4769-4e79-8604-54d440314bc0","idBagKeyName2","idBagkeyValue2"));
266
267 DiscoveryURLs discURLs = new DiscoveryURLs();
268 discURLs.addDiscoveryURL(new DiscoveryURL("http","http://www.sviens.com/service.wsdl"));
269 discURLs.addDiscoveryURL(new DiscoveryURL("https","https://www.sviens.com/service.wsdl"));
270 discURLs.addDiscoveryURL(new DiscoveryURL("smtp","servicemngr@sviens.com"));
271
272 Address address = new Address();
273 address.setUseType("myAddressUseType");
274 address.setSortCode("sortThis");
275 address.setTModelKey(null);
276 address.addAddressLine(new AddressLine("AddressLine1","keyNameAttr","keyValueAttr"));
277 address.addAddressLine(new AddressLine("AddressLine2"));
278
279 Contact contact = new Contact();
280 contact.setUseType("myAddressUseType");
281 contact.setPersonNameValue("Bob Whatever");
282 contact.addDescription(new Description("Bob is a big fat jerk"));
283 contact.addDescription(new Description("obBay sIay a igBay atFay erkJay","es"));
284 contact.addEmail(new Email("bob@whatever.com"));
285 contact.addPhone(new Phone("(603)559-1901"));
286 contact.addAddress(address);
287
288 Contacts contacts = new Contacts();
289 contacts.addContact(contact);
290
291 BusinessService service = new BusinessService();
292 service.setServiceKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f");
293 service.setBusinessKey("b8cc7266-9eed-4675-b621-34697f252a77");
294 service.setBindingTemplates(bindings);
295 service.setCategoryBag(catBag);
296 service.addName(new Name("serviceNm"));
297 service.addName(new Name("serviceNm2","en"));
298 service.addDescription(new Description("service whatever"));
299 service.addDescription(new Description("service whatever too","it"));
300
301 BusinessServices services = new BusinessServices();
302 services.addBusinessService(service);
303 services.addBusinessService(service);
304
305 BusinessEntity business = new BusinessEntity();
306 business.setBusinessKey("6c0ac186-d36b-4b81-bd27-066a5fe0fc1f");
307 business.setAuthorizedName("Steve Viens");
308 business.setOperator("jUDDI");
309 business.addName(new Name("businessNm"));
310 business.addName(new Name("businessNm2","en"));
311 business.addDescription(new Description("business whatever"));
312 business.addDescription(new Description("business whatever too","fr"));
313 business.setDiscoveryURLs(discURLs);
314 business.setCategoryBag(catBag);
315 business.setIdentifierBag(idBag);
316 business.setContacts(contacts);
317 business.setBusinessServices(services);
318
319 System.out.println();
320
321 RegistryObject regObject = business;
322 handler.marshal(regObject,parent);
323 child = (Element)parent.getFirstChild();
324 parent.removeChild(child);
325 XMLUtils.writeXML(child,System.out);
326
327 System.out.println();
328
329 regObject = handler.unmarshal(child);
330 handler.marshal(regObject,parent);
331 child = (Element)parent.getFirstChild();
332 parent.removeChild(child);
333 XMLUtils.writeXML(child,System.out);
334 }
335 }