1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.ws.scout.util; |
18 | |
|
19 | |
import java.util.Arrays; |
20 | |
import java.util.Collection; |
21 | |
import java.util.Iterator; |
22 | |
import java.util.List; |
23 | |
import java.util.StringTokenizer; |
24 | |
|
25 | |
import javax.xml.registry.JAXRException; |
26 | |
import javax.xml.registry.infomodel.Association; |
27 | |
import javax.xml.registry.infomodel.Classification; |
28 | |
import javax.xml.registry.infomodel.ClassificationScheme; |
29 | |
import javax.xml.registry.infomodel.Concept; |
30 | |
import javax.xml.registry.infomodel.EmailAddress; |
31 | |
import javax.xml.registry.infomodel.ExternalIdentifier; |
32 | |
import javax.xml.registry.infomodel.ExternalLink; |
33 | |
import javax.xml.registry.infomodel.InternationalString; |
34 | |
import javax.xml.registry.infomodel.Key; |
35 | |
import javax.xml.registry.infomodel.LocalizedString; |
36 | |
import javax.xml.registry.infomodel.Organization; |
37 | |
import javax.xml.registry.infomodel.PostalAddress; |
38 | |
import javax.xml.registry.infomodel.RegistryObject; |
39 | |
import javax.xml.registry.infomodel.Service; |
40 | |
import javax.xml.registry.infomodel.ServiceBinding; |
41 | |
import javax.xml.registry.infomodel.Slot; |
42 | |
import javax.xml.registry.infomodel.SpecificationLink; |
43 | |
import javax.xml.registry.infomodel.TelephoneNumber; |
44 | |
import javax.xml.registry.infomodel.User; |
45 | |
|
46 | |
import org.apache.commons.logging.Log; |
47 | |
import org.apache.commons.logging.LogFactory; |
48 | |
import org.uddi.api_v3.*; |
49 | |
import org.apache.ws.scout.registry.infomodel.InternationalStringImpl; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | 0 | public class ScoutJaxrUddiV3Helper |
60 | |
{ |
61 | |
private static final String UDDI_ORG_TYPES = "uuid:C1ACF26D-9672-4404-9D70-39B756E62AB4"; |
62 | 0 | private static Log log = LogFactory.getLog(ScoutJaxrUddiV3Helper.class); |
63 | 0 | private static ObjectFactory objectFactory = new ObjectFactory(); |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public static Address getAddress(PostalAddress postalAddress) throws JAXRException { |
69 | 0 | Address address = objectFactory.createAddress(); |
70 | |
|
71 | 0 | AddressLine[] addarr = new AddressLine[6]; |
72 | |
|
73 | 0 | String stnum = postalAddress.getStreetNumber(); |
74 | 0 | String st = postalAddress.getStreet(); |
75 | 0 | String city = postalAddress.getCity(); |
76 | 0 | String country = postalAddress.getCountry(); |
77 | 0 | String code = postalAddress.getPostalCode(); |
78 | 0 | String state = postalAddress.getStateOrProvince(); |
79 | |
|
80 | 0 | AddressLine stnumAL = objectFactory.createAddressLine(); |
81 | 0 | stnumAL.setKeyName("STREET_NUMBER"); |
82 | 0 | if (stnum != null) { |
83 | 0 | stnumAL.setKeyValue(stnum); |
84 | |
} |
85 | |
|
86 | 0 | AddressLine stAL = objectFactory.createAddressLine(); |
87 | 0 | stAL.setKeyName("STREET"); |
88 | 0 | if (st != null) { |
89 | 0 | stAL.setKeyValue(st); |
90 | |
} |
91 | |
|
92 | 0 | AddressLine cityAL = objectFactory.createAddressLine(); |
93 | 0 | cityAL.setKeyName("CITY"); |
94 | 0 | if (city != null) { |
95 | 0 | cityAL.setKeyValue(city); |
96 | |
} |
97 | |
|
98 | 0 | AddressLine countryAL = objectFactory.createAddressLine(); |
99 | 0 | countryAL.setKeyName("COUNTRY"); |
100 | 0 | if (country != null) { |
101 | 0 | countryAL.setKeyValue(country); |
102 | |
} |
103 | |
|
104 | 0 | AddressLine codeAL = objectFactory.createAddressLine(); |
105 | 0 | codeAL.setKeyName("POSTALCODE"); |
106 | 0 | if (code != null) { |
107 | 0 | codeAL.setKeyValue(code); |
108 | |
} |
109 | |
|
110 | 0 | AddressLine stateAL = objectFactory.createAddressLine(); |
111 | 0 | stateAL.setKeyName("STATE"); |
112 | 0 | if (state != null) { |
113 | 0 | stateAL.setKeyValue(state); |
114 | |
} |
115 | |
|
116 | |
|
117 | 0 | addarr[0] = stnumAL; |
118 | 0 | addarr[1] = stAL; |
119 | 0 | addarr[2] = cityAL; |
120 | 0 | addarr[3] = countryAL; |
121 | 0 | addarr[4] = codeAL; |
122 | 0 | addarr[5] = stateAL; |
123 | |
|
124 | 0 | address.getAddressLine().addAll(Arrays.asList(addarr)); |
125 | |
|
126 | 0 | return address; |
127 | |
} |
128 | |
|
129 | |
public static BindingTemplate getBindingTemplateFromJAXRSB( |
130 | |
ServiceBinding serviceBinding) throws JAXRException { |
131 | 0 | BindingTemplate bt = objectFactory.createBindingTemplate(); |
132 | 0 | if (serviceBinding.getKey() != null && serviceBinding.getKey().getId() != null) { |
133 | 0 | bt.setBindingKey(serviceBinding.getKey().getId()); |
134 | |
} else { |
135 | 0 | bt.setBindingKey(""); |
136 | |
} |
137 | |
|
138 | |
try { |
139 | |
|
140 | 0 | String accessuri = serviceBinding.getAccessURI(); |
141 | 0 | if (accessuri != null) { |
142 | 0 | AccessPoint accessPoint = objectFactory.createAccessPoint(); |
143 | 0 | accessPoint.setUseType(getUseType(accessuri)); |
144 | 0 | accessPoint.setValue(accessuri); |
145 | 0 | bt.setAccessPoint(accessPoint); |
146 | |
} |
147 | 0 | ServiceBinding sb = serviceBinding.getTargetBinding(); |
148 | 0 | if (sb != null) { |
149 | 0 | HostingRedirector red = objectFactory.createHostingRedirector(); |
150 | 0 | Key key = sb.getKey(); |
151 | 0 | if (key != null && key.getId() != null) { |
152 | 0 | red.setBindingKey(key.getId()); |
153 | |
} else { |
154 | 0 | red.setBindingKey(""); |
155 | |
} |
156 | 0 | bt.setHostingRedirector(red); |
157 | 0 | } else { |
158 | 0 | if (bt.getAccessPoint() == null) { |
159 | 0 | bt.setAccessPoint(objectFactory.createAccessPoint()); |
160 | |
} |
161 | |
} |
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | 0 | Service svc = serviceBinding.getService(); |
167 | 0 | if (svc != null && svc.getKey() != null && svc.getKey().getId() != null) { |
168 | 0 | bt.setServiceKey(svc.getKey().getId()); |
169 | |
} |
170 | |
|
171 | 0 | InternationalString idesc = serviceBinding.getDescription(); |
172 | |
|
173 | 0 | addDescriptions(bt.getDescription(), idesc); |
174 | |
|
175 | |
|
176 | 0 | Collection<SpecificationLink> slcol = serviceBinding.getSpecificationLinks(); |
177 | 0 | TModelInstanceDetails tid = objectFactory.createTModelInstanceDetails(); |
178 | 0 | if (slcol != null && !slcol.isEmpty()) { |
179 | 0 | Iterator<SpecificationLink> iter = slcol.iterator(); |
180 | 0 | while (iter.hasNext()) { |
181 | 0 | SpecificationLink slink = (SpecificationLink) iter.next(); |
182 | |
|
183 | 0 | TModelInstanceInfo emptyTInfo = objectFactory.createTModelInstanceInfo(); |
184 | 0 | tid.getTModelInstanceInfo().add(emptyTInfo); |
185 | |
|
186 | 0 | RegistryObject specificationObject = slink.getSpecificationObject(); |
187 | 0 | if (specificationObject.getKey() != null && specificationObject.getKey().getId() != null) { |
188 | 0 | emptyTInfo.setTModelKey(specificationObject.getKey().getId()); |
189 | 0 | if (specificationObject.getDescription()!=null) { |
190 | 0 | for (Object o : specificationObject.getDescription().getLocalizedStrings()) { |
191 | 0 | LocalizedString locDesc = (LocalizedString) o; |
192 | 0 | Description description = objectFactory.createDescription(); |
193 | 0 | emptyTInfo.getDescription().add(description); |
194 | 0 | description.setValue(locDesc.getValue()); |
195 | 0 | description.setLang(locDesc.getLocale().getLanguage()); |
196 | 0 | } |
197 | |
} |
198 | 0 | Collection<ExternalLink> externalLinks = slink.getExternalLinks(); |
199 | 0 | if (externalLinks!=null && externalLinks.size()>0) { |
200 | 0 | for (ExternalLink link : externalLinks) { |
201 | 0 | InstanceDetails ids = objectFactory.createInstanceDetails(); |
202 | 0 | emptyTInfo.setInstanceDetails(ids); |
203 | 0 | if (link.getDescription()!=null) { |
204 | 0 | Description description = objectFactory.createDescription(); |
205 | 0 | ids.getDescription().add(description); |
206 | 0 | description.setValue(link.getDescription().getValue()); |
207 | |
} |
208 | 0 | if (link.getExternalURI()!=null) { |
209 | 0 | OverviewDoc overviewDoc = objectFactory.createOverviewDoc(); |
210 | 0 | ids.getOverviewDoc().add(overviewDoc); |
211 | 0 | org.uddi.api_v3.OverviewURL ourl = new org.uddi.api_v3.OverviewURL(); |
212 | 0 | ourl.setValue(link.getExternalURI()); |
213 | 0 | overviewDoc.setOverviewURL(ourl); |
214 | |
} |
215 | 0 | } |
216 | |
} |
217 | |
} |
218 | 0 | } |
219 | |
} |
220 | 0 | if (tid.getTModelInstanceInfo().size() != 0) { |
221 | 0 | bt.setTModelInstanceDetails(tid); |
222 | |
} |
223 | 0 | log.debug("BindingTemplate=" + bt.toString()); |
224 | 0 | } catch (Exception ud) { |
225 | 0 | throw new JAXRException("Apache JAXR Impl:", ud); |
226 | 0 | } |
227 | 0 | return bt; |
228 | |
} |
229 | |
|
230 | |
public static PublisherAssertion getPubAssertionFromJAXRAssociation( |
231 | |
Association association) throws JAXRException { |
232 | 0 | PublisherAssertion pa = objectFactory.createPublisherAssertion(); |
233 | |
try { |
234 | 0 | if (association.getSourceObject().getKey() != null && |
235 | |
association.getSourceObject().getKey().getId() != null) { |
236 | 0 | pa.setFromKey(association.getSourceObject().getKey().getId()); |
237 | |
} |
238 | |
|
239 | 0 | if (association.getTargetObject().getKey() != null && |
240 | |
association.getTargetObject().getKey().getId() != null) { |
241 | 0 | pa.setToKey(association.getTargetObject().getKey().getId()); |
242 | |
} |
243 | 0 | Concept c = association.getAssociationType(); |
244 | 0 | String v = c.getValue(); |
245 | 0 | KeyedReference kr = objectFactory.createKeyedReference(); |
246 | 0 | Key key = c.getKey(); |
247 | 0 | if (key == null) { |
248 | |
|
249 | |
|
250 | 0 | key = c.getClassificationScheme().getKey(); |
251 | |
} |
252 | 0 | if (key != null && key.getId() != null) { |
253 | 0 | kr.setTModelKey(key.getId()); |
254 | |
} |
255 | 0 | kr.setKeyName("Concept"); |
256 | |
|
257 | 0 | if (v != null) { |
258 | 0 | kr.setKeyValue(v); |
259 | |
} |
260 | |
|
261 | 0 | pa.setKeyedReference(kr); |
262 | 0 | } catch (Exception ud) { |
263 | 0 | throw new JAXRException("Apache JAXR Impl:", ud); |
264 | 0 | } |
265 | 0 | return pa; |
266 | |
} |
267 | |
|
268 | |
public static PublisherAssertion getPubAssertionFromJAXRAssociationKey( |
269 | |
String key) throws JAXRException { |
270 | 0 | PublisherAssertion pa = objectFactory.createPublisherAssertion(); |
271 | |
try { |
272 | 0 | StringTokenizer token = new StringTokenizer(key, ":"); |
273 | 0 | if (token.hasMoreTokens()) { |
274 | 0 | pa.setFromKey(getToken(token.nextToken())); |
275 | 0 | pa.setToKey(getToken(token.nextToken())); |
276 | 0 | KeyedReference kr = objectFactory.createKeyedReference(); |
277 | |
|
278 | 0 | String str = getToken(token.nextToken()); |
279 | 0 | if ("UUID".equals(str)) |
280 | 0 | str += ":" + getToken(token.nextToken()); |
281 | 0 | kr.setTModelKey(str); |
282 | 0 | kr.setKeyName(getToken(token.nextToken())); |
283 | 0 | kr.setKeyValue(getToken(token.nextToken())); |
284 | 0 | pa.setKeyedReference(kr); |
285 | |
} |
286 | |
|
287 | 0 | } catch (Exception ud) { |
288 | 0 | throw new JAXRException("Apache JAXR Impl:", ud); |
289 | 0 | } |
290 | 0 | return pa; |
291 | |
} |
292 | |
|
293 | |
public static BusinessService getBusinessServiceFromJAXRService( |
294 | |
Service service) throws JAXRException { |
295 | 0 | BusinessService bs = objectFactory.createBusinessService(); |
296 | |
try { |
297 | 0 | InternationalString iname = service.getName(); |
298 | |
|
299 | 0 | addNames(bs.getName(), iname); |
300 | |
|
301 | 0 | InternationalString idesc = service.getDescription(); |
302 | |
|
303 | 0 | addDescriptions(bs.getDescription(), idesc); |
304 | |
|
305 | 0 | Organization o = service.getProvidingOrganization(); |
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | 0 | if (o != null) { |
311 | 0 | Key k = o.getKey(); |
312 | |
|
313 | 0 | if (k != null && k.getId() != null) { |
314 | 0 | bs.setBusinessKey(k.getId()); |
315 | |
} |
316 | |
|
317 | 0 | } else { |
318 | |
|
319 | |
|
320 | |
|
321 | 0 | throw new JAXRException( |
322 | |
"Service has no associated organization"); |
323 | |
} |
324 | |
|
325 | 0 | if (service.getKey() != null && service.getKey().getId() != null) { |
326 | 0 | bs.setServiceKey(service.getKey().getId()); |
327 | |
} else { |
328 | 0 | bs.setServiceKey(""); |
329 | |
} |
330 | |
|
331 | 0 | CategoryBag catBag = getCategoryBagFromClassifications(service.getClassifications()); |
332 | 0 | if (catBag!=null) { |
333 | 0 | bs.setCategoryBag(catBag); |
334 | |
} |
335 | |
|
336 | |
|
337 | 0 | BindingTemplates bt = getBindingTemplates(service.getServiceBindings()); |
338 | 0 | if (bt != null) { |
339 | 0 | bs.setBindingTemplates(bt); |
340 | |
} |
341 | |
|
342 | 0 | log.debug("BusinessService=" + bs.toString()); |
343 | 0 | } catch (Exception ud) { |
344 | 0 | throw new JAXRException("Apache JAXR Impl:", ud); |
345 | 0 | } |
346 | 0 | return bs; |
347 | |
} |
348 | |
|
349 | |
public static TModel getTModelFromJAXRClassificationScheme( |
350 | |
ClassificationScheme classificationScheme) throws JAXRException { |
351 | 0 | TModel tm = objectFactory.createTModel(); |
352 | |
try { |
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | 0 | Key k = classificationScheme.getKey(); |
358 | |
|
359 | 0 | if (k != null && k.getId() != null) { |
360 | 0 | tm.setTModelKey(k.getId()); |
361 | |
} else { |
362 | 0 | tm.setTModelKey(""); |
363 | |
} |
364 | |
|
365 | |
|
366 | |
|
367 | |
|
368 | |
|
369 | 0 | Slot s = classificationScheme.getSlot("authorizedName"); |
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | 0 | s = classificationScheme.getSlot("operator"); |
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | 0 | InternationalString iname = classificationScheme.getName(); |
382 | |
|
383 | 0 | tm.setName(getFirstName(iname)); |
384 | |
|
385 | 0 | InternationalString idesc = classificationScheme.getDescription(); |
386 | |
|
387 | 0 | addDescriptions(tm.getDescription(), idesc); |
388 | |
|
389 | 0 | IdentifierBag idBag = getIdentifierBagFromExternalIdentifiers(classificationScheme.getExternalIdentifiers()); |
390 | 0 | if (idBag!=null) { |
391 | 0 | tm.setIdentifierBag(idBag); |
392 | |
} |
393 | 0 | CategoryBag catBag = getCategoryBagFromClassifications(classificationScheme.getClassifications()); |
394 | 0 | if (catBag!=null) { |
395 | 0 | tm.setCategoryBag(catBag); |
396 | |
} |
397 | |
|
398 | |
|
399 | 0 | } catch (Exception ud) { |
400 | 0 | throw new JAXRException("Apache JAXR Impl:", ud); |
401 | 0 | } |
402 | 0 | return tm; |
403 | |
} |
404 | |
|
405 | |
public static TModel getTModelFromJAXRConcept(Concept concept) |
406 | |
throws JAXRException { |
407 | 0 | TModel tm = objectFactory.createTModel(); |
408 | 0 | if (concept == null) |
409 | 0 | return null; |
410 | |
try { |
411 | 0 | Key key = concept.getKey(); |
412 | 0 | if (key != null && key.getId() != null) |
413 | 0 | tm.setTModelKey(key.getId()); |
414 | 0 | Slot sl1 = concept.getSlot("authorizedName"); |
415 | |
|
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
|
421 | |
|
422 | |
|
423 | 0 | InternationalString iname = concept.getName(); |
424 | |
|
425 | 0 | tm.setName(getFirstName(iname)); |
426 | |
|
427 | 0 | InternationalString idesc = concept.getDescription(); |
428 | |
|
429 | 0 | addDescriptions(tm.getDescription(), idesc); |
430 | |
|
431 | |
|
432 | 0 | Collection<ExternalLink> externalLinks = concept.getExternalLinks(); |
433 | 0 | if(externalLinks != null && externalLinks.size() > 0) |
434 | |
{ |
435 | 0 | tm.getOverviewDoc().add(getOverviewDocFromExternalLink((ExternalLink)externalLinks.iterator().next())); |
436 | |
} |
437 | |
|
438 | 0 | IdentifierBag idBag = getIdentifierBagFromExternalIdentifiers(concept.getExternalIdentifiers()); |
439 | 0 | if (idBag!=null) { |
440 | 0 | tm.setIdentifierBag(idBag); |
441 | |
} |
442 | 0 | CategoryBag catBag = getCategoryBagFromClassifications(concept.getClassifications()); |
443 | 0 | if (catBag!=null) { |
444 | 0 | tm.setCategoryBag(catBag); |
445 | |
} |
446 | |
|
447 | 0 | } catch (Exception ud) { |
448 | 0 | throw new JAXRException("Apache JAXR Impl:", ud); |
449 | 0 | } |
450 | 0 | return tm; |
451 | |
} |
452 | |
|
453 | |
private static void addDescriptions(List<Description> descripions, InternationalString idesc) throws JAXRException { |
454 | 0 | if (idesc != null) { |
455 | 0 | for (Object o : idesc.getLocalizedStrings()) { |
456 | 0 | LocalizedString locName = (LocalizedString) o; |
457 | 0 | Description desc = objectFactory.createDescription(); |
458 | 0 | descripions.add(desc); |
459 | 0 | desc.setValue(locName.getValue()); |
460 | 0 | desc.setLang(locName.getLocale().getLanguage()); |
461 | 0 | } |
462 | |
} |
463 | 0 | } |
464 | |
|
465 | |
private static Name getFirstName(InternationalString iname) throws JAXRException { |
466 | 0 | for (Object o : iname.getLocalizedStrings()) { |
467 | 0 | LocalizedString locName = (LocalizedString) o; |
468 | 0 | Name name = objectFactory.createName(); |
469 | 0 | name.setValue(locName.getValue()); |
470 | 0 | name.setLang(locName.getLocale().getLanguage()); |
471 | 0 | return name; |
472 | |
} |
473 | 0 | return null; |
474 | |
} |
475 | |
private static void addNames(List<Name> names, InternationalString iname) throws JAXRException { |
476 | 0 | for (Object o : iname.getLocalizedStrings()) { |
477 | 0 | LocalizedString locName = (LocalizedString) o; |
478 | 0 | Name name = objectFactory.createName(); |
479 | 0 | name.setValue(locName.getValue()); |
480 | 0 | name.setLang(locName.getLocale().getLanguage()); |
481 | 0 | names.add(name); |
482 | 0 | } |
483 | 0 | } |
484 | |
|
485 | |
public static BusinessEntity getBusinessEntityFromJAXROrg(Organization organization) |
486 | |
throws JAXRException { |
487 | 0 | BusinessEntity biz = objectFactory.createBusinessEntity(); |
488 | 0 | BusinessServices bss = objectFactory.createBusinessServices(); |
489 | 0 | BusinessService[] barr = new BusinessService[0]; |
490 | |
|
491 | |
try { |
492 | |
|
493 | 0 | Key key = organization.getKey(); |
494 | 0 | if (key != null && key.getId() != null) { |
495 | 0 | biz.setBusinessKey(key.getId()); |
496 | |
} else { |
497 | 0 | biz.setBusinessKey(""); |
498 | |
} |
499 | |
|
500 | |
|
501 | 0 | InternationalString iname = organization.getName(); |
502 | |
|
503 | 0 | if (iname != null) { |
504 | 0 | addNames(biz.getName(), iname); |
505 | |
} |
506 | |
|
507 | 0 | InternationalString idesc = organization.getDescription(); |
508 | |
|
509 | 0 | addDescriptions(biz.getDescription(), idesc); |
510 | |
|
511 | 0 | if (organization.getPrimaryContact() != null && |
512 | |
organization.getPrimaryContact().getPersonName()!= null && |
513 | |
organization.getPrimaryContact().getPersonName().getFullName() != null) { |
514 | |
|
515 | |
|
516 | |
|
517 | |
} |
518 | |
|
519 | 0 | Collection<Service> s = organization.getServices(); |
520 | 0 | log.debug("?Org has services=" + s.isEmpty()); |
521 | |
|
522 | 0 | barr = new BusinessService[s.size()]; |
523 | |
|
524 | 0 | Iterator<Service> iter = s.iterator(); |
525 | 0 | int barrPos = 0; |
526 | 0 | while (iter.hasNext()) { |
527 | 0 | BusinessService bs = ScoutJaxrUddiV3Helper |
528 | |
.getBusinessServiceFromJAXRService((Service) iter |
529 | |
.next()); |
530 | 0 | barr[barrPos] = bs; |
531 | 0 | barrPos++; |
532 | 0 | } |
533 | |
|
534 | |
|
535 | |
|
536 | |
|
537 | |
|
538 | |
|
539 | |
|
540 | 0 | Contacts cts = objectFactory.createContacts(); |
541 | 0 | Contact[] carr = new Contact[0]; |
542 | |
|
543 | 0 | User primaryContact = organization.getPrimaryContact(); |
544 | 0 | Collection<User> users = organization.getUsers(); |
545 | |
|
546 | |
|
547 | |
|
548 | |
|
549 | 0 | int carrSize = 0; |
550 | |
|
551 | 0 | if (primaryContact != null) { |
552 | 0 | carrSize += 1; |
553 | |
} |
554 | |
|
555 | |
|
556 | 0 | Iterator<User> it = users.iterator(); |
557 | 0 | while (it.hasNext()) { |
558 | 0 | User u = (User) it.next(); |
559 | 0 | if (u != primaryContact) { |
560 | 0 | carrSize++; |
561 | |
} |
562 | 0 | } |
563 | |
|
564 | 0 | carr = new Contact[carrSize]; |
565 | |
|
566 | |
|
567 | |
|
568 | |
|
569 | 0 | if (primaryContact != null) { |
570 | 0 | Contact ct = getContactFromJAXRUser(primaryContact); |
571 | 0 | carr[0] = ct; |
572 | |
} |
573 | |
|
574 | 0 | it = users.iterator(); |
575 | 0 | int carrPos = 1; |
576 | 0 | while (it.hasNext()) { |
577 | 0 | User u = (User) it.next(); |
578 | |
|
579 | 0 | if (u != primaryContact) { |
580 | 0 | Contact ct = getContactFromJAXRUser(u); |
581 | 0 | carr[carrPos] = ct; |
582 | 0 | carrPos++; |
583 | |
} |
584 | 0 | } |
585 | |
|
586 | 0 | bss.getBusinessService().addAll(Arrays.asList(barr)); |
587 | 0 | if (carr.length>0) { |
588 | 0 | cts.getContact().addAll(Arrays.asList(carr)); |
589 | 0 | biz.setContacts(cts); |
590 | |
} |
591 | 0 | biz.setBusinessServices(bss); |
592 | |
|
593 | |
|
594 | 0 | Iterator<ExternalLink> exiter = organization.getExternalLinks().iterator(); |
595 | 0 | DiscoveryURLs emptyDUs = null; |
596 | 0 | boolean first = true; |
597 | 0 | while (exiter.hasNext()) { |
598 | 0 | ExternalLink link = (ExternalLink) exiter.next(); |
599 | |
|
600 | 0 | if (first) { |
601 | 0 | emptyDUs = objectFactory.createDiscoveryURLs(); |
602 | 0 | biz.setDiscoveryURLs(emptyDUs); |
603 | 0 | first = false; |
604 | |
} |
605 | 0 | DiscoveryURL emptyDU = objectFactory.createDiscoveryURL(); |
606 | 0 | emptyDUs.getDiscoveryURL().add(emptyDU); |
607 | 0 | emptyDU.setUseType("businessEntityExt"); |
608 | |
|
609 | 0 | if (link.getExternalURI() != null) { |
610 | 0 | emptyDU.setValue(link.getExternalURI()); |
611 | |
} |
612 | 0 | } |
613 | |
|
614 | 0 | IdentifierBag idBag = getIdentifierBagFromExternalIdentifiers(organization.getExternalIdentifiers()); |
615 | 0 | if (idBag!=null) { |
616 | 0 | biz.setIdentifierBag(idBag); |
617 | |
} |
618 | 0 | CategoryBag catBag = getCategoryBagFromClassifications(organization.getClassifications()); |
619 | 0 | if (catBag!=null) { |
620 | 0 | biz.setCategoryBag(catBag); |
621 | |
} |
622 | |
|
623 | 0 | } catch (Exception ud) { |
624 | 0 | throw new JAXRException("Apache JAXR Impl:", ud); |
625 | 0 | } |
626 | 0 | return biz; |
627 | |
} |
628 | |
|
629 | |
|
630 | |
|
631 | |
|
632 | |
|
633 | |
public static Contact getContactFromJAXRUser(User user) |
634 | |
throws JAXRException { |
635 | 0 | Contact ct = objectFactory.createContact(); |
636 | 0 | if (user == null) { |
637 | 0 | return null; |
638 | |
} |
639 | |
|
640 | 0 | Address[] addarr = new Address[0]; |
641 | 0 | Phone[] phonearr = new Phone[0]; |
642 | 0 | Email[] emailarr = new Email[0]; |
643 | |
try { |
644 | |
|
645 | 0 | if (user.getPersonName() != null && user.getPersonName().getFullName() != null) { |
646 | 0 | org.uddi.api_v3.PersonName pn = new org.uddi.api_v3.PersonName(); |
647 | 0 | pn.setValue(user.getPersonName().getFullName()); |
648 | 0 | ct.getPersonName().add(pn); |
649 | |
} |
650 | |
|
651 | 0 | if (user.getType() != null) { |
652 | 0 | ct.setUseType(user.getType()); |
653 | |
} |
654 | |
|
655 | 0 | Collection<PostalAddress> postc = user.getPostalAddresses(); |
656 | |
|
657 | 0 | addarr = new Address[postc.size()]; |
658 | |
|
659 | 0 | Iterator<PostalAddress> iterator = postc.iterator(); |
660 | 0 | int addarrPos = 0; |
661 | 0 | while (iterator.hasNext()) { |
662 | 0 | PostalAddress post = (PostalAddress) iterator.next(); |
663 | 0 | addarr[addarrPos] = ScoutJaxrUddiV3Helper.getAddress(post); |
664 | 0 | addarrPos++; |
665 | 0 | } |
666 | |
|
667 | 0 | Collection ph = user.getTelephoneNumbers(null); |
668 | |
|
669 | 0 | phonearr = new Phone[ph.size()]; |
670 | |
|
671 | 0 | Iterator it = ph.iterator(); |
672 | 0 | int phonearrPos = 0; |
673 | 0 | while (it.hasNext()) { |
674 | 0 | TelephoneNumber t = (TelephoneNumber) it.next(); |
675 | 0 | Phone phone = objectFactory.createPhone(); |
676 | 0 | String str = t.getNumber(); |
677 | 0 | log.debug("Telephone=" + str); |
678 | |
|
679 | |
|
680 | |
|
681 | 0 | if (str != null) { |
682 | 0 | phone.setValue(str); |
683 | |
} else { |
684 | 0 | phone.setValue(""); |
685 | |
} |
686 | |
|
687 | 0 | phonearr[phonearrPos] = phone; |
688 | 0 | phonearrPos++; |
689 | 0 | } |
690 | |
|
691 | |
|
692 | 0 | Collection ec = user.getEmailAddresses(); |
693 | |
|
694 | 0 | emailarr = new Email[ec.size()]; |
695 | |
|
696 | 0 | Iterator iter = ec.iterator(); |
697 | 0 | int emailarrPos = 0; |
698 | 0 | while (iter.hasNext()) { |
699 | 0 | EmailAddress ea = (EmailAddress) iter.next(); |
700 | 0 | Email email = objectFactory.createEmail(); |
701 | |
|
702 | 0 | if (ea.getAddress() != null) { |
703 | 0 | email.setValue(ea.getAddress()); |
704 | |
} |
705 | |
|
706 | |
|
707 | 0 | if (ea.getType() != null) { |
708 | 0 | email.setUseType(ea.getType()); |
709 | |
} |
710 | |
|
711 | 0 | emailarr[emailarrPos] = email; |
712 | 0 | emailarrPos++; |
713 | 0 | } |
714 | 0 | ct.getAddress().addAll(Arrays.asList(addarr)); |
715 | 0 | ct.getPhone().addAll(Arrays.asList(phonearr)); |
716 | 0 | ct.getEmail().addAll(Arrays.asList(emailarr)); |
717 | 0 | } catch (Exception ud) { |
718 | 0 | throw new JAXRException("Apache JAXR Impl:", ud); |
719 | 0 | } |
720 | 0 | return ct; |
721 | |
} |
722 | |
|
723 | |
private static String getToken(String tokenstr) { |
724 | |
|
725 | 0 | if (tokenstr.equals("NULL")) |
726 | 0 | tokenstr = ""; |
727 | 0 | return tokenstr; |
728 | |
} |
729 | |
|
730 | |
private static String getUseType(String accessuri) { |
731 | 0 | String acc = accessuri.toLowerCase(); |
732 | 0 | String uri = "other"; |
733 | 0 | if (acc.startsWith("http:")) |
734 | 0 | uri = "http:"; |
735 | 0 | else if (acc.startsWith("https:")) |
736 | 0 | uri = "https:"; |
737 | 0 | else if (acc.startsWith("ftp:")) |
738 | 0 | uri = "ftp:"; |
739 | 0 | else if (acc.startsWith("phone:")) |
740 | 0 | uri = "phone:"; |
741 | |
|
742 | 0 | return uri; |
743 | |
} |
744 | |
|
745 | |
|
746 | |
|
747 | |
|
748 | |
|
749 | |
|
750 | |
|
751 | |
|
752 | |
|
753 | |
|
754 | |
|
755 | |
|
756 | |
|
757 | |
|
758 | |
public static CategoryBag getCategoryBagFromClassifications(Collection classifications) throws JAXRException { |
759 | |
try { |
760 | 0 | if (classifications == null || classifications.size()==0) |
761 | 0 | return null; |
762 | |
|
763 | |
|
764 | 0 | CategoryBag cbag = objectFactory.createCategoryBag(); |
765 | 0 | Iterator classiter = classifications.iterator(); |
766 | 0 | while (classiter.hasNext()) { |
767 | 0 | Classification classification = (Classification) classiter.next(); |
768 | 0 | if (classification != null ) { |
769 | 0 | KeyedReference keyr = objectFactory.createKeyedReference(); |
770 | 0 | cbag.getKeyedReference().add(keyr); |
771 | |
|
772 | 0 | InternationalStringImpl iname = null; |
773 | 0 | String value = null; |
774 | 0 | ClassificationScheme scheme = classification.getClassificationScheme(); |
775 | 0 | if (scheme==null || (classification.isExternal() && classification.getConcept()==null)) { |
776 | |
|
777 | |
|
778 | |
|
779 | |
|
780 | |
|
781 | |
|
782 | |
|
783 | 0 | keyr.setTModelKey(UDDI_ORG_TYPES); |
784 | 0 | keyr.setKeyValue("specification"); |
785 | |
} else { |
786 | 0 | if (classification.isExternal()) { |
787 | 0 | iname = (InternationalStringImpl) ((RegistryObject) classification).getName(); |
788 | 0 | value = classification.getValue(); |
789 | |
} else { |
790 | 0 | Concept concept = classification.getConcept(); |
791 | 0 | if (concept != null) { |
792 | 0 | iname = (InternationalStringImpl) ((RegistryObject) concept).getName(); |
793 | 0 | value = concept.getValue(); |
794 | 0 | scheme = concept.getClassificationScheme(); |
795 | |
} |
796 | |
} |
797 | |
|
798 | 0 | String name = iname.getValue(); |
799 | 0 | if (name != null) |
800 | 0 | keyr.setKeyName(name); |
801 | |
|
802 | 0 | if (value != null) |
803 | 0 | keyr.setKeyValue(value); |
804 | |
|
805 | 0 | if (scheme != null) { |
806 | 0 | Key key = scheme.getKey(); |
807 | 0 | if (key != null && key.getId() != null) |
808 | 0 | keyr.setTModelKey(key.getId()); |
809 | |
} |
810 | |
} |
811 | |
} |
812 | 0 | } |
813 | 0 | return cbag; |
814 | 0 | } catch (Exception ud) { |
815 | 0 | throw new JAXRException("Apache JAXR Impl:", ud); |
816 | |
} |
817 | |
} |
818 | |
|
819 | |
public static TModelBag getTModelBagFromSpecifications(Collection specifications) throws JAXRException { |
820 | |
try { |
821 | 0 | if (specifications == null || specifications.size()==0) |
822 | 0 | return null; |
823 | |
|
824 | |
|
825 | 0 | TModelBag tbag = objectFactory.createTModelBag(); |
826 | 0 | Iterator speciter = specifications.iterator(); |
827 | 0 | while (speciter.hasNext()) { |
828 | 0 | RegistryObject registryobject = (RegistryObject) speciter.next(); |
829 | 0 | if (registryobject instanceof SpecificationLink) { |
830 | 0 | SpecificationLink specificationlink = (SpecificationLink) registryobject; |
831 | 0 | if (specificationlink.getSpecificationObject() != null) { |
832 | 0 | RegistryObject ro = specificationlink.getSpecificationObject(); |
833 | 0 | if (ro.getKey() != null) { |
834 | 0 | Key key = ro.getKey(); |
835 | 0 | tbag.getTModelKey().add(key.toString()); |
836 | |
} |
837 | |
} |
838 | 0 | } else { |
839 | 0 | log.info("ebXML case - the RegistryObject is an ExtrinsicObject, Not implemented"); |
840 | |
} |
841 | 0 | } |
842 | 0 | return tbag; |
843 | 0 | } catch (Exception ud) { |
844 | 0 | throw new JAXRException("Apache JAXR Impl:", ud); |
845 | |
} |
846 | |
} |
847 | |
|
848 | |
|
849 | |
|
850 | |
|
851 | |
|
852 | |
|
853 | |
|
854 | |
|
855 | |
public static IdentifierBag getIdentifierBagFromExternalIdentifiers(Collection identifiers) throws JAXRException { |
856 | |
try { |
857 | 0 | if (identifiers == null || identifiers.size()==0) |
858 | 0 | return null; |
859 | |
|
860 | |
|
861 | 0 | IdentifierBag ibag = objectFactory.createIdentifierBag(); |
862 | 0 | Iterator iditer = identifiers.iterator(); |
863 | 0 | while (iditer.hasNext()) { |
864 | 0 | ExternalIdentifier extid = (ExternalIdentifier) iditer.next(); |
865 | 0 | if (extid != null ) { |
866 | 0 | KeyedReference keyr = objectFactory.createKeyedReference(); |
867 | 0 | ibag.getKeyedReference().add(keyr); |
868 | |
|
869 | 0 | InternationalStringImpl iname = (InternationalStringImpl) ((RegistryObject) extid).getName(); |
870 | 0 | String value = extid.getValue(); |
871 | 0 | ClassificationScheme scheme = extid.getIdentificationScheme(); |
872 | |
|
873 | 0 | String name = iname.getValue(); |
874 | 0 | if (name != null) |
875 | 0 | keyr.setKeyName(name); |
876 | |
|
877 | 0 | if (value != null) |
878 | 0 | keyr.setKeyValue(value); |
879 | |
|
880 | 0 | if (scheme != null) { |
881 | 0 | Key key = scheme.getKey(); |
882 | 0 | if (key != null && key.getId() != null) |
883 | 0 | keyr.setTModelKey(key.getId()); |
884 | |
} |
885 | |
} |
886 | 0 | } |
887 | 0 | return ibag; |
888 | 0 | } catch (Exception ud) { |
889 | 0 | throw new JAXRException("Apache JAXR Impl:", ud); |
890 | |
} |
891 | |
} |
892 | |
|
893 | |
private static OverviewDoc getOverviewDocFromExternalLink(ExternalLink link) |
894 | |
throws JAXRException |
895 | |
{ |
896 | 0 | OverviewDoc od = objectFactory.createOverviewDoc(); |
897 | 0 | String url = link.getExternalURI(); |
898 | 0 | if(url != null) { |
899 | 0 | org.uddi.api_v3.OverviewURL ourl = new org.uddi.api_v3.OverviewURL(); |
900 | 0 | ourl.setValue(url.toString()); |
901 | 0 | od.setOverviewURL(ourl); |
902 | |
} |
903 | 0 | InternationalString extDesc = link.getDescription(); |
904 | 0 | if(extDesc != null) { |
905 | 0 | Description description = objectFactory.createDescription(); |
906 | 0 | od.getDescription().add(description); |
907 | 0 | description.setValue(extDesc.getValue()); |
908 | |
} |
909 | 0 | return od; |
910 | |
} |
911 | |
|
912 | |
private static BindingTemplates getBindingTemplates(Collection serviceBindings) |
913 | |
throws JAXRException { |
914 | 0 | BindingTemplates bt = null; |
915 | 0 | if(serviceBindings != null && serviceBindings.size() > 0) { |
916 | 0 | bt = objectFactory.createBindingTemplates(); |
917 | 0 | Iterator iter = serviceBindings.iterator(); |
918 | 0 | int currLoc = 0; |
919 | 0 | BindingTemplate[] bindingTemplateArray = new BindingTemplate[serviceBindings.size()]; |
920 | 0 | while(iter.hasNext()) { |
921 | 0 | ServiceBinding sb = (ServiceBinding)iter.next(); |
922 | 0 | bindingTemplateArray[currLoc] = getBindingTemplateFromJAXRSB(sb); |
923 | 0 | currLoc++; |
924 | 0 | } |
925 | 0 | if (bindingTemplateArray != null) { |
926 | 0 | bt.getBindingTemplate().addAll(Arrays.asList(bindingTemplateArray)); |
927 | |
} |
928 | |
} |
929 | 0 | return bt; |
930 | |
} |
931 | |
} |