You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ge...@apache.org on 2011/05/15 14:38:03 UTC
svn commit: r1103343 - in /geronimo/bundles/trunk/scout: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/ws/ src/main/java/org/apache/ws/scout/
src/main/java/org/apache/ws/scout/registry/ src/main/...
Author: genspring
Date: Sun May 15 12:38:02 2011
New Revision: 1103343
URL: http://svn.apache.org/viewvc?rev=1103343&view=rev
Log:
adding some fixes to scout bundle
Added:
geronimo/bundles/trunk/scout/src/
geronimo/bundles/trunk/scout/src/main/
geronimo/bundles/trunk/scout/src/main/java/
geronimo/bundles/trunk/scout/src/main/java/org/
geronimo/bundles/trunk/scout/src/main/java/org/apache/
geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/
geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/
geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/registry/
geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/registry/ConnectionFactoryImpl.java
geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/registry/RegistryV3Impl.java
geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/util/
geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiV3Helper.java
Modified:
geronimo/bundles/trunk/scout/pom.xml
Modified: geronimo/bundles/trunk/scout/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/scout/pom.xml?rev=1103343&r1=1103342&r2=1103343&view=diff
==============================================================================
--- geronimo/bundles/trunk/scout/pom.xml (original)
+++ geronimo/bundles/trunk/scout/pom.xml Sun May 15 12:38:02 2011
@@ -48,12 +48,30 @@
</properties>
<dependencies>
- <dependency>
+ <dependency>
<groupId>${pkgGroupId}</groupId>
<artifactId>${pkgArtifactId}</artifactId>
<version>${pkgVersion}</version>
<optional>true</optional>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.juddi</groupId>
+ <artifactId>uddi-ws</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
+ <dependency>
+ <groupId>org.apache.juddi</groupId>
+ <artifactId>uddi-ws</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
@@ -65,6 +83,11 @@
<instructions>
<Export-Package>org.apache.ws.scout*;version="1.2"</Export-Package>
<Import-Package>javax.xml.registry*;version="1.0",org.apache.axis.*;resolution:=optional,*</Import-Package>
+ <Include-Resource>
+ {maven-resources}, org/apache/ws/scout/registry/ConnectionFactoryImpl.class=target/classes/org/apache/ws/scout/registry/ConnectionFactoryImpl.class,
+ org/apache/ws/scout/registry/RegistryV3Impl.class=target/classes/org/apache/ws/scout/registry/RegistryV3Impl.class,
+ org/apache/ws/scout/util/ScoutJaxrUddiV3Helper.class=target/classes/org/apache/ws/scout/util/ScoutJaxrUddiV3Helper.class
+ </Include-Resource>
</instructions>
</configuration>
</plugin>
Added: geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/registry/ConnectionFactoryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/registry/ConnectionFactoryImpl.java?rev=1103343&view=auto
==============================================================================
--- geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/registry/ConnectionFactoryImpl.java (added)
+++ geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/registry/ConnectionFactoryImpl.java Sun May 15 12:38:02 2011
@@ -0,0 +1,273 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ws.scout.registry;
+
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.xml.registry.Connection;
+import javax.xml.registry.ConnectionFactory;
+import javax.xml.registry.FederatedConnection;
+import javax.xml.registry.InvalidRequestException;
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.UnsupportedCapabilityException;
+
+/**
+ * Our implmentation of javax.xml.registry.ConnectionFactory.
+ * Also exposes the properties as JavaBean properties to ease use
+ * with a managed environment such as an application server.
+ *
+ * @author Anil Saldhana <an...@apache.org>
+ * @author Jeremy Boynes <jb...@apache.org>
+ * @author Tom Cunningham <tc...@apache.org>
+ */
+public class ConnectionFactoryImpl extends ConnectionFactory implements Serializable
+{
+ private static final long serialVersionUID = -6902106826496922256L;
+ private static final String QUERYMANAGER_PROPERTY = "javax.xml.registry.queryManagerURL";
+ private static final String LIFECYCLEMANAGER_PROPERTY = "javax.xml.registry.lifeCycleManagerURL";
+ private static final String SECURITYMANAGER_PROPERTY = "javax.xml.registry.securityManagerURL";
+ private static final String SEMANTICEQUIVALENCES_PROPERTY = "javax.xml.registry.semanticEquivalences";
+ private static final String POSTALADDRESSSCHEME_PROPERTY = "javax.xml.registry.postalAddressScheme";
+ private static final String AUTHENTICATIONMETHOD_PROPERTY = "javax.xml.registry.security.authenticationMethod";
+ private static final String MAXROWS_PROPERTY = "javax.xml.registry.uddi.maxRows";
+
+ private String queryManagerURL;
+ private String lifeCycleManagerURL;
+ private String securityManagerURL;
+ private String transportClass;
+ private String semanticEquivalences;
+ private String authenticationMethod;
+ private Integer maxRows;
+ private String postalAddressScheme;
+ private String uddiNamespace;
+ private String uddiVersion;
+
+ /**
+ * Public no-arg constructor so that this ConnectionFactory can be
+ * instantiated by the JAXR ConnectionFactory;
+ */
+ public ConnectionFactoryImpl()
+ {
+/* System.setProperty(QUERYMANAGER_PROPERTY, "http://localhost:8080/juddi/UDDIInquiryService");
+ System.setProperty(LIFECYCLEMANAGER_PROPERTY, "http://localhost:8080/juddi/UDDIPublicationService");*/
+ System.setProperty(SECURITYMANAGER_PROPERTY, "http://localhost:8080/juddi/UDDISecurityService");
+ System.setProperty(RegistryImpl.UDDI_VERSION_PROPERTY_NAME, "3.0");
+ System.setProperty(RegistryImpl.UDDI_NAMESPACE_PROPERTY_NAME, "urn:uddi-org:api_v3");
+ }
+
+ public Connection createConnection() throws JAXRException
+ {
+ if (queryManagerURL == null)
+ {
+ throw new InvalidRequestException("queryManager is not set");
+ }
+ URI queryManager;
+ URI lifeCycleManager;
+ URI securityManager = null;
+ try
+ {
+ queryManager = new URI(queryManagerURL);
+ } catch (URISyntaxException e)
+ {
+ throw new InvalidRequestException("Invalid queryManagerURL: " + queryManagerURL, e);
+ }
+ try
+ {
+ lifeCycleManager = lifeCycleManagerURL == null ? queryManager : new URI(lifeCycleManagerURL);
+ } catch (URISyntaxException e)
+ {
+ throw new InvalidRequestException("Invalid lifeCycleManagerURL: " + lifeCycleManagerURL, e);
+ }
+ try
+ {
+ if (securityManagerURL != null) {
+ securityManager = new URI(securityManagerURL);
+ }
+ } catch (URISyntaxException e) {
+ securityManager = null;
+ }
+ return new ConnectionImpl(queryManager, lifeCycleManager, securityManager, transportClass, null, maxRows == null ? -1 : maxRows.intValue(),
+ uddiNamespace, uddiVersion);
+ }
+
+ public FederatedConnection createFederatedConnection(Collection collection) throws JAXRException
+ {
+ throw new UnsupportedCapabilityException("FederatedConnections are not supported in this release");
+ }
+
+ /**
+ * Returns a value copy of the properties that will be used to create
+ * a Connections. Operations on this Properties objects will not affect
+ * this ConnectionFactory; use setProperties(Properties) to save changes.
+ *
+ * @return a Properties object containing the properies that will be used to create Connection
+ */
+ public Properties getProperties()
+ {
+ Properties props = new Properties();
+ if (queryManagerURL != null)
+ {
+ props.put(QUERYMANAGER_PROPERTY, queryManagerURL);
+ }
+ if (lifeCycleManagerURL != null)
+ {
+ props.put(LIFECYCLEMANAGER_PROPERTY, lifeCycleManagerURL);
+ }
+ if (securityManagerURL != null)
+ {
+ props.put(SECURITYMANAGER_PROPERTY, securityManagerURL);
+ }
+ if (semanticEquivalences != null)
+ {
+ props.put(SEMANTICEQUIVALENCES_PROPERTY, semanticEquivalences);
+ }
+ if (postalAddressScheme != null)
+ {
+ props.put(POSTALADDRESSSCHEME_PROPERTY, postalAddressScheme);
+ }
+ if (authenticationMethod != null)
+ {
+ props.put(AUTHENTICATIONMETHOD_PROPERTY, authenticationMethod);
+ }
+ if (maxRows != null)
+ {
+ props.put(MAXROWS_PROPERTY, maxRows.toString());
+ }
+ if (uddiNamespace != null) {
+ props.put(RegistryImpl.UDDI_NAMESPACE_PROPERTY_NAME, uddiNamespace);
+ }
+ if (uddiVersion != null) {
+ props.put(RegistryImpl.UDDI_VERSION_PROPERTY_NAME, uddiVersion);
+ }
+
+ this.overrideProperties(System.getProperties(),props);
+
+ return props;
+ }
+
+ /**
+ * Update the properties used by this ConnectionFactory to obtain a connection.
+ *
+ * @param properties the new properties for this ConnectionFactory
+ */
+ public void setProperties(Properties properties)
+ {
+
+ this.overrideProperties(System.getProperties(),properties);
+ queryManagerURL = properties.getProperty(QUERYMANAGER_PROPERTY);
+ lifeCycleManagerURL = properties.getProperty(LIFECYCLEMANAGER_PROPERTY);
+ securityManagerURL = properties.getProperty(SECURITYMANAGER_PROPERTY);
+
+ transportClass = properties.getProperty(RegistryImpl.TRANSPORT_CLASS_PROPERTY_NAME);
+ semanticEquivalences = properties.getProperty(SEMANTICEQUIVALENCES_PROPERTY);
+ authenticationMethod = properties.getProperty(AUTHENTICATIONMETHOD_PROPERTY);
+ postalAddressScheme = properties.getProperty(POSTALADDRESSSCHEME_PROPERTY);
+ uddiVersion = properties.getProperty(RegistryImpl.UDDI_VERSION_PROPERTY_NAME);
+ uddiNamespace = properties.getProperty(RegistryImpl.UDDI_NAMESPACE_PROPERTY_NAME);
+
+ String val = properties.getProperty(MAXROWS_PROPERTY);
+ maxRows = (val == null) ? null : Integer.valueOf(val);
+ }
+
+ public static ConnectionFactory newInstance()
+ {
+ return new ConnectionFactoryImpl();
+ }
+
+ public String getAuthenticationMethod()
+ {
+ return authenticationMethod;
+ }
+
+ public void setAuthenticationMethod(String authenticationMethod)
+ {
+ this.authenticationMethod = authenticationMethod;
+ }
+
+ public String getLifeCycleManagerURL()
+ {
+ return lifeCycleManagerURL;
+ }
+
+ public void setLifeCycleManagerURL(String lifeCycleManagerURL)
+ {
+ this.lifeCycleManagerURL = lifeCycleManagerURL;
+ }
+
+ public Integer getMaxRows()
+ {
+ return maxRows;
+ }
+
+ public void setMaxRows(Integer maxRows)
+ {
+ this.maxRows = maxRows;
+ }
+
+ public String getPostalAddressScheme()
+ {
+ return postalAddressScheme;
+ }
+
+ public void setPostalAddressScheme(String postalAddressScheme)
+ {
+ this.postalAddressScheme = postalAddressScheme;
+ }
+
+ public String getQueryManagerURL()
+ {
+ return queryManagerURL;
+ }
+
+ public void setQueryManagerURL(String queryManagerURL)
+ {
+ this.queryManagerURL = queryManagerURL;
+ }
+
+ public String getSemanticEquivalences()
+ {
+ return semanticEquivalences;
+ }
+
+ public void setSemanticEquivalences(String semanticEquivalences)
+ {
+ this.semanticEquivalences = semanticEquivalences;
+ }
+
+ public String getTransportClass() {
+ return transportClass;
+ }
+
+ public void setTransportClass(String transportClass) {
+ this.transportClass = transportClass;
+ }
+
+ private static void overrideProperties(Properties source, Properties dest) {
+ for (Map.Entry<Object, Object> entry : source.entrySet()) {
+ if (!(entry.getKey() instanceof String)) continue;
+ if (!(entry.getValue() instanceof String)) continue;
+
+ String key = (String) entry.getKey();
+ dest.put(entry.getKey(), entry.getValue());
+ }
+ }
+}
Added: geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/registry/RegistryV3Impl.java
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/registry/RegistryV3Impl.java?rev=1103343&view=auto
==============================================================================
--- geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/registry/RegistryV3Impl.java (added)
+++ geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/registry/RegistryV3Impl.java Sun May 15 12:38:02 2011
@@ -0,0 +1,1256 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.scout.registry;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.scout.transport.Transport;
+import org.apache.ws.scout.transport.TransportException;
+import org.apache.ws.scout.util.XMLUtils;
+import org.uddi.api_v3.AssertionStatusReport;
+import org.uddi.api_v3.AuthToken;
+import org.uddi.api_v3.BindingDetail;
+import org.uddi.api_v3.BindingTemplate;
+import org.uddi.api_v3.BusinessDetail;
+import org.uddi.api_v3.BusinessEntity;
+import org.uddi.api_v3.BusinessList;
+import org.uddi.api_v3.BusinessService;
+import org.uddi.api_v3.CategoryBag;
+import org.uddi.api_v3.CompletionStatus;
+import org.uddi.api_v3.DeleteBinding;
+import org.uddi.api_v3.DeleteBusiness;
+import org.uddi.api_v3.DeletePublisherAssertions;
+import org.uddi.api_v3.DeleteService;
+import org.uddi.api_v3.DeleteTModel;
+import org.uddi.api_v3.DiscoveryURLs;
+import org.uddi.api_v3.DispositionReport;
+import org.uddi.api_v3.FindBinding;
+import org.uddi.api_v3.FindBusiness;
+import org.uddi.api_v3.FindQualifiers;
+import org.uddi.api_v3.FindService;
+import org.uddi.api_v3.FindTModel;
+import org.uddi.api_v3.GetAssertionStatusReport;
+import org.uddi.api_v3.GetAuthToken;
+import org.uddi.api_v3.GetBusinessDetail;
+import org.uddi.api_v3.GetPublisherAssertions;
+import org.uddi.api_v3.GetRegisteredInfo;
+import org.uddi.api_v3.GetServiceDetail;
+import org.uddi.api_v3.GetTModelDetail;
+import org.uddi.api_v3.IdentifierBag;
+import org.uddi.api_v3.InfoSelection;
+import org.uddi.api_v3.Name;
+import org.uddi.api_v3.ObjectFactory;
+import org.uddi.api_v3.PublisherAssertion;
+import org.uddi.api_v3.PublisherAssertions;
+import org.uddi.api_v3.PublisherAssertionsResponse;
+import org.uddi.api_v3.RegisteredInfo;
+import org.uddi.api_v3.SaveBinding;
+import org.uddi.api_v3.SaveBusiness;
+import org.uddi.api_v3.SaveService;
+import org.uddi.api_v3.SaveTModel;
+import org.uddi.api_v3.ServiceDetail;
+import org.uddi.api_v3.ServiceList;
+import org.uddi.api_v3.SetPublisherAssertions;
+import org.uddi.api_v3.TModel;
+import org.uddi.api_v3.TModelBag;
+import org.uddi.api_v3.TModelDetail;
+import org.uddi.api_v3.TModelList;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * RegistryImpl is the implementation of IRegistry.
+ *
+ * <p>The execute() function signature has been changed slightly from the jUDDI
+ * version, since the URL can no longer be decided dynamically (in an easy
+ * enough manner) as we don't use jUDDI data types anymore.</p>
+ *
+ * <i>The function code is borrowed from jUDDI, with appropriate modifications so
+ * that xmlbeans data types are used intead of jUDDI data types.</i>
+ *
+ */
+
+public class RegistryV3Impl implements IRegistryV3 {
+
+ public static final String INQUIRY_ENDPOINT_PROPERTY_NAME = "scout.proxy.inquiryURL";
+ public static final String PUBLISH_ENDPOINT_PROPERTY_NAME = "scout.proxy.publishURL";
+ public static final String SECURITY_ENDPOINT_PROPERTY_NAME = "scout.proxy.securityURL";
+ public static final String ADMIN_ENDPOINT_PROPERTY_NAME = "scout.proxy.adminURL";
+ public static final String TRANSPORT_CLASS_PROPERTY_NAME = "scout.proxy.transportClass";
+ public static final String SECURITY_PROVIDER_PROPERTY_NAME = "scout.proxy.securityProvider";
+ public static final String PROTOCOL_HANDLER_PROPERTY_NAME = "scout.proxy.protocolHandler";
+ public static final String UDDI_VERSION_PROPERTY_NAME = "scout.proxy.uddiVersion";
+ public static final String UDDI_NAMESPACE_PROPERTY_NAME = "scout.proxy.uddiNamespace";
+
+ public static final String DEFAULT_INQUIRY_ENDPOINT = "http://localhost/juddi/inquiry";
+ public static final String DEFAULT_PUBLISH_ENDPOINT = "http://localhost/juddi/publish";
+ public static final String DEFAULT_SECURITY_ENDPOINT = "http://localhost/juddi/security";
+ public static final String DEFAULT_ADMIN_ENDPOINT = "http://localhost/juddi/admin";
+ public static final String DEFAULT_TRANSPORT_CLASS = "org.apache.ws.scout.transport.AxisTransport";
+ public static final String DEFAULT_SECURITY_PROVIDER = "com.sun.net.ssl.internal.ssl.Provider";
+ public static final String DEFAULT_PROTOCOL_HANDLER = "com.sun.net.ssl.internal.www.protocol";
+ public static final String DEFAULT_UDDI_VERSION = "2.0";
+ public static final String DEFAULT_UDDI_NAMESPACE = "urn:uddi-org:api_v2";
+
+ private URI adminURI;
+ private URI inquiryURI;
+ private URI publishURI;
+ private URI securityURI;
+
+ private Transport transport;
+
+ private String securityProvider;
+ private String protocolHandler;
+ private String uddiVersion;
+ private String uddiNamespace;
+
+ private ObjectFactory objectFactory = new ObjectFactory();
+
+ private Marshaller marshaller = null;
+ private Unmarshaller unmarshaller = null;
+
+ private static Log log = LogFactory.getLog(RegistryV3Impl.class);
+
+ /**
+ * Creates a new instance of RegistryImpl.
+ */
+ public RegistryV3Impl(Properties props) {
+ super();
+
+ this.init(props);
+ }
+
+ /**
+ *
+ */
+ private void init(Properties props) {
+ // We need to have a non-null Properties
+ // instance so initialization takes place.
+ if (props == null)
+ props = new Properties();
+
+ // Override defaults with specific specific values
+ try {
+ String iURL = props.getProperty(INQUIRY_ENDPOINT_PROPERTY_NAME);
+ if (iURL != null)
+ this.setInquiryURI(new URI(iURL));
+ else
+ this.setInquiryURI(new URI(DEFAULT_INQUIRY_ENDPOINT));
+
+ String pURL = props.getProperty(PUBLISH_ENDPOINT_PROPERTY_NAME);
+ if (pURL != null)
+ this.setPublishURI(new URI(pURL));
+ else
+ this.setPublishURI(new URI(DEFAULT_PUBLISH_ENDPOINT));
+
+ String sURL = props.getProperty(SECURITY_ENDPOINT_PROPERTY_NAME);
+ if (sURL != null)
+ this.setSecurityURI(new URI(sURL));
+ else
+ this.setSecurityURI(new URI(DEFAULT_SECURITY_ENDPOINT));
+
+ String aURL = props.getProperty(ADMIN_ENDPOINT_PROPERTY_NAME);
+ if (aURL != null)
+ this.setAdminURI(new URI(aURL));
+ else
+ this.setAdminURI(new URI(DEFAULT_ADMIN_ENDPOINT));
+ } catch (URISyntaxException muex) {
+ throw new RuntimeException(muex);
+ }
+
+ String secProvider = props.getProperty(SECURITY_PROVIDER_PROPERTY_NAME);
+ if (secProvider != null)
+ this.setSecurityProvider(secProvider);
+ else
+ this.setSecurityProvider(DEFAULT_SECURITY_PROVIDER);
+
+ String protoHandler = props.getProperty(PROTOCOL_HANDLER_PROPERTY_NAME);
+ if (protoHandler != null)
+ this.setProtocolHandler(protoHandler);
+ else
+ this.setProtocolHandler(DEFAULT_PROTOCOL_HANDLER);
+
+ String uddiVer = props.getProperty(UDDI_VERSION_PROPERTY_NAME);
+ if (uddiVer != null)
+ this.setUddiVersion(uddiVer);
+ else
+ this.setUddiVersion(DEFAULT_UDDI_VERSION);
+
+ String uddiNS = props.getProperty(UDDI_NAMESPACE_PROPERTY_NAME);
+ if (uddiNS != null)
+ this.setUddiNamespace(uddiNS);
+ else
+ this.setUddiNamespace(DEFAULT_UDDI_NAMESPACE);
+
+ String transClass = props.getProperty(TRANSPORT_CLASS_PROPERTY_NAME);
+ if (transClass != null)
+ this.setTransport(this.getTransport(transClass));
+ else
+ this.setTransport(this.getTransport(DEFAULT_TRANSPORT_CLASS));
+
+ try
+ {
+ JAXBContext v3context = JAXBContextUtil.getContext(JAXBContextUtil.UDDI_V3_VERSION);
+ this.unmarshaller = v3context.createUnmarshaller();
+ this.marshaller = v3context.createMarshaller();
+
+ }
+ catch(JAXBException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ *
+ * @param uddiRequest
+ * @return String
+ * @throws RegistryV3Exception
+ */
+ public String execute(String uddiRequest, String urltype)
+ throws TransportException {
+ URI endPointURL = null;
+ if (urltype.equalsIgnoreCase("INQUIRY"))
+ endPointURL = this.getInquiryURI();
+ else
+ endPointURL = this.getPublishURI();
+
+ // A SOAP request is made and a SOAP response
+ // is returned.
+
+ return transport.send(uddiRequest, endPointURL);
+ }
+
+ /**
+ *
+ */
+ public JAXBElement<?> execute(JAXBElement<?> uddiRequest, URI endPointURI)
+ throws RegistryV3Exception {
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ Document doc;
+ try {
+ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+ docBuilderFactory.setNamespaceAware(true);
+ DocumentBuilder docBuilder= docBuilderFactory.newDocumentBuilder();
+ this.marshaller.marshal(uddiRequest, baos);
+ doc = docBuilder.parse(new ByteArrayInputStream(baos.toByteArray()));
+ } catch (SAXException saxe) {
+ throw (new RegistryV3Exception(saxe));
+ } catch (ParserConfigurationException pce) {
+ throw (new RegistryV3Exception(pce));
+ } catch (IOException ioe) {
+ throw (new RegistryV3Exception(ioe));
+ } catch (JAXBException ioe) {
+ throw (new RegistryV3Exception(ioe));
+ }
+ Element request = doc.getDocumentElement();
+
+ request.setAttribute("xmlns", this.getUddiNamespace());
+ if (!"3.0".equals(this.getUddiVersion())) {
+ request.setAttribute("generic", this.getUddiVersion());
+ }
+ //request.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns", this.getUddiNamespace());
+ // A SOAP request is made and a SOAP response
+ // is returned.
+
+ Element response;
+ try {
+ response = transport.send(request, endPointURI);
+ } catch (TransportException te) {
+ throw new RegistryV3Exception(te);
+ }
+ /* if (response.hasAttributes()) {
+ NamedNodeMap am = response.getAttributes();
+ ArrayList<String> al = new ArrayList<String>();
+ for (int i = 0; i < am.getLength(); i++) {
+ Node n = am.item(i);
+ String attribute = n.getNodeName();
+ if (attribute!= null && attribute.startsWith("xmlns")) {
+ al.add(attribute);
+ }
+ }
+ for (String attr : al) {
+ response.removeAttribute(attr);
+ }
+ }*/
+
+ if (response.getNamespaceURI()==null) {
+ response.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns", this.getUddiNamespace());
+ }
+
+ // If we are getting responses from a UDDI v3, remove the xmlns
+
+ // First, let's make sure that a response
+ // (any response) is found in the SOAP Body.
+
+ String responseName = response.getLocalName();
+ if (responseName == null) {
+ throw new RegistryV3Exception("Unsupported response "
+ + "from registry. A value was not present.");
+ }
+
+ // Let's now try to determine which UDDI response
+ // we received and unmarshal it appropriately or
+ // throw a RegistryV3Exception if it's unknown.
+ // Well, we have now determined that something was
+ // returned and it is "a something" that we know
+ // about so let's unmarshal it into a RegistryObject
+ // Next, let's make sure we didn't recieve a SOAP
+ // Fault. If it is a SOAP Fault then throw it
+ // immediately.
+
+ JAXBElement<?> uddiResponse = null;
+ try {
+ String xml = XMLUtils.convertNodeToXMLString(response);
+ log.debug("Response is: " + xml);
+
+ StringReader reader = new StringReader(xml);
+ uddiResponse = (JAXBElement<?>) unmarshaller.unmarshal(new StreamSource(reader));
+ //It is probably faster not to go to a String, but JAXB has issues with this
+ //uddiResponse = (JAXBElement<?>) unmarshaller.unmarshal(response);
+
+ } catch (JAXBException xmle) {
+ throw (new RegistryV3Exception(xmle));
+ }
+
+ if (responseName.toLowerCase().equals("fault")) {
+ NodeList nodeList = null;
+
+ // Child Elements
+ String fCode = null;
+ nodeList = response.getElementsByTagName("faultcode");
+ if (nodeList.getLength() > 0)
+ fCode = nodeList.item(0).getNodeValue();
+
+ String fString = null;
+ nodeList = response.getElementsByTagName("faultstring");
+ if (nodeList.getLength() > 0)
+ fString = nodeList.item(0).getNodeValue();
+
+ String fActor = null;
+ nodeList = response.getElementsByTagName("faultactor");
+ if (nodeList.getLength() > 0)
+ fActor = nodeList.item(0).getNodeValue();
+
+ DispositionReport dispRpt = null;
+
+ nodeList = response.getElementsByTagName("detail");
+ if (nodeList.getLength() > 0) {
+ nodeList = ((Element) nodeList.item(0))
+ .getElementsByTagName("dispositionReport");
+ if (nodeList.getLength() > 0) {
+ JAXBElement<DispositionReport> dispRptObj = null;
+ try {
+ dispRptObj = (JAXBElement<DispositionReport>) unmarshaller.unmarshal((Element) nodeList
+ .item(0));
+ } catch (JAXBException xmle) {
+ throw (new RegistryV3Exception(xmle));
+ }
+ dispRpt = dispRptObj.getValue();
+ }
+ }
+
+ RegistryV3Exception e = new RegistryV3Exception(fCode, fString, fActor, dispRpt);
+
+ // Create RegistryV3Exception instance and return
+ throw e;
+ }
+
+ return uddiResponse;
+ }
+
+ /**
+ * @return Returns the adminURL.
+ */
+ public URI getAdminURI() {
+ return this.adminURI;
+ }
+
+ /**
+ * @param url
+ * The adminURL to set.
+ */
+ public void setAdminURI(URI url) {
+ this.adminURI = url;
+ }
+
+ /**
+ * @return Returns the inquiryURL.
+ */
+ public URI getInquiryURI() {
+ return this.inquiryURI;
+ }
+
+ /**
+ * @param inquiryURI
+ * The inquiryURI to set.
+ */
+ public void setInquiryURI(URI inquiryURI) {
+ this.inquiryURI = inquiryURI;
+ }
+
+ /**
+ * @return Returns the protocolHandler.
+ */
+ public String getProtocolHandler() {
+ return this.protocolHandler;
+ }
+
+ /**
+ * @param protocolHandler
+ * The protocolHandler to set.
+ */
+ public void setProtocolHandler(String protocolHandler) {
+ this.protocolHandler = protocolHandler;
+ }
+
+ /**
+ * @return Returns the publishURL.
+ */
+ public URI getPublishURI() {
+ return this.publishURI;
+ }
+
+ /**
+ * @return Returns the publishURL.
+ */
+ public URI getSecurityURI() {
+ return this.securityURI;
+ }
+
+ /**
+ * @param publishURI
+ * The publishURI to set.
+ */
+ public void setPublishURI(URI publishURI) {
+ this.publishURI = publishURI;
+ }
+
+ /**
+ * @param publishURI
+ * The publishURI to set.
+ */
+ public void setSecurityURI(URI securityURI) {
+ this.securityURI = securityURI;
+ }
+
+ /**
+ * @return Returns the securityProvider.
+ */
+ public String getSecurityProvider() {
+ return this.securityProvider;
+ }
+
+ /**
+ * @param securityProvider
+ * The securityProvider to set.
+ */
+ public void setSecurityProvider(String securityProvider) {
+ this.securityProvider = securityProvider;
+ }
+
+ /**
+ * @return Returns the transport.
+ */
+ public Transport getTransport() {
+ return transport;
+ }
+
+ /**
+ * @param transport
+ * The transport to set.
+ */
+ public void setTransport(Transport transport) {
+ this.transport = transport;
+ }
+
+ /**
+ * @return Returns the uddiNS.
+ */
+ public String getUddiNamespace() {
+ return this.uddiNamespace;
+ }
+
+ /**
+ * @param uddiNS
+ * The uddiNS to set.
+ */
+ public void setUddiNamespace(String uddiNS) {
+ this.uddiNamespace = uddiNS;
+ }
+
+ /**
+ * @return Returns the uddiVersion.
+ */
+ public String getUddiVersion() {
+ return this.uddiVersion;
+ }
+
+ /**
+ * @param uddiVersion
+ * The uddiVersion to set.
+ */
+ public void setUddiVersion(String uddiVersion) {
+ this.uddiVersion = uddiVersion;
+ }
+
+ /**
+ * "Used to remove an existing bindingTemplate from the bindingTemplates
+ * collection that is part of a specified businessService structure."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public DispositionReport deleteBinding(String authInfo,
+ String[] bindingKeyArray) throws RegistryV3Exception {
+ DeleteBinding request = this.objectFactory.createDeleteBinding();
+
+ if (authInfo != null) {
+ request.setAuthInfo(authInfo);
+ }
+
+ if (bindingKeyArray != null) {
+ request.getBindingKey().addAll(Arrays.asList(bindingKeyArray));
+ }
+
+ DispositionReport dr;
+ JAXBElement<?> o = execute(this.objectFactory.createDeleteBinding(request), this.getPublishURI());
+ dr = (DispositionReport) o.getValue();
+
+ return dr;
+ }
+
+ /**
+ * "Used to delete registered businessEntity information from the registry."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public DispositionReport deleteBusiness(String authInfo,
+ String[] businessKeyArray) throws RegistryV3Exception {
+ DeleteBusiness request = this.objectFactory.createDeleteBusiness();
+
+ if (authInfo != null) {
+ request.setAuthInfo(authInfo);
+ }
+
+ if (businessKeyArray != null) {
+ request.getBusinessKey().addAll(Arrays.asList(businessKeyArray));
+ }
+
+ DispositionReport dr;
+ JAXBElement<?> o = execute(this.objectFactory.createDeleteBusiness(request), this.getPublishURI());
+ dr = (DispositionReport) o.getValue();
+
+ return dr;
+ }
+
+ /**
+ * @exception RegistryV3Exception;
+ */
+ public DispositionReport deletePublisherAssertions(String authInfo,
+ PublisherAssertion[] assertionArray) throws RegistryV3Exception {
+ DeletePublisherAssertions request = this.objectFactory.createDeletePublisherAssertions();
+
+ if (authInfo != null) {
+ request.setAuthInfo(authInfo);
+ }
+
+ if (assertionArray != null) {
+ request.getPublisherAssertion().addAll(Arrays.asList(assertionArray));
+ }
+
+ DispositionReport dr;
+ JAXBElement<?> o = execute(this.objectFactory.createDeletePublisherAssertions(request),
+ this.getPublishURI());
+ dr = (DispositionReport) o.getValue();
+
+ return dr;
+ }
+
+ /**
+ * "Used to delete an existing businessService from the businessServices
+ * collection that is part of a specified businessEntity."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public DispositionReport deleteService(String authInfo,
+ String[] serviceKeyArray) throws RegistryV3Exception {
+ DeleteService request = this.objectFactory.createDeleteService();
+
+ if (authInfo != null) {
+ request.setAuthInfo(authInfo);
+ }
+
+ if (serviceKeyArray != null) {
+ request.getServiceKey().addAll(Arrays.asList(serviceKeyArray));
+ }
+
+ DispositionReport dr;
+ JAXBElement<?> o = execute(this.objectFactory.createDeleteService(request),
+ this.getPublishURI());
+ dr = (DispositionReport) o.getValue();
+
+ return dr;
+ }
+
+ /**
+ * "Used to delete registered information about a tModel. If there are any
+ * references to a tModel when this call is made, the tModel will be marked
+ * deleted instead of being physically removed."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public DispositionReport deleteTModel(String authInfo,
+ String[] tModelKeyArray) throws RegistryV3Exception {
+ DeleteTModel request = this.objectFactory.createDeleteTModel();
+
+ if (authInfo != null) {
+ request.setAuthInfo(authInfo);
+ }
+
+ if (tModelKeyArray != null) {
+ request.getTModelKey().addAll(Arrays.asList(tModelKeyArray));
+ }
+
+ DispositionReport dr;
+ JAXBElement<?> o = execute(this.objectFactory.createDeleteTModel(request),
+ this.getPublishURI());
+ dr = (DispositionReport) o.getValue();
+
+ return dr;
+ }
+
+ /**
+ * Used to locate information about one or more businesses. Returns a
+ * businessList message that matches the conditions specified.
+ *
+ * @exception RegistryV3Exception;
+ */
+ public BusinessList findBusiness(Name[] nameArray,
+ DiscoveryURLs discoveryURLs, IdentifierBag identifierBag,
+ CategoryBag categoryBag, TModelBag tModelBag,
+ FindQualifiers findQualifiers, int maxRows)
+ throws RegistryV3Exception {
+ FindBusiness request = this.objectFactory.createFindBusiness();
+
+ if (nameArray != null) {
+ request.getName().addAll(Arrays.asList(nameArray));
+ }
+
+ if (discoveryURLs != null) {
+ request.setDiscoveryURLs(discoveryURLs);
+ }
+
+ if (identifierBag != null) {
+ request.setIdentifierBag(identifierBag);
+ }
+
+ if (categoryBag != null) {
+ request.setCategoryBag(categoryBag);
+ }
+
+ if (tModelBag != null) {
+ request.setTModelBag(tModelBag);
+ }
+
+ if (findQualifiers != null) {
+ request.setFindQualifiers(findQualifiers);
+ }
+
+ request.setMaxRows(maxRows);
+
+ BusinessList bl;
+ JAXBElement<?> o = execute(this.objectFactory.createFindBusiness(request),
+ this.getInquiryURI());
+ bl = (BusinessList) o.getValue();
+
+ return bl;
+ }
+
+ /**
+ * "Used to locate specific bindings within a registered businessService.
+ * Returns a bindingDetail message."
+ *
+ * @exception RegistryV3Exception
+ */
+ public BindingDetail findBinding(String serviceKey,
+ CategoryBag categoryBag, TModelBag tModelBag,
+ FindQualifiers findQualifiers, int maxRows)
+ throws RegistryV3Exception {
+ // FIXME: Juddi's methods also set category bag (per uddi spec v3).
+ // However, we are sticking to v2 for now, so categorybag doesn't
+ // exist under FindBinding. It is fine for now, since the incoming
+ // parameter value is always null anyways -- but this may change
+ // in the future.
+
+ FindBinding request = this.objectFactory.createFindBinding();
+
+ if (serviceKey != null) {
+ request.setServiceKey(serviceKey);
+ }
+
+ if (categoryBag != null) {
+ request.setCategoryBag(categoryBag);
+ }
+
+ if (tModelBag != null) {
+ request.setTModelBag(tModelBag);
+ }
+
+ if (findQualifiers != null) {
+ request.setFindQualifiers(findQualifiers);
+ }
+ request.setMaxRows(maxRows);
+
+ BindingDetail bd;
+ JAXBElement<?> o = execute(this.objectFactory.createFindBinding(request),
+ this.getInquiryURI());
+ bd = (BindingDetail) o.getValue();
+
+ return bd;
+ }
+
+ /**
+ * "Used to locate specific services within a registered businessEntity.
+ * Return a serviceList message." From the XML spec (API, p18) it appears
+ * that the name, categoryBag, and tModelBag arguments are mutually
+ * exclusive.
+ *
+ * @exception RegistryV3Exception;
+ */
+ public ServiceList findService(String businessKey, Name[] nameArray,
+ CategoryBag categoryBag, TModelBag tModelBag,
+ FindQualifiers findQualifiers, int maxRows)
+ throws RegistryV3Exception {
+ FindService request = this.objectFactory.createFindService();
+
+ if (businessKey != null) {
+ request.setBusinessKey(businessKey);
+ }
+
+ if (nameArray != null) {
+ request.getName().addAll(Arrays.asList(nameArray));
+ }
+
+ if (categoryBag != null) {
+ request.setCategoryBag(categoryBag);
+ }
+
+ if (tModelBag != null) {
+ request.setTModelBag(tModelBag);
+ }
+
+ if (findQualifiers != null) {
+ request.setFindQualifiers(findQualifiers);
+ }
+
+ request.setMaxRows(maxRows);
+
+ ServiceList sl;
+ JAXBElement<?> o = execute(this.objectFactory.createFindService(request),
+ this.getInquiryURI());
+ sl = (ServiceList) o.getValue();
+
+ return sl;
+ }
+
+ /**
+ * "Used to locate one or more tModel information structures. Returns a
+ * tModelList structure."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public TModelList findTModel(String name, CategoryBag categoryBag,
+ IdentifierBag identifierBag, FindQualifiers findQualifiers,
+ int maxRows) throws RegistryV3Exception {
+ FindTModel request = this.objectFactory.createFindTModel();
+
+ Name jaxbName = this.objectFactory.createName();
+
+ if (name != null) {
+ jaxbName.setValue(name);
+ }
+
+ request.setName(jaxbName);
+
+ if (categoryBag != null) {
+ request.setCategoryBag(categoryBag);
+ }
+
+ if (identifierBag != null) {
+ request.setIdentifierBag(identifierBag);
+ }
+
+ if (findQualifiers != null) {
+ request.setFindQualifiers(findQualifiers);
+ }
+
+ request.setMaxRows(maxRows);
+
+ TModelList tml;
+ JAXBElement<?> o = execute(this.objectFactory.createFindTModel(request),
+ this.getInquiryURI());
+ tml = (TModelList) o.getValue();
+
+ return tml;
+ }
+
+ /**
+ * @exception RegistryV3Exception;
+ */
+ public AssertionStatusReport getAssertionStatusReport(String authInfo,
+ String completionStatus) throws RegistryV3Exception {
+ GetAssertionStatusReport request = this.objectFactory.createGetAssertionStatusReport();
+
+ if (authInfo != null) {
+ request.setAuthInfo(authInfo);
+ }
+
+ if (completionStatus != null) {
+ CompletionStatus cs = CompletionStatus.fromValue(completionStatus);
+ request.setCompletionStatus(cs);
+ }
+
+ AssertionStatusReport asr;
+ JAXBElement<?> o = execute(this.objectFactory.createGetAssertionStatusReport(request),
+ this.getPublishURI());
+ asr = (AssertionStatusReport) o.getValue();
+
+ return asr;
+ }
+
+ /**
+ * "Used to request an authentication token from an Operator Site.
+ * Authentication tokens are required to use all other APIs defined in the
+ * publishers API. This server serves as the program's equivalent of a login
+ * request."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public AuthToken getAuthToken(String userID, String cred)
+ throws RegistryV3Exception {
+ GetAuthToken request = this.objectFactory.createGetAuthToken();
+
+ if (userID != null) {
+ request.setUserID(userID);
+ }
+
+ if (cred != null) {
+ request.setCred(cred);
+ }
+
+ URI getAuthTokenURI = null;
+ if ("3.0".equals(uddiVersion)) {
+ getAuthTokenURI = this.getSecurityURI();
+ } else {
+ getAuthTokenURI = this.getPublishURI();
+ }
+
+ AuthToken at;
+ JAXBElement<?> o = execute(this.objectFactory.createGetAuthToken(request),
+ getAuthTokenURI);
+ at = (AuthToken) o.getValue();
+
+ return at;
+ }
+
+ /**
+ * Used to get the full businessEntity information for a particular business
+ * entity. Returns a businessDetail message.
+ *
+ * @exception RegistryV3Exception;
+ */
+ public BusinessDetail getBusinessDetail(String businessKey)
+ throws RegistryV3Exception {
+ String[] keys = new String[1];
+ keys[0] = businessKey;
+
+ return getBusinessDetail(keys);
+ }
+
+ /**
+ * "Used to get the full businessEntity information for one or more
+ * businesses. Returns a businessDetail message."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public BusinessDetail getBusinessDetail(String[] businessKeyArray)
+ throws RegistryV3Exception {
+ GetBusinessDetail request = this.objectFactory.createGetBusinessDetail();
+
+ if (businessKeyArray != null) {
+ request.getBusinessKey().addAll(Arrays.asList(businessKeyArray));
+ }
+
+ BusinessDetail bd;
+ JAXBElement<?> o = execute(this.objectFactory.createGetBusinessDetail(request),
+ this.getInquiryURI());
+ bd = (BusinessDetail) o.getValue();
+ return bd;
+ }
+
+ /**
+ * @exception RegistryV3Exception;
+ */
+ public PublisherAssertions getPublisherAssertions(String authInfo)
+ throws RegistryV3Exception {
+ GetPublisherAssertions request = this.objectFactory.createGetPublisherAssertions();
+
+ if (authInfo != null) {
+ request.setAuthInfo(authInfo);
+ }
+
+ PublisherAssertions pa = new PublisherAssertions();
+ JAXBElement<?> o = execute(this.objectFactory.createGetPublisherAssertions(request),
+ this.getPublishURI());
+ PublisherAssertionsResponse par = (PublisherAssertionsResponse) o.getValue();
+ List<PublisherAssertion> assertions = par.getPublisherAssertion();
+ for (int i = 0; i < assertions.size(); i++ ) {
+ pa.getPublisherAssertion().add((PublisherAssertion)assertions.get(i));
+ }
+
+ return pa;
+ }
+
+ /**
+ * @exception RegistryV3Exception;
+ */
+ public RegisteredInfo getRegisteredInfo(String authInfo)
+ throws RegistryV3Exception {
+ GetRegisteredInfo request = this.objectFactory.createGetRegisteredInfo();
+
+ if (authInfo != null) {
+ request.setAuthInfo(authInfo);
+ }
+
+ request.setInfoSelection(InfoSelection.ALL);
+
+ RegisteredInfo ri;
+ JAXBElement<?> o = execute(this.objectFactory.createGetRegisteredInfo(request),
+ this.getPublishURI());
+ ri = (RegisteredInfo) o.getValue();
+
+ return ri;
+ }
+
+ /**
+ * "Used to get full details for a particular registered businessService.
+ * Returns a serviceDetail message."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public ServiceDetail getServiceDetail(String serviceKey)
+ throws RegistryV3Exception {
+ String[] keys = new String[1];
+ keys[0] = serviceKey;
+
+ return getServiceDetail(keys);
+ }
+
+ /**
+ * "Used to get full details for a given set of registered businessService
+ * data. Returns a serviceDetail message."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public ServiceDetail getServiceDetail(String[] serviceKeyArray)
+ throws RegistryV3Exception {
+ GetServiceDetail request = this.objectFactory.createGetServiceDetail();
+
+ if (serviceKeyArray != null) {
+ request.getServiceKey().addAll(Arrays.asList(serviceKeyArray));
+ }
+
+ ServiceDetail sd;
+ JAXBElement<?> o = execute(this.objectFactory.createGetServiceDetail(request),
+ this.getInquiryURI());
+ sd = (ServiceDetail) o.getValue();
+
+ return sd;
+ }
+
+ /**
+ * "Used to get full details for a particular registered TModel. Returns a
+ * tModelDetail message."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public TModelDetail getTModelDetail(String tModelKey)
+ throws RegistryV3Exception {
+ String[] keys = new String[1];
+ keys[0] = tModelKey;
+
+ return getTModelDetail(keys);
+ }
+
+ /**
+ * "Used to get full details for a given set of registered tModel data.
+ * Returns a tModelDetail message."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public TModelDetail getTModelDetail(String[] tModelKeyArray)
+ throws RegistryV3Exception {
+ GetTModelDetail request = this.objectFactory.createGetTModelDetail();
+
+ if (tModelKeyArray != null) {
+ request.getTModelKey().addAll(Arrays.asList(tModelKeyArray));
+ }
+
+ TModelDetail tmd;
+ JAXBElement<?> o = execute(this.objectFactory.createGetTModelDetail(request),
+ this.getInquiryURI());
+ tmd = (TModelDetail) o.getValue();
+
+ return tmd;
+ }
+
+ /**
+ * @exception RegistryV3Exception;
+ */
+ public PublisherAssertions setPublisherAssertions(String authInfo,
+ PublisherAssertion[] assertionArray) throws RegistryV3Exception {
+ SetPublisherAssertions request = this.objectFactory.createSetPublisherAssertions();
+
+ if (authInfo != null) {
+ request.setAuthInfo(authInfo);
+ }
+
+ if (assertionArray != null) {
+ request.getPublisherAssertion().addAll(Arrays.asList(assertionArray));
+ }
+
+ PublisherAssertions pa;
+ JAXBElement<?> o = execute(this.objectFactory.createSetPublisherAssertions(request),
+ this.getPublishURI());
+ pa = (PublisherAssertions) o.getValue();
+
+ return pa;
+ }
+
+ /**
+ * "Used to register new bindingTemplate information or update existing
+ * bindingTemplate information. Use this to control information about
+ * technical capabilities exposed by a registered business."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public BindingDetail saveBinding(String authInfo,
+ BindingTemplate[] bindingArray) throws RegistryV3Exception {
+ SaveBinding request = this.objectFactory.createSaveBinding();
+
+ if (authInfo != null) {
+ request.setAuthInfo(authInfo);
+ }
+
+ if (bindingArray != null) {
+ request.getBindingTemplate().addAll(Arrays.asList(bindingArray));
+ }
+
+ BindingDetail bd;
+ JAXBElement<?> o = execute(this.objectFactory.createSaveBinding(request),
+ this.getPublishURI());
+ bd = (BindingDetail) o.getValue();
+
+ return bd;
+ }
+
+ /**
+ * "Used to register new businessEntity information or update existing
+ * businessEntity information. Use this to control the overall information
+ * about the entire business. Of the save_x APIs this one has the broadest
+ * effect."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public BusinessDetail saveBusiness(String authInfo,
+ BusinessEntity[] businessArray) throws RegistryV3Exception {
+ SaveBusiness request = this.objectFactory.createSaveBusiness();
+
+ if (authInfo != null) {
+ request.setAuthInfo(authInfo);
+ }
+
+ if (businessArray != null) {
+ for (int i = 0; i < businessArray.length; i++) {
+ BusinessEntity be = businessArray[i];
+ if (be.getBusinessServices().getBusinessService().size() == 0) {
+ be.setBusinessServices(null);
+ }
+ }
+
+ request.getBusinessEntity().addAll(Arrays.asList(businessArray));
+ }
+
+ BusinessDetail bd;
+ JAXBElement<?> o = execute(this.objectFactory.createSaveBusiness(request),
+ this.getPublishURI());
+ bd = (BusinessDetail) o.getValue();
+
+ return bd;
+ }
+
+ /**
+ * "Used to register or update complete information about a businessService
+ * exposed by a specified businessEntity."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public ServiceDetail saveService(String authInfo,
+ BusinessService[] serviceArray) throws RegistryV3Exception {
+ SaveService request = this.objectFactory.createSaveService();
+
+ if (authInfo != null) {
+ request.setAuthInfo(authInfo);
+ }
+
+ if (serviceArray != null) {
+ request.getBusinessService().addAll(Arrays.asList(serviceArray));
+ }
+
+ ServiceDetail sd;
+ JAXBElement<?> o = execute(this.objectFactory.createSaveService(request),
+ this.getPublishURI());
+ sd = (ServiceDetail) o.getValue();
+
+ return sd;
+ }
+
+ /**
+ * "Used to register or update complete information about a tModel."
+ *
+ * @exception RegistryV3Exception;
+ */
+ public TModelDetail saveTModel(String authInfo, TModel[] tModelArray)
+ throws RegistryV3Exception {
+ SaveTModel request = this.objectFactory.createSaveTModel();
+
+ if (authInfo != null) {
+ request.setAuthInfo(authInfo);
+ }
+
+ if (tModelArray != null) {
+ request.getTModel().addAll(Arrays.asList(tModelArray));
+ }
+
+ TModelDetail tmd;
+ JAXBElement<?> o = execute(this.objectFactory.createSaveTModel(request),
+ this.getPublishURI());
+ tmd = (TModelDetail) o.getValue();
+ return tmd;
+ }
+
+ /**
+ * Returns an implementation of Transport based on the className passed in.
+ * If a null value is passed then the default Transport implementation
+ * "org.apache.ws.scout.transport.AxisTransport" is created and returned.
+ *
+ * @return Transport
+ */
+ public Transport getTransport(String className) {
+ Transport transport = null;
+ Class transportClass = null;
+
+ // If a Transport class name isn't supplied use
+ // the default Transport implementation.
+ if (className == null)
+ className = DEFAULT_TRANSPORT_CLASS;
+
+ try {
+ // instruct class loader to load the TransportFactory
+ transportClass = getClassForName(className);
+ } catch (ClassNotFoundException cnfex) {
+ throw new RuntimeException(cnfex);
+ }
+
+ try {
+ // try to instantiate the TransportFactory
+ transport = (Transport) transportClass.newInstance();
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+
+ return transport;
+ }
+
+ /**
+ *
+ * @param name
+ * @return The class object for the name given
+ * @throws ClassNotFoundException
+ * @throws NoClassDefFoundError
+ */
+ public static Class getClassForName(String name)
+ throws ClassNotFoundException, NoClassDefFoundError {
+ Class clazz = null;
+
+ try {
+ // log.info("Using the Context ClassLoader");
+ ClassLoader ccl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+
+ clazz = Class.forName(name, true, ccl);
+ } catch (Exception e) {
+ log.debug("Failed to load the class " + name + " with context class loader " + e);
+ }
+
+ if (null == clazz) {
+ ClassLoader scl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run() {
+ return ClassLoader.getSystemClassLoader();
+ }
+ });
+
+ try {
+ clazz = Class.forName(name, true, scl);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ return clazz;
+ }
+}
Added: geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiV3Helper.java
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiV3Helper.java?rev=1103343&view=auto
==============================================================================
--- geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiV3Helper.java (added)
+++ geronimo/bundles/trunk/scout/src/main/java/org/apache/ws/scout/util/ScoutJaxrUddiV3Helper.java Sun May 15 12:38:02 2011
@@ -0,0 +1,951 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.scout.util;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.infomodel.Association;
+import javax.xml.registry.infomodel.Classification;
+import javax.xml.registry.infomodel.ClassificationScheme;
+import javax.xml.registry.infomodel.Concept;
+import javax.xml.registry.infomodel.EmailAddress;
+import javax.xml.registry.infomodel.ExternalIdentifier;
+import javax.xml.registry.infomodel.ExternalLink;
+import javax.xml.registry.infomodel.InternationalString;
+import javax.xml.registry.infomodel.Key;
+import javax.xml.registry.infomodel.LocalizedString;
+import javax.xml.registry.infomodel.Organization;
+import javax.xml.registry.infomodel.PostalAddress;
+import javax.xml.registry.infomodel.RegistryObject;
+import javax.xml.registry.infomodel.Service;
+import javax.xml.registry.infomodel.ServiceBinding;
+import javax.xml.registry.infomodel.Slot;
+import javax.xml.registry.infomodel.SpecificationLink;
+import javax.xml.registry.infomodel.TelephoneNumber;
+import javax.xml.registry.infomodel.User;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.uddi.api_v3.*;
+import org.apache.ws.scout.registry.infomodel.InternationalStringImpl;
+
+/**
+ * Helper class that does Jaxr->UDDI Mapping
+ *
+ * @author <a href="mailto:anil@apache.org">Anil Saldhana</a>
+ * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
+ * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
+ * @author <a href="mailto:tcunning@apache.org">Tom Cunningham</a>
+ */
+public class ScoutJaxrUddiV3Helper
+{
+ private static final String UDDI_ORG_TYPES = "uuid:C1ACF26D-9672-4404-9D70-39B756E62AB4";
+ private static Log log = LogFactory.getLog(ScoutJaxrUddiV3Helper.class);
+ private static ObjectFactory objectFactory = new ObjectFactory();
+
+ /**
+ * Get UDDI Address given JAXR Postal Address
+ */
+ public static Address getAddress(PostalAddress postalAddress) throws JAXRException {
+ Address address = objectFactory.createAddress();
+
+ AddressLine[] addarr = new AddressLine[7];
+
+ String stnum = postalAddress.getStreetNumber();
+ String st = postalAddress.getStreet();
+ String city = postalAddress.getCity();
+ String country = postalAddress.getCountry();
+ String code = postalAddress.getPostalCode();
+ String state = postalAddress.getStateOrProvince();
+ String type = postalAddress.getType();
+
+ AddressLine stnumAL = objectFactory.createAddressLine();
+ stnumAL.setKeyName("STREET_NUMBER");
+ if (stnum != null) {
+ stnumAL.setKeyValue(stnum);
+ stnumAL.setValue(stnum);
+ }
+
+ AddressLine stAL = objectFactory.createAddressLine();
+ stAL.setKeyName("STREET");
+ if (st != null) {
+ stAL.setKeyValue(st);
+ stAL.setValue(st);
+ }
+
+ AddressLine cityAL = objectFactory.createAddressLine();
+ cityAL.setKeyName("CITY");
+ if (city != null) {
+ cityAL.setKeyValue(city);
+ cityAL.setValue(city);
+ }
+
+ AddressLine countryAL = objectFactory.createAddressLine();
+ countryAL.setKeyName("COUNTRY");
+ if (country != null) {
+ countryAL.setKeyValue(country);
+ countryAL.setValue(country);
+ }
+
+ AddressLine codeAL = objectFactory.createAddressLine();
+ codeAL.setKeyName("POSTALCODE");
+ if (code != null) {
+ codeAL.setKeyValue(code);
+ codeAL.setValue(code);
+ }
+
+ AddressLine stateAL = objectFactory.createAddressLine();
+ stateAL.setKeyName("STATE");
+ if (state != null) {
+ stateAL.setKeyValue(state);
+ stateAL.setValue(state);
+ }
+
+ AddressLine typeAL = objectFactory.createAddressLine();
+ typeAL.setKeyName("TYPE");
+ if (type != null) {
+ typeAL.setKeyValue(type);
+ typeAL.setValue(type);
+ }
+
+ // Add the AddressLine to vector
+ addarr[0] = stnumAL;
+ addarr[1] = stAL;
+ addarr[2] = cityAL;
+ addarr[3] = countryAL;
+ addarr[4] = codeAL;
+ addarr[5] = stateAL;
+ addarr[6] = typeAL;
+
+ address.getAddressLine().addAll(Arrays.asList(addarr));
+
+ return address;
+ }
+
+ public static BindingTemplate getBindingTemplateFromJAXRSB(
+ ServiceBinding serviceBinding) throws JAXRException {
+ BindingTemplate bt = objectFactory.createBindingTemplate();
+ if (serviceBinding.getKey() != null && serviceBinding.getKey().getId() != null) {
+ bt.setBindingKey(serviceBinding.getKey().getId());
+ } else {
+ bt.setBindingKey("");
+ }
+
+ try {
+ // Set Access URI
+ String accessuri = serviceBinding.getAccessURI();
+ if (accessuri != null) {
+ AccessPoint accessPoint = objectFactory.createAccessPoint();
+ accessPoint.setUseType(getUseType(accessuri));
+ accessPoint.setValue(accessuri);
+ bt.setAccessPoint(accessPoint);
+ }
+ ServiceBinding sb = serviceBinding.getTargetBinding();
+ if (sb != null) {
+ HostingRedirector red = objectFactory.createHostingRedirector();
+ Key key = sb.getKey();
+ if (key != null && key.getId() != null) {
+ red.setBindingKey(key.getId());
+ } else {
+ red.setBindingKey("");
+ }
+ bt.setHostingRedirector(red);
+ } else {
+ if (bt.getAccessPoint() == null) {
+ bt.setAccessPoint(objectFactory.createAccessPoint());
+ }
+ }
+ // TODO:Need to look further at the mapping b/w BindingTemplate and
+ // Jaxr ServiceBinding
+
+ // Get Service information
+ Service svc = serviceBinding.getService();
+ if (svc != null && svc.getKey() != null && svc.getKey().getId() != null) {
+ bt.setServiceKey(svc.getKey().getId());
+ }
+
+ InternationalString idesc = serviceBinding.getDescription();
+
+ addDescriptions(bt.getDescription(), idesc);
+
+ // SpecificationLink
+ Collection<SpecificationLink> slcol = serviceBinding.getSpecificationLinks();
+ TModelInstanceDetails tid = objectFactory.createTModelInstanceDetails();
+ if (slcol != null && !slcol.isEmpty()) {
+ Iterator<SpecificationLink> iter = slcol.iterator();
+ while (iter.hasNext()) {
+ SpecificationLink slink = (SpecificationLink) iter.next();
+
+ TModelInstanceInfo emptyTInfo = objectFactory.createTModelInstanceInfo();
+ tid.getTModelInstanceInfo().add(emptyTInfo);
+
+ RegistryObject specificationObject = slink.getSpecificationObject();
+ if (specificationObject.getKey() != null && specificationObject.getKey().getId() != null) {
+ emptyTInfo.setTModelKey(specificationObject.getKey().getId());
+ if (specificationObject.getDescription()!=null) {
+ for (Object o : specificationObject.getDescription().getLocalizedStrings()) {
+ LocalizedString locDesc = (LocalizedString) o;
+ Description description = objectFactory.createDescription();
+ emptyTInfo.getDescription().add(description);
+ description.setValue(locDesc.getValue());
+ description.setLang(locDesc.getLocale().getLanguage());
+ }
+ }
+ Collection<ExternalLink> externalLinks = slink.getExternalLinks();
+ if (externalLinks!=null && externalLinks.size()>0) {
+ for (ExternalLink link : externalLinks) {
+ InstanceDetails ids = objectFactory.createInstanceDetails();
+ emptyTInfo.setInstanceDetails(ids);
+ if (link.getDescription()!=null) {
+ Description description = objectFactory.createDescription();
+ ids.getDescription().add(description);
+ description.setValue(link.getDescription().getValue());
+ }
+ if (link.getExternalURI()!=null) {
+ OverviewDoc overviewDoc = objectFactory.createOverviewDoc();
+ ids.getOverviewDoc().add(overviewDoc);
+ org.uddi.api_v3.OverviewURL ourl = new org.uddi.api_v3.OverviewURL();
+ ourl.setValue(link.getExternalURI());
+ overviewDoc.setOverviewURL(ourl);
+ }
+ }
+ }
+ }
+ }
+ }
+ if (tid.getTModelInstanceInfo().size() != 0) {
+ bt.setTModelInstanceDetails(tid);
+ }
+ log.debug("BindingTemplate=" + bt.toString());
+ } catch (Exception ud) {
+ throw new JAXRException("Apache JAXR Impl:", ud);
+ }
+ return bt;
+ }
+
+ public static PublisherAssertion getPubAssertionFromJAXRAssociation(
+ Association association) throws JAXRException {
+ PublisherAssertion pa = objectFactory.createPublisherAssertion();
+ try {
+ if (association.getSourceObject().getKey() != null &&
+ association.getSourceObject().getKey().getId() != null) {
+ pa.setFromKey(association.getSourceObject().getKey().getId());
+ }
+
+ if (association.getTargetObject().getKey() != null &&
+ association.getTargetObject().getKey().getId() != null) {
+ pa.setToKey(association.getTargetObject().getKey().getId());
+ }
+ Concept c = association.getAssociationType();
+ String v = c.getValue();
+ KeyedReference kr = objectFactory.createKeyedReference();
+ Key key = c.getKey();
+ if (key == null) {
+ // TODO:Need to check this. If the concept is a predefined
+ // enumeration, the key can be the parent classification scheme
+ key = c.getClassificationScheme().getKey();
+ }
+ if (key != null && key.getId() != null) {
+ kr.setTModelKey(key.getId());
+ }
+ kr.setKeyName("Concept");
+
+ if (v != null) {
+ kr.setKeyValue(v);
+ }
+
+ pa.setKeyedReference(kr);
+ } catch (Exception ud) {
+ throw new JAXRException("Apache JAXR Impl:", ud);
+ }
+ return pa;
+ }
+
+ public static PublisherAssertion getPubAssertionFromJAXRAssociationKey(
+ String key) throws JAXRException {
+ PublisherAssertion pa = objectFactory.createPublisherAssertion();
+ try {
+ StringTokenizer token = new StringTokenizer(key, ":");
+ if (token.hasMoreTokens()) {
+ pa.setFromKey(getToken(token.nextToken()));
+ pa.setToKey(getToken(token.nextToken()));
+ KeyedReference kr = objectFactory.createKeyedReference();
+ // Sometimes the Key is UUID:something
+ String str = getToken(token.nextToken());
+ if ("UUID".equals(str))
+ str += ":" + getToken(token.nextToken());
+ kr.setTModelKey(str);
+ kr.setKeyName(getToken(token.nextToken()));
+ kr.setKeyValue(getToken(token.nextToken()));
+ pa.setKeyedReference(kr);
+ }
+
+ } catch (Exception ud) {
+ throw new JAXRException("Apache JAXR Impl:", ud);
+ }
+ return pa;
+ }
+
+ public static BusinessService getBusinessServiceFromJAXRService(
+ Service service) throws JAXRException {
+ BusinessService bs = objectFactory.createBusinessService();
+ try {
+ InternationalString iname = service.getName();
+
+ addNames(bs.getName(), iname);
+
+ InternationalString idesc = service.getDescription();
+
+ addDescriptions(bs.getDescription(), idesc);
+
+ Organization o = service.getProvidingOrganization();
+
+ /*
+ * there may not always be a key...
+ */
+ if (o != null) {
+ Key k = o.getKey();
+
+ if (k != null && k.getId() != null) {
+ bs.setBusinessKey(k.getId());
+ }
+
+ } else {
+ /*
+ * gmj - I *think* this is the right thing to do
+ */
+ throw new JAXRException(
+ "Service has no associated organization");
+ }
+
+ if (service.getKey() != null && service.getKey().getId() != null) {
+ bs.setServiceKey(service.getKey().getId());
+ } else {
+ bs.setServiceKey("");
+ }
+
+ CategoryBag catBag = getCategoryBagFromClassifications(service.getClassifications());
+ if (catBag!=null) {
+ bs.setCategoryBag(catBag);
+ }
+
+ //Add the ServiceBinding information
+ BindingTemplates bt = getBindingTemplates(service.getServiceBindings());
+ if (bt != null) {
+ bs.setBindingTemplates(bt);
+ }
+
+ log.debug("BusinessService=" + bs.toString());
+ } catch (Exception ud) {
+ throw new JAXRException("Apache JAXR Impl:", ud);
+ }
+ return bs;
+ }
+
+ public static TModel getTModelFromJAXRClassificationScheme(
+ ClassificationScheme classificationScheme) throws JAXRException {
+ TModel tm = objectFactory.createTModel();
+ try {
+ /*
+ * a fresh scheme might not have a key
+ */
+
+ Key k = classificationScheme.getKey();
+
+ if (k != null && k.getId() != null) {
+ tm.setTModelKey(k.getId());
+ } else {
+ tm.setTModelKey("");
+ }
+
+ /*
+ * There's no reason to believe these are here either
+ */
+
+ Slot s = classificationScheme.getSlot("authorizedName");
+/*
+ if (s != null && s.getName() != null) {
+ tm.setAuthorizedName(s.getName());
+ }
+*/
+ s = classificationScheme.getSlot("operator");
+/*
+ if (s != null && s.getName() != null) {
+ tm.setOperator(s.getName());
+ }
+*/
+ InternationalString iname = classificationScheme.getName();
+
+ tm.setName(getFirstName(iname));
+
+ InternationalString idesc = classificationScheme.getDescription();
+
+ addDescriptions(tm.getDescription(), idesc);
+
+ IdentifierBag idBag = getIdentifierBagFromExternalIdentifiers(classificationScheme.getExternalIdentifiers());
+ if (idBag!=null) {
+ tm.setIdentifierBag(idBag);
+ }
+ CategoryBag catBag = getCategoryBagFromClassifications(classificationScheme.getClassifications());
+ if (catBag!=null) {
+ tm.setCategoryBag(catBag);
+ }
+
+ // ToDO: overviewDoc
+ } catch (Exception ud) {
+ throw new JAXRException("Apache JAXR Impl:", ud);
+ }
+ return tm;
+ }
+
+ public static TModel getTModelFromJAXRConcept(Concept concept)
+ throws JAXRException {
+ TModel tm = objectFactory.createTModel();
+ if (concept == null)
+ return null;
+ try {
+ Key key = concept.getKey();
+ if (key != null && key.getId() != null)
+ tm.setTModelKey(key.getId());
+ Slot sl1 = concept.getSlot("authorizedName");
+ /*
+ if (sl1 != null && sl1.getName() != null)
+ tm.setAuthorizedName(sl1.getName());
+
+ Slot sl2 = concept.getSlot("operator");
+ if (sl2 != null && sl2.getName() != null)
+ tm.setOperator(sl2.getName());
+ */
+ InternationalString iname = concept.getName();
+
+ tm.setName(getFirstName(iname));
+
+ InternationalString idesc = concept.getDescription();
+
+ addDescriptions(tm.getDescription(), idesc);
+
+// External Links
+ Collection<ExternalLink> externalLinks = concept.getExternalLinks();
+ if(externalLinks != null && externalLinks.size() > 0)
+ {
+ tm.getOverviewDoc().add(getOverviewDocFromExternalLink((ExternalLink)externalLinks.iterator().next()));
+ }
+
+ IdentifierBag idBag = getIdentifierBagFromExternalIdentifiers(concept.getExternalIdentifiers());
+ if (idBag!=null) {
+ tm.setIdentifierBag(idBag);
+ }
+ CategoryBag catBag = getCategoryBagFromClassifications(concept.getClassifications());
+ if (catBag!=null) {
+ tm.setCategoryBag(catBag);
+ }
+
+ } catch (Exception ud) {
+ throw new JAXRException("Apache JAXR Impl:", ud);
+ }
+ return tm;
+ }
+
+ private static void addDescriptions(List<Description> descripions, InternationalString idesc) throws JAXRException {
+ if (idesc != null) {
+ for (Object o : idesc.getLocalizedStrings()) {
+ LocalizedString locName = (LocalizedString) o;
+ Description desc = objectFactory.createDescription();
+ descripions.add(desc);
+ desc.setValue(locName.getValue());
+ desc.setLang(locName.getLocale().getLanguage());
+ }
+ }
+ }
+
+ private static Name getFirstName(InternationalString iname) throws JAXRException {
+ for (Object o : iname.getLocalizedStrings()) {
+ LocalizedString locName = (LocalizedString) o;
+ Name name = objectFactory.createName();
+ name.setValue(locName.getValue());
+ name.setLang(locName.getLocale().getLanguage());
+ return name;
+ }
+ return null;
+ }
+ private static void addNames(List<Name> names, InternationalString iname) throws JAXRException {
+ for (Object o : iname.getLocalizedStrings()) {
+ LocalizedString locName = (LocalizedString) o;
+ Name name = objectFactory.createName();
+ name.setValue(locName.getValue());
+ name.setLang(locName.getLocale().getLanguage());
+ names.add(name);
+ }
+ }
+
+ public static BusinessEntity getBusinessEntityFromJAXROrg(Organization organization)
+ throws JAXRException {
+ BusinessEntity biz = objectFactory.createBusinessEntity();
+ BusinessServices bss = objectFactory.createBusinessServices();
+ BusinessService[] barr = new BusinessService[0];
+
+ try {
+ // It may just be an update
+ Key key = organization.getKey();
+ if (key != null && key.getId() != null) {
+ biz.setBusinessKey(key.getId());
+ } else {
+ biz.setBusinessKey("");
+ }
+ // Lets get the Organization attributes at the top level
+
+ InternationalString iname = organization.getName();
+
+ if (iname != null) {
+ addNames(biz.getName(), iname);
+ }
+
+ InternationalString idesc = organization.getDescription();
+
+ addDescriptions(biz.getDescription(), idesc);
+
+ if (organization.getPrimaryContact() != null &&
+ organization.getPrimaryContact().getPersonName()!= null &&
+ organization.getPrimaryContact().getPersonName().getFullName() != null) {
+
+ //biz.setAuthorizedName(organization.getPrimaryContact().getPersonName()
+ // .getFullName());
+ }
+
+ Collection<Service> s = organization.getServices();
+ log.debug("?Org has services=" + s.isEmpty());
+
+ barr = new BusinessService[s.size()];
+
+ Iterator<Service> iter = s.iterator();
+ int barrPos = 0;
+ while (iter.hasNext()) {
+ BusinessService bs = ScoutJaxrUddiV3Helper
+ .getBusinessServiceFromJAXRService((Service) iter
+ .next());
+ barr[barrPos] = bs;
+ barrPos++;
+ }
+
+ /*
+ * map users : JAXR has concept of 'primary contact', which is a
+ * special designation for one of the users, and D6.1 seems to say
+ * that the first UDDI user is the primary contact
+ */
+
+ Contacts cts = objectFactory.createContacts();
+ Contact[] carr = new Contact[0];
+
+ User primaryContact = organization.getPrimaryContact();
+ Collection<User> users = organization.getUsers();
+
+ // Expand array to necessary size only (xmlbeans does not like
+ // null items in cases like this)
+
+ int carrSize = 0;
+
+ if (primaryContact != null) {
+ carrSize += 1;
+ }
+
+ // TODO: Clean this up and make it more efficient
+ Iterator<User> it = users.iterator();
+ while (it.hasNext()) {
+ User u = (User) it.next();
+ if (u != primaryContact) {
+ carrSize++;
+ }
+ }
+
+ carr = new Contact[carrSize];
+
+ /*
+ * first do primary, and then filter that out in the loop
+ */
+ if (primaryContact != null) {
+ Contact ct = getContactFromJAXRUser(primaryContact);
+ carr[0] = ct;
+ }
+
+ it = users.iterator();
+ int carrPos = 1;
+ while (it.hasNext()) {
+ User u = (User) it.next();
+
+ if (u != primaryContact) {
+ Contact ct = getContactFromJAXRUser(u);
+ carr[carrPos] = ct;
+ carrPos++;
+ }
+ }
+
+ bss.getBusinessService().addAll(Arrays.asList(barr));
+ if (carr.length>0) {
+ cts.getContact().addAll(Arrays.asList(carr));
+ biz.setContacts(cts);
+ }
+ biz.setBusinessServices(bss);
+
+ // External Links
+ Iterator<ExternalLink> exiter = organization.getExternalLinks().iterator();
+ DiscoveryURLs emptyDUs = null;
+ boolean first = true;
+ while (exiter.hasNext()) {
+ ExternalLink link = (ExternalLink) exiter.next();
+ /** Note: jUDDI adds its own discoverURL as the businessEntity* */
+ if (first) {
+ emptyDUs = objectFactory.createDiscoveryURLs();
+ biz.setDiscoveryURLs(emptyDUs);
+ first = false;
+ }
+ DiscoveryURL emptyDU = objectFactory.createDiscoveryURL();
+ emptyDUs.getDiscoveryURL().add(emptyDU);
+ emptyDU.setUseType("businessEntityExt");
+
+ if (link.getExternalURI() != null) {
+ emptyDU.setValue(link.getExternalURI());
+ }
+ }
+
+ IdentifierBag idBag = getIdentifierBagFromExternalIdentifiers(organization.getExternalIdentifiers());
+ if (idBag!=null) {
+ biz.setIdentifierBag(idBag);
+ }
+ CategoryBag catBag = getCategoryBagFromClassifications(organization.getClassifications());
+ if (catBag!=null) {
+ biz.setCategoryBag(catBag);
+ }
+
+ } catch (Exception ud) {
+ throw new JAXRException("Apache JAXR Impl:", ud);
+ }
+ return biz;
+ }
+
+ /**
+ *
+ * Convert JAXR User Object to UDDI Contact
+ */
+ public static Contact getContactFromJAXRUser(User user)
+ throws JAXRException {
+ Contact ct = objectFactory.createContact();
+ if (user == null) {
+ return null;
+ }
+
+ Address[] addarr = new Address[0];
+ Phone[] phonearr = new Phone[0];
+ Email[] emailarr = new Email[0];
+ try {
+
+ if (user.getPersonName() != null && user.getPersonName().getFullName() != null) {
+ org.uddi.api_v3.PersonName pn = new org.uddi.api_v3.PersonName();
+ pn.setValue(user.getPersonName().getFullName());
+ ct.getPersonName().add(pn);
+ }
+
+ if (user.getType() != null) {
+ ct.setUseType(user.getType());
+ }
+ // Postal Address
+ Collection<PostalAddress> postc = user.getPostalAddresses();
+
+ addarr = new Address[postc.size()];
+
+ Iterator<PostalAddress> iterator = postc.iterator();
+ int addarrPos = 0;
+ while (iterator.hasNext()) {
+ PostalAddress post = (PostalAddress) iterator.next();
+ addarr[addarrPos] = ScoutJaxrUddiV3Helper.getAddress(post);
+ addarrPos++;
+ }
+ // Phone Numbers
+ Collection ph = user.getTelephoneNumbers(null);
+
+ phonearr = new Phone[ph.size()];
+
+ Iterator it = ph.iterator();
+ int phonearrPos = 0;
+ while (it.hasNext()) {
+ TelephoneNumber t = (TelephoneNumber) it.next();
+ Phone phone = objectFactory.createPhone();
+ String str = t.getNumber();
+ log.debug("Telephone=" + str);
+
+ // FIXME: If phone number is null, should the phone
+ // not be set at all, or set to empty string?
+ if (str != null) {
+ phone.setValue(str);
+ } else {
+ phone.setValue("");
+ }
+
+ phonearr[phonearrPos] = phone;
+ phonearrPos++;
+ }
+
+ // Email Addresses
+ Collection ec = user.getEmailAddresses();
+
+ emailarr = new Email[ec.size()];
+
+ Iterator iter = ec.iterator();
+ int emailarrPos = 0;
+ while (iter.hasNext()) {
+ EmailAddress ea = (EmailAddress) iter.next();
+ Email email = objectFactory.createEmail();
+
+ if (ea.getAddress() != null) {
+ email.setValue(ea.getAddress());
+ }
+ // email.setText( ea.getAddress() );
+
+ if (ea.getType() != null) {
+ email.setUseType(ea.getType());
+ }
+
+ emailarr[emailarrPos] = email;
+ emailarrPos++;
+ }
+ ct.getAddress().addAll(Arrays.asList(addarr));
+ ct.getPhone().addAll(Arrays.asList(phonearr));
+ ct.getEmail().addAll(Arrays.asList(emailarr));
+ } catch (Exception ud) {
+ throw new JAXRException("Apache JAXR Impl:", ud);
+ }
+ return ct;
+ }
+
+ private static String getToken(String tokenstr) {
+ // Token can have the value NULL which need to be converted into null
+ if (tokenstr.equals("NULL"))
+ tokenstr = "";
+ return tokenstr;
+ }
+
+ private static String getUseType(String accessuri) {
+ String acc = accessuri.toLowerCase();
+ String uri = "other";
+ if (acc.startsWith("http:"))
+ uri = "http:";
+ else if (acc.startsWith("https:"))
+ uri = "https:";
+ else if (acc.startsWith("ftp:"))
+ uri = "ftp:";
+ else if (acc.startsWith("phone:"))
+ uri = "phone:";
+
+ return uri;
+ }
+
+ /**
+ * According to JAXR Javadoc, there are two types of classification, internal and external and they use the Classification, Concept,
+ * and ClassificationScheme objects. It seems the only difference between internal and external (as related to UDDI) is that the
+ * name/value pair of the categorization is held in the Concept for internal classifications and the Classification for external (bypassing
+ * the Concept entirely).
+ *
+ * The translation to UDDI is simple. Relevant objects have a category bag which contains a bunch of KeyedReferences (name/value pairs).
+ * These KeyedReferences optionally refer to a tModel that identifies the type of category (translates to the ClassificationScheme key). If
+ * this is set and the tModel doesn't exist in the UDDI registry, then an invalid key error will occur when trying to save the object.
+ *
+ * @param classifications classifications to turn into categories
+ * @throws JAXRException
+ */
+ public static CategoryBag getCategoryBagFromClassifications(Collection classifications) throws JAXRException {
+ try {
+ if (classifications == null || classifications.size()==0)
+ return null;
+
+ // Classifications
+ CategoryBag cbag = objectFactory.createCategoryBag();
+ Iterator classiter = classifications.iterator();
+ while (classiter.hasNext()) {
+ Classification classification = (Classification) classiter.next();
+ if (classification != null ) {
+ KeyedReference keyr = objectFactory.createKeyedReference();
+ cbag.getKeyedReference().add(keyr);
+
+ InternationalStringImpl iname = null;
+ String value = null;
+ ClassificationScheme scheme = classification.getClassificationScheme();
+ if (scheme==null || (classification.isExternal() && classification.getConcept()==null)) {
+ /*
+ * JAXR 1.0 Specification: Section D6.4.4
+ * Specification related tModels mapped from Concept may be automatically
+ * categorized by the well-known uddi-org:types taxonomy in UDDI (with
+ * tModelKey uuid:C1ACF26D-9672-4404-9D70-39B756E62AB4) as follows:
+ * The keyed reference is assigned a taxonomy value of specification.
+ */
+ keyr.setTModelKey(UDDI_ORG_TYPES);
+ keyr.setKeyValue("specification");
+ } else {
+ if (classification.isExternal()) {
+ iname = (InternationalStringImpl) ((RegistryObject) classification).getName();
+ value = classification.getValue();
+ } else {
+ Concept concept = classification.getConcept();
+ if (concept != null) {
+ iname = (InternationalStringImpl) ((RegistryObject) concept).getName();
+ value = concept.getValue();
+ scheme = concept.getClassificationScheme();
+ }
+ }
+
+ String name = iname.getValue();
+ if (name != null)
+ keyr.setKeyName(name);
+
+ if (value != null)
+ keyr.setKeyValue(value);
+
+ if (scheme != null) {
+ Key key = scheme.getKey();
+ if (key != null && key.getId() != null)
+ keyr.setTModelKey(key.getId());
+ }
+ }
+ }
+ }
+ return cbag;
+ } catch (Exception ud) {
+ throw new JAXRException("Apache JAXR Impl:", ud);
+ }
+ }
+
+ public static TModelBag getTModelBagFromSpecifications(Collection specifications) throws JAXRException {
+ try {
+ if (specifications == null || specifications.size()==0)
+ return null;
+
+ // Classifications
+ TModelBag tbag = objectFactory.createTModelBag();
+ Iterator speciter = specifications.iterator();
+ while (speciter.hasNext()) {
+ RegistryObject registryobject = (RegistryObject) speciter.next();
+ if (registryobject instanceof SpecificationLink) {
+ SpecificationLink specificationlink = (SpecificationLink) registryobject;
+ if (specificationlink.getSpecificationObject() != null) {
+ RegistryObject ro = specificationlink.getSpecificationObject();
+ if (ro.getKey() != null) {
+ Key key = ro.getKey();
+ tbag.getTModelKey().add(key.toString());
+ }
+ }
+ } else {
+
+ if(registryobject.getKey()!=null){
+ tbag.getTModelKey().add(registryobject.getKey().toString());
+ }
+
+ log.info("ebXML case - the RegistryObject is an ExtrinsicObject, Not implemented");
+ }
+ }
+ return tbag;
+ } catch (Exception ud) {
+ throw new JAXRException("Apache JAXR Impl:", ud);
+ }
+ }
+
+
+ /**
+ * Adds the objects identifiers from JAXR's external identifier collection
+ *
+ * @param identifiers external identifiers to turn into identifiers
+ * @throws JAXRException
+ */
+ public static IdentifierBag getIdentifierBagFromExternalIdentifiers(Collection identifiers) throws JAXRException {
+ try {
+ if (identifiers == null || identifiers.size()==0)
+ return null;
+
+ // Identifiers
+ IdentifierBag ibag = objectFactory.createIdentifierBag();
+ Iterator iditer = identifiers.iterator();
+ while (iditer.hasNext()) {
+ ExternalIdentifier extid = (ExternalIdentifier) iditer.next();
+ if (extid != null ) {
+ KeyedReference keyr = objectFactory.createKeyedReference();
+ ibag.getKeyedReference().add(keyr);
+
+ InternationalStringImpl iname = (InternationalStringImpl) ((RegistryObject) extid).getName();
+ String value = extid.getValue();
+ ClassificationScheme scheme = extid.getIdentificationScheme();
+
+ String name = iname.getValue();
+ if (name != null)
+ keyr.setKeyName(name);
+
+ if (value != null)
+ keyr.setKeyValue(value);
+
+ if (scheme != null) {
+ Key key = scheme.getKey();
+ if (key != null && key.getId() != null)
+ keyr.setTModelKey(key.getId());
+ }
+ }
+ }
+ return ibag;
+ } catch (Exception ud) {
+ throw new JAXRException("Apache JAXR Impl:", ud);
+ }
+ }
+
+ private static OverviewDoc getOverviewDocFromExternalLink(ExternalLink link)
+ throws JAXRException
+ {
+ OverviewDoc od = objectFactory.createOverviewDoc();
+ String url = link.getExternalURI();
+ if(url != null) {
+ org.uddi.api_v3.OverviewURL ourl = new org.uddi.api_v3.OverviewURL();
+ ourl.setValue(url.toString());
+ od.setOverviewURL(ourl);
+ }
+ InternationalString extDesc = link.getDescription();
+ if(extDesc != null) {
+ Description description = objectFactory.createDescription();
+ od.getDescription().add(description);
+ description.setValue(extDesc.getValue());
+ }
+ return od;
+ }
+
+ private static BindingTemplates getBindingTemplates(Collection serviceBindings)
+ throws JAXRException {
+ BindingTemplates bt = null;
+ if(serviceBindings != null && serviceBindings.size() > 0) {
+ bt = objectFactory.createBindingTemplates();
+ Iterator iter = serviceBindings.iterator();
+ int currLoc = 0;
+ BindingTemplate[] bindingTemplateArray = new BindingTemplate[serviceBindings.size()];
+ while(iter.hasNext()) {
+ ServiceBinding sb = (ServiceBinding)iter.next();
+ bindingTemplateArray[currLoc] = getBindingTemplateFromJAXRSB(sb);
+ currLoc++;
+ }
+ if (bindingTemplateArray != null) {
+ bt.getBindingTemplate().addAll(Arrays.asList(bindingTemplateArray));
+ }
+ }
+ return bt;
+ }
+}