incubator-yoko-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmidd...@apache.org
Subject svn commit: r525848 - in /incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba: CorbaConduit.java CorbaDestination.java interceptors/CorbaOutInterceptor.java runtime/CorbaStaxObject.java utils/CorbaObjectReferenceHelper.java
Date Thu, 05 Apr 2007 15:38:47 GMT
Author: dmiddlem
Date: Thu Apr  5 08:38:45 2007
New Revision: 525848

URL: http://svn.apache.org/viewvc?view=rev&rev=525848
Log:
Commit for YOKO-332:
- Updates to preserve EndpointReferenceType information through the binding.  EPRs should
contain
the same information on both the client and server sides.
- Fix to locate bindings when the namespace information may be missing.
- Removed dependancy on maintaining a list of known object references.

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/interceptors/CorbaOutInterceptor.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/runtime/CorbaStaxObject.java
    incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/utils/CorbaObjectReferenceHelper.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=525848&r1=525847&r2=525848
==============================================================================
--- 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
Thu Apr  5 08:38:45 2007
@@ -52,7 +52,6 @@
 import org.apache.yoko.bindings.corba.types.CorbaObjectHandler;
 import org.apache.yoko.bindings.corba.utils.ContextUtils;
 import org.apache.yoko.bindings.corba.utils.CorbaBindingHelper;
-import org.apache.yoko.bindings.corba.utils.CorbaObjectReferenceHelper;
 import org.apache.yoko.bindings.corba.utils.CorbaUtils;
 import org.apache.yoko.bindings.corba.utils.OrbConfig;
 import org.apache.yoko.wsdl.CorbaConstants;
@@ -94,14 +93,13 @@
                 throw new CorbaBindingException("Unable to locate a valid CORBA address");
             }
             List args = message.getContent(List.class);
-            //EndpointReferenceType ref = (EndpointReferenceType)message.get(Message.ENDPOINT_ADDRESS);
             String ref = (String)message.get(Message.ENDPOINT_ADDRESS);
             org.omg.CORBA.Object targetObject;
             // A non-null endpoint address from the message means that we want to invoke
on a particular
             // 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 = CorbaObjectReferenceHelper.getReferenceById(ref);  
+                targetObject = CorbaUtils.importObjectReference(orb, ref);
             } 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=525848&r1=525847&r2=525848
==============================================================================
--- 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 Apr  5 08:38:45 2007
@@ -38,7 +38,6 @@
 
 import org.apache.yoko.bindings.corba.runtime.CorbaDSIServant;
 import org.apache.yoko.bindings.corba.utils.CorbaBindingHelper;
-import org.apache.yoko.bindings.corba.utils.CorbaObjectReferenceHelper;
 import org.apache.yoko.bindings.corba.utils.CorbaUtils;
 import org.apache.yoko.bindings.corba.utils.OrbConfig;
 
@@ -156,12 +155,6 @@
             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.
-            CorbaObjectReferenceHelper.addReference(location, 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/interceptors/CorbaOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaOutInterceptor.java?view=diff&rev=525848&r1=525847&r2=525848
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaOutInterceptor.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/interceptors/CorbaOutInterceptor.java
Thu Apr  5 08:38:45 2007
@@ -192,8 +192,10 @@
                 evtReader.nextEvent();
             }
             if (wrap) {
-                //read the wrapper element from the reader
-                evtReader.nextEvent();
+                // read the wrapper element from the reader.  Since this contains all of
the namespaces
+                // we use for the rest of the stax events, we should save if (object references
need
+                // this information).
+                corbaStaxObject.setRootStaxElement(evtReader.nextEvent());
             }
 
             for (Iterator<ParamType> iter = params.iterator(); iter.hasNext();) {
@@ -261,8 +263,10 @@
                 evtReader.nextEvent();
             }
             if (wrap) {
-                //read the wrapper element from the reader
-                evtReader.nextEvent();
+                // read the wrapper element from the reader.  Since this contains all of
the namespaces
+                // we use for the rest of the stax events, we should save if (object references
need
+                // this information).
+                corbaStaxObject.setRootStaxElement(evtReader.nextEvent());
             }
             int index = 0;
             ArgType returnParam = opType.getReturn();

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/runtime/CorbaStaxObject.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/runtime/CorbaStaxObject.java?view=diff&rev=525848&r1=525847&r2=525848
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/runtime/CorbaStaxObject.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/runtime/CorbaStaxObject.java
Thu Apr  5 08:38:45 2007
@@ -20,8 +20,10 @@
 package org.apache.yoko.bindings.corba.runtime;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -36,6 +38,7 @@
 import javax.xml.stream.events.Attribute;
 import javax.xml.stream.events.Characters;
 import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.Namespace;
 import javax.xml.stream.events.StartElement;
 import javax.xml.stream.events.XMLEvent;
 
