You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2008/03/04 17:52:26 UTC

svn commit: r633545 - in /incubator/tuscany/java/sca/modules: binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/ interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/ interface-wsdl/src/main/java/org/apache/tus...

Author: rfeng
Date: Tue Mar  4 08:52:24 2008
New Revision: 633545

URL: http://svn.apache.org/viewvc?rev=633545&view=rev
Log:
Partial fix for TUSCANY-2045 to support WSDL resolution by service/portType/binding/message

Added:
    incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLObject.java   (with props)
    incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLObjectImpl.java   (with props)
Modified:
    incubator/tuscany/java/sca/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java
    incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java
    incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java
    incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/XSDefinition.java
    incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java

Modified: incubator/tuscany/java/sca/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java?rev=633545&r1=633544&r2=633545&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java Tue Mar  4 08:52:24 2008
@@ -24,7 +24,7 @@
 
 import java.util.Map;
 
-import javax.wsdl.Definition;
+import javax.wsdl.Binding;
 import javax.wsdl.Port;
 import javax.wsdl.PortType;
 import javax.wsdl.Service;
@@ -52,19 +52,18 @@
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject;
 import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
 import org.apache.tuscany.sca.policy.PolicyFactory;
 
-public class WebServiceBindingProcessor implements
-    StAXArtifactProcessor<WebServiceBinding>, WebServiceConstants {
+public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServiceBinding>, WebServiceConstants {
 
     private WSDLFactory wsdlFactory;
     private WebServiceBindingFactory wsFactory;
     private PolicyFactory policyFactory;
     private PolicyAttachPointProcessor policyProcessor;
-    private IntentAttachPointTypeFactory  intentAttachPointTypeFactory;
+    private IntentAttachPointTypeFactory intentAttachPointTypeFactory;
     private ConfiguredOperationProcessor configuredOperationProcessor;
-    
 
     public WebServiceBindingProcessor(ModelFactoryExtensionPoint modelFactories) {
         this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
@@ -87,7 +86,7 @@
 
         // Read policies
         policyProcessor.readPolicies(wsBinding, reader);
-        
+
         // Read the binding name
         String name = reader.getAttributeValue(null, NAME);
         if (name != null) {
@@ -107,8 +106,7 @@
         if (wsdlElement != null) {
             int index = wsdlElement.indexOf('#');
             if (index == -1) {
-                throw new ContributionReadException(
-                                                    "Invalid WebService binding wsdlElement attribute: " + wsdlElement);
+                throw new ContributionReadException("Invalid WebService binding wsdlElement attribute: " + wsdlElement);
             }
             String namespace = wsdlElement.substring(0, index);
             wsBinding.setNamespace(namespace);
@@ -148,12 +146,11 @@
                 // Read a wsdl.service
                 localName = localName.substring("wsdl.binding(".length(), localName.length() - 1);
                 wsBinding.setBindingName(new QName(namespace, localName));
-                
+
                 wsdlElementIsBinding = true;
 
             } else {
-                throw new ContributionReadException(
-                                                    "Invalid WebService binding wsdlElement attribute: " + wsdlElement);
+                throw new ContributionReadException("Invalid WebService binding wsdlElement attribute: " + wsdlElement);
             }
         }
 
@@ -165,23 +162,24 @@
         while (reader.hasNext()) {
             int event = reader.next();
             switch (event) {
-                case START_ELEMENT  : {
+                case START_ELEMENT: {
                     if (END_POINT_REFERENCE.equals(reader.getName().getLocalPart())) {
                         if (wsdlElementIsBinding != null && wsdlElementIsBinding) {
-                            throw new ContributionReadException(wsdlElement + " must use wsdl.binding when using wsa:EndpointReference");
+                            throw new ContributionReadException(
+                                                                wsdlElement + " must use wsdl.binding when using wsa:EndpointReference");
                         }
                         wsBinding.setEndPointReference(EndPointReferenceHelper.readEndPointReference(reader));
-                    } else if ( Constants.OPERATION_QNAME.equals(reader.getName()) ) {
+                    } else if (Constants.OPERATION_QNAME.equals(reader.getName())) {
                         confOp = configuredOperationProcessor.read(reader);
-                        if ( confOp != null ) {
+                        if (confOp != null) {
                             ((OperationsConfigurator)wsBinding).getConfiguredOperations().add(confOp);
                         }
-                    } 
+                    }
                 }
-                break;
-                
+                    break;
+
             }
-            
+
             if (event == END_ELEMENT && BINDING_WS_QNAME.equals(reader.getName())) {
                 break;
             }
@@ -192,13 +190,14 @@
     protected void processEndPointReference(XMLStreamReader reader, WebServiceBinding wsBinding) {
     }
 
-    public void write(WebServiceBinding wsBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+    public void write(WebServiceBinding wsBinding, XMLStreamWriter writer) throws ContributionWriteException,
+        XMLStreamException {
 
         // Write a <binding.ws>
         policyProcessor.writePolicyPrefixes(wsBinding, writer);
         writer.writeStartElement(Constants.SCA10_NS, BINDING_WS);
         policyProcessor.writePolicyAttributes(wsBinding, writer);
-        
+
         // Write binding name
         if (wsBinding.getName() != null) {
             writer.writeAttribute(NAME, wsBinding.getName());
@@ -213,37 +212,41 @@
         if (wsBinding.getPortName() != null) {
 
             // Write namespace#wsdl.port(service/port)
-            String wsdlElement = wsBinding.getServiceName().getNamespaceURI() + "#wsdl.port("
-                                 + wsBinding.getServiceName().getLocalPart()
-                                 + "/"
-                                 + wsBinding.getPortName()
-                                 + ")";
+            String wsdlElement =
+                wsBinding.getServiceName().getNamespaceURI() + "#wsdl.port("
+                    + wsBinding.getServiceName().getLocalPart()
+                    + "/"
+                    + wsBinding.getPortName()
+                    + ")";
             writer.writeAttribute(WSDL_ELEMENT, wsdlElement);
 
         } else if (wsBinding.getEndpointName() != null) {
 
             // Write namespace#wsdl.endpoint(service/endpoint)
-            String wsdlElement = wsBinding.getServiceName().getNamespaceURI() + "#wsdl.endpoint("
-                                 + wsBinding.getServiceName().getLocalPart()
-                                 + "/"
-                                 + wsBinding.getEndpointName()
-                                 + ")";
+            String wsdlElement =
+                wsBinding.getServiceName().getNamespaceURI() + "#wsdl.endpoint("
+                    + wsBinding.getServiceName().getLocalPart()
+                    + "/"
+                    + wsBinding.getEndpointName()
+                    + ")";
             writer.writeAttribute(WSDL_ELEMENT, wsdlElement);
 
         } else if (wsBinding.getBindingName() != null) {
 
             // Write namespace#wsdl.binding(binding)
-            String wsdlElement = wsBinding.getBindingName().getNamespaceURI() + "#wsdl.binding("
-                                 + wsBinding.getBindingName().getLocalPart()
-                                 + ")";
+            String wsdlElement =
+                wsBinding.getBindingName().getNamespaceURI() + "#wsdl.binding("
+                    + wsBinding.getBindingName().getLocalPart()
+                    + ")";
             writer.writeAttribute(WSDL_ELEMENT, wsdlElement);
 
         } else if (wsBinding.getServiceName() != null) {
 
             // Write namespace#wsdl.service(service)
-            String wsdlElement = wsBinding.getServiceName().getNamespaceURI() + "#wsdl.service("
-                                 + wsBinding.getServiceName().getLocalPart()
-                                 + ")";
+            String wsdlElement =
+                wsBinding.getServiceName().getNamespaceURI() + "#wsdl.service("
+                    + wsBinding.getServiceName().getLocalPart()
+                    + ")";
             writer.writeAttribute(WSDL_ELEMENT, wsdlElement);
         }
 
@@ -255,7 +258,7 @@
         if (wsBinding.getEndPointReference() != null) {
             EndPointReferenceHelper.writeEndPointReference(wsBinding.getEndPointReference(), writer);
         }
-        
+
         writer.writeEndElement();
     }
 
@@ -263,21 +266,31 @@
         WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition();
         wsdlDefinition.setUnresolved(true);
         wsdlDefinition.setNamespace(model.getNamespace());
-        wsdlDefinition = resolver.resolveModel(WSDLDefinition.class, wsdlDefinition);
-        
-        if (!wsdlDefinition.isUnresolved()) {
+        WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, wsdlDefinition);
+
+        if (!resolved.isUnresolved()) {
+            wsdlDefinition.setDefinition(resolved.getDefinition());
+            wsdlDefinition.setLocation(resolved.getLocation());
+            wsdlDefinition.getXmlSchemas().addAll(resolved.getXmlSchemas());
+            wsdlDefinition.setUnresolved(false);
             model.setDefinition(wsdlDefinition);
-            Definition definition = wsdlDefinition.getDefinition();
             if (model.getBindingName() != null) {
-                model.setBinding(definition.getBinding(model.getBindingName()));
+                WSDLObject<Binding> binding = wsdlDefinition.getWSDLObject(Binding.class, model.getBindingName());
+                if (binding != null) {
+                    wsdlDefinition.setDefinition(binding.getDefinition());
+                    model.setBinding(binding.getElement());
+                }
             }
             if (model.getServiceName() != null) {
-                Service service = definition.getService(model.getServiceName());
-                model.setService(service);
-                if (service != null && model.getPortName() != null) {
-                    Port port = service.getPort(model.getPortName());
-                    model.setPort(port);
-                    model.setBinding(port.getBinding());
+                WSDLObject<Service> service = wsdlDefinition.getWSDLObject(Service.class, model.getServiceName());
+                if (service != null) {
+                    wsdlDefinition.setDefinition(service.getDefinition());
+                    model.setService(service.getElement());
+                    if (model.getPortName() != null) {
+                        Port port = service.getElement().getPort(model.getPortName());
+                        model.setPort(port);
+                        model.setBinding(port.getBinding());
+                    }
                 }
             }
 
@@ -294,9 +307,9 @@
                 model.setBindingInterfaceContract(interfaceContract);
             }
         }
-        policyProcessor.resolvePolicies(model, resolver); 
+        policyProcessor.resolvePolicies(model, resolver);
         OperationsConfigurator opCongigurator = (OperationsConfigurator)model;
-        for ( ConfiguredOperation confOp : opCongigurator.getConfiguredOperations() ) {
+        for (ConfiguredOperation confOp : opCongigurator.getConfiguredOperations()) {
             policyProcessor.resolvePolicies(confOp, resolver);
         }
     }

Modified: incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java?rev=633545&r1=633544&r2=633545&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java Tue Mar  4 08:52:24 2008
@@ -39,6 +39,7 @@
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject;
 
 public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfaceContract>, WSDLConstants {
 
@@ -141,20 +142,25 @@
                 WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition();
                 wsdlDefinition.setUnresolved(true);
                 wsdlDefinition.setNamespace(wsdlInterface.getName().getNamespaceURI());
-                wsdlDefinition = resolver.resolveModel(WSDLDefinition.class, wsdlDefinition);
-                if (!wsdlDefinition.isUnresolved()) {
-                    PortType portType = wsdlDefinition.getDefinition().getPortType(wsdlInterface.getName());
+                WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, wsdlDefinition);
+                if (!resolved.isUnresolved()) {
+                    wsdlDefinition.setDefinition(resolved.getDefinition());
+                    wsdlDefinition.setLocation(resolved.getLocation());
+                    wsdlDefinition.getXmlSchemas().addAll(resolved.getXmlSchemas());
+                    wsdlDefinition.setUnresolved(false);
+                    WSDLObject<PortType> portType = wsdlDefinition.getWSDLObject(PortType.class, wsdlInterface.getName());
                     if (portType != null) {
                         
                         // Introspect the WSDL portType and add the resulting
                         // WSDLInterface to the resolver
                         try {
-                            wsdlInterface = wsdlFactory.createWSDLInterface(portType, wsdlDefinition, resolver);
+                            wsdlDefinition.setDefinition(portType.getDefinition());
+                            wsdlInterface = wsdlFactory.createWSDLInterface(portType.getElement(), wsdlDefinition, resolver);
+                            wsdlInterface.setWsdlDefinition(wsdlDefinition);
                         } catch (InvalidInterfaceException e) {
                             throw new ContributionResolveException(e);
                         }
                         resolver.addModel(wsdlInterface);
-                        wsdlInterface.setWsdlDefinition(wsdlDefinition);
                     }
                 }
             }

Modified: incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java?rev=633545&r1=633544&r2=633545&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java Tue Mar  4 08:52:24 2008
@@ -23,6 +23,7 @@
 import java.util.List;
 
 import javax.wsdl.Definition;
+import javax.wsdl.WSDLElement;
 import javax.xml.namespace.QName;
 
 import org.apache.tuscany.sca.assembly.Base;
@@ -36,19 +37,22 @@
  * @version $Rev$ $Date$
  */
 public interface WSDLDefinition extends Base {
-    
+
     /**
-     * Returns the WSDL definition model
+     * Returns the WSDL definition model, if there are more than one WSDL definition under the 
+     * same namespace, the defintion will be a facade which imports all the physical WSDL 
+     * definitions
+     * 
      * @return the WSDL definition model
      */
     Definition getDefinition();
-    
+
     /**
      * Sets the WSDL definition model
      * @param definition the WSDL definition model
      */
     void setDefinition(Definition definition);
-    
+
     /**
      * Returns the namespace of this WSDL definition.
      * @return the namespace of this WSDL definition
@@ -60,16 +64,46 @@
      * @param namespace the namespace of this WSDL definition
      */
     void setNamespace(String namespace);
-    
+
     /**
-     * @return
+     * Get a list of inline XML schema defintions
+     * @return A list of inline XML schema definitions
      */
     List<XSDefinition> getXmlSchemas();
-    
+
+    /**
+     * Get the location of the WSDL file
+     * @return The location of the WSDL file
+     */
     URI getLocation();
+
+    /**
+     * Set the location of the WSDL file
+     * @param url
+     */
     void setLocation(URI url);
-    
+
+    /**
+     * Get an XSD element by QName
+     * @param name
+     * @return
+     */
     XmlSchemaElement getXmlSchemaElement(QName name);
+
+    /**
+     * Get an XSD type by QName
+     * @param name
+     * @return
+     */
     XmlSchemaType getXmlSchemaType(QName name);
     
+    /**
+     * Get the WSDL object by type and name
+     * @param <T>
+     * @param type javax.wsdl.Service/PortType/Binding/Message.class
+     * @param name The QName of the object
+     * @return WSDLObject
+     */
+    <T extends WSDLElement> WSDLObject<T> getWSDLObject(Class<T> type, QName name);
+
 }

Added: incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLObject.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLObject.java?rev=633545&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLObject.java (added)
+++ incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLObject.java Tue Mar  4 08:52:24 2008
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.tuscany.sca.interfacedef.wsdl;
+
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLElement;
+
+/**
+ * Model for objects in a WSDL definition
+ * @version $Rev$ $Date$
+ */
+public interface WSDLObject<T extends WSDLElement> {
+    /**
+     * Get the owning defintion where the element is declared
+     * @return The owning definition
+     */
+    Definition getDefinition();
+
+    /**
+     * Set the owning definition
+     * @param definition
+     */
+    void setDefinition(Definition definition);
+
+    /**
+     * Get the WSDL element such as Service, PortType, Binding or Message
+     * @return The WSDL element
+     */
+    T getElement();
+
+    /**
+     * Set the WSDL element
+     * @param element
+     */
+    void setElement(T element);
+}

Propchange: incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLObject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLObject.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/XSDefinition.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/XSDefinition.java?rev=633545&r1=633544&r2=633545&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/XSDefinition.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/XSDefinition.java Tue Mar  4 08:52:24 2008
@@ -88,7 +88,16 @@
      */
     void setDocument(Document document);
 
+    /**
+     * Get the XSD element by QName
+     * @param name
+     * @return The XSD element
+     */
     XmlSchemaElement getXmlSchemaElement(QName name);
 
+    /**
+     * @param name Get the XSD type by QName
+     * @return The XSD type
+     */
     XmlSchemaType getXmlSchemaType(QName name);
 }

Modified: incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java?rev=633545&r1=633544&r2=633545&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java Tue Mar  4 08:52:24 2008
@@ -24,11 +24,19 @@
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
+import javax.wsdl.Binding;
 import javax.wsdl.Definition;
+import javax.wsdl.Import;
+import javax.wsdl.Message;
+import javax.wsdl.PortType;
+import javax.wsdl.Service;
+import javax.wsdl.WSDLElement;
 import javax.xml.namespace.QName;
 
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject;
 import org.apache.tuscany.sca.interfacedef.wsdl.XSDefinition;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
@@ -206,6 +214,44 @@
             return schemaCollection.getTypeByQName(name);
         }
         return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    private static <T extends WSDLElement> WSDLObject<T> getWSDLObject(Definition definition, Class<T> type, QName name) {
+        if (definition == null) {
+            return null;
+        }
+        Map<QName, WSDLElement> map = null;
+        if (type == PortType.class) {
+            map = definition.getPortTypes();
+        } else if (type == Service.class) {
+            map = definition.getServices();
+        } else if (type == Binding.class) {
+            map = definition.getBindings();
+        } else if (type == Message.class) {
+            map = definition.getMessages();
+        } else {
+            throw new IllegalArgumentException("Invalid type: " + type.getName());
+        }
+        if (map.containsKey(name)) {
+            return (WSDLObject<T>)new WSDLObjectImpl(definition, map.get(name));
+        } else {
+            for (Object imports : definition.getImports().values()) {
+                List<Import> importList = (List<Import>)imports;
+                for (Import i : importList) {
+                    definition = i.getDefinition();
+                    WSDLObject<T> element = getWSDLObject(definition, type, name);
+                    if (element != null) {
+                        return element;
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    public <T extends WSDLElement> WSDLObject<T> getWSDLObject(Class<T> type, QName name) {
+        return getWSDLObject(definition, type, name);
     }
 
 }

Added: incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLObjectImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLObjectImpl.java?rev=633545&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLObjectImpl.java (added)
+++ incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLObjectImpl.java Tue Mar  4 08:52:24 2008
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.tuscany.sca.interfacedef.wsdl.impl;
+
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLElement;
+
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WSDLObjectImpl<T extends WSDLElement> implements WSDLObject<T> {
+    private Definition definition;
+    private T element;
+
+    public WSDLObjectImpl() {
+        super();
+    }
+
+    public WSDLObjectImpl(Definition definition, T element) {
+        super();
+        this.definition = definition;
+        this.element = element;
+    }
+
+    public Definition getDefinition() {
+        return definition;
+    }
+
+    public void setDefinition(Definition definition) {
+        this.definition = definition;
+    }
+
+    public T getElement() {
+        return element;
+    }
+
+    public void setElement(T element) {
+        this.element = element;
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLObjectImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLObjectImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org