8164907: Eliminate dependency on java.naming/com.sun.jndi.toolkit.url

Reviewed-by: chegar, rriggs
This commit is contained in:
Pavel Rappo 2016-12-19 16:01:24 +00:00
parent 6dc6e34384
commit 4d6180564c
16 changed files with 3716 additions and 0 deletions

View File

@ -0,0 +1,235 @@
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jndi.cosnaming;
import javax.naming.*;
import javax.naming.spi.NamingManager;
import java.util.NoSuchElementException;
import java.util.Hashtable;
import org.omg.CosNaming.*;
/**
* Implements the JNDI NamingEnumeration interface for COS
* Naming. Gets hold of a list of bindings from the COS Naming Server
* and allows the client to iterate through them.
*
* @author Raj Krishnamurthy
* @author Rosanna Lee
*/
final class CNBindingEnumeration
implements NamingEnumeration<javax.naming.Binding> {
private static final int DEFAULT_BATCHSIZE = 100;
private BindingListHolder _bindingList; // list of bindings
private BindingIterator _bindingIter; // iterator for getting list of bindings
private int counter; // pointer in _bindingList
private int batchsize = DEFAULT_BATCHSIZE; // how many to ask for each time
private CNCtx _ctx; // ctx to list
private Hashtable<?,?> _env; // environment for getObjectInstance
private boolean more = false; // iterator done?
private boolean isLookedUpCtx = false; // iterating on a context beneath this context ?
/**
* Creates a CNBindingEnumeration object.
* @param ctx Context to enumerate
*/
CNBindingEnumeration(CNCtx ctx, boolean isLookedUpCtx, Hashtable<?,?> env) {
// Get batch size to use
String batch = (env != null ?
(String)env.get(javax.naming.Context.BATCHSIZE) : null);
if (batch != null) {
try {
batchsize = Integer.parseInt(batch);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Batch size not numeric: " + batch);
}
}
_ctx = ctx;
_ctx.incEnumCount();
this.isLookedUpCtx = isLookedUpCtx;
_env = env;
_bindingList = new BindingListHolder();
BindingIteratorHolder _bindingIterH = new BindingIteratorHolder();
// Perform listing and request that bindings be returned in _bindingIter
// Upon return,_bindingList returns a zero length list
_ctx._nc.list(0, _bindingList, _bindingIterH);
_bindingIter = _bindingIterH.value;
// Get first batch using _bindingIter
if (_bindingIter != null) {
more = _bindingIter.next_n(batchsize, _bindingList);
} else {
more = false;
}
counter = 0;
}
/**
* Returns the next binding in the list.
* @exception NamingException any naming exception.
*/
public javax.naming.Binding next() throws NamingException {
if (more && counter >= _bindingList.value.length) {
getMore();
}
if (more && counter < _bindingList.value.length) {
org.omg.CosNaming.Binding bndg = _bindingList.value[counter];
counter++;
return mapBinding(bndg);
} else {
throw new NoSuchElementException();
}
}
/**
* Returns true or false depending on whether there are more bindings.
* @return boolean value
*/
public boolean hasMore() throws NamingException {
// If there's more, check whether current bindingList has been exhausted,
// and if so, try to get more.
// If no more, just say so.
return more ? (counter < _bindingList.value.length || getMore()) : false;
}
/**
* Returns true or false depending on whether there are more bindings.
* Need to define this to satisfy the Enumeration api requirement.
* @return boolean value
*/
public boolean hasMoreElements() {
try {
return hasMore();
} catch (NamingException e) {
return false;
}
}
/**
* Returns the next binding in the list.
* @exception NoSuchElementException Thrown when the end of the
* list is reached.
*/
public javax.naming.Binding nextElement() {
try {
return next();
} catch (NamingException ne) {
throw new NoSuchElementException();
}
}
public void close() throws NamingException {
more = false;
if (_bindingIter != null) {
_bindingIter.destroy();
_bindingIter = null;
}
if (_ctx != null) {
_ctx.decEnumCount();
/**
* context was obtained by CNCtx, the user doesn't have a handle to
* it, close it as we are done enumerating through the context
*/
if (isLookedUpCtx) {
_ctx.close();
}
_ctx = null;
}
}
protected void finalize() {
try {
close();
} catch (NamingException e) {
// ignore failures
}
}
/**
* Get the next batch using _bindingIter. Update the 'more' field.
*/
private boolean getMore() throws NamingException {
try {
more = _bindingIter.next_n(batchsize, _bindingList);
counter = 0; // reset
} catch (Exception e) {
more = false;
NamingException ne = new NamingException(
"Problem getting binding list");
ne.setRootCause(e);
throw ne;
}
return more;
}
/**
* Constructs a JNDI Binding object from the COS Naming binding
* object.
* @exception NameNotFound No objects under the name.
* @exception CannotProceed Unable to obtain a continuation context
* @exception InvalidName Name not understood.
* @exception NamingException One of the above.
*/
private javax.naming.Binding mapBinding(org.omg.CosNaming.Binding bndg)
throws NamingException {
java.lang.Object obj = _ctx.callResolve(bndg.binding_name);
Name cname = CNNameParser.cosNameToName(bndg.binding_name);
try {
obj = NamingManager.getObjectInstance(obj, cname, _ctx, _env);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
NamingException ne = new NamingException(
"problem generating object using object factory");
ne.setRootCause(e);
throw ne;
}
// Use cname.toString() instead of bindingName because the name
// in the binding should be a composite name
String cnameStr = cname.toString();
javax.naming.Binding jbndg = new javax.naming.Binding(cnameStr, obj);
NameComponent[] comps = _ctx.makeFullName(bndg.binding_name);
String fullName = CNNameParser.cosNameToInsString(comps);
jbndg.setNameInNamespace(fullName);
return jbndg;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jndi.cosnaming;
import javax.naming.spi.InitialContextFactory;
import javax.naming.*;
import java.util.Hashtable;
/**
* Implements the JNDI SPI InitialContextFactory interface used to
* create the InitialContext objects.
*
* @author Raj Krishnamurthy
*/
public class CNCtxFactory implements InitialContextFactory {
/**
* Creates the InitialContext object. Properties parameter should
* should contain the ORB object for the value jndi.corba.orb.
* @param env Properties object
*/
public Context getInitialContext(Hashtable<?,?> env) throws NamingException {
return new CNCtx(env);
}
}

View File

@ -0,0 +1,500 @@
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jndi.cosnaming;
import javax.naming.*;
import java.util.Properties;
import java.util.Vector;
import java.util.Enumeration;
import org.omg.CosNaming.NameComponent;
/**
* Parsing routines for NameParser as well as COS Naming stringified names.
* This is used by CNCtx to create a NameComponent[] object and vice versa.
* It follows Section 4.5 of Interoperable Naming Service (INS) 98-10-11.
* In summary, the stringified form is a left-to-right, forward-slash
* separated name. id and kinds are separated by '.'. backslash is the
* escape character.
*
* @author Rosanna Lee
*/
final public class CNNameParser implements NameParser {
private static final Properties mySyntax = new Properties();
private static final char kindSeparator = '.';
private static final char compSeparator = '/';
private static final char escapeChar = '\\';
static {
mySyntax.put("jndi.syntax.direction", "left_to_right");
mySyntax.put("jndi.syntax.separator", ""+compSeparator);
mySyntax.put("jndi.syntax.escape", ""+escapeChar);
};
/**
* Constructs a new name parser for parsing names in INS syntax.
*/
public CNNameParser() {
}
/**
* Returns a CompoundName given a string in INS syntax.
* @param name The non-null string representation of the name.
* @return a non-null CompoundName
*/
public Name parse(String name) throws NamingException {
Vector<String> comps = insStringToStringifiedComps(name);
return new CNCompoundName(comps.elements());
}
/**
* Creates a NameComponent[] from a Name structure.
* Used by CNCtx to convert the input Name arg into a NameComponent[].
* @param a CompoundName or a CompositeName;
* each component must be the stringified form of a NameComponent.
*/
static NameComponent[] nameToCosName(Name name)
throws InvalidNameException {
int len = name.size();
if (len == 0) {
return new NameComponent[0];
}
NameComponent[] answer = new NameComponent[len];
for (int i = 0; i < len; i++) {
answer[i] = parseComponent(name.get(i));
}
return answer;
}
/**
* Returns the INS stringified form of a NameComponent[].
* Used by CNCtx.getNameInNamespace(), CNCompoundName.toString().
*/
static String cosNameToInsString(NameComponent[] cname) {
StringBuilder str = new StringBuilder();
for ( int i = 0; i < cname.length; i++) {
if ( i > 0) {
str.append(compSeparator);
}
str.append(stringifyComponent(cname[i]));
}
return str.toString();
}
/**
* Creates a CompositeName from a NameComponent[].
* Used by ExceptionMapper and CNBindingEnumeration to convert
* a NameComponent[] into a composite name.
*/
static Name cosNameToName(NameComponent[] cname) {
Name nm = new CompositeName();
for ( int i = 0; cname != null && i < cname.length; i++) {
try {
nm.add(stringifyComponent(cname[i]));
} catch (InvalidNameException e) {
// ignore
}
}
return nm;
}
/**
* Converts an INS-syntax string name into a Vector in which
* each element of the vector contains a stringified form of
* a NameComponent.
*/
private static Vector<String> insStringToStringifiedComps(String str)
throws InvalidNameException {
int len = str.length();
Vector<String> components = new Vector<>(10);
char[] id = new char[len];
char[] kind = new char[len];
int idCount, kindCount;
boolean idMode;
for (int i = 0; i < len; ) {
idCount = kindCount = 0; // reset for new component
idMode = true; // always start off parsing id
while (i < len) {
if (str.charAt(i) == compSeparator) {
break;
} else if (str.charAt(i) == escapeChar) {
if (i + 1 >= len) {
throw new InvalidNameException(str +
": unescaped \\ at end of component");
} else if (isMeta(str.charAt(i+1))) {
++i; // skip escape and let meta through
if (idMode) {
id[idCount++] = str.charAt(i++);
} else {
kind[kindCount++] = str.charAt(i++);
}
} else {
throw new InvalidNameException(str +
": invalid character being escaped");
}
} else if (idMode && str.charAt(i) == kindSeparator) {
// just look for the first kindSeparator
++i; // skip kind separator
idMode = false;
} else {
if (idMode) {
id[idCount++] = str.charAt(i++);
} else {
kind[kindCount++] = str.charAt(i++);
}
}
}
components.addElement(stringifyComponent(
new NameComponent(new String(id, 0, idCount),
new String(kind, 0, kindCount))));
if (i < len) {
++i; // skip separator
}
}
return components;
}
/**
* Return a NameComponent given its stringified form.
*/
private static NameComponent parseComponent(String compStr)
throws InvalidNameException {
NameComponent comp = new NameComponent();
int kindSep = -1;
int len = compStr.length();
int j = 0;
char[] newStr = new char[len];
boolean escaped = false;
// Find the kind separator
for (int i = 0; i < len && kindSep < 0; i++) {
if (escaped) {
newStr[j++] = compStr.charAt(i);
escaped = false;
} else if (compStr.charAt(i) == escapeChar) {
if (i + 1 >= len) {
throw new InvalidNameException(compStr +
": unescaped \\ at end of component");
} else if (isMeta(compStr.charAt(i+1))) {
escaped = true;
} else {
throw new InvalidNameException(compStr +
": invalid character being escaped");
}
} else if (compStr.charAt(i) == kindSeparator) {
kindSep = i;
} else {
newStr[j++] = compStr.charAt(i);
}
}
// Set id
comp.id = new String(newStr, 0, j);
// Set kind
if (kindSep < 0) {
comp.kind = ""; // no kind separator
} else {
// unescape kind
j = 0;
escaped = false;
for (int i = kindSep+1; i < len; i++) {
if (escaped) {
newStr[j++] = compStr.charAt(i);
escaped = false;
} else if (compStr.charAt(i) == escapeChar) {
if (i + 1 >= len) {
throw new InvalidNameException(compStr +
": unescaped \\ at end of component");
} else if (isMeta(compStr.charAt(i+1))) {
escaped = true;
} else {
throw new InvalidNameException(compStr +
": invalid character being escaped");
}
} else {
newStr[j++] = compStr.charAt(i);
}
}
comp.kind = new String(newStr, 0, j);
}
return comp;
}
private static String stringifyComponent(NameComponent comp) {
StringBuilder one = new StringBuilder(escape(comp.id));
if (comp.kind != null && !comp.kind.equals("")) {
one.append(kindSeparator).append(escape(comp.kind));
}
if (one.length() == 0) {
return ""+kindSeparator; // if neither id nor kind specified
} else {
return one.toString();
}
}
/**
* Returns a string with '.', '\', '/' escaped. Used when
* stringifying the name into its INS stringified form.
*/
private static String escape(String str) {
if (str.indexOf(kindSeparator) < 0 &&
str.indexOf(compSeparator) < 0 &&
str.indexOf(escapeChar) < 0) {
return str; // no meta characters to escape
} else {
int len = str.length();
int j = 0;
char[] newStr = new char[len+len];
for (int i = 0; i < len; i++) {
if (isMeta(str.charAt(i))) {
newStr[j++] = escapeChar; // escape meta character
}
newStr[j++] = str.charAt(i);
}
return new String(newStr, 0, j);
}
}
/**
* In INS, there are three meta characters: '.', '/' and '\'.
*/
private static boolean isMeta(char ch) {
switch (ch) {
case kindSeparator:
case compSeparator:
case escapeChar:
return true;
}
return false;
}
/**
* An implementation of CompoundName that bypasses the parsing
* and stringifying code of the default CompoundName.
*/
static final class CNCompoundName extends CompoundName {
CNCompoundName(Enumeration<String> enum_) {
super(enum_, CNNameParser.mySyntax);
}
public Object clone() {
return new CNCompoundName(getAll());
}
public Name getPrefix(int posn) {
Enumeration<String> comps = super.getPrefix(posn).getAll();
return new CNCompoundName(comps);
}
public Name getSuffix(int posn) {
Enumeration<String> comps = super.getSuffix(posn).getAll();
return new CNCompoundName(comps);
}
public String toString() {
try {
// Convert Name to NameComponent[] then stringify
return cosNameToInsString(nameToCosName(this));
} catch (InvalidNameException e) {
return super.toString();
}
}
private static final long serialVersionUID = -6599252802678482317L;
}
// for testing only
/*
private static void print(String input) {
try {
System.out.println("\n >>>>>> input: " + input);
System.out.println("--Compound Name: ");
NameParser parser = new CNNameParser();
Name name = parser.parse(input);
for (int i = 0; i < name.size(); i++) {
System.out.println("\t" + i + ": " + name.get(i));
NameComponent cp = parseComponent(name.get(i));
System.out.println("\t\t" + "id: " + cp.id + ";kind: " + cp.kind);
}
System.out.println("\t" + name.toString());
System.out.println("--Composite Name: ");
Name composite = new CompositeName(input);
for (int i = 0; i < composite.size(); i++) {
System.out.println("\t" + i+": " + composite.get(i));
}
System.out.println("\t" + composite.toString());
System.out.println("--Composite To NameComponent");
NameComponent[] names = nameToCosName(composite);
for (int i = 0; i < composite.size(); i++) {
System.out.println("\t" + i+": id: " + names[i].id + "; kind: " + names[i].kind);
}
System.out.println("\t" + cosNameToInsString(names));
} catch (NamingException e) {
System.out.println(e);
}
}
private static void checkName(Name name, String[] comps) throws Exception {
if (name.size() != comps.length) {
throw new Exception(
"test failed; incorrect component count in " + name + "; " +
"expecting " + comps.length + " got " + name.size());
}
for (int i = 0; i < name.size(); i++) {
if (!comps[i].equals(name.get(i))) {
throw new Exception (
"test failed; invalid component in " + name + "; " +
"expecting '" + comps[i] + "' got '" + name.get(i) + "'");
}
}
}
private static void checkCompound(NameParser parser,
String input, String[] comps) throws Exception {
checkName(parser.parse(input), comps);
}
private static void checkComposite(String input, String[] comps)
throws Exception {
checkName(new CompositeName(input), comps);
}
private static String[] compounds = {
"a/b/c",
"a.b/c.d",
"a",
".",
"a.",
"c.d",
".e",
"a/x\\/y\\/z/b",
"a\\.b.c\\.d/e.f",
"a/b\\\\/c",
"x\\\\.y",
"x\\.y",
"x.\\\\y",
"x.y\\\\",
"\\\\x.y",
"a.b\\.c/d"
};
private static String[][] compoundComps = {
{"a", "b", "c"},
{"a.b", "c.d"},
{"a"},
{"."},
{"a"},
{"c.d"},
{".e"},
{"a", "x\\/y\\/z", "b"},
{"a\\.b.c\\.d", "e.f"},
{"a", "b\\\\", "c"},
{"x\\\\.y"},
{"x\\.y"},
{"x.\\\\y"},
{"x.y\\\\"},
{"\\\\x.y"},
{"a.b\\.c", "d"},
};
private static String[] composites = {
"a/b/c",
"a.b/c.d",
"a",
".",
"a.",
"c.d",
".e",
"a/x\\\\\\/y\\\\\\/z/b",
"a\\\\.b.c\\\\.d/e.f",
"a/b\\\\\\\\/c",
"x\\\\\\.y",
"x\\\\.y",
"x.\\\\\\\\y",
"x.y\\\\\\\\",
"\\\\\\\\x.y"
};
private static String[][] compositeComps = {
{"a", "b", "c"},
{"a.b", "c.d"},
{"a"},
{"."},
{"a."}, // unlike compound, kind sep is not consumed
{"c.d"},
{".e"},
{"a", "x\\/y\\/z", "b"},
{"a\\.b.c\\.d", "e.f"},
{"a", "b\\\\", "c"},
{"x\\\\.y"},
{"x\\.y"},
{"x.\\\\y"},
{"x.y\\\\"},
{"\\\\x.y"}
};
public static void main(String[] args) throws Exception {
if (args.length > 0) {
for (int i = 0; i < args.length; i++) {
print(args[0]);
}
} else {
print("x\\\\.y");
print("x\\.y");
print("x.\\\\y");
print("x.y\\\\");
print("\\\\x.y");
}
NameParser parser = new com.sun.jndi.cosnaming.CNNameParser();
for (int i = 0; i < compounds.length; i++) {
checkCompound(parser, compounds[i], compoundComps[i]);
}
for (int i = 0; i < composites.length; i++) {
checkComposite(composites[i], compositeComps[i]);
}
System.out.println("hardwire");
NameComponent[] foo = new NameComponent[1];
foo[0] = new NameComponent("foo\\", "bar");
System.out.println(cosNameToInsString(foo));
System.out.println(cosNameToName(foo));
}
*/
}

View File

@ -0,0 +1,132 @@
/*
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jndi.cosnaming;
import javax.naming.Name;
import javax.naming.NamingException;
import java.net.MalformedURLException;
import com.sun.jndi.toolkit.corba.CorbaUtils;
/**
* Extract components of a "corbaname" URL.
*
* The format of an corbaname URL is defined in INS 99-12-03 as follows.
* <pre>{@code
* corbaname url = "corbaname:" <corbaloc_obj> ["#" <string_name>]
* corbaloc_obj = <obj_addr_list> ["/" <key_string>]
* obj_addr_list = as defined in a corbaloc URL
* key_string = as defined in a corbaloc URL
* string_name = stringified COS name | empty_string
* }</pre>
* Characters in {@code <string_name>} are escaped as follows.
* US-ASCII alphanumeric characters are not escaped. Any characters outside
* of this range are escaped except for the following:
* <pre>{@code
* ; / : ? @ & = + $ , - _ . ! ~ * ; ( )
* }</pre>
* Escaped characters is escaped by using a % followed by its 2 hexadecimal
* numbers representing the octet.
* <p>
* The corbaname URL is parsed into two parts: a corbaloc URL and a COS name.
* The corbaloc URL is constructed by concatenation {@code "corbaloc:"} with
* {@code <corbaloc_obj>}.
* The COS name is {@code <string_name>} with the escaped characters resolved.
* <p>
* A corbaname URL is resolved by:
* <ol>
* <li>Construct a corbaloc URL by concatenating {@code "corbaloc:"} and {@code <corbaloc_obj>}.
* <li>Resolve the corbaloc URL to a NamingContext by using
* <pre>{@code
* nctx = ORB.string_to_object(corbalocUrl);
* }</pre>
* <li>Resolve {@code <string_name>} in the NamingContext.
* </ol>
*
* @author Rosanna Lee
*/
public final class CorbanameUrl {
private String stringName;
private String location;
/**
* Returns a possibly empty but non-null string that is the "string_name"
* portion of the URL.
*/
public String getStringName() {
return stringName;
}
public Name getCosName() throws NamingException {
return CNCtx.parser.parse(stringName);
}
public String getLocation() {
return "corbaloc:" + location;
}
public CorbanameUrl(String url) throws MalformedURLException {
if (!url.startsWith("corbaname:")) {
throw new MalformedURLException("Invalid corbaname URL: " + url);
}
int addrStart = 10; // "corbaname:"
int addrEnd = url.indexOf('#', addrStart);
if (addrEnd < 0) {
addrEnd = url.length();
stringName = "";
} else {
stringName = CorbaUtils.decode(url.substring(addrEnd+1));
}
location = url.substring(addrStart, addrEnd);
int keyStart = location.indexOf('/');
if (keyStart >= 0) {
// Has key string
if (keyStart == (location.length() -1)) {
location += "NameService";
}
} else {
location += "/NameService";
}
}
/*
// for testing only
public static void main(String[] args) {
try {
CorbanameUrl url = new CorbanameUrl(args[0]);
System.out.println("location: " + url.getLocation());
System.out.println("string name: " + url.getStringName());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
*/
}

View File

@ -0,0 +1,242 @@
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jndi.cosnaming;
import javax.naming.*;
import javax.naming.directory.*;
import javax.naming.spi.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
/**
* A convenience class to map the COS Naming exceptions to the JNDI exceptions.
* @author Raj Krishnamurthy
*/
public final class ExceptionMapper {
private ExceptionMapper() {} // ensure no instance
private static final boolean debug = false;
public static final NamingException mapException(Exception e,
CNCtx ctx, NameComponent[] inputName) throws NamingException {
if (e instanceof NamingException) {
return (NamingException)e;
}
if (e instanceof RuntimeException) {
throw (RuntimeException)e;
}
NamingException ne;
if (e instanceof NotFound) {
if (ctx.federation) {
return tryFed((NotFound)e, ctx, inputName);
} else {
ne = new NameNotFoundException();
}
} else if (e instanceof CannotProceed) {
ne = new CannotProceedException();
NamingContext nc = ((CannotProceed) e).cxt;
NameComponent[] rest = ((CannotProceed) e).rest_of_name;
// %%% We assume that rest returns *all* unprocessed components.
// Don't' know if that is a good assumption, given
// NotFound doesn't set rest as expected. -RL
if (inputName != null && (inputName.length > rest.length)) {
NameComponent[] resolvedName =
new NameComponent[inputName.length - rest.length];
System.arraycopy(inputName, 0, resolvedName, 0, resolvedName.length);
// Wrap resolved NamingContext inside a CNCtx
// Guess that its name (which is relative to ctx)
// is the part of inputName minus rest_of_name
ne.setResolvedObj(new CNCtx(ctx._orb, ctx.orbTracker, nc,
ctx._env,
ctx.makeFullName(resolvedName)));
} else {
ne.setResolvedObj(ctx);
}
ne.setRemainingName(CNNameParser.cosNameToName(rest));
} else if (e instanceof InvalidName) {
ne = new InvalidNameException();
} else if (e instanceof AlreadyBound) {
ne = new NameAlreadyBoundException();
} else if (e instanceof NotEmpty) {
ne = new ContextNotEmptyException();
} else {
ne = new NamingException("Unknown reasons");
}
ne.setRootCause(e);
return ne;
}
private static final NamingException tryFed(NotFound e, CNCtx ctx,
NameComponent[] inputName) throws NamingException {
NameComponent[] rest = e.rest_of_name;
if (debug) {
System.out.println(e.why.value());
System.out.println(rest.length);
}
// %%% Using 1.2 & 1.3 Sun's tnameserv, 'rest' contains only the first
// component that failed, not *rest* as advertized. This is useless
// because what if you have something like aa/aa/aa/aa/aa.
// If one of those is not found, you get "aa" as 'rest'.
if (rest.length == 1 && inputName != null) {
// Check that we're not talking to 1.2/1.3 Sun tnameserv
NameComponent lastIn = inputName[inputName.length-1];
if (rest[0].id.equals(lastIn.id) &&
rest[0].kind != null &&
rest[0].kind.equals(lastIn.kind)) {
// Might be legit
;
} else {
// Due to 1.2/1.3 bug that always returns single-item 'rest'
NamingException ne = new NameNotFoundException();
ne.setRemainingName(CNNameParser.cosNameToName(rest));
ne.setRootCause(e);
throw ne;
}
}
// Fixed in 1.4; perform calculations based on correct (1.4) behavior
// Calculate the components of the name that has been resolved
NameComponent[] resolvedName = null;
int len = 0;
if (inputName != null && (inputName.length >= rest.length)) {
if (e.why == NotFoundReason.not_context) {
// First component of rest is found but not a context; keep it
// as part of resolved name
len = inputName.length - (rest.length - 1);
// Remove resolved component from rest
if (rest.length == 1) {
// No more remaining
rest = null;
} else {
NameComponent[] tmp = new NameComponent[rest.length-1];
System.arraycopy(rest, 1, tmp, 0, tmp.length);
rest = tmp;
}
} else {
len = inputName.length - rest.length;
}
if (len > 0) {
resolvedName = new NameComponent[len];
System.arraycopy(inputName, 0, resolvedName, 0, len);
}
}
// Create CPE and set common fields
CannotProceedException cpe = new CannotProceedException();
cpe.setRootCause(e);
if (rest != null && rest.length > 0) {
cpe.setRemainingName(CNNameParser.cosNameToName(rest));
}
cpe.setEnvironment(ctx._env);
if (debug) {
System.out.println("rest of name: " + cpe.getRemainingName());
}
// Lookup resolved name to get resolved object
final java.lang.Object resolvedObj =
(resolvedName != null) ? ctx.callResolve(resolvedName) : ctx;
if (resolvedObj instanceof javax.naming.Context) {
// obj is a context and child is not found
// try getting its nns dynamically by constructing
// a Reference containing obj.
RefAddr addr = new RefAddr("nns") {
public java.lang.Object getContent() {
return resolvedObj;
}
private static final long serialVersionUID =
669984699392133792L;
};
Reference ref = new Reference("java.lang.Object", addr);
// Resolved name has trailing slash to indicate nns
CompositeName cname = new CompositeName();
cname.add(""); // add trailing slash
cpe.setResolvedObj(ref);
cpe.setAltName(cname);
cpe.setAltNameCtx((javax.naming.Context)resolvedObj);
return cpe;
} else {
// Not a context, use object factory to transform object.
Name cname = CNNameParser.cosNameToName(resolvedName);
java.lang.Object resolvedObj2;
try {
resolvedObj2 = NamingManager.getObjectInstance(resolvedObj,
cname, ctx, ctx._env);
} catch (NamingException ge) {
throw ge;
} catch (Exception ge) {
NamingException ne = new NamingException(
"problem generating object using object factory");
ne.setRootCause(ge);
throw ne;
}
// If a context, continue operation with context
if (resolvedObj2 instanceof javax.naming.Context) {
cpe.setResolvedObj(resolvedObj2);
} else {
// Add trailing slash
cname.add("");
cpe.setAltName(cname);
// Create nns reference
final java.lang.Object rf2 = resolvedObj2;
RefAddr addr = new RefAddr("nns") {
public java.lang.Object getContent() {
return rf2;
}
private static final long serialVersionUID =
-785132553978269772L;
};
Reference ref = new Reference("java.lang.Object", addr);
cpe.setResolvedObj(ref);
cpe.setAltNameCtx(ctx);
}
return cpe;
}
}
}

View File

@ -0,0 +1,228 @@
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jndi.cosnaming;
import javax.naming.Name;
import javax.naming.NamingException;
import java.net.MalformedURLException;
import java.util.Vector;
import java.util.StringTokenizer;
import com.sun.jndi.toolkit.corba.CorbaUtils;
/**
* Extract components of an "iiop" or "iiopname" URL.
*
* The format of an iiopname URL is defined in INS 98-10-11 as follows:
*
* <pre>
* iiopname url = "iiopname://" [addr_list]["/" string_name]
* addr_list = [address ","]* address
* address = [version host [":" port]]
* host = DNS style host name | IP address
* version = major "." minor "@" | empty_string
* port = number
* major = number
* minor = number
* string_name = stringified name | empty_string
* </pre>
*
* The default port is 9999. The default version is "1.0"
* US-ASCII alphanumeric characters are not escaped. Any characters outside
* of this range are escaped except for the following:
* <pre>{@code
* ; / : ? : @ & = + $ , - _ . ! ~ * ' ( )
* }</pre>
* Escaped characters is escaped by using a % followed by its 2 hexadecimal
* numbers representing the octet.
*
* For backward compatibility, the "iiop" URL as defined in INS 97-6-6
* is also supported:
* <pre>{@code
* iiop url = "iiop://" [host [":" port]] ["/" string_name]
* }</pre>
* The default port is 900.
*
* @author Rosanna Lee
*/
public final class IiopUrl {
static final private int DEFAULT_IIOPNAME_PORT = 9999;
static final private int DEFAULT_IIOP_PORT = 900;
static final private String DEFAULT_HOST = "localhost";
private Vector<Address> addresses;
private String stringName;
public static class Address {
public int port = -1;
public int major, minor;
public String host;
public Address(String hostPortVers, boolean oldFormat)
throws MalformedURLException {
// [version host [":" port]]
int start;
// Parse version
int at;
if (oldFormat || (at = hostPortVers.indexOf('@')) < 0) {
major = 1;
minor = 0;
start = 0; // start at the beginning
} else {
int dot = hostPortVers.indexOf('.');
if (dot < 0) {
throw new MalformedURLException(
"invalid version: " + hostPortVers);
}
try {
major = Integer.parseInt(hostPortVers.substring(0, dot));
minor = Integer.parseInt(hostPortVers.substring(dot+1, at));
} catch (NumberFormatException e) {
throw new MalformedURLException(
"Nonnumeric version: " + hostPortVers);
}
start = at + 1; // skip '@' sign
}
// Parse host and port
int slash = hostPortVers.indexOf('/', start);
if (slash < 0) {
slash = hostPortVers.length();
}
if (hostPortVers.startsWith("[", start)) { // at IPv6 literal
int brac = hostPortVers.indexOf(']', start + 1);
if (brac < 0 || brac > slash) {
throw new IllegalArgumentException(
"IiopURL: name is an Invalid URL: " + hostPortVers);
}
// include brackets
host = hostPortVers.substring(start, brac + 1);
start = brac + 1;
} else { // at hostname or IPv4
int colon = hostPortVers.indexOf(':', start);
int hostEnd = (colon < 0 || colon > slash)
? slash
: colon;
if (start < hostEnd) {
host = hostPortVers.substring(start, hostEnd);
}
start = hostEnd; // skip past host
}
if ((start + 1 < slash)) {
if ( hostPortVers.startsWith(":", start)) { // parse port
start++; // skip past ":"
port = Integer.parseInt(hostPortVers.
substring(start, slash));
} else {
throw new IllegalArgumentException(
"IiopURL: name is an Invalid URL: " + hostPortVers);
}
}
start = slash;
if ("".equals(host) || host == null) {
host = DEFAULT_HOST ;
}
if (port == -1) {
port = (oldFormat ? DEFAULT_IIOP_PORT :
DEFAULT_IIOPNAME_PORT);
}
}
}
public Vector<Address> getAddresses() {
return addresses;
}
/**
* Returns a possibly empty but non-null string that is the "string_name"
* portion of the URL.
*/
public String getStringName() {
return stringName;
}
public Name getCosName() throws NamingException {
return CNCtx.parser.parse(stringName);
}
public IiopUrl(String url) throws MalformedURLException {
int addrStart;
boolean oldFormat;
if (url.startsWith("iiopname://")) {
oldFormat = false;
addrStart = 11;
} else if (url.startsWith("iiop://")) {
oldFormat = true;
addrStart = 7;
} else {
throw new MalformedURLException("Invalid iiop/iiopname URL: " + url);
}
int addrEnd = url.indexOf('/', addrStart);
if (addrEnd < 0) {
addrEnd = url.length();
stringName = "";
} else {
stringName = CorbaUtils.decode(url.substring(addrEnd+1));
}
addresses = new Vector<>(3);
if (oldFormat) {
// Only one host:port part, not multiple
addresses.addElement(
new Address(url.substring(addrStart, addrEnd), oldFormat));
} else {
StringTokenizer tokens =
new StringTokenizer(url.substring(addrStart, addrEnd), ",");
while (tokens.hasMoreTokens()) {
addresses.addElement(new Address(tokens.nextToken(), oldFormat));
}
if (addresses.size() == 0) {
addresses.addElement(new Address("", oldFormat));
}
}
}
// for testing only
/*public static void main(String[] args) {
try {
IiopUrl url = new IiopUrl(args[0]);
Vector addrs = url.getAddresses();
String name = url.getStringName();
for (int i = 0; i < addrs.size(); i++) {
Address addr = (Address)addrs.elementAt(i);
System.out.println("host: " + addr.host);
System.out.println("port: " + addr.port);
System.out.println("version: " + addr.major + " " + addr.minor);
}
System.out.println("name: " + name);
} catch (MalformedURLException e) {
e.printStackTrace();
}
} */
}

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jndi.cosnaming;
import org.omg.CORBA.ORB;
/**
* This class keeps track of references to the shared ORB object
* and destroys it when no more references are made to the ORB
* object. This object is created for each ORB object that CNCtx
* creates.
*/
class OrbReuseTracker {
int referenceCnt;
ORB orb;
private static final boolean debug = false;
OrbReuseTracker(ORB orb) {
this.orb = orb;
referenceCnt++;
if (debug) {
System.out.println("New OrbReuseTracker created");
}
}
synchronized void incRefCount() {
referenceCnt++;
if (debug) {
System.out.println("Increment orb ref count to:" + referenceCnt);
}
}
synchronized void decRefCount() {
referenceCnt--;
if (debug) {
System.out.println("Decrement orb ref count to:" + referenceCnt);
}
if ((referenceCnt == 0)) {
if (debug) {
System.out.println("Destroying the ORB");
}
orb.destroy();
}
}
}

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jndi.cosnaming;
import javax.naming.*;
import javax.naming.spi.StateFactory;
import java.util.Hashtable;
import org.omg.CORBA.ORB;
import java.rmi.Remote;
import java.rmi.server.ExportException;
import com.sun.jndi.toolkit.corba.CorbaUtils; // for RMI-IIOP
/**
* StateFactory that turns java.rmi.Remote objects to org.omg.CORBA.Object.
*
* @author Rosanna Lee
*/
public class RemoteToCorba implements StateFactory {
public RemoteToCorba() {
}
/**
* Returns the CORBA object for a Remote object.
* If input is not a Remote object, or if Remote object uses JRMP, return null.
* If the RMI-IIOP library is not available, throw ConfigurationException.
*
* @param orig The object to turn into a CORBA object. If not Remote,
* or if is a JRMP stub or impl, return null.
* @param name Ignored
* @param ctx The non-null CNCtx whose ORB to use.
* @param env Ignored
* @return The CORBA object for {@code orig} or null.
* @exception ConfigurationException If the CORBA object cannot be obtained
* due to configuration problems, for instance, if RMI-IIOP not available.
* @exception NamingException If some other problem prevented a CORBA
* object from being obtained from the Remote object.
*/
public Object getStateToBind(Object orig, Name name, Context ctx,
Hashtable<?,?> env) throws NamingException {
if (orig instanceof org.omg.CORBA.Object) {
// Already a CORBA object, just use it
return null;
}
if (orig instanceof Remote) {
// Turn remote object into org.omg.CORBA.Object
// Returns null if JRMP; let next factory try
// CNCtx will eventually throw IllegalArgumentException if
// no CORBA object gotten
return CorbaUtils.remoteToCorba((Remote)orig, ((CNCtx)ctx)._orb);
}
return null; // pass and let next state factory try
}
}

View File

@ -0,0 +1,4 @@
# Provider resource file for the COS Naming service provider.
# State factory to turn java.rmi.Remote into org.omg.CORBA.Object.
java.naming.factory.state=com.sun.jndi.cosnaming.RemoteToCorba

View File

@ -0,0 +1,217 @@
/*
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jndi.toolkit.corba;
// Needed for RMI/IIOP
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Hashtable;
import java.util.Properties;
import java.util.Enumeration;
import java.applet.Applet;
import org.omg.CORBA.ORB;
import javax.naming.Context;
import javax.naming.ConfigurationException;
import javax.rmi.CORBA.Stub;
import javax.rmi.PortableRemoteObject;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URLDecoder;
/**
* Contains utilities for performing CORBA-related tasks:
* 1. Get the org.omg.CORBA.Object for a java.rmi.Remote object.
* 2. Create an ORB to use for a given host/port, and environment properties.
* ...
*
* @author Simon Nash
* @author Bryan Atsatt
*/
public class CorbaUtils {
/**
* Returns the CORBA object reference associated with a Remote
* object by using the javax.rmi.CORBA package.
*<p>
* This method effective does the following:
* <blockquote><pre>
* java.lang.Object stub;
* try {
* stub = PortableRemoteObject.toStub(remoteObj);
* } catch (Exception e) {
* throw new ConfigurationException("Object not exported or not found");
* }
* if (!(stub instanceof javax.rmi.CORBA.Stub)) {
* return null; // JRMP impl or JRMP stub
* }
* try {
* ((javax.rmi.CORBA.Stub)stub).connect(orb); // try to connect IIOP stub
* } catch (RemoteException e) {
* // ignore 'already connected' error
* }
* return (javax.rmi.CORBA.Stub)stub;
* </pre></blockquote>
*
* @param remoteObj The non-null remote object for
* @param orb The non-null ORB to connect the remote object to
* @return The CORBA Object for remoteObj; null if {@code remoteObj}
* is a JRMP implementation or JRMP stub.
* @exception ConfigurationException The CORBA Object cannot be obtained
* because of configuration problems.
*/
public static org.omg.CORBA.Object remoteToCorba(Remote remoteObj, ORB orb)
throws ConfigurationException {
// First, get remoteObj's stub
// javax.rmi.CORBA.Stub stub = PortableRemoteObject.toStub(remoteObj);
Remote stub;
try {
stub = PortableRemoteObject.toStub(remoteObj);
} catch (Throwable t) {
ConfigurationException ce = new ConfigurationException(
"Problem with PortableRemoteObject.toStub(); object not exported or stub not found");
ce.setRootCause(t);
throw ce;
}
// Next, make sure that the stub is javax.rmi.CORBA.Stub
if (!(stub instanceof Stub)) {
return null; // JRMP implementation or JRMP stub
}
// Next, make sure that the stub is connected
try {
((Stub) stub).connect(orb);
} catch (RemoteException e) {
// ignore RemoteException because stub might have already
// been connected
} catch (Throwable t) {
ConfigurationException ce = new ConfigurationException(
"Problem invoking javax.rmi.CORBA.Stub.connect()");
ce.setRootCause(t);
throw ce;
}
// Finally, return stub
return (org.omg.CORBA.Object)stub;
}
/**
* Get ORB using given server and port number, and properties from environment.
*
* @param server Possibly null server; if null means use default;
* For applet, it is the applet host; for app, it is localhost.
* @param port Port number, -1 means default port
* @param env Possibly null environment. Contains environment properties.
* Could contain ORB itself; or applet used for initializing ORB.
* Use all String properties from env for initializing ORB
* @return A non-null ORB.
*/
public static ORB getOrb(String server, int port, Hashtable<?,?> env) {
// See if we can get info from environment
Properties orbProp;
// Extract any org.omg.CORBA properties from environment
if (env != null) {
if (env instanceof Properties) {
// Already a Properties, just clone
orbProp = (Properties) env.clone();
} else {
// Get all String properties
Enumeration<?> envProp;
orbProp = new Properties();
for (envProp = env.keys(); envProp.hasMoreElements();) {
String key = (String)envProp.nextElement();
Object val = env.get(key);
if (val instanceof String) {
orbProp.put(key, val);
}
}
}
} else {
orbProp = new Properties();
}
if (server != null) {
orbProp.put("org.omg.CORBA.ORBInitialHost", server);
}
if (port >= 0) {
orbProp.put("org.omg.CORBA.ORBInitialPort", ""+port);
}
// Get Applet from environment
if (env != null) {
@SuppressWarnings("deprecation")
Applet applet = (Applet) env.get(Context.APPLET);
if (applet != null) {
// Create ORBs using applet and orbProp
return ORB.init(applet, orbProp);
}
}
return ORB.init(new String[0], orbProp);
}
/**
* Decode a URI string (according to RFC 2396).
*/
public static final String decode(String s) throws MalformedURLException {
try {
return decode(s, "8859_1");
} catch (UnsupportedEncodingException e) {
// ISO-Latin-1 should always be available?
throw new MalformedURLException("ISO-Latin-1 decoder unavailable");
}
}
/**
* Decode a URI string (according to RFC 2396).
*
* Three-character sequences '%xy', where 'xy' is the two-digit
* hexadecimal representation of the lower 8-bits of a character,
* are decoded into the character itself.
*
* The string is subsequently converted using the specified encoding
*/
public static final String decode(String s, String enc)
throws MalformedURLException, UnsupportedEncodingException {
try {
return URLDecoder.decode(s, enc);
} catch (IllegalArgumentException iae) {
MalformedURLException mue = new MalformedURLException("Invalid URI encoding: " + s);
mue.initCause(iae);
throw mue;
}
}
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jndi.url.corbaname;
import com.sun.jndi.url.iiop.iiopURLContextFactory;
/**
* A corbaname URL context factory.
* It just uses the iiop URL context factory but is needed here
* so that NamingManager.getURLContext() will find it.
*
* @author Rosanna Lee
*/
final public class corbanameURLContextFactory extends iiopURLContextFactory {
}

View File

@ -0,0 +1,537 @@
/*
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jndi.url.iiop;
import com.sun.jndi.toolkit.corba.CorbaUtils;
import javax.naming.*;
import javax.naming.spi.ResolveResult;
import javax.naming.spi.NamingManager;
import java.util.Hashtable;
import java.net.MalformedURLException;
/**
* This abstract class is a generic URL context that accepts as the
* name argument either a string URL or a Name whose first component
* is a URL. It resolves the URL to a target context and then continues
* the operation using the remaining name in the target context as if
* the first component names a junction.
*
* A subclass must define getRootURLContext()
* to process the URL into head/tail pieces. If it wants to control how
* URL strings are parsed and compared for the rename() operation, then
* it should override getNonRootURLSuffixes() and urlEquals().
*
* @author Scott Seligman
* @author Rosanna Lee
*/
abstract public class GenericURLContext implements Context {
protected Hashtable<String, Object> myEnv = null;
@SuppressWarnings("unchecked") // Expect Hashtable<String, Object>
public GenericURLContext(Hashtable<?,?> env) {
// context that is not tied to any specific URL
myEnv =
(Hashtable<String, Object>)(env == null ? null : env.clone());
}
public void close() throws NamingException {
myEnv = null;
}
public String getNameInNamespace() throws NamingException {
return ""; // %%% check this out: A URL context's name is ""
}
/**
* Resolves 'name' into a target context with remaining name.
* For example, with a JNDI URL "jndi://dnsname/rest_name",
* this method resolves "jndi://dnsname/" to a target context,
* and returns the target context with "rest_name".
* The definition of "root URL" and how much of the URL to
* consume is implementation specific.
* If rename() is supported for a particular URL scheme,
* getRootURLContext(), getURLPrefix(), and getURLSuffix()
* must be in sync wrt how URLs are parsed and returned.
*/
abstract protected ResolveResult getRootURLContext(String url,
Hashtable<?,?> env) throws NamingException;
/**
* Returns the suffix of the url. The result should be identical to
* that of calling getRootURLContext().getRemainingName(), but
* without the overhead of doing anything with the prefix like
* creating a context.
*<p>
* This method returns a Name instead of a String because to give
* the provider an opportunity to return a Name (for example,
* for weakly separated naming systems like COS naming).
*<p>
* The default implementation uses skips 'prefix', calls
* CorbaUtils.decode() on it, and returns the result as a single component
* CompositeName.
* Subclass should override if this is not appropriate.
* This method is used only by rename().
* If rename() is supported for a particular URL scheme,
* getRootURLContext(), getURLPrefix(), and getURLSuffix()
* must be in sync wrt how URLs are parsed and returned.
*<p>
* For many URL schemes, this method is very similar to URL.getFile(),
* except getFile() will return a leading slash in the
* 2nd, 3rd, and 4th cases. For schemes like "ldap" and "iiop",
* the leading slash must be skipped before the name is an acceptable
* format for operation by the Context methods. For schemes that treat the
* leading slash as significant (such as "file"),
* the subclass must override getURLSuffix() to get the correct behavior.
* Remember, the behavior must match getRootURLContext().
*
* <pre>{@code
* URL Suffix
* foo://host:port <empty string>
* foo://host:port/rest/of/name rest/of/name
* foo:///rest/of/name rest/of/name
* foo:/rest/of/name rest/of/name
* foo:rest/of/name rest/of/name
* }</pre>
*/
protected Name getURLSuffix(String prefix, String url) throws NamingException {
String suffix = url.substring(prefix.length());
if (suffix.length() == 0) {
return new CompositeName();
}
if (suffix.charAt(0) == '/') {
suffix = suffix.substring(1); // skip leading slash
}
try {
return new CompositeName().add(CorbaUtils.decode(suffix));
} catch (MalformedURLException e) {
throw new InvalidNameException(e.getMessage());
}
}
/**
* Finds the prefix of a URL.
* Default implementation looks for slashes and then extracts
* prefixes using String.substring().
* Subclass should override if this is not appropriate.
* This method is used only by rename().
* If rename() is supported for a particular URL scheme,
* getRootURLContext(), getURLPrefix(), and getURLSuffix()
* must be in sync wrt how URLs are parsed and returned.
*<p>
* URL Prefix
* foo://host:port foo://host:port
* foo://host:port/rest/of/name foo://host:port
* foo:///rest/of/name foo://
* foo:/rest/of/name foo:
* foo:rest/of/name foo:
*/
protected String getURLPrefix(String url) throws NamingException {
int start = url.indexOf(':');
if (start < 0) {
throw new OperationNotSupportedException("Invalid URL: " + url);
}
++start; // skip ':'
if (url.startsWith("//", start)) {
start += 2; // skip double slash
// find last slash
int posn = url.indexOf('/', start);
if (posn >= 0) {
start = posn;
} else {
start = url.length(); // rest of URL
}
}
// else 0 or 1 initial slashes; start is unchanged
return url.substring(0, start);
}
/**
* Determines whether two URLs are the same.
* Default implementation uses String.equals().
* Subclass should override if this is not appropriate.
* This method is used by rename().
*/
protected boolean urlEquals(String url1, String url2) {
return url1.equals(url2);
}
/**
* Gets the context in which to continue the operation. This method
* is called when this context is asked to process a multicomponent
* Name in which the first component is a URL.
* Treat the first component like a junction: resolve it and then use
* NamingManager.getContinuationContext() to get the target context in
* which to operate on the remainder of the name (n.getSuffix(1)).
*/
protected Context getContinuationContext(Name n) throws NamingException {
Object obj = lookup(n.get(0));
CannotProceedException cpe = new CannotProceedException();
cpe.setResolvedObj(obj);
cpe.setEnvironment(myEnv);
return NamingManager.getContinuationContext(cpe);
}
public Object lookup(String name) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
return ctx.lookup(res.getRemainingName());
} finally {
ctx.close();
}
}
public Object lookup(Name name) throws NamingException {
if (name.size() == 1) {
return lookup(name.get(0));
} else {
Context ctx = getContinuationContext(name);
try {
return ctx.lookup(name.getSuffix(1));
} finally {
ctx.close();
}
}
}
public void bind(String name, Object obj) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
ctx.bind(res.getRemainingName(), obj);
} finally {
ctx.close();
}
}
public void bind(Name name, Object obj) throws NamingException {
if (name.size() == 1) {
bind(name.get(0), obj);
} else {
Context ctx = getContinuationContext(name);
try {
ctx.bind(name.getSuffix(1), obj);
} finally {
ctx.close();
}
}
}
public void rebind(String name, Object obj) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
ctx.rebind(res.getRemainingName(), obj);
} finally {
ctx.close();
}
}
public void rebind(Name name, Object obj) throws NamingException {
if (name.size() == 1) {
rebind(name.get(0), obj);
} else {
Context ctx = getContinuationContext(name);
try {
ctx.rebind(name.getSuffix(1), obj);
} finally {
ctx.close();
}
}
}
public void unbind(String name) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
ctx.unbind(res.getRemainingName());
} finally {
ctx.close();
}
}
public void unbind(Name name) throws NamingException {
if (name.size() == 1) {
unbind(name.get(0));
} else {
Context ctx = getContinuationContext(name);
try {
ctx.unbind(name.getSuffix(1));
} finally {
ctx.close();
}
}
}
public void rename(String oldName, String newName) throws NamingException {
String oldPrefix = getURLPrefix(oldName);
String newPrefix = getURLPrefix(newName);
if (!urlEquals(oldPrefix, newPrefix)) {
throw new OperationNotSupportedException(
"Renaming using different URL prefixes not supported : " +
oldName + " " + newName);
}
ResolveResult res = getRootURLContext(oldName, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
ctx.rename(res.getRemainingName(), getURLSuffix(newPrefix, newName));
} finally {
ctx.close();
}
}
public void rename(Name name, Name newName) throws NamingException {
if (name.size() == 1) {
if (newName.size() != 1) {
throw new OperationNotSupportedException(
"Renaming to a Name with more components not supported: " + newName);
}
rename(name.get(0), newName.get(0));
} else {
// > 1 component with 1st one being URL
// URLs must be identical; cannot deal with diff URLs
if (!urlEquals(name.get(0), newName.get(0))) {
throw new OperationNotSupportedException(
"Renaming using different URLs as first components not supported: " +
name + " " + newName);
}
Context ctx = getContinuationContext(name);
try {
ctx.rename(name.getSuffix(1), newName.getSuffix(1));
} finally {
ctx.close();
}
}
}
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
return ctx.list(res.getRemainingName());
} finally {
ctx.close();
}
}
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
if (name.size() == 1) {
return list(name.get(0));
} else {
Context ctx = getContinuationContext(name);
try {
return ctx.list(name.getSuffix(1));
} finally {
ctx.close();
}
}
}
public NamingEnumeration<Binding> listBindings(String name)
throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
return ctx.listBindings(res.getRemainingName());
} finally {
ctx.close();
}
}
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
if (name.size() == 1) {
return listBindings(name.get(0));
} else {
Context ctx = getContinuationContext(name);
try {
return ctx.listBindings(name.getSuffix(1));
} finally {
ctx.close();
}
}
}
public void destroySubcontext(String name) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
ctx.destroySubcontext(res.getRemainingName());
} finally {
ctx.close();
}
}
public void destroySubcontext(Name name) throws NamingException {
if (name.size() == 1) {
destroySubcontext(name.get(0));
} else {
Context ctx = getContinuationContext(name);
try {
ctx.destroySubcontext(name.getSuffix(1));
} finally {
ctx.close();
}
}
}
public Context createSubcontext(String name) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
return ctx.createSubcontext(res.getRemainingName());
} finally {
ctx.close();
}
}
public Context createSubcontext(Name name) throws NamingException {
if (name.size() == 1) {
return createSubcontext(name.get(0));
} else {
Context ctx = getContinuationContext(name);
try {
return ctx.createSubcontext(name.getSuffix(1));
} finally {
ctx.close();
}
}
}
public Object lookupLink(String name) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
return ctx.lookupLink(res.getRemainingName());
} finally {
ctx.close();
}
}
public Object lookupLink(Name name) throws NamingException {
if (name.size() == 1) {
return lookupLink(name.get(0));
} else {
Context ctx = getContinuationContext(name);
try {
return ctx.lookupLink(name.getSuffix(1));
} finally {
ctx.close();
}
}
}
public NameParser getNameParser(String name) throws NamingException {
ResolveResult res = getRootURLContext(name, myEnv);
Context ctx = (Context)res.getResolvedObj();
try {
return ctx.getNameParser(res.getRemainingName());
} finally {
ctx.close();
}
}
public NameParser getNameParser(Name name) throws NamingException {
if (name.size() == 1) {
return getNameParser(name.get(0));
} else {
Context ctx = getContinuationContext(name);
try {
return ctx.getNameParser(name.getSuffix(1));
} finally {
ctx.close();
}
}
}
public String composeName(String name, String prefix)
throws NamingException {
if (prefix.equals("")) {
return name;
} else if (name.equals("")) {
return prefix;
} else {
return (prefix + "/" + name);
}
}
public Name composeName(Name name, Name prefix) throws NamingException {
Name result = (Name)prefix.clone();
result.addAll(name);
return result;
}
public Object removeFromEnvironment(String propName)
throws NamingException {
if (myEnv == null) {
return null;
}
return myEnv.remove(propName);
}
public Object addToEnvironment(String propName, Object propVal)
throws NamingException {
if (myEnv == null) {
myEnv = new Hashtable<String, Object>(11, 0.75f);
}
return myEnv.put(propName, propVal);
}
@SuppressWarnings("unchecked") // clone()
public Hashtable<String, Object> getEnvironment() throws NamingException {
if (myEnv == null) {
return new Hashtable<>(5, 0.75f);
} else {
return (Hashtable<String, Object>)myEnv.clone();
}
}
/*
// To test, declare getURLPrefix and getURLSuffix static.
public static void main(String[] args) throws Exception {
String[] tests = {"file://host:port",
"file:///rest/of/name",
"file://host:port/rest/of/name",
"file:/rest/of/name",
"file:rest/of/name"};
for (int i = 0; i < tests.length; i++) {
String pre = getURLPrefix(tests[i]);
System.out.println(pre);
System.out.println(getURLSuffix(pre, tests[i]));
}
}
*/
}