@@ -110,6 +113,7 @@
     private ORB orb;
     private List<CorbaTypeMap> typeMaps;       
     private ServiceInfo serviceInfo;
+    private XMLEvent rootElement;
     
     public CorbaStaxObject() {         
     }
@@ -141,6 +145,14 @@
     public ServiceInfo getServiceInfo() {
         return serviceInfo;
     }
+    
+    public void setRootStaxElement(XMLEvent evt) {
+        rootElement = evt;
+    }
+    
+    public XMLEvent getRootStaxElement() {
+        return rootElement;
+    }
 
     public CorbaObjectHandler readObjectFromStax(XMLEventReader reader, 
                                                  QName idlType)
@@ -1356,13 +1368,24 @@
     }
 
     protected CorbaObjectHandler readObjectReferenceFromStax(XMLEventReader reader,
-                                                             QName idlType,
-                                                             TypeCode tc,
-                                                             XmlSchemaObject schemaType)
{
+                                 QName idlType,
+                                 TypeCode tc,
+                                 XmlSchemaObject schemaType) {
         CorbaObjectReferenceHandler obj = null;
         try {
             Object objType = (Object)CorbaUtils.getCorbaType(idlType, typeMaps);
             StartElement objStartEl = reader.nextEvent().asStartElement();
+            
+            // We need the namespace information of the root element in the Stax output to
obtain
+            // namespace information that is used by later events.
+            if (rootElement == null) {
+                setRootStaxElement(objStartEl);
+            }
+            
+            String address = null;
+            QName interfaceName = null;
+            QName serviceName = null;
+            String endpointName = null;
 
             obj = new CorbaObjectReferenceHandler(objStartEl.getName(), idlType, tc, objType);
             while (true) {
@@ -1375,11 +1398,10 @@
                     while (true) {
                         StartElement metaEl = reader.nextEvent().asStartElement();
                         if (metaEl.getName().getLocalPart().equals("InterfaceName")) {
-                            Characters intfChars = reader.nextEvent().asCharacters();
-                            // TODO: How do we want to handle this information
+                            interfaceName = getQNameFromStax(metaEl, reader);
                         } else if (metaEl.getName().getLocalPart().equals("ServiceName"))
{
-                            Characters svcChars = reader.nextEvent().asCharacters();
-                            // TODO: How do we want to handle this information
+                            endpointName = getAttributeFromStartElement(metaEl, "EndpointName");
+                            serviceName = getQNameFromStax(metaEl, reader);
                         }
                         reader.nextEvent().asEndElement();
                         if (reader.peek().isEndElement()) {
@@ -1388,9 +1410,7 @@
                     }
                 } else if (startEl.getName().getLocalPart().equals("Address")) {
                     Characters addrChars = reader.nextEvent().asCharacters();
-                    org.omg.CORBA.Object ref =
-                        CorbaObjectReferenceHelper.getReferenceById(addrChars.getData());
-                    obj.setReference(ref);
+                    address = addrChars.getData();
                 }
 
                 reader.nextEvent().asEndElement();
@@ -1402,8 +1422,10 @@
             }
             reader.nextEvent().asEndElement();
 
-            // TODO: Verify that the reference has been set for the object
-
+            org.omg.CORBA.Object ref = orb.string_to_object(address);
+            ref = CorbaObjectReferenceHelper.addYokoProfileToReference(ref, address, endpointName,
+                                                                       interfaceName, serviceName);
+            obj.setReference(ref);
         } catch (java.lang.Exception ex) {
             LOG.log(Level.SEVERE, "Received exception while reading object of type " + idlType);
             throw new CorbaBindingException("Error while reading object reference corba type",
ex);
@@ -1411,7 +1433,7 @@
 
         return obj;
     }
-   
+    
     protected void writeObjectReferenceToStax(CorbaObjectHandler obj,
                                               QName objName,
                                               XmlSchemaObject schemaType,
@@ -1428,11 +1450,17 @@
             orb = CorbaBindingHelper.getDefaultORB(new OrbConfig());
         }
         
-        // Register the servant if not already done.
-        String objAddress = orb.object_to_string(corbaObject);
-        org.omg.CORBA.Object servant = CorbaObjectReferenceHelper.getReferenceById(objAddress);
-        if (servant == null) {
-            CorbaObjectReferenceHelper.addReference(objAddress, corbaObject);
+        // Define buffers to use when getting information from the Yoko profile 
+        StringBuffer addr = new StringBuffer();
+        StringBuffer epName = new StringBuffer();
+        StringBuffer intfName = new StringBuffer();
+        StringBuffer svcName = new StringBuffer();
+        
+        CorbaObjectReferenceHelper.getYokoProfileInformation(corbaObject, addr, epName, intfName,
svcName);
+        
+        // Use the IOR as the address if one does not exist in the Yoko profile
+        if (addr.length() == 0) {
+            addr.append(orb.object_to_string(corbaObject));
         }
         
         // We need to access the WSDL to find the information to build the metadata for the

@@ -1441,56 +1469,75 @@
             (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 = CorbaObjectReferenceHelper.getDefaultBinding(corbaObject, wsdlDef);
-        }
+        Binding wsdlBinding = getObjectReferenceBinding(wsdlDef, bindingName, corbaObject);
 
-        QName interfaceName = null;
+        String endpointName = epName.toString();
+        QName interfaceName = QName.valueOf(intfName.toString());
+        QName serviceName = QName.valueOf(svcName.toString());
         QName referenceName = null;
+
+        // Fill in any missing information that we were unable to get from the Yoko profile
using 
+        // information from the wsdl definition.
         if (wsdlBinding != null) {
-            interfaceName = wsdlBinding.getPortType().getQName();
+            if (endpointName.length() == 0) {
+                endpointName = CorbaObjectReferenceHelper.getEndpointName(wsdlBinding, wsdlDef);
+            }
+        
+            if (interfaceName.getLocalPart().length() == 0) {
+                interfaceName = wsdlBinding.getPortType().getQName(); 
+            }
+        
+            if (serviceName.getLocalPart().length() == 0) {
+                serviceName = CorbaObjectReferenceHelper.getServiceName(wsdlBinding, wsdlDef);

+            }
+
             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
         QName addrQName = new QName(CorbaObjectReferenceHelper.ADDRESSING_NAMESPACE_URI,
"Address");
         writer.add(factory.createStartElement(addrQName, null, null));
-        writer.add(factory.createCharacters(objAddress));
+        writer.add(factory.createCharacters(addr.toString()));
         writer.add(factory.createEndElement(addrQName, null));
 
         if (wsdlBinding != null) {
-            String refNSPrefix = "objrefns";
-            
-            // Add the Metadata information
+            String wsdlLocation = CorbaObjectReferenceHelper.getWSDLLocation(wsdlDef);
+            writeObjectReferenceMetaData(endpointName, interfaceName, serviceName, 
+                                         wsdlLocation, writer, factory);
+        }
+        writer.add(factory.createEndElement(referenceName, null));
+    }    
+    
+    private void writeObjectReferenceMetaData(String endpointName, QName interfaceName, QName
serviceName,
+                                              String wsdlLocation, XMLEventWriter writer,

+                                              XMLEventFactory factory) 
+        throws CorbaBindingException {
+        String refNSPrefix = "objrefns";
+        
+        try {
+            // Add the Metadata root tag
             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"),

-                                                  CorbaObjectReferenceHelper.getWSDLLocation(wsdlDef)));
+            metaAttrs.add(factory.createAttribute(new QName(WSDLI_NAMESPACE_URI, "wsdlLocation"),
+                                                  wsdlLocation));
             writer.add(factory.createStartElement(metaQName, metaAttrs.iterator(), null));
 
             // Add ServiceName information to Metadata
             QName serviceQName = new QName(CorbaObjectReferenceHelper.ADDRESSING_WSDL_NAMESPACE_URI,

                                            "ServiceName");
             List<Attribute> serviceAttrs = new ArrayList<Attribute>();
-            serviceAttrs.add(factory.createAttribute(new QName("EndpointName"), 
-                                                     CorbaObjectReferenceHelper.getEndpointName(wsdlBinding,
-                                                                                        
       wsdlDef)));
-            QName service = CorbaObjectReferenceHelper.getServiceName(wsdlBinding, wsdlDef);
-            QName serviceNS = new QName(service.getNamespaceURI(), refNSPrefix, refNSPrefix);
+            serviceAttrs.add(factory.createAttribute(new QName("EndpointName"), endpointName));

+                                                 
+            // QName service = CorbaObjectReferenceHelper.getServiceName(wsdlBinding, wsdlDef);
+            QName serviceNS = new QName(serviceName.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.createCharacters(refNSPrefix + ":" + serviceName.getLocalPart()));
             writer.add(factory.createEndElement(serviceQName, null));
 
             // Add InterfaceName information to Metadata
@@ -1504,8 +1551,39 @@
             writer.add(factory.createEndElement(interfaceQName, null));
 
             writer.add(factory.createEndElement(metaQName, null));
+        } catch (XMLStreamException ex) {
+            throw new CorbaBindingException("Unable to write object reference metadata to
Stax", ex);
         }
-        writer.add(factory.createEndElement(referenceName, null));
+        
+    }
+    
+    private Binding getObjectReferenceBinding(Definition wsdlDef, QName bindingName, 
+                                              org.omg.CORBA.Object obj) {
+        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 = CorbaObjectReferenceHelper.getDefaultBinding(obj, wsdlDef);
+        }
+
+        // If the binding name does not have a namespace associated with it, then we'll need
to 
+        // get the list of all bindings and compare their local parts against our name.
+        if (wsdlBinding == null && bindingName.getNamespaceURI().equals("")) {
+            Map bindings = wsdlDef.getBindings();
+            Collection bindingsCollection = bindings.values();
+            for (Iterator i = bindingsCollection.iterator(); i.hasNext();) {
+                Binding b = (Binding)i.next();
+                if (b.getQName().getLocalPart().equals(bindingName.getLocalPart())) {
+                    wsdlBinding = b;
+                    break;
+                }
+            }
+        }
+
+        return wsdlBinding;
     }
     
     private boolean isNestedSequence(TypeCode tc) {
@@ -1574,4 +1652,69 @@
         }
         return result;
     }
