diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | gnu/CORBA/Functional_ORB.java | 35 | ||||
-rw-r--r-- | gnu/CORBA/NamingService/NameParser.java | 306 | ||||
-rw-r--r-- | org/omg/CORBA/ORB.java | 22 |
4 files changed, 364 insertions, 6 deletions
@@ -1,3 +1,10 @@ +2005-08-29 <AudriusA@Bioinformatics.org> + + * 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. + 2005-08-28 Mark Wielaard <mark@klomp.org> * javax/swing/text/AbstractDocument.java (addEdit): Document gcj bug diff --git a/gnu/CORBA/Functional_ORB.java b/gnu/CORBA/Functional_ORB.java index bf6497953..495a601f5 100644 --- a/gnu/CORBA/Functional_ORB.java +++ b/gnu/CORBA/Functional_ORB.java @@ -45,15 +45,18 @@ import gnu.CORBA.GIOP.ErrorMessage; 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 @@ public class Functional_ORB extends Restricted_ORB * 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) { diff --git a/gnu/CORBA/NamingService/NameParser.java b/gnu/CORBA/NamingService/NameParser.java new file mode 100644 index 000000000..a415f2120 --- /dev/null +++ b/gnu/CORBA/NamingService/NameParser.java @@ -0,0 +1,306 @@ +/* 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 {@link java.net.URLDecoder} that replaces + * the agreed escape sequences by the corresponding non alphanumeric characters. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +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:[iiop][version.subversion@]: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:1.3@155axyz.com/Prod/aTradingService", orb); + corbalocT("corbaloc:iiop:2.7@255bxyz.com/Prod/bTradingService", orb); + corbalocT("corbaloc:iiop:355cxyz.com/Prod/cTradingService", orb); + corbalocT("corbaloc:iiop:2.7@255bxyz.com/Prod/bTradingService", orb); + corbalocT("corbaloc:iiop:355cxyz.com:7777/Prod/cTradingService", orb); + + corbalocT("corbaloc::556xyz.com:80/Dev/NameService", orb); + corbalocT("corbaloc:iiop:1.2@host1: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); + } + } +} diff --git a/org/omg/CORBA/ORB.java b/org/omg/CORBA/ORB.java index 5761b9505..5ea733d56 100644 --- a/org/omg/CORBA/ORB.java +++ b/org/omg/CORBA/ORB.java @@ -896,7 +896,7 @@ public abstract class ORB * </tr> * * <tr><td>PICurrent</td><td>{@link 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 @@ public abstract class ORB } /** - * 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 {@link #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); |