View File

@ -0,0 +1,84 @@
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jndi.url.iiop;
import javax.naming.spi.ResolveResult;
import javax.naming.*;
import java.util.Hashtable;
import java.net.MalformedURLException;
import com.sun.jndi.cosnaming.IiopUrl;
import com.sun.jndi.cosnaming.CorbanameUrl;
/**
* An IIOP URL context.
*
* @author Rosanna Lee
*/
public class iiopURLContext
extends GenericURLContext {
iiopURLContext(Hashtable<?,?> env) {
super(env);
}
/**
* Resolves 'name' into a target context with remaining name.
* It only resolves the hostname/port number. The remaining name
* contains the rest of the name found in the URL.
*
* For example, with a iiop URL "iiop://localhost:900/rest/of/name",
* this method resolves "iiop://localhost:900/" to the "NameService"
* context on for the ORB at 'localhost' on port 900,
* and returns as the remaining name "rest/of/name".
*/
protected ResolveResult getRootURLContext(String name, Hashtable<?,?> env)
throws NamingException {
return iiopURLContextFactory.getUsingURLIgnoreRest(name, env);
}
/**
* Return the suffix of an "iiop", "iiopname", or "corbaname" url.
* prefix parameter is ignored.
*/
protected Name getURLSuffix(String prefix, String url)
throws NamingException {
try {
if (url.startsWith("iiop://") || url.startsWith("iiopname://")) {
IiopUrl parsedUrl = new IiopUrl(url);
return parsedUrl.getCosName();
} else if (url.startsWith("corbaname:")) {
CorbanameUrl parsedUrl = new CorbanameUrl(url);
return parsedUrl.getCosName();
} else {
throw new MalformedURLException("Not a valid URL: " + url);
}
} catch (MalformedURLException e) {
throw new InvalidNameException(e.getMessage());
}
}
}

