You are viewing a plain text version of this content. The canonical link for it is here.
Posted to yoko-commits@incubator.apache.org by dm...@apache.org on 2007/02/08 16:56:43 UTC

svn commit: r504962 - in /incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba: CorbaDestination.java CorbaStaxObject.java CorbaUtils.java

Author: dmiddlem
Date: Thu Feb  8 08:56:42 2007
New Revision: 504962

URL: http://svn.apache.org/viewvc?view=rev&rev=504962
Log:
Adding further object reference support via ws-addressing (YOKO-270).  This commit
provides basic functionality for default Object types and custom IDL types.  
However, full object reference support is not yet functional.

Modified:
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDestination.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDestination.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDestination.java?view=diff&rev=504962&r1=504961&r2=504962
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDestination.java (original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaDestination.java Thu Feb  8 08:56:42 2007
@@ -161,6 +161,12 @@
             byte[] objectId = bindingPOA.activate_object(servant);
             obj = bindingPOA.id_to_reference(objectId);
             
+            // Register the object reference so we can support passing references as
+            // parameters and return types.  Note that we need the actual endpoint that
+            // this object reference has been created on.  This is available through the
+            // endpointInfo object passed during construction.
+            CorbaObjectReferenceRegistry.addReference(endpointInfo.getAddress(), obj);
+           
             if (location.startsWith("relfile:")) {
                 String iorFile = location.substring("relfile:".length(), location.length());
                 // allow for up to 3 '/' to match common uses of relfile url format

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java?view=diff&rev=504962&r1=504961&r2=504962
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java (original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaStaxObject.java Thu Feb  8 08:56:42 2007
@@ -17,16 +17,19 @@
  * under the License.
  */
 
-
 package org.apache.yoko.bindings.corba;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.wsdl.Binding;
 import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLEventFactory;
 import javax.xml.stream.XMLEventReader;
@@ -46,6 +49,7 @@
 import org.apache.schemas.yoko.bindings.corba.Anonarray;
 import org.apache.schemas.yoko.bindings.corba.Anonsequence;
 import org.apache.schemas.yoko.bindings.corba.Array;
+import org.apache.schemas.yoko.bindings.corba.BindingType;
 import org.apache.schemas.yoko.bindings.corba.CaseType;
 import org.apache.schemas.yoko.bindings.corba.Enum;
 import org.apache.schemas.yoko.bindings.corba.Exception;
@@ -97,7 +101,7 @@
     private static final String XMLSCHEMA_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema";
     private static final String XMLSCHEMA_PREFIX = "xs";
 
-    // TODO: XXX Check names...
+    // TODO: These might be better in a CorbaObjectReferenceHelper type class
     private static final String WSDLI_NAMESPACE_URI = "http://www.w3.org/2006/01/wsdl-instance";
     private static final String ADDRESSING_NAMESPACE_URI = "http://www.w3.org/2005/08/addressing";
     private static final String ADDRESSING_WSDL_NAMESPACE_URI = "http://www.w3.org/2005/08/addressing/wsdl";
@@ -1316,33 +1320,43 @@
                                               XMLEventWriter writer,
                                               XMLEventFactory factory)
         throws XMLStreamException {
-        if (objName == null) {
-            objName = obj.getName();
-        }
 
         CorbaObjectReferenceHandler objRefHandler = (CorbaObjectReferenceHandler)obj;
-        org.omg.CORBA.Object corbaObj = objRefHandler.getReference();
+        org.omg.CORBA.Object corbaObject = objRefHandler.getReference();
 
         // Register the servant if not already done.
-        String objAddress = orb.object_to_string(corbaObj);
+        String objAddress = orb.object_to_string(corbaObject);
         org.omg.CORBA.Object servant = CorbaObjectReferenceRegistry.getReferenceById(objAddress);
         if (servant == null) {
-            CorbaObjectReferenceRegistry.addReference(objAddress, corbaObj);
+            CorbaObjectReferenceRegistry.addReference(objAddress, corbaObject);
         }
 
-        // TODO: This is not a guaranteed way to get all of the meta info if we use a
-        // wsdl generated by a non-Yoko idltowsdl tool.  For now, we are using this to
-        // test the concepts for object references.  In the future, we need a more
-        // correct way of obtaining the metadata values.
-        String interfaceName = 
-            ((org.apache.schemas.yoko.bindings.corba.Object)objRefHandler.getType()).getName();
-        String referenceName = interfaceName + "Ref";
-        String serviceName = interfaceName + "CORBAService";
-        String endpointName = interfaceName + "CORBAPort";
-        String referenceNamespace = serviceInfo.getTargetNamespace();
-        String refNSPrefix = "objrefns";
+        // We need to access the WSDL to find the information to build the metadata for the 
+        // endpoint reference type we are about to create.
+        org.apache.schemas.yoko.bindings.corba.Object refObject = 
+            (org.apache.schemas.yoko.bindings.corba.Object)objRefHandler.getType();
+        Definition wsdlDef = (Definition)serviceInfo.getProperty(WSDLServiceBuilder.WSDL_DEFINITION);
+        QName bindingName = refObject.getBinding();
+        Binding wsdlBinding = null;
+        if (bindingName != null) {
+            wsdlBinding = wsdlDef.getBinding(bindingName);
+        } else {
+            // TODO: Revisit: We are doing this for default object references to obtain the binding 
+            // that defines the object.  Is this the correct thing to do or do we not even try to 
+            // find a binding since the information is not provided by the typemapping object?
+            wsdlBinding = getDefaultObjectReferenceBinding(corbaObject, wsdlDef);
+        }
 
-        StartElement refStart = factory.createStartElement(new QName(referenceName), null, null);
+        QName interfaceName = null;
+        QName referenceName = null;
+        if (wsdlBinding != null) {
+            interfaceName = wsdlBinding.getPortType().getQName();
+            referenceName = new QName(interfaceName.getLocalPart() + "Ref");
+        } else {
+            referenceName = new QName("CORBA.Object");
+        }
+        
+        StartElement refStart = factory.createStartElement(referenceName, null, null);
         writer.add(refStart);
 
         // Add the Address information
@@ -1351,34 +1365,40 @@
         writer.add(factory.createCharacters(objAddress));
         writer.add(factory.createEndElement(addrQName, null));
 
-        // Add the Metadata information
-        QName metaQName = new QName(ADDRESSING_NAMESPACE_URI, "Metadata");
-        List<Attribute> metaAttrs = new ArrayList<Attribute>();
-        metaAttrs.add(factory.createAttribute(new QName(WSDLI_NAMESPACE_URI, "wsdlLocation"), 
-                      getWSDLLocationFromService()));
-        // TODO: This is a hack to get around namespaces not working correctly for Stax.  Find
-        // out why this is happening.
-        QName serviceNS = new QName(referenceNamespace, refNSPrefix, refNSPrefix);
-        metaAttrs.add(factory.createAttribute(serviceNS, ""));
-        writer.add(factory.createStartElement(metaQName, metaAttrs.iterator(), null));
-
-        // Add ServiceName information to Metadata
-        QName serviceQName = new QName(ADDRESSING_WSDL_NAMESPACE_URI, "ServiceName");
-        List<Attribute> serviceAttrs = new ArrayList<Attribute>();
-        serviceAttrs.add(factory.createAttribute(new QName("EndpointName"), endpointName));
-        writer.add(factory.createStartElement(serviceQName, serviceAttrs.iterator(), null));
-        writer.add(factory.createCharacters(refNSPrefix + ":" + serviceName));
-        writer.add(factory.createEndElement(serviceQName, null));
-
-        // Add InterfaceName information to Metadata
-        QName interfaceQName = new QName(ADDRESSING_WSDL_NAMESPACE_URI, "InterfaceName");
-        writer.add(factory.createStartElement(interfaceQName, null, null));
-        writer.add(factory.createCharacters(refNSPrefix + ":" + interfaceName));
-        writer.add(factory.createEndElement(interfaceQName, null));
-
-        writer.add(factory.createEndElement(metaQName, null));
+        if (wsdlBinding != null) {
+            String refNSPrefix = "objrefns";
+            
+            // Add the Metadata information
+            QName metaQName = new QName(ADDRESSING_NAMESPACE_URI, "Metadata");
+            List<Attribute> metaAttrs = new ArrayList<Attribute>();
+            metaAttrs.add(factory.createAttribute(new QName(WSDLI_NAMESPACE_URI, "wsdlLocation"), 
+                          getObjectReferenceWSDLLocation(wsdlDef)));
+            writer.add(factory.createStartElement(metaQName, metaAttrs.iterator(), null));
+
+            // Add ServiceName information to Metadata
+            QName serviceQName = new QName(ADDRESSING_WSDL_NAMESPACE_URI, "ServiceName");
+            List<Attribute> serviceAttrs = new ArrayList<Attribute>();
+            serviceAttrs.add(factory.createAttribute(new QName("EndpointName"), 
+                                                     getObjectReferenceEndpointName(wsdlBinding, wsdlDef)));
+            QName service = getObjectReferenceServiceName(wsdlBinding, wsdlDef);
+            QName serviceNS = new QName(service.getNamespaceURI(), refNSPrefix, refNSPrefix);
+            serviceAttrs.add(factory.createAttribute(serviceNS, ""));
+            writer.add(factory.createStartElement(serviceQName, serviceAttrs.iterator(), null));
+            writer.add(factory.createCharacters(refNSPrefix + ":" + service.getLocalPart()));
+            writer.add(factory.createEndElement(serviceQName, null));
+
+            // Add InterfaceName information to Metadata
+            QName interfaceQName = new QName(ADDRESSING_WSDL_NAMESPACE_URI, "InterfaceName");
+            List<Attribute> interfaceAttrs = new ArrayList<Attribute>();
+            QName interfaceNS = new QName(interfaceName.getNamespaceURI(), refNSPrefix, refNSPrefix);
+            interfaceAttrs.add(factory.createAttribute(interfaceNS, ""));
+            writer.add(factory.createStartElement(interfaceQName, interfaceAttrs.iterator(), null));
+            writer.add(factory.createCharacters(refNSPrefix + ":" + interfaceName.getLocalPart()));
+            writer.add(factory.createEndElement(interfaceQName, null));
 
-        writer.add(factory.createEndElement(new QName(referenceName), null));
+            writer.add(factory.createEndElement(metaQName, null));
+        }
+        writer.add(factory.createEndElement(referenceName, null));
     }
     
     private boolean isNestedSequence(TypeCode tc) {
@@ -1448,8 +1468,60 @@
         return result;
     }
     
-    private String getWSDLLocationFromService() {
-        Definition wsdlDef = (Definition)serviceInfo.getProperty(WSDLServiceBuilder.WSDL_DEFINITION);
+    private String getObjectReferenceWSDLLocation(Definition wsdlDef) {
         return wsdlDef.getDocumentBaseURI();
+    }
+    
+    private QName getObjectReferenceServiceName(Binding binding, Definition wsdlDef) {
+        Collection services = wsdlDef.getServices().values();
+        for (Iterator iter = services.iterator(); iter.hasNext();) {
+            Service serv = (Service)iter.next();
+            Collection ports = serv.getPorts().values();
+            for (Iterator portIter = ports.iterator(); portIter.hasNext();) {
+                Port pt = (Port)portIter.next();
+                if (pt.getBinding().equals(binding)) {
+                    return serv.getQName();
+                }
+            }
+        }
+        return null;
+    }
+    
+    private String getObjectReferenceEndpointName(Binding binding, Definition wsdlDef) {
+        Collection services = wsdlDef.getServices().values();
+        for (Iterator iter = services.iterator(); iter.hasNext();) {
+            Service serv = (Service)iter.next();
+            Collection ports = serv.getPorts().values();
+            for (Iterator portIter = ports.iterator(); portIter.hasNext();) {
+                Port pt = (Port)portIter.next();
+                if (pt.getBinding().equals(binding)) {
+                    return pt.getName();
+                }
+            }
+        }
+        return null;
+    }
+    
+    private Binding getDefaultObjectReferenceBinding(org.omg.CORBA.Object obj, Definition wsdlDef) {
+        Collection bindings = wsdlDef.getBindings().values();
+        for (Iterator iter = bindings.iterator(); iter.hasNext();) {
+            Binding b = (Binding)iter.next();
+            List extElements = b.getExtensibilityElements();
+            
+            // Get the list of all extensibility elements
+            for (Iterator extIter = extElements.iterator(); extIter.hasNext();) {
+                Object element = extIter.next();
+
+                // Find a binding type so we can check against its repository ID
+                if (element instanceof BindingType) {
+                    BindingType type = (BindingType)element;
+                    if (obj._is_a(type.getRepositoryID())) {
+                        return b;
+                    }
+                }
+            }
+        }
+        
+        return null;
     }
 }

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java?view=diff&rev=504962&r1=504961&r2=504962
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java (original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaUtils.java Thu Feb  8 08:56:42 2007
@@ -194,7 +194,11 @@
         } else if (obj instanceof org.apache.schemas.yoko.bindings.corba.Object) {
             org.apache.schemas.yoko.bindings.corba.Object objType =
                 (org.apache.schemas.yoko.bindings.corba.Object)obj;
-            tc = orb.create_interface_tc(objType.getRepositoryID(), objType.getName());            
+            if (objType.getName().equals("CORBA.Object")) {
+                tc = orb.create_interface_tc(objType.getRepositoryID(), "Object");
+            } else {
+                tc = orb.create_interface_tc(objType.getRepositoryID(), objType.getName());
+            }
         } else if (obj instanceof Sequence) {
             Sequence seqType = (Sequence)obj;
             tc = orb.create_sequence_tc((int) seqType.getBound(),