classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Implementing "corbaloc:" object reference parsing in C


From: Meskauskas Audrius
Subject: [cp-patches] FYI: Implementing "corbaloc:" object reference parsing in CORBA ORB.
Date: Mon, 29 Aug 2005 23:15:03 +0200
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

This patch extends the ORB.string_to_object supported protocol set by
corbaloc:rir: and corbaloc:iiop: protocols.

The parsing is done as it works in 1.4.2, while 1.5.0_04 contains regression.
Sun receives from us regression report 6317211.

2005-08-29  <address@hidden>

       * org/omg/CORBA/ORB.java (string_to_object): Documentation update.
       * gnu/CORBA/Functional_ORB.java (string_to_object): Rewritten.
       (ior_to_object): New method.
       * gnu/CORBA/NamingService/NameParser.java: New file.
? gnu/CORBA/NamingService/NameParser.java
? gnu/javax/swing/plaf/gtk/icons/Thumbs.db
Index: gnu/CORBA/Functional_ORB.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/CORBA/Functional_ORB.java,v
retrieving revision 1.16
diff -u -r1.16 Functional_ORB.java
--- gnu/CORBA/Functional_ORB.java       28 Aug 2005 11:23:36 -0000      1.16
+++ gnu/CORBA/Functional_ORB.java       29 Aug 2005 14:06:28 -0000
@@ -45,15 +45,18 @@
 import gnu.CORBA.GIOP.MessageHeader;
 import gnu.CORBA.GIOP.ReplyHeader;
 import gnu.CORBA.GIOP.RequestHeader;
+import gnu.CORBA.NamingService.NameParser;
 import gnu.CORBA.NamingService.NamingServiceTransient;
 import gnu.CORBA.Poa.gnuForwardRequest;
 
 import org.omg.CORBA.BAD_OPERATION;
 import org.omg.CORBA.BAD_PARAM;
 import org.omg.CORBA.CompletionStatus;
+import org.omg.CORBA.DATA_CONVERSION;
 import org.omg.CORBA.MARSHAL;
 import org.omg.CORBA.NO_RESOURCES;
 import org.omg.CORBA.OBJECT_NOT_EXIST;
+import org.omg.CORBA.Object;
 import org.omg.CORBA.ORBPackage.InvalidName;
 import org.omg.CORBA.Request;
 import org.omg.CORBA.SystemException;
@@ -934,15 +937,41 @@
    * representation. The object can (an usually is) located on a remote
    * computer, possibly running a different (not necessary java) CORBA
    * implementation.
-   *
+   * 
    * @param ior the object IOR representation string.
-   *
+   * 
    * @return the found CORBA object.
    * @see object_to_string(org.omg.CORBA.Object)
    */
   public org.omg.CORBA.Object string_to_object(String an_ior)
   {
-    IOR ior = IOR.parse(an_ior);
+    int p = an_ior.indexOf(':');
+    if (p < 0)
+      throw new BAD_PARAM("IOR: or CORBALOC: prefix expected");
+
+    String prefix = an_ior.substring(0, p).toLowerCase();
+
+    if (prefix.equals("ior"))
+      {
+        IOR ior = IOR.parse(an_ior);
+        return ior_to_object(ior);
+      }
+    else if (prefix.equals("corbaloc"))
+      {
+        java.lang.Object r = NameParser.corbaloc(an_ior, this);
+        if (r instanceof IOR)
+          return ior_to_object((IOR) r);
+        else
+          return (org.omg.CORBA.Object) r;
+      }
+    else throw new DATA_CONVERSION("Unsupported prefix '"+prefix+"'");
+  }
+  
+  /**
+   * Convert ior reference to CORBA object.
+   */
+  private org.omg.CORBA.Object ior_to_object(IOR ior)
+  {
     org.omg.CORBA.Object object = find_local_object(ior);
     if (object == null)
       {
Index: org/omg/CORBA/ORB.java
===================================================================
RCS file: /cvsroot/classpath/classpath/org/omg/CORBA/ORB.java,v
retrieving revision 1.13
diff -u -r1.13 ORB.java
--- org/omg/CORBA/ORB.java      28 Aug 2005 11:23:36 -0000      1.13
+++ org/omg/CORBA/ORB.java      29 Aug 2005 20:55:18 -0000
@@ -896,7 +896,7 @@
    * </tr>
    *
    * <tr><td>PICurrent</td><td>address@hidden 
org.omg.PortableInterceptor.Current}</td>
-   * Contains multiple slots where an interceptor can rememeber the
+   * <td>Contains multiple slots where an interceptor can rememeber the
    * request - specific values between subsequent
    * calls of the interceptor methods.</td>
    * </tr>
@@ -962,16 +962,32 @@
   }
 
   /**
-   * Find and return the CORBA object, addressed by the given
-   * IOR string representation. The object can (an usually is)
+   * <p>Find and return the CORBA object, addressed by the given
+   * string representation. The object can be (an usually is)
    * located on a remote computer, possibly running a different
    * (not necessary java) CORBA implementation. The returned
    * object is typically casted to the more specific reference
    * using the <code>narrow(Object)</code> method of its helper.
+   * </p><p>
+   * This function supports the following input formats:<br>
+   * 1. IOR reference (<b>ior:</b>nnnnn ..), usually computer generated.<br> 
+   * 2. 
<b>corbaloc:</b>[<b>iiop</b>][version.subversion<b>@</b>]<b>:</b>host[<b>:</b>port]<b>/</b><i>key</i>
+   * defines similar information as IOR reference, but is more human readable.
+   * This type of reference may also contain multiple addresses (see
+   * OMG documentation for complete format).<br>
+   * 3. <b>corbaloc:rir:/</b><i>name</i> defines internal reference on this
+   * ORB that is resolved using address@hidden #resolve_initial_references}, 
using 
+   * the given <i>name</i>.
+   * <br>
    *
    * @param IOR the object IOR representation string.
    *
    * @return the found CORBA object.
+   * 
+   * @throws BAD_PARAM if the string being parsed is invalid.
+   * @throws DATA_CONVERSION if the string being parsed contains unsupported
+   * prefix or protocol.
+   * 
    * @see object_to_string(org.omg.CORBA.Object)
    */
   public abstract Object string_to_object(String IOR);
