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/09 16:50:58 UTC

svn commit: r505361 - in /incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba: CorbaConduit.java CorbaDestination.java CorbaObjectReferenceHelper.java CorbaObjectReferenceRegistry.java CorbaStaxObject.java

Author: dmiddlem
Date: Fri Feb  9 08:50:57 2007
New Revision: 505361

URL: http://svn.apache.org/viewvc?view=rev&rev=505361
Log:
Some minor refactoring in binding for object reference support. (YOKO-270)

Added:
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceHelper.java   (with props)
Removed:
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceRegistry.java
Modified:
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaConduit.java
    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

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaConduit.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaConduit.java?view=diff&rev=505361&r1=505360&r2=505361
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaConduit.java (original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaConduit.java Fri Feb  9 08:50:57 2007
@@ -106,7 +106,7 @@
             // object reference specified by the endpoint reference type.  If the reference is null, then
             // we want to invoke on the default location as specified in the WSDL.
             if (ref != null) {
-                targetObject = CorbaObjectReferenceRegistry.getReferenceById(ref.getAddress().getValue());  
+                targetObject = CorbaObjectReferenceHelper.getReferenceById(ref.getAddress().getValue());  
             } else {
                 targetObject = CorbaUtils.importObjectReference(orb, address.getLocation());
             }

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=505361&r1=505360&r2=505361
==============================================================================
--- 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 Fri Feb  9 08:50:57 2007
@@ -165,7 +165,7 @@
             // 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);
+            CorbaObjectReferenceHelper.addReference(endpointInfo.getAddress(), obj);
            
             if (location.startsWith("relfile:")) {
                 String iorFile = location.substring("relfile:".length(), location.length());

Added: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceHelper.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceHelper.java?view=auto&rev=505361
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceHelper.java (added)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceHelper.java Fri Feb  9 08:50:57 2007
@@ -0,0 +1,124 @@
+/**
+ * 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.yoko.bindings.corba;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+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 org.apache.cxf.common.logging.LogUtils;
+import org.apache.schemas.yoko.bindings.corba.BindingType;
+
+public class CorbaObjectReferenceHelper {
+
+    public static final String WSDLI_NAMESPACE_URI = "http://www.w3.org/2006/01/wsdl-instance";
+    public static final String ADDRESSING_NAMESPACE_URI = "http://www.w3.org/2005/08/addressing";
+    public static final String ADDRESSING_WSDL_NAMESPACE_URI = "http://www.w3.org/2005/08/addressing/wsdl";
+    
+    private static final Logger LOG = LogUtils.getL7dLogger(CorbaObjectReferenceHelper.class);
+
+    //  We need to keep a list of all object references that we have used in the binding.
+    //  This helps us in two ways:
+    //    1. When we receive a CORBA object reference in Yoko, we can make sure that 
+    //       when Yoko makes any invocation on that reference, the binding selects the 
+    //       correct target to send the request to.
+    //    2. When we want to send a Yoko reference to a CORBA target, we make sure that 
+    //       we provide the correct DSI servant to the request so that the CORBA target
+    //       can correctly call the corresponding Yoko object.
+    private static Map<String, org.omg.CORBA.Object> objectReferences =
+        new HashMap<String, org.omg.CORBA.Object>();
+
+    public static void addReference(String id, org.omg.CORBA.Object reference) {
+        LOG.log(Level.INFO, "Registering object with id " + id);
+        objectReferences.put(id, reference);
+    }
+
+    public static org.omg.CORBA.Object getReferenceById(String id) {
+        LOG.log(Level.INFO, "Retrieving object with id " + id);
+        return objectReferences.get(id);
+    }
+    
+    public static String getWSDLLocation(Definition wsdlDef) {
+        return wsdlDef.getDocumentBaseURI();
+    }
+    
+    public static QName getServiceName(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;
+    }
+    
+    public static String getEndpointName(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;
+    }
+    
+    public static Binding getDefaultBinding(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;
+    }
+}

Propchange: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/CorbaObjectReferenceHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

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=505361&r1=505360&r2=505361
==============================================================================
--- 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 Fri Feb  9 08:50:57 2007
@@ -20,7 +20,6 @@
 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;
@@ -28,8 +27,6 @@
 
 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;
@@ -49,7 +46,6 @@
 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;
@@ -100,12 +96,8 @@
     private static final String XSI_PREFIX = "xsi";
     private static final String XMLSCHEMA_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema";
     private static final String XMLSCHEMA_PREFIX = "xs";
-
-    // 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";
-  
+
     private ORB orb;
     private List<CorbaTypeMap> typeMaps;       
     private ServiceInfo serviceInfo;
@@ -1291,7 +1283,7 @@
                 } else if (startEl.getName().getLocalPart().equals("Address")) {
                     Characters addrChars = reader.nextEvent().asCharacters();
                     org.omg.CORBA.Object ref =
-                        CorbaObjectReferenceRegistry.getReferenceById(addrChars.getData());
+                        CorbaObjectReferenceHelper.getReferenceById(addrChars.getData());
                     obj.setReference(ref);
                 }
 
@@ -1323,14 +1315,14 @@
 
         CorbaObjectReferenceHandler objRefHandler = (CorbaObjectReferenceHandler)obj;
         org.omg.CORBA.Object corbaObject = objRefHandler.getReference();
-
+        
         // Register the servant if not already done.
         String objAddress = orb.object_to_string(corbaObject);
-        org.omg.CORBA.Object servant = CorbaObjectReferenceRegistry.getReferenceById(objAddress);
+        org.omg.CORBA.Object servant = CorbaObjectReferenceHelper.getReferenceById(objAddress);
         if (servant == null) {
-            CorbaObjectReferenceRegistry.addReference(objAddress, corbaObject);
+            CorbaObjectReferenceHelper.addReference(objAddress, corbaObject);
         }
-
+        
         // 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 = 
@@ -1344,7 +1336,7 @@
             // 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);
+            wsdlBinding = CorbaObjectReferenceHelper.getDefaultBinding(corbaObject, wsdlDef);
         }
 
         QName interfaceName = null;
@@ -1360,7 +1352,7 @@
         writer.add(refStart);
 
         // Add the Address information
-        QName addrQName = new QName(ADDRESSING_NAMESPACE_URI, "Address");
+        QName addrQName = new QName(CorbaObjectReferenceHelper.ADDRESSING_NAMESPACE_URI, "Address");
         writer.add(factory.createStartElement(addrQName, null, null));
         writer.add(factory.createCharacters(objAddress));
         writer.add(factory.createEndElement(addrQName, null));
@@ -1369,18 +1361,20 @@
             String refNSPrefix = "objrefns";
             
             // Add the Metadata information
-            QName metaQName = new QName(ADDRESSING_NAMESPACE_URI, "Metadata");
+            QName metaQName = new QName(CorbaObjectReferenceHelper.ADDRESSING_NAMESPACE_URI, "Metadata");
             List<Attribute> metaAttrs = new ArrayList<Attribute>();
             metaAttrs.add(factory.createAttribute(new QName(WSDLI_NAMESPACE_URI, "wsdlLocation"), 
-                          getObjectReferenceWSDLLocation(wsdlDef)));
+                                                  CorbaObjectReferenceHelper.getWSDLLocation(wsdlDef)));
             writer.add(factory.createStartElement(metaQName, metaAttrs.iterator(), null));
 
             // Add ServiceName information to Metadata
-            QName serviceQName = new QName(ADDRESSING_WSDL_NAMESPACE_URI, "ServiceName");
+            QName serviceQName = new QName(CorbaObjectReferenceHelper.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);
+                                                     CorbaObjectReferenceHelper.getEndpointName(wsdlBinding,
+                                                                                                wsdlDef)));
+            QName service = CorbaObjectReferenceHelper.getServiceName(wsdlBinding, wsdlDef);
             QName serviceNS = new QName(service.getNamespaceURI(), refNSPrefix, refNSPrefix);
             serviceAttrs.add(factory.createAttribute(serviceNS, ""));
             writer.add(factory.createStartElement(serviceQName, serviceAttrs.iterator(), null));
@@ -1388,7 +1382,8 @@
             writer.add(factory.createEndElement(serviceQName, null));
 
             // Add InterfaceName information to Metadata
-            QName interfaceQName = new QName(ADDRESSING_WSDL_NAMESPACE_URI, "InterfaceName");
+            QName interfaceQName = new QName(CorbaObjectReferenceHelper.ADDRESSING_WSDL_NAMESPACE_URI, 
+                                             "InterfaceName");
             List<Attribute> interfaceAttrs = new ArrayList<Attribute>();
             QName interfaceNS = new QName(interfaceName.getNamespaceURI(), refNSPrefix, refNSPrefix);
             interfaceAttrs.add(factory.createAttribute(interfaceNS, ""));
@@ -1466,62 +1461,5 @@
             }
         }
         return result;
-    }
-    
-    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;
     }
 }