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