+    
+    private QName getQNameFromStax(StartElement start, XMLEventReader reader) 
+        throws CorbaBindingException {
+        QName name = null;
+        
+        try {
+            Characters charElement = reader.nextEvent().asCharacters();
+            String data = charElement.getData();
+            String prefix = null;
+            String namespace = null;
+            String localName = null;
+            int index = data.indexOf(':');
+            if (index != -1) {
+                // This means the name has a namespace prefix associated with it
+                prefix = data.substring(0, index);
+                localName = data.substring(index + 1);
+                
+                if (rootElement instanceof StartElement) {
+                    StartElement el = (StartElement)rootElement;
+                
+                    for (Iterator iter = el.getNamespaces(); iter.hasNext();) {
+                        Namespace ns = (Namespace)iter.next();
+                        QName nsName = ns.getName();
+                        if (nsName.getLocalPart().equals(prefix)) {
+                            namespace = ns.getValue();
+                            break;
+                        }
+                    }
+                } 
+                if (name == null) {
+                    for (Iterator iter = start.getNamespaces(); iter.hasNext();) {
+                        Namespace ns = (Namespace)iter.next();
+                        QName nsName = ns.getName();
+                        if (nsName.getLocalPart().equals(prefix)) {
+                            namespace = ns.getValue();
+                            break;
+                        }
+                    }
+                }
+                name = new QName(namespace, localName); 
+            } else {
+                name = new QName(data);
+            }
+        } catch (XMLStreamException ex) {
+            throw new CorbaBindingException("Unable to build QName from Stax data", ex);
+        }
+        
+        return name;
+    }
+    
+    private String getAttributeFromStartElement(StartElement start, String attributeName)