/* NameParser.java --
 Copyright (C) 2005 Free Software Foundation, Inc.

 This file is part of GNU Classpath.

 GNU Classpath is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2, or (at your option)
 any later version.

 GNU Classpath is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with GNU Classpath; see the file COPYING.  If not, write to the
 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 02110-1301 USA.

 Linking this library statically or dynamically with other modules is
 making a combined work based on this library.  Thus, the terms and
 conditions of the GNU General Public License cover the whole
 combination.

 As a special exception, the copyright holders of this library give you
 permission to link this library with independent modules to produce an
 executable, regardless of the license terms of these independent
 modules, and to copy and distribute the resulting executable under
 terms of your choice, provided that you also meet, for each linked
 independent module, the terms and conditions of the license of that
 module.  An independent module is a module which is not derived from
 or based on this library.  If you modify this library, you may extend
 this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */


package gnu.CORBA.NamingService;

import gnu.CORBA.IOR;
import gnu.CORBA.Unexpected;
import gnu.CORBA.Version;

import org.omg.CORBA.BAD_PARAM;
import org.omg.CORBA.DATA_CONVERSION;
import org.omg.CORBA.ORB;
import org.omg.CORBA.Object;
import org.omg.CORBA.ORBPackage.InvalidName;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 * Parses the alternative IOR representations into our IOR structure.
 * 
 * TODO This parser currently supports only one address per target string. A
 * string with the multiple addresses will be accepted, but only the last
 * address will be taken into consideration. The fault tolerance is not yet
 * implemented.
 * 
 * The key string is filtered using address@hidden java.net.URLDecoder} that 
replaces
 * the agreed escape sequences by the corresponding non alphanumeric characters.
 * 
 * @author Audrius Meskauskas, Lithuania (address@hidden)
 */
public class NameParser
{
  /**
   * The mandatory prefix.
   */
  public static final String CORBALOC = "corbaloc";

  /**
   * Marks iiop protocol.
   */
  public static final String IIOP = "iiop";

  /**
   * Marks rir protocol.
   */
  public static final String RIR = "rir";

  /**
   * The default port value, as specified in OMG documentation.
   */
  public static final int DEFAULT_PORT = 2809;

