feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,240 @@
/*
* 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.*;
import com.sun.jndi.toolkit.corba.CorbaUtils;
/**
* 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 {
// Check whether object factory codebase is trusted
if (CorbaUtils.isObjectFactoryTrusted(obj)) {
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) {
StringBuffer str = new StringBuffer();
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) {
StringBuffer one = new StringBuffer(escape(comp.id));
if (comp.kind != null && !comp.kind.equals("")) {
one.append(kindSeparator + 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,128 @@
/*
* 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.url.UrlUtil;
/**
* Extract components of a "corbaname" URL.
*
* The format of an corbaname URL is defined in INS 99-12-03 as follows.
*<p>
* 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
*<p>
* Characters in <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:
* ; / : ? @ & = + $ , - _ . ! ~ * ; ( )
* 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 "corbaloc:" with
* <corbaloc_obj>.
* The COS name is <string_name> with the escaped characters resolved.
*<p>
* A corbaname URL is resolved by:
*<ol>
*<li>Construct a corbaloc URL by concatenating "corbaloc:" and <corbaloc_obj>.
*<li>Resolve the corbaloc URL to a NamingContext by using
* nctx = ORB.string_to_object(corbalocUrl);
*<li>Resolve <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 = UrlUtil.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,247 @@
/*
* 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.*;
import com.sun.jndi.toolkit.corba.CorbaUtils;
/**
* 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 = null;
try {
// Check whether object factory codebase is trusted
if (CorbaUtils.isObjectFactoryTrusted(resolvedObj)) {
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,223 @@
/*
* 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.url.UrlUtil;
/**
* Extract components of an "iiop" or "iiopname" URL.
*
* The format of an iiopname URL is defined in INS 98-10-11 as follows:
*
* 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
*
* 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:
* ; / : ? : @ & = + $ , - _ . ! ~ * ' ( )
* 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:
*
* iiop url = "iiop://" [host [":" port]] ["/" string_name]
* 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 = UrlUtil.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,88 @@
/*
* 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.*;
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 <tt>orig</tt> 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
try {
// 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);
} catch (ClassNotFoundException e) {
// RMI-IIOP library not available
throw new ConfigurationException(
"javax.rmi packages not available");
}
}
return null; // pass and let next state factory try
}
}