This project has retired. For details please refer to its Attic page.
RegistryV3Impl xref
View Javadoc
1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.ws.scout.registry;
17  
18  import java.io.ByteArrayInputStream;
19  import java.io.ByteArrayOutputStream;
20  import java.io.IOException;
21  import java.io.StringReader;
22  import java.net.URI;
23  import java.net.URISyntaxException;
24  import java.security.AccessController;
25  import java.security.PrivilegedAction;
26  import java.util.Arrays;
27  import java.util.List;
28  import java.util.Properties;
29  
30  import javax.xml.bind.JAXBContext;
31  import javax.xml.bind.JAXBElement;
32  import javax.xml.bind.JAXBException;
33  import javax.xml.bind.Marshaller;
34  import javax.xml.bind.Unmarshaller;
35  import javax.xml.parsers.DocumentBuilder;
36  import javax.xml.parsers.DocumentBuilderFactory;
37  import javax.xml.parsers.ParserConfigurationException;
38  import javax.xml.registry.InvalidRequestException;
39  import javax.xml.transform.stream.StreamSource;
40  
41  import org.apache.commons.logging.Log;
42  import org.apache.commons.logging.LogFactory;
43  import org.apache.ws.scout.transport.LocalTransport;
44  import org.apache.ws.scout.transport.Transport;
45  import org.apache.ws.scout.transport.TransportException;
46  import org.apache.ws.scout.util.XMLUtils;
47  import org.uddi.api_v3.AssertionStatusReport;
48  import org.uddi.api_v3.AuthToken;
49  import org.uddi.api_v3.BindingDetail;
50  import org.uddi.api_v3.BindingTemplate;
51  import org.uddi.api_v3.BusinessDetail;
52  import org.uddi.api_v3.BusinessEntity;
53  import org.uddi.api_v3.BusinessList;
54  import org.uddi.api_v3.BusinessService;
55  import org.uddi.api_v3.CategoryBag;
56  import org.uddi.api_v3.CompletionStatus;
57  import org.uddi.api_v3.DeleteBinding;
58  import org.uddi.api_v3.DeleteBusiness;
59  import org.uddi.api_v3.DeletePublisherAssertions;
60  import org.uddi.api_v3.DeleteService;
61  import org.uddi.api_v3.DeleteTModel;
62  import org.uddi.api_v3.DiscoveryURLs;
63  import org.uddi.api_v3.DispositionReport;
64  import org.uddi.api_v3.FindBinding;
65  import org.uddi.api_v3.FindBusiness;
66  import org.uddi.api_v3.FindQualifiers;
67  import org.uddi.api_v3.FindService;
68  import org.uddi.api_v3.FindTModel;
69  import org.uddi.api_v3.GetAssertionStatusReport;
70  import org.uddi.api_v3.GetAuthToken;
71  import org.uddi.api_v3.GetBusinessDetail;
72  import org.uddi.api_v3.GetPublisherAssertions;
73  import org.uddi.api_v3.GetRegisteredInfo;
74  import org.uddi.api_v3.GetServiceDetail;
75  import org.uddi.api_v3.GetTModelDetail;
76  import org.uddi.api_v3.IdentifierBag;
77  import org.uddi.api_v3.InfoSelection;
78  import org.uddi.api_v3.Name;
79  import org.uddi.api_v3.ObjectFactory;
80  import org.uddi.api_v3.PublisherAssertion;
81  import org.uddi.api_v3.PublisherAssertions;
82  import org.uddi.api_v3.PublisherAssertionsResponse;
83  import org.uddi.api_v3.RegisteredInfo;
84  import org.uddi.api_v3.SaveBinding;
85  import org.uddi.api_v3.SaveBusiness;
86  import org.uddi.api_v3.SaveService;
87  import org.uddi.api_v3.SaveTModel;
88  import org.uddi.api_v3.ServiceDetail;
89  import org.uddi.api_v3.ServiceList;
90  import org.uddi.api_v3.SetPublisherAssertions;
91  import org.uddi.api_v3.TModel;
92  import org.uddi.api_v3.TModelBag;
93  import org.uddi.api_v3.TModelDetail;
94  import org.uddi.api_v3.TModelList;
95  import org.w3c.dom.Document;
96  import org.w3c.dom.Element;
97  import org.w3c.dom.NodeList;
98  import org.xml.sax.SAXException;
99  
100 /**
101  * RegistryImpl is the implementation of IRegistry.
102  * 
103  * <p>The execute() function signature has been changed slightly from the jUDDI
104  * version, since the URL can no longer be decided dynamically (in an easy
105  * enough manner) as we don't use jUDDI data types anymore.</p>
106  * 
107  * <i>The function code is borrowed from jUDDI, with appropriate modifications so
108  * that xmlbeans data types are used intead of jUDDI data types.</i>
109  * 
110  */
111 
112 public class RegistryV3Impl implements IRegistryV3 {
113 
114 	public static final String DEFAULT_INQUIRY_ENDPOINT  = "org.apache.juddi.v3.client.transport.wrapper.UDDIInquiryService#inquire";;
115 	public static final String DEFAULT_PUBLISH_ENDPOINT  = "org.apache.juddi.v3.client.transport.wrapper.UDDIPublicationService#publish";
116 	public static final String DEFAULT_SECURITY_ENDPOINT = "org.apache.juddi.v3.client.transport.wrapper.UDDISecurityService#secure";
117 	public static final String DEFAULT_ADMIN_ENDPOINT    = "http://localhost/juddiv3/";
118 	public static final String DEFAULT_TRANSPORT_CLASS   = "org.apache.ws.scout.transport.LocalTransport";
119 	public static final String DEFAULT_SECURITY_PROVIDER = "com.sun.net.ssl.internal.ssl.Provider";
120 	public static final String DEFAULT_PROTOCOL_HANDLER  = "com.sun.net.ssl.internal.www.protocol";
121 	public static final String DEFAULT_UDDI_VERSION      = "3.0";
122 	public static final String DEFAULT_UDDI_NAMESPACE    = "urn:uddi-org:api_v3";
123 
124 	private URI adminURI;
125 	private URI inquiryURI;
126 	private URI publishURI;
127 	private URI securityURI;
128 
129 	private Transport transport;
130 
131 	private String securityProvider;
132 	private String protocolHandler;
133 	private String uddiVersion;
134 	private String uddiNamespace;
135 	
136 	private String nodeName;
137 	private String managerName;
138 	
139 	private ObjectFactory objectFactory = new ObjectFactory();
140 	
141 	private Marshaller marshaller = null;
142 	private Unmarshaller unmarshaller = null;
143 	
144 	private static Log log = LogFactory.getLog(RegistryV3Impl.class);
145 
146 	/**
147 	 * Creates a new instance of RegistryImpl.
148 	 * @throws InvalidRequestException 
149 	 */
150 	public RegistryV3Impl(Properties props, String nodeName, String managerName) throws InvalidRequestException {
151 		super();
152 
153 		this.init(props, nodeName, managerName);
154 	}
155 
156 	/**
157 	 * @throws InvalidRequestException 
158 	 * 
159 	 */
160 	private void init(Properties props, String nodeName, String managerName) throws InvalidRequestException {
161 	    this.nodeName = nodeName;
162 	    this.managerName = managerName;
163         // We need to have a non-null Properties
164         // instance so initialization takes place.
165         if (props == null) props = new Properties();
166 
167         // Override defaults with specific specific values
168         try {
169             // note that since we are using the juddi-client, these settings are fixed!
170             // the URL settings will be passed down to the juddi-client config. 
171             // (see the parameters in the "META-INF/jaxr-uddi.xml)
172             setInquiryURI(new URI(DEFAULT_INQUIRY_ENDPOINT));
173             setPublishURI(new URI(DEFAULT_PUBLISH_ENDPOINT));
174             setSecurityURI(new URI(DEFAULT_SECURITY_ENDPOINT));
175             setTransport(getTransport(DEFAULT_TRANSPORT_CLASS));
176             // the following parameters are still configurable however
177             setAdminURI(new URI(props.getProperty(ConnectionFactoryImpl.ADMIN_ENDPOINT_PROPERTY, DEFAULT_ADMIN_ENDPOINT)));
178             setSecurityProvider(props.getProperty(ConnectionFactoryImpl.SECURITY_PROVIDER_PROPERTY, DEFAULT_SECURITY_PROVIDER));
179             setProtocolHandler(props.getProperty(ConnectionFactoryImpl.PROTOCOL_HANDLER_PROPERTY, DEFAULT_PROTOCOL_HANDLER));
180             setUddiVersion(props.getProperty(ConnectionFactoryImpl.UDDI_VERSION_PROPERTY, DEFAULT_UDDI_VERSION));
181             setUddiNamespace(props.getProperty(ConnectionFactoryImpl.UDDI_NAMESPACE_PROPERTY, DEFAULT_UDDI_NAMESPACE));
182             
183             JAXBContext context = JAXBContextUtil.getContext(JAXBContextUtil.UDDI_V3_VERSION);
184             unmarshaller = context.createUnmarshaller(); 
185             marshaller = context.createMarshaller();
186             
187         } catch (URISyntaxException muex) {
188             throw new InvalidRequestException(muex.getMessage(), muex);
189         } catch(JAXBException e) {
190            throw new RuntimeException(e);
191         }
192 	}
193 
194 	/**
195 	 * 
196 	 * @param uddiRequest
197 	 * @return String
198 	 * @throws RegistryV3Exception
199 	 */
200 	public String execute(String uddiRequest, String urltype)
201 			throws TransportException {
202 		URI endPointURL = null;
203 		if (urltype.equalsIgnoreCase("INQUIRY"))
204 			endPointURL = this.getInquiryURI();
205 		else
206 			endPointURL = this.getPublishURI();
207 
208 		// A SOAP request is made and a SOAP response
209 		// is returned.
210 
211 		return transport.send(uddiRequest, endPointURL);
212 	}
213 
214 	/**
215 	 * 
216 	 */
217 	public JAXBElement<?> execute(JAXBElement<?> uddiRequest, URI endPointURI)
218 			throws RegistryV3Exception {
219 
220 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
221 		
222         Document doc;
223         try {
224             DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
225             docBuilderFactory.setNamespaceAware(true);
226             DocumentBuilder docBuilder= docBuilderFactory.newDocumentBuilder();
227             this.marshaller.marshal(uddiRequest, baos);
228             doc = docBuilder.parse(new ByteArrayInputStream(baos.toByteArray()));
229         } catch (SAXException saxe) {
230             throw (new RegistryV3Exception(saxe));
231         } catch (ParserConfigurationException pce) {
232             throw (new RegistryV3Exception(pce));
233         } catch (IOException ioe) {
234             throw (new RegistryV3Exception(ioe));
235         } catch (JAXBException ioe) {
236             throw (new RegistryV3Exception(ioe));
237         }
238 		Element request = doc.getDocumentElement();
239 
240 	    request.setAttribute("xmlns", this.getUddiNamespace());
241 	    if (!"3.0".equals(this.getUddiVersion())) {
242 	    	request.setAttribute("generic", this.getUddiVersion());
243 	    }
244 	    //request.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns", this.getUddiNamespace());
245 	    // A SOAP request is made and a SOAP response
246 	    // is returned.
247 	    if (log.isDebugEnabled()) {
248 	    	String xmlIn = XMLUtils.convertNodeToXMLString(request);
249 	    	log.debug("Request send to UDDI Registry: " + xmlIn);
250 	    }
251 	    
252 	    Element response;
253 	    try {
254 	    	response = transport.send(request, endPointURI);
255 	    } catch (TransportException te) {
256 	    	throw new RegistryV3Exception(te);
257 	    }
258 	    /* if (response.hasAttributes()) {
259 		    NamedNodeMap am = response.getAttributes();
260 		    ArrayList<String> al = new ArrayList<String>();
261 		    for (int i = 0; i < am.getLength(); i++) {
262 		    	Node n = am.item(i);
263 		    	String attribute = n.getNodeName();
264 		    	if (attribute!= null && attribute.startsWith("xmlns")) {
265 		    		al.add(attribute);
266 		    	}
267 		    }
268 		    for (String attr : al) {
269 		    	response.removeAttribute(attr);
270 		    }
271 	    }*/
272 	    JAXBElement<?> uddiResponse = null;
273 	    if (response!=null) {
274 		    if (response.getNamespaceURI()==null) {
275 	            response.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns", this.getUddiNamespace());
276 	        }
277 		    
278 		    // If we are getting responses from a UDDI v3, remove the xmlns
279 		    
280 		    // First, let's make sure that a response
281 		    // (any response) is found in the SOAP Body.
282 	
283 		    String responseName = response.getLocalName();
284 		    if (responseName == null) {
285 		        throw new RegistryV3Exception("Unsupported response "
286 		                + "from registry. A value was not present.");
287 			} 
288 		    
289 	        // Let's now try to determine which UDDI response
290 	        // we received and unmarshal it appropriately or
291 	        // throw a RegistryV3Exception if it's unknown.
292 	        // Well, we have now determined that something was
293 	        // returned and it is "a something" that we know
294 	        // about so let's unmarshal it into a RegistryObject
295 	        // Next, let's make sure we didn't recieve a SOAP
296 	        // Fault. If it is a SOAP Fault then throw it
297 	        // immediately.
298 	
299 	        
300 		    try {
301 		    	String xml = XMLUtils.convertNodeToXMLString(response);
302 		        log.debug("Response is: " + xml);
303 		    	
304 			StringReader reader = new StringReader(xml);
305 			uddiResponse = (JAXBElement<?>) unmarshaller.unmarshal(new StreamSource(reader));
306 		    	//It is probably faster not to go to a String, but JAXB has issues with this
307 		        //uddiResponse = (JAXBElement<?>) unmarshaller.unmarshal(response);
308 	
309 		    } catch (JAXBException xmle) {
310 		        throw (new RegistryV3Exception(xmle));
311 		    }
312 	
313 			if (responseName.toLowerCase().equals("fault")) {
314 				NodeList nodeList = null;
315 				
316 				// Child Elements
317 				String fCode = null;
318 				nodeList = response.getElementsByTagName("faultcode");
319 				if (nodeList.getLength() > 0)
320 					fCode = nodeList.item(0).getNodeValue();
321 	
322 				String fString = null;
323 				nodeList = response.getElementsByTagName("faultstring");
324 				if (nodeList.getLength() > 0)
325 					fString = nodeList.item(0).getNodeValue();
326 	
327 				String fActor = null;
328 				nodeList = response.getElementsByTagName("faultactor");
329 				if (nodeList.getLength() > 0)
330 					fActor = nodeList.item(0).getNodeValue();
331 	
332 				DispositionReport dispRpt = null;
333 	
334 				nodeList = response.getElementsByTagName("detail");
335 				if (nodeList.getLength() > 0) {
336 					nodeList = ((Element) nodeList.item(0))
337 							.getElementsByTagName("dispositionReport");
338 					if (nodeList.getLength() > 0) {
339 						JAXBElement<DispositionReport> dispRptObj = null;
340 						try {
341 							dispRptObj = (JAXBElement<DispositionReport>) unmarshaller.unmarshal((Element) nodeList
342 									.item(0));
343 						} catch (JAXBException xmle) {
344 							throw (new RegistryV3Exception(xmle));
345 						}
346 	                    dispRpt = dispRptObj.getValue();
347 	                }
348 				}
349 	
350 				RegistryV3Exception e = new RegistryV3Exception(fCode, fString, fActor, dispRpt);
351 			
352 				// Create RegistryV3Exception instance and return
353 				throw e;
354 			}
355 	    }
356 
357 		return uddiResponse;
358 	}
359  
360 	/**
361 	 * @return Returns the adminURL.
362 	 */
363 	public URI getAdminURI() {
364 		return this.adminURI;
365 	}
366 
367 	/**
368 	 * @param url
369 	 *            The adminURL to set.
370 	 */
371 	public void setAdminURI(URI url) {
372 		this.adminURI = url;
373 	}
374 
375 	/**
376 	 * @return Returns the inquiryURL.
377 	 */
378 	public URI getInquiryURI() {
379 		return this.inquiryURI;
380 	}
381 
382 	/**
383 	 * @param inquiryURI
384 	 *            The inquiryURI to set.
385 	 */
386 	public void setInquiryURI(URI inquiryURI) {
387 		this.inquiryURI = inquiryURI;
388 	}
389 
390 	/**
391 	 * @return Returns the protocolHandler.
392 	 */
393 	public String getProtocolHandler() {
394 		return this.protocolHandler;
395 	}
396 
397 	/**
398 	 * @param protocolHandler
399 	 *            The protocolHandler to set.
400 	 */
401 	public void setProtocolHandler(String protocolHandler) {
402 		this.protocolHandler = protocolHandler;
403 	}
404 
405 	/**
406 	 * @return Returns the publishURL.
407 	 */
408 	public URI getPublishURI() {
409 		return this.publishURI;
410 	}
411 	
412 	/**
413 	 * @return Returns the publishURL.
414 	 */
415 	public URI getSecurityURI() {
416 		return this.securityURI;
417 	}
418 
419 	/**
420 	 * @param publishURI
421 	 *            The publishURI to set.
422 	 */
423 	public void setPublishURI(URI publishURI) {
424 		this.publishURI = publishURI;
425 	}
426 	
427 	/**
428 	 * @param publishURI
429 	 *            The publishURI to set.
430 	 */
431 	public void setSecurityURI(URI securityURI) {
432 		this.securityURI = securityURI;
433 	}
434 
435 	/**
436 	 * @return Returns the securityProvider.
437 	 */
438 	public String getSecurityProvider() {
439 		return this.securityProvider;
440 	}
441 
442 	/**
443 	 * @param securityProvider
444 	 *            The securityProvider to set.
445 	 */
446 	public void setSecurityProvider(String securityProvider) {
447 		this.securityProvider = securityProvider;
448 	}
449 
450 	/**
451 	 * @return Returns the transport.
452 	 */
453 	public Transport getTransport() {
454 		return transport;
455 	}
456 
457 	/**
458 	 * @param transport
459 	 *            The transport to set.
460 	 */
461 	public void setTransport(Transport transport) {
462 		this.transport = transport;
463 	}
464 
465 	/**
466 	 * @return Returns the uddiNS.
467 	 */
468 	public String getUddiNamespace() {
469 		return this.uddiNamespace;
470 	}
471 
472 	/**
473 	 * @param uddiNS
474 	 *            The uddiNS to set.
475 	 */
476 	public void setUddiNamespace(String uddiNS) {
477 		this.uddiNamespace = uddiNS;
478 	}
479 
480 	/**
481 	 * @return Returns the uddiVersion.
482 	 */
483 	public String getUddiVersion() {
484 		return this.uddiVersion;
485 	}
486 
487 	/**
488 	 * @param uddiVersion
489 	 *            The uddiVersion to set.
490 	 */
491 	public void setUddiVersion(String uddiVersion) {
492 		this.uddiVersion = uddiVersion;
493 	}
494 
495 	/**
496 	 * "Used to remove an existing bindingTemplate from the bindingTemplates
497 	 * collection that is part of a specified businessService structure."
498 	 * 
499 	 * @exception RegistryV3Exception;
500 	 */
501 	public DispositionReport deleteBinding(String authInfo,
502 			String[] bindingKeyArray) throws RegistryV3Exception {
503 		DeleteBinding request = this.objectFactory.createDeleteBinding();
504 
505 		if (authInfo != null) {
506 			request.setAuthInfo(authInfo);
507 		}
508 
509 		if (bindingKeyArray != null) {
510 			request.getBindingKey().addAll(Arrays.asList(bindingKeyArray));
511 		}
512 
513         DispositionReport dr = new DispositionReport();
514         JAXBElement<?> o = execute(this.objectFactory.createDeleteBinding(request), this.getPublishURI());
515         if (o!=null) {
516         	dr = (DispositionReport) o.getValue();
517         }
518 
519         return dr;
520 	}
521 
522 	/**
523 	 * "Used to delete registered businessEntity information from the registry."
524 	 * 
525 	 * @exception RegistryV3Exception;
526 	 */
527 	public DispositionReport deleteBusiness(String authInfo,
528 			String[] businessKeyArray) throws RegistryV3Exception {
529 		DeleteBusiness request = this.objectFactory.createDeleteBusiness();
530 		
531 		if (authInfo != null) {
532 			request.setAuthInfo(authInfo);
533 		}
534 
535 		if (businessKeyArray != null) {
536 			request.getBusinessKey().addAll(Arrays.asList(businessKeyArray));
537 		}
538 
539         DispositionReport dr = new DispositionReport();
540         JAXBElement<?> o = execute(this.objectFactory.createDeleteBusiness(request), this.getPublishURI());
541         if (o!=null){
542         	dr = (DispositionReport) o.getValue();
543         }
544 
545         return dr;
546 	}
547 
548 	/**
549 	 * @exception RegistryV3Exception;
550 	 */
551 	public DispositionReport deletePublisherAssertions(String authInfo,
552 			PublisherAssertion[] assertionArray) throws RegistryV3Exception {
553 		DeletePublisherAssertions request = this.objectFactory.createDeletePublisherAssertions();
554 
555 		if (authInfo != null) {
556 			request.setAuthInfo(authInfo);
557 		}
558 
559 		if (assertionArray != null) {
560 			request.getPublisherAssertion().addAll(Arrays.asList(assertionArray));
561 		}
562 
563         DispositionReport dr = new DispositionReport();
564         JAXBElement<?> o = execute(this.objectFactory.createDeletePublisherAssertions(request), 
565         		this.getPublishURI());
566         if (o!=null) {
567         	dr = (DispositionReport) o.getValue();
568         }
569 
570         return dr;
571 	}
572 
573 	/**
574 	 * "Used to delete an existing businessService from the businessServices
575 	 * collection that is part of a specified businessEntity."
576 	 * 
577 	 * @exception RegistryV3Exception;
578 	 */
579 	public DispositionReport deleteService(String authInfo,
580 			String[] serviceKeyArray) throws RegistryV3Exception {
581 		DeleteService request = this.objectFactory.createDeleteService();
582 		
583 		if (authInfo != null) {
584 			request.setAuthInfo(authInfo);
585 		}
586 
587 		if (serviceKeyArray != null) {
588 			request.getServiceKey().addAll(Arrays.asList(serviceKeyArray));
589 		}
590 
591         DispositionReport dr = new DispositionReport();
592         JAXBElement<?> o = execute(this.objectFactory.createDeleteService(request), 
593         		this.getPublishURI());
594         if (o!=null) {
595         	dr = (DispositionReport) o.getValue();
596         }
597 
598         return dr;
599 	}
600 
601 	/**
602 	 * "Used to delete registered information about a tModel. If there are any
603 	 * references to a tModel when this call is made, the tModel will be marked
604 	 * deleted instead of being physically removed."
605 	 * 
606 	 * @exception RegistryV3Exception;
607 	 */
608 	public DispositionReport deleteTModel(String authInfo,
609 			String[] tModelKeyArray) throws RegistryV3Exception {
610 		DeleteTModel request = this.objectFactory.createDeleteTModel();
611 
612 		if (authInfo != null) {
613 			request.setAuthInfo(authInfo);
614 		}
615 
616 		if (tModelKeyArray != null) {
617 			request.getTModelKey().addAll(Arrays.asList(tModelKeyArray));
618 		}
619 
620         DispositionReport dr = new DispositionReport();
621         JAXBElement<?> o = execute(this.objectFactory.createDeleteTModel(request), 
622         		this.getPublishURI());
623         if (o!=null) {
624         	dr = (DispositionReport) o.getValue();
625         }
626 
627         return dr;
628 	}
629 
630 	/**
631 	 * Used to locate information about one or more businesses. Returns a
632 	 * businessList message that matches the conditions specified.
633 	 * 
634 	 * @exception RegistryV3Exception;
635 	 */
636 	public BusinessList findBusiness(Name[] nameArray,
637 			DiscoveryURLs discoveryURLs, IdentifierBag identifierBag,
638 			CategoryBag categoryBag, TModelBag tModelBag,
639 			FindQualifiers findQualifiers, int maxRows)
640 			throws RegistryV3Exception {
641 		FindBusiness request = this.objectFactory.createFindBusiness();
642 
643 		if (nameArray != null) {
644 			request.getName().addAll(Arrays.asList(nameArray));
645 		}
646 
647 		if (discoveryURLs != null) {
648 			request.setDiscoveryURLs(discoveryURLs);
649 		}
650 
651 		if (identifierBag != null) {
652 			request.setIdentifierBag(identifierBag);
653 		}
654 
655 		if (categoryBag != null) {
656 			request.setCategoryBag(categoryBag);
657 		}
658 
659 		if (tModelBag != null) {
660 			request.setTModelBag(tModelBag);
661 		} 
662 
663 		if (findQualifiers != null) {
664 			request.setFindQualifiers(findQualifiers);
665 		}
666 
667 		request.setMaxRows(maxRows);
668 
669         BusinessList bl = null;
670         JAXBElement<?> o = execute(this.objectFactory.createFindBusiness(request),
671         		this.getInquiryURI());
672         if (o != null) bl = (BusinessList) o.getValue();
673 
674         return bl;
675 	}
676 
677 	/**
678 	 * "Used to locate specific bindings within a registered businessService.
679 	 * Returns a bindingDetail message."
680 	 * 
681 	 * @exception RegistryV3Exception
682 	 */
683 	public BindingDetail findBinding(String serviceKey,
684 			CategoryBag categoryBag, TModelBag tModelBag,
685 			FindQualifiers findQualifiers, int maxRows)
686 			throws RegistryV3Exception {
687 		// FIXME: Juddi's methods also set category bag (per uddi spec v3).
688 		// However, we are sticking to v2 for now, so categorybag doesn't
689 		// exist under FindBinding. It is fine for now, since the incoming
690 		// parameter value is always null anyways -- but this may change
691 		// in the future.
692 
693 		FindBinding request = this.objectFactory.createFindBinding();
694 
695 		if (serviceKey != null) {
696 			request.setServiceKey(serviceKey);
697 		}
698 
699 		if (categoryBag != null) {
700 			request.setCategoryBag(categoryBag);
701 		}
702 		
703 		if (tModelBag != null) {
704 			request.setTModelBag(tModelBag);
705 		}
706 
707 		if (findQualifiers != null) {
708 			request.setFindQualifiers(findQualifiers);
709 		}
710 		request.setMaxRows(maxRows);
711 
712                 BindingDetail bd = null;
713                 JAXBElement<?> o = execute(this.objectFactory.createFindBinding(request), 
714                                 this.getInquiryURI());
715                 if (o != null) bd = (BindingDetail) o.getValue();
716 
717                 return bd;
718 	}
719 
720 	/**
721 	 * "Used to locate specific services within a registered businessEntity.
722 	 * Return a serviceList message." From the XML spec (API, p18) it appears
723 	 * that the name, categoryBag, and tModelBag arguments are mutually
724 	 * exclusive.
725 	 * 
726 	 * @exception RegistryV3Exception;
727 	 */
728 	public ServiceList findService(String businessKey, Name[] nameArray,
729 			CategoryBag categoryBag, TModelBag tModelBag,
730 			FindQualifiers findQualifiers, int maxRows)
731 			throws RegistryV3Exception {
732 		FindService request = this.objectFactory.createFindService();
733 
734 		if (businessKey != null) {
735 			request.setBusinessKey(businessKey);
736 		}
737 
738 		if (nameArray != null) {
739 			request.getName().addAll(Arrays.asList(nameArray));
740 		}
741 
742 		if (categoryBag != null) {
743 			request.setCategoryBag(categoryBag);
744 		}
745 
746 		if (tModelBag != null) {
747 			request.setTModelBag(tModelBag);
748 		}
749 
750 		if (findQualifiers != null) {
751 			request.setFindQualifiers(findQualifiers);
752 		}
753 
754 		request.setMaxRows(maxRows);
755 
756         ServiceList sl = null;
757         JAXBElement<?> o = execute(this.objectFactory.createFindService(request), 
758         		this.getInquiryURI());
759         if (o != null) sl = (ServiceList) o.getValue();
760 
761         return sl;
762 	}
763 
764 	/**
765 	 * "Used to locate one or more tModel information structures. Returns a
766 	 * tModelList structure."
767 	 * 
768 	 * @exception RegistryV3Exception;
769 	 */
770 	public TModelList findTModel(String name, CategoryBag categoryBag,
771 			IdentifierBag identifierBag, FindQualifiers findQualifiers,
772 			int maxRows) throws RegistryV3Exception {
773 		FindTModel request = this.objectFactory.createFindTModel();
774 
775 		Name jaxbName = this.objectFactory.createName();
776 
777 		if (name != null) {
778 			jaxbName.setValue(name);
779 		}
780 
781 		request.setName(jaxbName);
782 
783 		if (categoryBag != null) {
784 			request.setCategoryBag(categoryBag);
785 		}
786 
787 		if (identifierBag != null) {
788 			request.setIdentifierBag(identifierBag);
789 		}
790 
791 		if (findQualifiers != null) {
792 			request.setFindQualifiers(findQualifiers);
793 		}
794 
795 		request.setMaxRows(maxRows);
796 
797         TModelList tml = null;
798         JAXBElement<?> o = execute(this.objectFactory.createFindTModel(request), 
799         		this.getInquiryURI());
800         if (o !=null) tml = (TModelList) o.getValue();
801 
802         return tml;
803 	}
804 
805 	/**
806 	 * @exception RegistryV3Exception;
807 	 */
808 	public AssertionStatusReport getAssertionStatusReport(String authInfo,
809 			String completionStatus) throws RegistryV3Exception {
810 		GetAssertionStatusReport request = this.objectFactory.createGetAssertionStatusReport();
811 
812 		if (authInfo != null) {
813 			request.setAuthInfo(authInfo);
814 		}
815 
816 		if (completionStatus != null) {
817 			CompletionStatus cs = CompletionStatus.fromValue(completionStatus);
818 			request.setCompletionStatus(cs);
819 		}
820 
821         AssertionStatusReport asr = new AssertionStatusReport();
822         JAXBElement<?> o = execute(this.objectFactory.createGetAssertionStatusReport(request), 
823         		this.getPublishURI());
824         asr = (AssertionStatusReport) o.getValue();
825 
826         return asr;
827 	}
828 
829 	/**
830 	 * "Used to request an authentication token from an Operator Site.
831 	 * Authentication tokens are required to use all other APIs defined in the
832 	 * publishers API. This server serves as the program's equivalent of a login
833 	 * request."
834 	 * 
835 	 * @exception RegistryV3Exception;
836 	 */
837 	public AuthToken getAuthToken(String userID, String cred)
838 			throws RegistryV3Exception {
839 		GetAuthToken request = this.objectFactory.createGetAuthToken();
840 
841 		if (userID != null) {
842 			request.setUserID(userID);
843 		}
844 
845 		if (cred != null) {
846 			request.setCred(cred);
847 		}
848 
849 		URI getAuthTokenURI = null;
850 		if ("3.0".equals(uddiVersion)) {
851 			getAuthTokenURI = this.getSecurityURI();
852 		} else {
853 			getAuthTokenURI = this.getPublishURI();
854 		}
855 		
856         AuthToken at = null;
857         JAXBElement<?> o = execute(this.objectFactory.createGetAuthToken(request), 
858         		getAuthTokenURI);
859         if (o!=null)
860         at = (AuthToken) o.getValue();
861 
862         return at;
863 	}
864 
865 	/**
866 	 * Used to get the full businessEntity information for a particular business
867 	 * entity. Returns a businessDetail message.
868 	 * 
869 	 * @exception RegistryV3Exception;
870 	 */
871 	public BusinessDetail getBusinessDetail(String businessKey)
872 			throws RegistryV3Exception {
873 		String[] keys = new String[1];
874 		keys[0] = businessKey;
875 
876 		return getBusinessDetail(keys);
877 	}
878 
879 	/**
880 	 * "Used to get the full businessEntity information for one or more
881 	 * businesses. Returns a businessDetail message."
882 	 * 
883 	 * @exception RegistryV3Exception;
884 	 */
885 	public BusinessDetail getBusinessDetail(String[] businessKeyArray)
886 			throws RegistryV3Exception {
887 		GetBusinessDetail request = this.objectFactory.createGetBusinessDetail();
888 
889 		if (businessKeyArray != null) {
890 			request.getBusinessKey().addAll(Arrays.asList(businessKeyArray));
891 		}
892 
893         BusinessDetail bd = null;
894         JAXBElement<?> o = execute(this.objectFactory.createGetBusinessDetail(request), 
895         		this.getInquiryURI());
896         bd = (BusinessDetail) o.getValue(); 
897         return bd;
898 	}
899 
900 	/**
901 	 * @exception RegistryV3Exception;
902 	 */
903 	public PublisherAssertions getPublisherAssertions(String authInfo)
904 			throws RegistryV3Exception {
905 		GetPublisherAssertions request = this.objectFactory.createGetPublisherAssertions();
906 
907 		if (authInfo != null) {
908 			request.setAuthInfo(authInfo);
909 		}
910 
911         PublisherAssertions pa = new PublisherAssertions();
912         JAXBElement<?> o = execute(this.objectFactory.createGetPublisherAssertions(request),
913         		this.getPublishURI());
914         if (o != null) {
915             PublisherAssertionsResponse par = (PublisherAssertionsResponse) o.getValue();
916             List<PublisherAssertion> assertions = par.getPublisherAssertion();
917             for (int i = 0; i < assertions.size(); i++ ) {
918             	pa.getPublisherAssertion().add((PublisherAssertion)assertions.get(i));
919             }
920         }
921 
922         return pa;
923 	}
924 
925 	/**
926 	 * @exception RegistryV3Exception;
927 	 */
928 	public RegisteredInfo getRegisteredInfo(String authInfo)
929 			throws RegistryV3Exception {
930 		GetRegisteredInfo request = this.objectFactory.createGetRegisteredInfo();
931 
932 		if (authInfo != null) {
933 			request.setAuthInfo(authInfo);
934 		}
935 		
936 		request.setInfoSelection(InfoSelection.ALL);
937 
938         RegisteredInfo ri = null;
939         JAXBElement<?> o = execute(this.objectFactory.createGetRegisteredInfo(request), 
940         		this.getPublishURI());
941         if (o != null) ri = (RegisteredInfo) o.getValue();
942 
943         return ri;
944 	}
945 	
946 	/**
947 	 * "Used to get full details for a particular registered businessService.
948 	 * Returns a serviceDetail message."
949 	 * 
950 	 * @exception RegistryV3Exception;
951 	 */
952 	public ServiceDetail getServiceDetail(String serviceKey)
953 			throws RegistryV3Exception {
954 		String[] keys = new String[1];
955 		keys[0] = serviceKey;
956 
957 		return getServiceDetail(keys);
958 	}
959 
960 	/**
961 	 * "Used to get full details for a given set of registered businessService
962 	 * data. Returns a serviceDetail message."
963 	 * 
964 	 * @exception RegistryV3Exception;
965 	 */
966 	public ServiceDetail getServiceDetail(String[] serviceKeyArray)
967 			throws RegistryV3Exception {
968 		GetServiceDetail request = this.objectFactory.createGetServiceDetail();
969 
970 		if (serviceKeyArray != null) {
971 			request.getServiceKey().addAll(Arrays.asList(serviceKeyArray));
972 		}
973 
974         ServiceDetail sd = null;
975         JAXBElement<?> o = execute(this.objectFactory.createGetServiceDetail(request), 
976         		this.getInquiryURI());
977         if (o != null) sd = (ServiceDetail) o.getValue();
978 
979         return sd;
980 	}
981 
982 	/**
983 	 * "Used to get full details for a particular registered TModel. Returns a
984 	 * tModelDetail message."
985 	 * 
986 	 * @exception RegistryV3Exception;
987 	 */
988 	public TModelDetail getTModelDetail(String tModelKey)
989 			throws RegistryV3Exception {
990 		String[] keys = new String[1];
991 		keys[0] = tModelKey;
992 
993 		return getTModelDetail(keys);
994 	}
995 
996 	/**
997 	 * "Used to get full details for a given set of registered tModel data.
998 	 * Returns a tModelDetail message."
999 	 * 
1000 	 * @exception RegistryV3Exception;
1001 	 */
1002 	public TModelDetail getTModelDetail(String[] tModelKeyArray)
1003 			throws RegistryV3Exception {
1004 		GetTModelDetail request = this.objectFactory.createGetTModelDetail();
1005 
1006 		if (tModelKeyArray != null) {
1007 			request.getTModelKey().addAll(Arrays.asList(tModelKeyArray));
1008 		}
1009 
1010         TModelDetail tmd = null;
1011         JAXBElement<?> o = execute(this.objectFactory.createGetTModelDetail(request), 
1012         		this.getInquiryURI());
1013         if (o != null) tmd = (TModelDetail) o.getValue();
1014 
1015         return tmd;
1016 	}
1017 
1018 	/**
1019 	 * @exception RegistryV3Exception;
1020 	 */
1021 	public PublisherAssertions setPublisherAssertions(String authInfo,
1022 			PublisherAssertion[] assertionArray) throws RegistryV3Exception {
1023 		SetPublisherAssertions request = this.objectFactory.createSetPublisherAssertions();
1024 
1025 		if (authInfo != null) {
1026 			request.setAuthInfo(authInfo);
1027 		}
1028 
1029 		if (assertionArray != null) {
1030 			request.getPublisherAssertion().addAll(Arrays.asList(assertionArray));
1031 		}
1032 
1033         PublisherAssertions pa = null;
1034         JAXBElement<?> o = execute(this.objectFactory.createSetPublisherAssertions(request), 
1035         		this.getPublishURI());
1036         if (o!=null) pa = (PublisherAssertions) o.getValue();
1037 
1038         return pa;
1039 	}
1040 
1041 	/**
1042 	 * "Used to register new bindingTemplate information or update existing
1043 	 * bindingTemplate information. Use this to control information about
1044 	 * technical capabilities exposed by a registered business."
1045 	 * 
1046 	 * @exception RegistryV3Exception;
1047 	 */
1048 	public BindingDetail saveBinding(String authInfo,
1049 			BindingTemplate[] bindingArray) throws RegistryV3Exception {
1050 		SaveBinding request = this.objectFactory.createSaveBinding();
1051 
1052 		if (authInfo != null) {
1053 			request.setAuthInfo(authInfo);
1054 		}
1055 
1056 		if (bindingArray != null) {
1057 			request.getBindingTemplate().addAll(Arrays.asList(bindingArray));
1058 		}
1059 		
1060         BindingDetail bd = null;
1061         JAXBElement<?> o = execute(this.objectFactory.createSaveBinding(request), 
1062         		this.getPublishURI());
1063         if (o != null) bd = (BindingDetail) o.getValue();
1064 
1065         return bd;
1066 	}
1067 
1068 	/**
1069 	 * "Used to register new businessEntity information or update existing
1070 	 * businessEntity information. Use this to control the overall information
1071 	 * about the entire business. Of the save_x APIs this one has the broadest
1072 	 * effect."
1073 	 * 
1074 	 * @exception RegistryV3Exception;
1075 	 */
1076 	public BusinessDetail saveBusiness(String authInfo,
1077 			BusinessEntity[] businessArray) throws RegistryV3Exception {
1078 		SaveBusiness request = this.objectFactory.createSaveBusiness();
1079 
1080 		if (authInfo != null) {
1081 			request.setAuthInfo(authInfo);
1082 		}
1083 			
1084 		if (businessArray != null) {
1085 			for (int i = 0; i < businessArray.length; i++) {
1086 				BusinessEntity be = businessArray[i];
1087                                 if (be.getBusinessServices()!=null)
1088                                     
1089                                     if (be.getBusinessServices().getBusinessService().size() == 0) {
1090                                             be.setBusinessServices(null);
1091                                     }
1092 			}
1093 
1094 			request.getBusinessEntity().addAll(Arrays.asList(businessArray));
1095 		}
1096 		
1097         BusinessDetail bd = null;
1098         JAXBElement<?> o = execute(this.objectFactory.createSaveBusiness(request), 
1099         		this.getPublishURI());
1100         if (o != null) bd = (BusinessDetail) o.getValue();
1101 
1102         return bd;
1103 	}
1104 
1105 	/**
1106 	 * "Used to register or update complete information about a businessService
1107 	 * exposed by a specified businessEntity."
1108 	 * 
1109 	 * @exception RegistryV3Exception;
1110 	 */
1111 	public ServiceDetail saveService(String authInfo,
1112 			BusinessService[] serviceArray) throws RegistryV3Exception {
1113 		SaveService request = this.objectFactory.createSaveService();
1114 
1115 		if (authInfo != null) {
1116 			request.setAuthInfo(authInfo);
1117 		}
1118 
1119 		if (serviceArray != null) {
1120 			request.getBusinessService().addAll(Arrays.asList(serviceArray));
1121 		}
1122 
1123         ServiceDetail sd = null;
1124         JAXBElement<?> o = execute(this.objectFactory.createSaveService(request), 
1125         		this.getPublishURI());
1126         if (o != null) sd = (ServiceDetail) o.getValue();
1127 
1128         return sd;
1129 	}
1130 
1131 	/**
1132 	 * "Used to register or update complete information about a tModel."
1133 	 * 
1134 	 * @exception RegistryV3Exception;
1135 	 */
1136 	public TModelDetail saveTModel(String authInfo, TModel[] tModelArray)
1137 			throws RegistryV3Exception {
1138 		SaveTModel request = this.objectFactory.createSaveTModel();
1139 
1140 		if (authInfo != null) {
1141 			request.setAuthInfo(authInfo);
1142 		}
1143 
1144 		if (tModelArray != null) {
1145 			request.getTModel().addAll(Arrays.asList(tModelArray));
1146 		}
1147 
1148         TModelDetail tmd = null;
1149         JAXBElement<?> o = execute(this.objectFactory.createSaveTModel(request), 
1150         		this.getPublishURI());
1151         if (o != null) tmd = (TModelDetail) o.getValue();
1152         return tmd;
1153 	}
1154 
1155 	/**
1156 	 * Returns an implementation of Transport based on the className passed in.
1157 	 * If a null value is passed then the default Transport implementation
1158 	 * "org.apache.ws.scout.transport.AxisTransport" is created and returned.
1159 	 * 
1160 	 * @return Transport
1161 	 */
1162 	public Transport getTransport(String className) {
1163 		Transport transport = null;
1164 		Class transportClass = null;
1165 
1166 		// If a Transport class name isn't supplied use
1167 		// the default Transport implementation.
1168 		if (className == null)
1169 			className = DEFAULT_TRANSPORT_CLASS;
1170 
1171 		try {
1172 			// instruct class loader to load the TransportFactory
1173 			transportClass = getClassForName(className);
1174 		} catch (ClassNotFoundException cnfex) {
1175 			throw new RuntimeException(cnfex);
1176 		}
1177 
1178 		try {
1179 			// try to instantiate the TransportFactory
1180 		    if (LocalTransport.class.getName().equals(className) && managerName!=null) {
1181 		        transport = (Transport) transportClass.getConstructor(
1182 		                new Class[]{String.class,String.class})
1183 		                .newInstance(nodeName,managerName);
1184 		    } else {
1185 		        transport = (Transport) transportClass.newInstance();
1186 		    }
1187 		} catch (Exception ex) {
1188 			throw new RuntimeException(ex);
1189 		}
1190 
1191 		return transport;
1192 	}
1193 
1194 	/**
1195 	 * 
1196 	 * @param name
1197 	 * @return The class object for the name given
1198 	 * @throws ClassNotFoundException
1199 	 * @throws NoClassDefFoundError
1200 	 */
1201 	public static Class getClassForName(String name)
1202 			throws ClassNotFoundException, NoClassDefFoundError {
1203 		Class clazz = null;
1204 
1205 		try {
1206 			// log.info("Using the Context ClassLoader");
1207 			ClassLoader ccl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() 
1208 		    {
1209 				public ClassLoader run() {
1210 					return Thread.currentThread().getContextClassLoader();
1211 		        }
1212 			});
1213 			
1214 			clazz = Class.forName(name, true, ccl);
1215 		} catch (Exception e) {
1216 			 log.debug("Failed to load the class " + name + " with context class loader " + e);
1217 		}
1218 
1219 		if (null == clazz) {
1220 			ClassLoader scl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
1221 			{ 
1222 				public ClassLoader run() {
1223 					return ClassLoader.getSystemClassLoader();
1224 				}
1225 			});
1226 
1227 			try {
1228 				clazz = Class.forName(name, true, scl);
1229 			} catch (Exception e) {
1230 		          throw new RuntimeException(e);
1231 			}
1232 		}
1233 
1234 		return clazz;
1235 	}
1236 }