+        throws CorbaBindingException {
+        String value = null;
+        
+        for (Iterator iter = start.getAttributes(); iter.hasNext();) {
+            Attribute attr = (Attribute)iter.next();
+            if (attr.getName().getLocalPart().equals(attributeName)) {
+                value = attr.getValue();
+                break;
+            }
+        }
+        
+        return value;
+    }
+
 }

Modified: incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/utils/CorbaObjectReferenceHelper.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/utils/CorbaObjectReferenceHelper.java?view=diff&rev=525848&r1=525847&r2=525848
==============================================================================
--- incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/utils/CorbaObjectReferenceHelper.java
(original)
+++ incubator/yoko/trunk/bindings/src/main/java/org/apache/yoko/bindings/corba/utils/CorbaObjectReferenceHelper.java
Thu Apr  5 08:38:45 2007
@@ -19,11 +19,10 @@
 
 package org.apache.yoko.bindings.corba.utils;
 
+import java.io.IOException;
 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;
 
@@ -35,6 +34,17 @@
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.schemas.yoko.bindings.corba.BindingType;
+import org.apache.yoko.bindings.corba.CorbaBindingException;
+import org.apache.yoko.orb.CORBA.InputStream;
+import org.apache.yoko.orb.CORBA.OutputStream;
+import org.apache.yoko.orb.OB.HexConverter;
+import org.apache.yoko.orb.OCI.Buffer;
+
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.Object;
+import org.omg.IOP.IOR;
+import org.omg.IOP.IORHelper;
+import org.omg.IOP.TaggedProfile;
 
 public class CorbaObjectReferenceHelper {
 
@@ -42,34 +52,21 @@
     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";
     
+    public static final int YOKO_PROFILE_ID = 1000;
+    public static final int YOKO_ENDPOINT_ADDRESS_ID = 1001;
+    public static final int YOKO_ENDPOINT_NAME_ID = 1002;
+    public static final int YOKO_INTERFACE_NAME_ID = 1003;
+    public static final int YOKO_SERVICE_NAME_ID = 1004;
+    
     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) {
+        LOG.log(Level.INFO, "Getting location of the WSDL for an object reference");
         return wsdlDef.getDocumentBaseURI();
     }
     
     public static QName getServiceName(Binding binding, Definition wsdlDef) {
+        LOG.log(Level.INFO, "Getting service name for an object reference");
         Collection services = wsdlDef.getServices().values();
         for (Iterator iter = services.iterator(); iter.hasNext();) {
             Service serv = (Service)iter.next();
@@ -85,6 +82,7 @@
     }
     
     public static String getEndpointName(Binding binding, Definition wsdlDef) {
+        LOG.log(Level.INFO, "Getting endpoint name for an object reference");
         Collection services = wsdlDef.getServices().values();
         for (Iterator iter = services.iterator(); iter.hasNext();) {
             Service serv = (Service)iter.next();
@@ -99,7 +97,8 @@
         return null;
     }
     
-    public static Binding getDefaultBinding(org.omg.CORBA.Object obj, Definition wsdlDef)
{
+    public static Binding getDefaultBinding(Object obj, Definition wsdlDef) {
+        LOG.log(Level.INFO, "Getting binding for a default object reference");
         Collection bindings = wsdlDef.getBindings().values();
         for (Iterator iter = bindings.iterator(); iter.hasNext();) {
             Binding b = (Binding)iter.next();
@@ -107,7 +106,7 @@
             
             // Get the list of all extensibility elements
             for (Iterator extIter = extElements.iterator(); extIter.hasNext();) {
-                Object element = extIter.next();
+                java.lang.Object element = extIter.next();
 
                 // Find a binding type so we can check against its repository ID
                 if (element instanceof BindingType) {
@@ -121,4 +120,156 @@
         
         return null;
     }
-}
+    
+    public static Object addYokoProfileToReference(Object obj, String endpointAddress, String
endpointName,
+                                                   QName interfaceName, QName serviceName)

+        throws IOException {
+        LOG.log(Level.INFO, "Adding a Yoko profile to the object references IOR");
+        ORB orb = CorbaBindingHelper.getDefaultORB(new OrbConfig());
+        
+        // Read the IOR data from the object which currently does not have the yoko profile.
+        byte[] originalRef = HexConverter.asciiToOctets(orb.object_to_string(obj), 4);
+        Buffer inBuf = new Buffer(originalRef, originalRef.length);
+        InputStream in = new InputStream(inBuf);
+        
+        boolean endian = in.read_boolean();
+        in._OB_swap(endian);
+
+        IOR ior = IORHelper.read(in);
+        
+        TaggedProfile yokoProfile = new TaggedProfile();
+        yokoProfile.tag = YOKO_PROFILE_ID;
+        
+        // We need to know how many items we are going to write, so that when we do the read,
+        // we won't try to read too many items from the profile.
+        int count = 0;
+        if (endpointAddress != null) {
+            count++;
+        }
+        if (endpointName != null) {
+            count++;
+        }
+        if (interfaceName != null) {
+            count++;
+        }
+        if (serviceName != null) {
+            count++;
+        }
+        
+        // Write the non-null items to the profile, along with the count we obtained above.
+        Buffer profileBuf = new Buffer();
+        OutputStream profileOut = new OutputStream(profileBuf);
+        try {
+            profileOut.write_ulong(count);
+            if (endpointAddress != null) {
+                profileOut.write_ulong(YOKO_ENDPOINT_ADDRESS_ID);
+                profileOut.write_string(endpointAddress);
+            }
+            if (endpointName != null) {
+                profileOut.write_ulong(YOKO_ENDPOINT_NAME_ID);
+                profileOut.write_string(endpointName);
+            }
+            if (interfaceName != null) {
+                profileOut.write_ulong(YOKO_INTERFACE_NAME_ID);
+                profileOut.write_string(interfaceName.getNamespaceURI());
+                profileOut.write_string(interfaceName.getLocalPart());
+            }
+            if (serviceName != null) {
+                profileOut.write_ulong(YOKO_SERVICE_NAME_ID);
+                profileOut.write_string(serviceName.getNamespaceURI());
+                profileOut.write_string(serviceName.getLocalPart());
+            }
+            profileOut.flush();
+        } catch (java.io.IOException ex) {
+            throw new CorbaBindingException("Unable to write Yoko profile to object reference");
           
+        }
+        yokoProfile.profile_data = profileBuf.data();
+        
+        // Add the new profile to the list of profiles and repackage the IOR so that it contains
the
+        // updated information.
+        TaggedProfile[] origProfiles = ior.profiles;
+        TaggedProfile[] newProfiles = new TaggedProfile[origProfiles.length + 1];
+        
+        for (int i = 0; i < origProfiles.length; ++i) {
+            newProfiles[i] = origProfiles[i];
+        }
+        newProfiles[origProfiles.length] = yokoProfile;
+        ior.profiles = newProfiles;
+        
+        Buffer outBuf = new Buffer();
+        OutputStream out = new OutputStream(outBuf);
+        try {
+            out.write_boolean(endian);
+            IORHelper.write(out, ior);
+            out.flush();
+        } catch (IOException ex) {
+            throw new CorbaBindingException("Unable to write Yoko profile to object reference");
+        }
+        
+        byte[] newRef = outBuf.data();
+        String stringRef = "IOR:" + HexConverter.octetsToAscii(newRef, newRef.length);
+        
+        return orb.string_to_object(stringRef);
+    }
+
+    public static void getYokoProfileInformation(Object obj, StringBuffer address, StringBuffer
endpointName,
+                                                 StringBuffer interfaceName, StringBuffer
serviceName) 
+        throws CorbaBindingException {
+        LOG.log(Level.INFO, "Retrieving the Yoko profile from the object references IOR");
+        
+        ORB orb = CorbaBindingHelper.getDefaultORB(new OrbConfig());
+        
+        byte[] ref = HexConverter.asciiToOctets(orb.object_to_string(obj), 4);
+        Buffer buf = new Buffer(ref, ref.length);
+        InputStream in = new InputStream(buf);
+        
+        boolean endian = in.read_boolean();
+        in._OB_swap(endian);
+
+        IOR ior = IORHelper.read(in);
+        
+        TaggedProfile[] profiles = ior.profiles;
+        for (int i = 0; i < profiles.length; ++i) {
+            if (profiles[i].tag == YOKO_PROFILE_ID) {
+                byte[] profileData = profiles[i].profile_data;
+                Buffer profileBuf = new Buffer(profileData, profileData.length);
+                InputStream profileStream = new InputStream(profileBuf);
+
+                int count = profileStream.read_ulong();
+                for (int j = 0; j < count; ++j) {
+                    int id = profileStream.read_ulong();
+                    switch(id) {
+                    case YOKO_ENDPOINT_ADDRESS_ID:
+                        address.append(profileStream.read_string());
+                        break;
+                    case YOKO_ENDPOINT_NAME_ID:
+                        endpointName.append(profileStream.read_string());
+                        break;
+                    case YOKO_INTERFACE_NAME_ID:
+                        String intfNs = profileStream.read_string();
+                        if (intfNs != null && intfNs.length() > 0) {
+                            interfaceName.append('{');
+                            interfaceName.append(intfNs);
+                            interfaceName.append('}');
+                        }
+                        interfaceName.append(profileStream.read_string());
+                        break;
+                    case YOKO_SERVICE_NAME_ID:
+                        String svcNs = profileStream.read_string();
+                        if (svcNs != null && svcNs.length() > 0) {
+                            serviceName.append('{');
+                            serviceName.append(svcNs);
+                            serviceName.append('}');
+                        }
+                        serviceName.append(profileStream.read_string());
+                        break;
+                    default:
+                        throw new CorbaBindingException("Unexpected data in object reference
Yoko profile");
+                    }
+                }
+                
+                break;
+            }
+        }
+    }
+}
\ No newline at end of file



Mime
View raw message