  /**
   * Parse CORBALOC.
   * 
   * The expected format is: <br>
   * 1. corbaloc:address@hidden:host[:port]/key <br>
   * 2. corbaloc:rir:/key <br>
   * 
   * protocol defaults to IOP.
   * 
   * @param corbaloc the string to parse.
   * @param orb the ORB, needed to create IORs and resolve rir references.
   * 
   * @return the constructed IOR.
   */
  public static java.lang.Object corbaloc(String corbaloc, ORB orb)
    throws BAD_PARAM
  {

    // The alternative addresses, if given.
    ArrayList alt_addr = new ArrayList();

    // The version numbers with default values.
    int major = 1;
    int minor = 0;

    // The host address.
    String host;

    // The port.
    int port = DEFAULT_PORT;

    // The object key as string.
    String key;

    StringTokenizer st = new StringTokenizer(corbaloc, ":@/.,", true);

    String[] t = new String[st.countTokens()];

    for (int i = 0; i < t.length; i++)
      {
        t[i] = st.nextToken();
      }

    int p = 0;

    if (!t[p++].equalsIgnoreCase(CORBALOC))
      throw new BAD_PARAM("Must start with corbaloc:");

    if (!t[p++].equals(":"))
      throw new BAD_PARAM("Must start with corbaloc:");

    // Check for rir:
    if (t[p].equals(RIR))
      {
        p++;
        if (!t[p++].equals(":"))
          throw new BAD_PARAM("':' expected after 'rir'");

        key = readKey(p, t);
        
        Object object;
        try
          {
            object = orb.resolve_initial_references(key);
          }
        catch (InvalidName e)
          {
            throw new BAD_PARAM("Unknown initial reference '"+key+"'");
          }
        return object;
      }
    else
    // Check for iiop.
    if (t[p].equals(IIOP) || t[p].equals(":"))
      {
        IOR ior = new IOR();
        
        Addresses: do
          { // Read addresses.
            if (t[p].equals(":"))
              {
                p++;
              }
            else
              {
                p++;
                if (!t[p++].equals(":"))
                  throw new BAD_PARAM("':' expected after 'iiop'");
                // Check if version is present.
                if (t[p + 1].equals("."))
                  if (t[p + 3].equals("@"))
                    {
                      // Version info present.
                      try
                        {
                          major = Integer.parseInt(t[p++]);
                        }
                      catch (NumberFormatException e)
                        {
                          throw new BAD_PARAM("Major version number '"
                            + t[p - 1] + "'");
                        }
                      p++; // '.' at this point.
                      try
                        {
                          minor = Integer.parseInt(t[p++]);
                        }
                      catch (NumberFormatException e)
                        {
                          throw new BAD_PARAM("Major version number '"
                            + t[p - 1] + "'");
                        }
                      p++; // '@' at this point.
                    }
              }
            
            ior.Internet.version = new Version(major, minor);
            
            // Then host data goes till '/' or ':'.
            StringBuffer bhost = new StringBuffer(corbaloc.length());
            while (!t[p].equals(":") && !t[p].equals("/") && !t[p].equals(","))
              bhost.append(t[p++]);

            host = bhost.toString();

            ior.Internet.host = host;

            if (t[p].equals(":"))
              {
                // Port specified.
                p++;
                try
                  {
                    port = Integer.parseInt(t[p++]);
                  }
                catch (NumberFormatException e)
                  {
                    throw new BAD_PARAM("Invalid port '" + t[p - 1] + "'");
                  }
              }
            
            ior.Internet.port = port;
            
            // Id is not listed.
            ior.Id = "";
            
            if (t[p].equals(","))
              p++;
            else
              break Addresses;
          }
        while (true);

        key = readKey(p, t);
        ior.key = key.getBytes();
        
        return ior;
      }
    else
      throw new DATA_CONVERSION("Unsupported protocol '" + t[p] + "'");

  }

  private static String readKey(int p, String[] t)
    throws BAD_PARAM
  {
    if (!t[p].equals("/"))
      throw new BAD_PARAM("'/keyString' expected '" + t[p] + "' found");

    StringBuffer bKey = new StringBuffer();
    p++;

    while (p < t.length)
      bKey.append(t[p++]);

    try
      {
        return URLDecoder.decode(bKey.toString(), "UTF-8");
      }
    catch (UnsupportedEncodingException e)
      {
        throw new Unexpected("URLDecoder does not support UTF-8", e);
      }
  }
  
  static void corbalocT(String ior, ORB orb)
  {
    System.out.println(ior);
    System.out.println(corbaloc(ior, orb));
    System.out.println();
  }

  public static void main(String[] args)
  {
    try
      {
        ORB orb = ORB.init(args, null);
        corbalocT("corbaloc:iiop:address@hidden/Prod/aTradingService", orb);
        corbalocT("corbaloc:iiop:address@hidden/Prod/bTradingService", orb);
        corbalocT("corbaloc:iiop:355cxyz.com/Prod/cTradingService", orb);
        corbalocT("corbaloc:iiop:address@hidden/Prod/bTradingService", orb);
        corbalocT("corbaloc:iiop:355cxyz.com:7777/Prod/cTradingService", orb);

        corbalocT("corbaloc::556xyz.com:80/Dev/NameService", orb);
        corbalocT("corbaloc:iiop:address@hidden:3076/0", orb);

        corbalocT("corbaloc:rir:/NameService", orb);

        corbalocT("corbaloc::555xyz.com,:556xyz.com:80/Dev/NameService", orb);
      }
    catch (BAD_PARAM e)
      {
        e.printStackTrace(System.out);
      }
  }
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]