View File

@ -0,0 +1,101 @@
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jndi.url.iiop;
import javax.naming.*;
import javax.naming.spi.*;
import java.util.Hashtable;
import com.sun.jndi.cosnaming.CNCtx;
/**
* An IIOP URL context factory.
*
* @author Rosanna Lee
*/
public class iiopURLContextFactory implements ObjectFactory {
public Object getObjectInstance(Object urlInfo, Name name, Context nameCtx,
Hashtable<?,?> env) throws Exception {
//System.out.println("iiopURLContextFactory " + urlInfo);
if (urlInfo == null) {
return new iiopURLContext(env);
}
if (urlInfo instanceof String) {
return getUsingURL((String)urlInfo, env);
} else if (urlInfo instanceof String[]) {
return getUsingURLs((String[])urlInfo, env);
} else {
throw (new IllegalArgumentException(
"iiopURLContextFactory.getObjectInstance: " +
"argument must be a URL String or array of URLs"));
}
}
/**
* Resolves 'name' into a target context with remaining name.
* It only resolves the hostname/port number. The remaining name
* contains the rest of the name found in the URL.
*
* For example, with a iiop URL "iiop://localhost:900/rest/of/name",
* this method resolves "iiop://localhost:900/" to the "NameService"
* context on for the ORB at 'localhost' on port 900,
* and returns as the remaining name "rest/of/name".
*/
static ResolveResult getUsingURLIgnoreRest(String url, Hashtable<?,?> env)
throws NamingException {
return CNCtx.createUsingURL(url, env);
}
private static Object getUsingURL(String url, Hashtable<?,?> env)
throws NamingException {
ResolveResult res = getUsingURLIgnoreRest(url, env);
Context ctx = (Context)res.getResolvedObj();
try {
return ctx.lookup(res.getRemainingName());
} finally {
ctx.close();
}
}
private static Object getUsingURLs(String[] urls, Hashtable<?,?> env) {
for (int i = 0; i < urls.length; i++) {
String url = urls[i];
try {
Object obj = getUsingURL(url, env);
if (obj != null) {
return obj;
}
} catch (NamingException e) {
}
}
return null; // %%% exception??
}
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.jndi.url.iiopname;
import com.sun.jndi.url.iiop.iiopURLContextFactory;
/**
* An iiopname URL context factory.
* It just uses the iiop URL context factory but is needed here
* so that NamingManager.getURLContext() will find it.
*
* @author Rosanna Lee
*/
final public class iiopnameURLContextFactory extends iiopURLContextFactory {
}