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,692 @@
/*
* 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.toolkit.ctx;
import javax.naming.*;
/**
* Clients: deal only with names for its own naming service
* and deals with single contexts that can be built up into
* hierarchical naming systems.
* Direct subclasses of AtomicContext must provide implementations for
* the abstract a_ Context methods, and c_parseComponent().
*
* If the subclass implements the notion of implicit nns,
* it must override the a_*_nns Context methods as well.
*
* @author Rosanna Lee
*
*/
public abstract class AtomicContext extends ComponentContext {
private static int debug = 0;
protected AtomicContext () {
_contextType = _ATOMIC;
}
// ------ Abstract methods whose implementation are provided by subclasses
/* Equivalent to Context methods */
protected abstract Object a_lookup(String name, Continuation cont)
throws NamingException;
protected abstract Object a_lookupLink(String name, Continuation cont)
throws NamingException;
protected abstract NamingEnumeration<NameClassPair> a_list(
Continuation cont) throws NamingException;
protected abstract NamingEnumeration<Binding> a_listBindings(
Continuation cont) throws NamingException;
protected abstract void a_bind(String name, Object obj, Continuation cont)
throws NamingException;
protected abstract void a_rebind(String name, Object obj, Continuation cont)
throws NamingException;
protected abstract void a_unbind(String name, Continuation cont)
throws NamingException;
protected abstract void a_destroySubcontext(String name, Continuation cont)
throws NamingException;
protected abstract Context a_createSubcontext(String name,
Continuation cont) throws NamingException;
protected abstract void a_rename(String oldname, Name newname,
Continuation cont) throws NamingException;
protected abstract NameParser a_getNameParser(Continuation cont)
throws NamingException;
/* Parsing */
/**
* Parse 'inputName' into two parts:
* head: the first component in this name
* tail: the rest of the unused name.
*
* Subclasses should provide an implementation for this method
* which parses inputName using its own name syntax.
*/
protected abstract StringHeadTail c_parseComponent(String inputName,
Continuation cont) throws NamingException;
// ------ Methods that need to be overridden by subclass
/* Resolution method for supporting federation */
/**
* Resolves the nns for 'name' when the named context is acting
* as an intermediate context.
*
* For a system that supports junctions, this would be equilvalent to
* a_lookup(name, cont);
* because for junctions, an intermediate slash simply signifies
* a syntactic separator.
*
* For a system that supports implicit nns, this would be equivalent to
* a_lookup_nns(name, cont);
* because for implicit nns, a slash always signifies the implicit nns,
* regardless of whether it is intermediate or trailing.
*
* By default this method supports junctions, and also allows for an
* implicit nns to be dynamically determined through the use of the
* "nns" reference (see a_processJunction_nns()).
* Contexts that implement implicit nns directly should provide an
* appropriate override.
*/
protected Object a_resolveIntermediate_nns(String name, Continuation cont)
throws NamingException {
try {
final Object obj = a_lookup(name, cont);
// Do not append "" to Continuation 'cont' even if set
// because the intention is to ignore the nns
//
if (obj != null && getClass().isInstance(obj)) {
// If "obj" is in the same type as this object, it must
// not be a junction. Continue the lookup with "/".
cont.setContinueNNS(obj, name, this);
return null;
} else if (obj != null && !(obj instanceof Context)) {
// obj is not even a context, so try to find its nns
// dynamically by constructing a Reference containing obj.
RefAddr addr = new RefAddr("nns") {
public Object getContent() {
return obj;
}
private static final long serialVersionUID =
-3399518522645918499L;
};
Reference ref = new Reference("java.lang.Object", addr);
// Resolved name has trailing slash to indicate nns
CompositeName resName = new CompositeName();
resName.add(name);
resName.add(""); // add trailing slash
// Set continuation leave it to
// PartialCompositeContext.getPCContext() to throw CPE.
// Do not use setContinueNNS() because we've already
// consumed "/" (i.e., moved it to resName).
cont.setContinue(ref, resName, this);
return null;
} else {
return obj;
}
} catch (NamingException e) {
e.appendRemainingComponent(""); // add nns back
throw e;
}
}
/* Equivalent of Context Methods for supporting nns */
// The following methods are called when the DirContext methods
// are invoked with a name that has a trailing slash.
// For naming systems that support implicit nns,
// the trailing slash signifies the implicit nns.
// For such naming systems, override these a_*_nns methods.
//
// For naming systems that support junctions (explicit nns),
// the trailing slash is meaningless because a junction does not
// have an implicit nns. The default implementation here
// throws a NameNotFoundException for such names.
// If a context wants to accept a trailing slash as having
// the same meaning as the same name without a trailing slash,
// then it should override these a_*_nns methods.
protected Object a_lookup_nns(String name, Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
return null;
}
protected Object a_lookupLink_nns(String name, Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
return null;
}
protected NamingEnumeration<NameClassPair> a_list_nns(Continuation cont)
throws NamingException {
a_processJunction_nns(cont);
return null;
}
protected NamingEnumeration<Binding> a_listBindings_nns(Continuation cont)
throws NamingException {
a_processJunction_nns(cont);
return null;
}
protected void a_bind_nns(String name, Object obj, Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
}
protected void a_rebind_nns(String name, Object obj, Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
}
protected void a_unbind_nns(String name, Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
}
protected Context a_createSubcontext_nns(String name, Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
return null;
}
protected void a_destroySubcontext_nns(String name, Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
}
protected void a_rename_nns(String oldname, Name newname, Continuation cont)
throws NamingException {
a_processJunction_nns(oldname, cont);
}
protected NameParser a_getNameParser_nns(Continuation cont)
throws NamingException {
a_processJunction_nns(cont);
return null;
}
protected boolean isEmpty(String name) {
return name == null || name.equals("");
}
// ------ implementations of c_ and c_*_nns methods using
// ------ the corresponding a_ and a_*_nns methods
/* Equivalent to methods in Context interface */
protected Object c_lookup(Name name, Continuation cont)
throws NamingException {
Object ret = null;
if (resolve_to_penultimate_context(name, cont)) {
ret = a_lookup(name.toString(), cont);
if (ret != null && ret instanceof LinkRef) {
cont.setContinue(ret, name, this);
ret = null;
}
}
return ret;
}
protected Object c_lookupLink(Name name, Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context(name, cont)) {
return a_lookupLink(name.toString(), cont);
}
return null;
}
protected NamingEnumeration<NameClassPair> c_list(Name name,
Continuation cont) throws NamingException {
if (resolve_to_context(name, cont)) {
return a_list(cont);
}
return null;
}
protected NamingEnumeration<Binding> c_listBindings(Name name,
Continuation cont) throws NamingException {
if (resolve_to_context(name, cont)) {
return a_listBindings(cont);
}
return null;
}
protected void c_bind(Name name, Object obj, Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context(name, cont))
a_bind(name.toString(), obj, cont);
}
protected void c_rebind(Name name, Object obj, Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context(name, cont))
a_rebind(name.toString(), obj, cont);
}
protected void c_unbind(Name name, Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context(name, cont))
a_unbind(name.toString(), cont);
}
protected void c_destroySubcontext(Name name, Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context(name, cont))
a_destroySubcontext(name.toString(), cont);
}
protected Context c_createSubcontext(Name name,
Continuation cont) throws NamingException {
if (resolve_to_penultimate_context(name, cont))
return a_createSubcontext(name.toString(), cont);
else
return null;
}
protected void c_rename(Name oldname, Name newname,
Continuation cont) throws NamingException {
if (resolve_to_penultimate_context(oldname, cont))
a_rename(oldname.toString(), newname, cont);
}
protected NameParser c_getNameParser(Name name,
Continuation cont) throws NamingException {
if (resolve_to_context(name, cont))
return a_getNameParser(cont);
return null;
}
/* The following are overridden only for AtomicContexts.
* AtomicContext is used by PartialCompositeDirContext and ComponentDirContext
* in the inheritance tree to make use of methods in
* PartialCompositeContext and ComponentContext. We only want to use the
* atomic forms when we're actually an atomic context.
*/
/* From ComponentContext */
protected Object c_resolveIntermediate_nns(Name name, Continuation cont)
throws NamingException {
if (_contextType == _ATOMIC) {
Object ret = null;
if (resolve_to_penultimate_context_nns(name, cont)) {
ret = a_resolveIntermediate_nns(name.toString(), cont);
if (ret != null && ret instanceof LinkRef) {
cont.setContinue(ret, name, this);
ret = null;
}
}
return ret;
} else {
// use ComponentContext
return super.c_resolveIntermediate_nns(name, cont);
}
}
/* Equivalent to methods in Context interface for nns */
protected Object c_lookup_nns(Name name, Continuation cont)
throws NamingException {
if (_contextType == _ATOMIC) {
Object ret = null;
if (resolve_to_penultimate_context_nns(name, cont)) {
ret = a_lookup_nns(name.toString(), cont);
if (ret != null && ret instanceof LinkRef) {
cont.setContinue(ret, name, this);
ret = null;
}
}
return ret;
} else {
return super.c_lookup_nns(name, cont);
}
}
protected Object c_lookupLink_nns(Name name, Continuation cont)
throws NamingException {
if (_contextType == _ATOMIC) {
// %%% check logic
resolve_to_nns_and_continue(name, cont);
return null;
} else {
// use ComponentContext
return super.c_lookupLink_nns(name, cont);
}
}
protected NamingEnumeration<NameClassPair> c_list_nns(Name name,
Continuation cont) throws NamingException {
if (_contextType == _ATOMIC) {
resolve_to_nns_and_continue(name, cont);
return null;
} else {
// use ComponentContext
return super.c_list_nns(name, cont);
}
}
protected NamingEnumeration<Binding> c_listBindings_nns(Name name,
Continuation cont) throws NamingException {
if (_contextType == _ATOMIC) {
resolve_to_nns_and_continue(name, cont);
return null;
} else {
// use ComponentContext
return super.c_listBindings_nns(name, cont);
}
}
protected void c_bind_nns(Name name, Object obj, Continuation cont)
throws NamingException {
if (_contextType == _ATOMIC) {
if (resolve_to_penultimate_context_nns(name, cont))
a_bind_nns(name.toString(), obj, cont);
} else {
// use ComponentContext
super.c_bind_nns(name, obj, cont);
}
}
protected void c_rebind_nns(Name name, Object obj, Continuation cont)
throws NamingException {
if (_contextType == _ATOMIC) {
if (resolve_to_penultimate_context_nns(name, cont))
a_rebind_nns(name.toString(), obj, cont);
} else {
// use ComponentContext
super.c_rebind_nns(name, obj, cont);
}
}
protected void c_unbind_nns(Name name, Continuation cont)
throws NamingException {
if (_contextType == _ATOMIC) {
if (resolve_to_penultimate_context_nns(name, cont))
a_unbind_nns(name.toString(), cont);
} else {
// use ComponentContext
super.c_unbind_nns(name, cont);
}
}
protected Context c_createSubcontext_nns(Name name,
Continuation cont) throws NamingException {
if (_contextType == _ATOMIC) {
if (resolve_to_penultimate_context_nns(name, cont))
return a_createSubcontext_nns(name.toString(), cont);
else
return null;
} else {
// use ComponentContext
return super.c_createSubcontext_nns(name, cont);
}
}
protected void c_destroySubcontext_nns(Name name, Continuation cont)
throws NamingException {
if (_contextType == _ATOMIC) {
if (resolve_to_penultimate_context_nns(name, cont))
a_destroySubcontext_nns(name.toString(), cont);
} else {
// use ComponentContext
super.c_destroySubcontext_nns(name, cont);
}
}
protected void c_rename_nns(Name oldname, Name newname, Continuation cont)
throws NamingException {
if (_contextType == _ATOMIC) {
if (resolve_to_penultimate_context_nns(oldname, cont))
a_rename_nns(oldname.toString(), newname, cont);
} else {
// use ComponentContext
super.c_rename_nns(oldname, newname, cont);
}
}
protected NameParser c_getNameParser_nns(Name name, Continuation cont)
throws NamingException {
if (_contextType == _ATOMIC) {
resolve_to_nns_and_continue(name, cont);
return null;
} else {
// use COmponentContext
return super.c_getNameParser_nns(name, cont);
}
}
// -------------- internal methods used by this class
/* Handles nns for junctions */
/**
* This function is used when implementing a naming system that
* supports junctions. For example, when the a_bind_nns(name, newobj)
* method is invoked, that means the caller is attempting to bind the
* object 'newobj' to the nns of 'name'. For context that supports
* junctions, 'name' names a junction and is pointing to the root
* of another naming system, which in turn might have an nns.
* This means that a_bind_nns() should first resolve 'name' and attempt to
* continue the operation in the context named by 'name'. (i.e. bind
* to the nns of the context named by 'name').
* If name is already empty, then throw NameNotFoundException because
* this context by default does not have any nns.
*/
protected void a_processJunction_nns(String name, Continuation cont)
throws NamingException {
if (name.equals("")) {
NameNotFoundException e = new NameNotFoundException();
cont.setErrorNNS(this, name);
throw cont.fillInException(e);
}
try {
// lookup name to continue operation in nns
Object target = a_lookup(name, cont);
if (cont.isContinue())
cont.appendRemainingComponent(""); // add nns back
else {
cont.setContinueNNS(target, name, this);
}
} catch (NamingException e) {
e.appendRemainingComponent(""); // add nns back
throw e;
}
}
/**
* This function is used when implementing a naming system that
* supports junctions. For example, when the a_list_nns(newobj)
* method is invoked, that means the caller is attempting to list the
* the nns context of of this context. For a context that supports
* junctions, it by default does not have any nns. Consequently,
* a NameNotFoundException is thrown.
*/
protected void a_processJunction_nns(Continuation cont) throws NamingException {
// Construct a new Reference that contains this context.
RefAddr addr = new RefAddr("nns") {
public Object getContent() {
return AtomicContext.this;
}
private static final long serialVersionUID = 3449785852664978312L;
};
Reference ref = new Reference("java.lang.Object", addr);
// Set continuation leave it to PartialCompositeContext.getPCContext()
// to throw the exception.
// Do not use setContinueNNS() because we've are
// setting relativeResolvedName to "/".
cont.setContinue(ref, _NNS_NAME, this);
}
/* *********** core resolution routines ******************* */
/** Resolve to context named by 'name'.
* Returns true if at named context (i.e. 'name' is empty name).
* Returns false otherwise, and sets Continuation on parts of 'name'
* not yet resolved.
*/
protected boolean resolve_to_context(Name name, Continuation cont)
throws NamingException {
String target = name.toString();
StringHeadTail ht = c_parseComponent(target, cont);
String tail = ht.getTail();
String head = ht.getHead();
if (debug > 0)
System.out.println("RESOLVE TO CONTEXT(" + target + ") = {" +
head + ", " + tail + "}");
if (head == null) {
// something is wrong; no name at all
InvalidNameException e = new InvalidNameException();
throw cont.fillInException(e);
}
if (!isEmpty(head)) {
// if there is head is a non-empty name
// this means more resolution to be done
try {
Object headCtx = a_lookup(head, cont);
// System.out.println("answer " + headCtx);
if (headCtx != null)
cont.setContinue(headCtx, head, this, (tail == null ? "" : tail));
else if (cont.isContinue())
cont.appendRemainingComponent(tail);
} catch (NamingException e) {
e.appendRemainingComponent(tail);
throw e;
}
} else {
cont.setSuccess(); // clear
return true;
}
return false;
}
/**
* Resolves to penultimate context named by 'name'.
* Returns true if penultimate context has been reached (i.e. name
* only has one atomic component left).
* Returns false otherwise, and sets Continuation to parts of name
* not yet resolved.
*/
protected boolean resolve_to_penultimate_context(Name name, Continuation cont)
throws NamingException {
String target = name.toString();
if (debug > 0)
System.out.println("RESOLVE TO PENULTIMATE" + target);
StringHeadTail ht = c_parseComponent(target, cont);
String tail = ht.getTail();
String head = ht.getHead();
if (head == null) {
// something is wrong; no name at all
InvalidNameException e = new InvalidNameException();
throw cont.fillInException(e);
}
if (!isEmpty(tail)) {
// more components; hence not at penultimate context yet
try {
Object headCtx = a_lookup(head, cont);
if (headCtx != null)
cont.setContinue(headCtx, head, this, tail);
else if (cont.isContinue())
cont.appendRemainingComponent(tail);
} catch (NamingException e) {
e.appendRemainingComponent(tail);
throw e;
}
} else {
// already at penultimate context
cont.setSuccess(); // clear
return true;
}
return false;
}
/**
* This function is similar to resolve_to_penultimate_context()
* except it should only be called by the nns() functions.
* This function fixes any exception or continuations so that
* it will have the proper nns name.
*/
protected boolean resolve_to_penultimate_context_nns(Name name,
Continuation cont)
throws NamingException {
try {
if (debug > 0)
System.out.println("RESOLVE TO PENULTIMATE NNS" + name.toString());
boolean answer = resolve_to_penultimate_context(name, cont);
// resolve_to_penultimate_context() only calls a_lookup().
// Any continuation it sets is lacking the nns, so
// we need to add it back
if (cont.isContinue())
cont.appendRemainingComponent("");
return answer;
} catch (NamingException e) {
// resolve_to_penultimate_context() only calls a_lookup().
// Any exceptions it throws is lacking the nns, so
// we need to add it back.
e.appendRemainingComponent("");
throw e;
}
}
/**
* Resolves to nns associated with 'name' and set Continuation
* to the result.
*/
protected void resolve_to_nns_and_continue(Name name, Continuation cont)
throws NamingException {
if (debug > 0)
System.out.println("RESOLVE TO NNS AND CONTINUE" + name.toString());
if (resolve_to_penultimate_context_nns(name, cont)) {
Object nns = a_lookup_nns(name.toString(), cont);
if (nns != null)
cont.setContinue(nns, name, this);
}
}
}

View File

@@ -0,0 +1,393 @@
/*
* 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.toolkit.ctx;
import javax.naming.*;
import javax.naming.directory.*;
/**
* Direct subclasses of AtomicDirContext must provide implementations for
* the abstract a_ DirContext methods, and override the a_ Context methods
* (which are no longer abstract because they have been overriden by
* PartialCompositeDirContext with dummy implementations).
*
* If the subclass implements the notion of implicit nns,
* it must override the a_*_nns DirContext and Context methods as well.
*
* @author Rosanna Lee
*
*/
public abstract class AtomicDirContext extends ComponentDirContext {
protected AtomicDirContext() {
_contextType = _ATOMIC;
}
// ------ Abstract methods whose implementations come from subclass
protected abstract Attributes a_getAttributes(String name, String[] attrIds,
Continuation cont)
throws NamingException;
protected abstract void a_modifyAttributes(String name, int mod_op,
Attributes attrs,
Continuation cont)
throws NamingException;
protected abstract void a_modifyAttributes(String name,
ModificationItem[] mods,
Continuation cont)
throws NamingException;
protected abstract void a_bind(String name, Object obj,
Attributes attrs,
Continuation cont)
throws NamingException;
protected abstract void a_rebind(String name, Object obj,
Attributes attrs,
Continuation cont)
throws NamingException;
protected abstract DirContext a_createSubcontext(String name,
Attributes attrs,
Continuation cont)
throws NamingException;
protected abstract NamingEnumeration<SearchResult> a_search(
Attributes matchingAttributes,
String[] attributesToReturn,
Continuation cont)
throws NamingException;
protected abstract NamingEnumeration<SearchResult> a_search(
String name,
String filterExpr,
Object[] filterArgs,
SearchControls cons,
Continuation cont)
throws NamingException;
protected abstract NamingEnumeration<SearchResult> a_search(
String name,
String filter,
SearchControls cons,
Continuation cont)
throws NamingException;
protected abstract DirContext a_getSchema(Continuation cont)
throws NamingException;
protected abstract DirContext a_getSchemaClassDefinition(Continuation cont)
throws NamingException;
// ------ Methods that need to be overridden by subclass
// default implementations of a_*_nns methods
// The following methods are called when the DirContext methods
// are invoked with a name that has a trailing slash.
// For naming systems that support implicit nns,
// the trailing slash signifies the implicit nns.
// For such naming systems, override these a_*_nns methods.
//
// For naming systems that support junctions (explicit nns),
// the trailing slash is meaningless because a junction does not
// have an implicit nns. The default implementation here
// throws a NameNotFoundException for such names.
// If a context wants to accept a trailing slash as having
// the same meaning as the same name without a trailing slash,
// then it should override these a_*_nns methods.
protected Attributes a_getAttributes_nns(String name,
String[] attrIds,
Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
return null;
}
protected void a_modifyAttributes_nns(String name, int mod_op,
Attributes attrs,
Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
}
protected void a_modifyAttributes_nns(String name,
ModificationItem[] mods,
Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
}
protected void a_bind_nns(String name, Object obj,
Attributes attrs,
Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
}
protected void a_rebind_nns(String name, Object obj,
Attributes attrs,
Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
}
protected DirContext a_createSubcontext_nns(String name,
Attributes attrs,
Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
return null;
}
protected NamingEnumeration<SearchResult> a_search_nns(
Attributes matchingAttributes,
String[] attributesToReturn,
Continuation cont)
throws NamingException {
a_processJunction_nns(cont);
return null;
}
protected NamingEnumeration<SearchResult> a_search_nns(String name,
String filterExpr,
Object[] filterArgs,
SearchControls cons,
Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
return null;
}
protected NamingEnumeration<SearchResult> a_search_nns(String name,
String filter,
SearchControls cons,
Continuation cont)
throws NamingException {
a_processJunction_nns(name, cont);
return null;
}
protected DirContext a_getSchema_nns(Continuation cont) throws NamingException {
a_processJunction_nns(cont);
return null;
}
protected DirContext a_getSchemaDefinition_nns(Continuation cont)
throws NamingException {
a_processJunction_nns(cont);
return null;
}
// ------- implementations of c_ DirContext methods using corresponding
// ------- a_ and a_*_nns methods
protected Attributes c_getAttributes(Name name, String[] attrIds,
Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context(name, cont))
return a_getAttributes(name.toString(), attrIds, cont);
return null;
}
protected void c_modifyAttributes(Name name, int mod_op,
Attributes attrs, Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context(name, cont))
a_modifyAttributes(name.toString(), mod_op, attrs, cont);
}
protected void c_modifyAttributes(Name name, ModificationItem[] mods,
Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context(name, cont))
a_modifyAttributes(name.toString(), mods, cont);
}
protected void c_bind(Name name, Object obj,
Attributes attrs, Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context(name, cont))
a_bind(name.toString(), obj, attrs, cont);
}
protected void c_rebind(Name name, Object obj,
Attributes attrs, Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context(name, cont))
a_rebind(name.toString(), obj, attrs, cont);
}
protected DirContext c_createSubcontext(Name name,
Attributes attrs,
Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context(name, cont))
return a_createSubcontext(name.toString(),
attrs, cont);
return null;
}
protected NamingEnumeration<SearchResult> c_search(Name name,
Attributes matchingAttributes,
String[] attributesToReturn,
Continuation cont)
throws NamingException {
if (resolve_to_context(name, cont))
return a_search(matchingAttributes, attributesToReturn, cont);
return null;
}
protected NamingEnumeration<SearchResult> c_search(Name name,
String filter,
SearchControls cons,
Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context(name, cont))
return a_search(name.toString(), filter, cons, cont);
return null;
}
protected NamingEnumeration<SearchResult> c_search(Name name,
String filterExpr,
Object[] filterArgs,
SearchControls cons,
Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context(name, cont))
return a_search(name.toString(), filterExpr, filterArgs, cons, cont);
return null;
}
protected DirContext c_getSchema(Name name, Continuation cont)
throws NamingException {
if (resolve_to_context(name, cont))
return a_getSchema(cont);
return null;
}
protected DirContext c_getSchemaClassDefinition(Name name, Continuation cont)
throws NamingException {
if (resolve_to_context(name, cont))
return a_getSchemaClassDefinition(cont);
return null;
}
/* equivalent to methods in DirContext interface for nns */
protected Attributes c_getAttributes_nns(Name name, String[] attrIds,
Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context_nns(name, cont))
return a_getAttributes_nns(name.toString(), attrIds, cont);
return null;
}
protected void c_modifyAttributes_nns(Name name, int mod_op,
Attributes attrs, Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context_nns(name, cont))
a_modifyAttributes_nns(name.toString(), mod_op, attrs, cont);
}
protected void c_modifyAttributes_nns(Name name, ModificationItem[] mods,
Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context_nns(name, cont))
a_modifyAttributes_nns(name.toString(), mods, cont);
}
protected void c_bind_nns(Name name, Object obj,
Attributes attrs, Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context_nns(name, cont))
a_bind_nns(name.toString(), obj, attrs, cont);
}
protected void c_rebind_nns(Name name, Object obj,
Attributes attrs, Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context_nns(name, cont))
a_rebind_nns(name.toString(), obj, attrs, cont);
}
protected DirContext c_createSubcontext_nns(Name name,
Attributes attrs,
Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context_nns(name, cont))
return a_createSubcontext_nns(name.toString(), attrs, cont);
return null;
}
protected NamingEnumeration<SearchResult> c_search_nns(
Name name,
Attributes matchingAttributes,
String[] attributesToReturn,
Continuation cont)
throws NamingException {
resolve_to_nns_and_continue(name, cont);
return null;
}
protected NamingEnumeration<SearchResult> c_search_nns(Name name,
String filter,
SearchControls cons,
Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context_nns(name, cont))
return a_search_nns(name.toString(), filter, cons, cont);
return null;
}
protected NamingEnumeration<SearchResult> c_search_nns(Name name,
String filterExpr,
Object[] filterArgs,
SearchControls cons,
Continuation cont)
throws NamingException {
if (resolve_to_penultimate_context_nns(name, cont))
return a_search_nns(name.toString(), filterExpr, filterArgs,
cons, cont);
return null;
}
protected DirContext c_getSchema_nns(Name name, Continuation cont)
throws NamingException {
resolve_to_nns_and_continue(name, cont);
return null;
}
protected DirContext c_getSchemaClassDefinition_nns(Name name, Continuation cont)
throws NamingException {
resolve_to_nns_and_continue(name, cont);
return null;
}
}

View File

@@ -0,0 +1,805 @@
/*
* 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.toolkit.ctx;
import javax.naming.*;
import javax.naming.spi.ResolveResult;
/**
* Provides implementation of p_* operations using
* c_* operations provided by subclasses.
*
* Clients: deal only with names for its own naming service. Must
* provide implementations for c_* methods, and for p_parseComponent()
* and the c_*_nns methods if the defaults are not appropriate.
*
* @author Rosanna Lee
* @author Scott Seligman
*/
public abstract class ComponentContext extends PartialCompositeContext {
private static int debug = 0;
protected ComponentContext() {
_contextType = _COMPONENT;
}
// ------ Abstract methods whose implementation are provided by subclass
/* Equivalent methods in Context interface */
protected abstract Object c_lookup(Name name, Continuation cont)
throws NamingException;
protected abstract Object c_lookupLink(Name name, Continuation cont)
throws NamingException;
protected abstract NamingEnumeration<NameClassPair> c_list(Name name,
Continuation cont) throws NamingException;
protected abstract NamingEnumeration<Binding> c_listBindings(Name name,
Continuation cont) throws NamingException;
protected abstract void c_bind(Name name, Object obj, Continuation cont)
throws NamingException;
protected abstract void c_rebind(Name name, Object obj, Continuation cont)
throws NamingException;
protected abstract void c_unbind(Name name, Continuation cont)
throws NamingException;
protected abstract void c_destroySubcontext(Name name, Continuation cont)
throws NamingException;
protected abstract Context c_createSubcontext(Name name,
Continuation cont) throws NamingException;
protected abstract void c_rename(Name oldname, Name newname,
Continuation cont) throws NamingException;
protected abstract NameParser c_getNameParser(Name name, Continuation cont)
throws NamingException;
// ------ Methods that may need to be overridden by subclass
/* Parsing method */
/**
* Determines which of the first components of 'name' belong
* to this naming system.
* If no components belong to this naming system, return
* the empty name (new CompositeName()) as the head,
* and the entire name as the tail.
*
* The default implementation supports strong separation.
* If the name is empty or if the first component is empty,
* head is the empty name and tail is the entire name.
* (This means that this context does not have any name to work with).
* Otherwise, it returns the first component as head, and the rest of
* the components as tail.
*
* Subclass should override this method according its own policies.
*
* For example, a weakly separated system with dynamic boundary
* determination would simply return as head 'name'.
* A weakly separated with static boundary
* determination would select the components in the front of 'name'
* that conform to some syntax rules. (e.g. in X.500 syntax, perhaps
* select front components that have a equal sign).
* If none conforms, return an empty name.
*/
protected HeadTail p_parseComponent(Name name, Continuation cont)
throws NamingException {
int separator;
// if no name to parse, or if we're already at boundary
if (name.isEmpty() || name.get(0).equals("")) {
separator = 0;
} else {
separator = 1;
}
Name head, tail;
if (name instanceof CompositeName) {
head = name.getPrefix(separator);
tail = name.getSuffix(separator);
} else {
// treat like compound name
head = new CompositeName().add(name.toString());
tail = null;
}
if (debug > 2) {
System.err.println("ORIG: " + name);
System.err.println("PREFIX: " + name);
System.err.println("SUFFIX: " + null);
}
return new HeadTail(head, tail);
}
/* Resolution method for supporting federation */
/**
* Resolves the nns for 'name' when the named context is acting
* as an intermediate context.
*
* For a system that supports only junctions, this would be
* equilvalent to
* c_lookup(name, cont);
* because for junctions, an intermediate slash simply signifies
* a syntactic separator.
*
* For a system that supports only implicit nns, this would be
* equivalent to
* c_lookup_nns(name, cont);
* because for implicit nns, a slash always signifies the implicit nns,
* regardless of whether it is intermediate or trailing.
*
* By default this method supports junctions, and also allows for an
* implicit nns to be dynamically determined through the use of the
* "nns" reference (see c_processJunction_nns()).
* Contexts that implement implicit nns directly should provide an
* appropriate override.
*
* A junction, by definition, is a binding of a name in one
* namespace to an object in another. The default implementation
* of this method detects the crossover into another namespace
* using the following heuristic: there is a junction when "name"
* resolves to a context that is not an instance of
* this.getClass(). Contexts supporting junctions for which this
* heuristic is inappropriate should override this method.
*/
protected Object c_resolveIntermediate_nns(Name name, Continuation cont)
throws NamingException {
try {
final Object obj = c_lookup(name, cont);
// Do not append "" to Continuation 'cont' even if set
// because the intention is to ignore the nns
if (obj != null && getClass().isInstance(obj)) {
// If "obj" is in the same type as this object, it must
// not be a junction. Continue the lookup with "/".
cont.setContinueNNS(obj, name, this);
return null;
} else if (obj != null && !(obj instanceof Context)) {
// obj is not even a context, so try to find its nns
// dynamically by constructing a Reference containing obj.
RefAddr addr = new RefAddr("nns") {
public Object getContent() {
return obj;
}
private static final long serialVersionUID =
-8831204798861786362L;
};
Reference ref = new Reference("java.lang.Object", addr);
// Resolved name has trailing slash to indicate nns
CompositeName resName = (CompositeName)name.clone();
resName.add(""); // add trailing slash
// Set continuation leave it to
// PartialCompositeContext.getPCContext() to throw CPE.
// Do not use setContinueNNS() because we've already
// consumed "/" (i.e., moved it to resName).
cont.setContinue(ref, resName, this);
return null;
} else {
// Consume "/" and continue
return obj;
}
} catch (NamingException e) {
e.appendRemainingComponent(""); // add nns back
throw e;
}
}
/* Equivalent of Context Methods for supporting nns */
// The following methods are called when the Context methods
// are invoked with a name that has a trailing slash.
// For naming systems that support implicit nns,
// the trailing slash signifies the implicit nns.
// For such naming systems, override these c_*_nns methods.
//
// For naming systems that do not support implicit nns, the
// default implementations here throw an exception. See
// c_processJunction_nns() for details.
protected Object c_lookup_nns(Name name, Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
return null;
}
protected Object c_lookupLink_nns(Name name, Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
return null;
}
protected NamingEnumeration<NameClassPair> c_list_nns(Name name,
Continuation cont) throws NamingException {
c_processJunction_nns(name, cont);
return null;
}
protected NamingEnumeration<Binding> c_listBindings_nns(Name name,
Continuation cont) throws NamingException {
c_processJunction_nns(name, cont);
return null;
}
protected void c_bind_nns(Name name, Object obj, Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
}
protected void c_rebind_nns(Name name, Object obj, Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
}
protected void c_unbind_nns(Name name, Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
}
protected Context c_createSubcontext_nns(Name name,
Continuation cont) throws NamingException {
c_processJunction_nns(name, cont);
return null;
}
protected void c_destroySubcontext_nns(Name name, Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
}
protected void c_rename_nns(Name oldname, Name newname, Continuation cont)
throws NamingException {
c_processJunction_nns(oldname, cont);
}
protected NameParser c_getNameParser_nns(Name name, Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
return null;
}
// ------ internal method used by ComponentContext
/**
* Locates the nns using the default policy. This policy fully
* handles junctions, but otherwise throws an exception when an
* attempt is made to resolve an implicit nns.
*
* The default policy is as follows: If there is a junction in
* the namespace, then resolve to the junction and continue the
* operation there (thus deferring to that context to find its own
* nns). Otherwise, resolve as far as possible and then throw
* CannotProceedException with the resolved object being a reference:
* the address type is "nns", and the address contents is this
* context.
*
* For example, when c_bind_nns(name, obj, ...) is invoked, the
* caller is attempting to bind the object "obj" to the nns of
* "name". If "name" is a junction, it names an object in another
* naming system that (presumably) has an nns. c_bind_nns() will
* first resolve "name" to a context and then attempt to continue
* the bind operation there, (thus binding to the nns of the
* context named by "name"). If "name" is empty then throw an
* exception, since this context does not by default support an
* implicit nns.
*
* To implement a context that does support an implicit nns, it is
* necessary to override this default policy. This is done by
* overriding the c_*_nns() methods (which each call this method
* by default).
*/
protected void c_processJunction_nns(Name name, Continuation cont)
throws NamingException
{
if (name.isEmpty()) {
// Construct a new Reference that contains this context.
RefAddr addr = new RefAddr("nns") {
public Object getContent() {
return ComponentContext.this;
}
private static final long serialVersionUID =
-1389472957988053402L;
};
Reference ref = new Reference("java.lang.Object", addr);
// Set continuation leave it to PartialCompositeContext.getPCContext()
// to throw the exception.
// Do not use setContinueNNS() because we've are
// setting relativeResolvedName to "/".
cont.setContinue(ref, _NNS_NAME, this);
return;
}
try {
// lookup name to continue operation in nns
Object target = c_lookup(name, cont);
if (cont.isContinue())
cont.appendRemainingComponent("");
else {
cont.setContinueNNS(target, name, this);
}
} catch (NamingException e) {
e.appendRemainingComponent(""); // add nns back
throw e;
}
}
protected static final byte USE_CONTINUATION = 1;
protected static final byte TERMINAL_COMPONENT = 2;
protected static final byte TERMINAL_NNS_COMPONENT = 3;
/**
* Determine whether 'name' is a terminal component in
* this naming system.
* If so, return status indicating so, so that caller
* can perform context operation on this name.
*
* If not, then the first component(s) of 'name' names
* an intermediate context. In that case, resolve these components
* and set Continuation to be the object named.
*
* see test cases at bottom of file.
*/
protected HeadTail p_resolveIntermediate(Name name, Continuation cont)
throws NamingException {
int ret = USE_CONTINUATION;
cont.setSuccess(); // initialize
HeadTail p = p_parseComponent(name, cont);
Name tail = p.getTail();
Name head = p.getHead();
if (tail == null || tail.isEmpty()) {
//System.out.println("terminal : " + head);
ret = TERMINAL_COMPONENT;
} else if (!tail.get(0).equals("")) {
// tail does not begin with "/"
/*
if (head.isEmpty()) {
// Context could not find name that it can use
// illegal syntax error or name not found
//System.out.println("nnf exception : " + head);
NamingException e = new NameNotFoundException();
cont.setError(this, name);
throw cont.fillInException(e);
} else {
*/
// head is being used as intermediate context,
// resolve head and set Continuation with tail
try {
Object obj = c_resolveIntermediate_nns(head, cont);
//System.out.println("resInter : " + head + "=" + obj);
if (obj != null)
cont.setContinue(obj, head, this, tail);
else if (cont.isContinue()) {
checkAndAdjustRemainingName(cont.getRemainingName());
cont.appendRemainingName(tail);
}
} catch (NamingException e) {
checkAndAdjustRemainingName(e.getRemainingName());
e.appendRemainingName(tail);
throw e;
}
/*
}
*/
} else {
// tail begins with "/"
if (tail.size() == 1) {
ret = TERMINAL_NNS_COMPONENT;
//System.out.println("terminal_nns : " + head);
} else if (head.isEmpty() || isAllEmpty(tail)) {
// resolve nns of head and continue with tail.getSuffix(1)
Name newTail = tail.getSuffix(1);
try {
Object obj = c_lookup_nns(head, cont);
//System.out.println("lookup_nns : " + head + "=" + obj);
if (obj != null)
cont.setContinue(obj, head, this, newTail);
else if (cont.isContinue()) {
cont.appendRemainingName(newTail);
// Name rname = cont.getRemainingName();
//System.out.println("cont.rname" + rname);
}
} catch (NamingException e) {
e.appendRemainingName(newTail);
throw e;
}
} else {
// head is being used as intermediate context
// resolve and set continuation to tail
try {
Object obj = c_resolveIntermediate_nns(head, cont);
//System.out.println("resInter2 : " + head + "=" + obj);
if (obj != null)
cont.setContinue(obj, head, this, tail);
else if (cont.isContinue()) {
checkAndAdjustRemainingName(cont.getRemainingName());
cont.appendRemainingName(tail);
}
} catch (NamingException e) {
checkAndAdjustRemainingName(e.getRemainingName());
e.appendRemainingName(tail);
throw e;
}
}
}
p.setStatus(ret);
return p;
}
// When c_resolveIntermediate_nns() or c_lookup_nns() sets up
// its continuation, to indicate "nns", it appends an empty
// component to the remaining name (e.g. "eng/"). If last
// component of remaining name is empty; delete empty component
// before appending tail so that composition of the names work
// correctly. For example, when merging "eng/" and "c.b.a", we want
// the result to be "eng/c.b.a" because the trailing slash in eng
// is extraneous. When merging "" and "c.b.a", we want the result
// to be "/c.b.a" and so must keep the trailing slash (empty name).
void checkAndAdjustRemainingName(Name rname) throws InvalidNameException {
int count;
if (rname != null && (count=rname.size()) > 1 &&
rname.get(count-1).equals("")) {
rname.remove(count-1);
}
}
// Returns true if n contains only empty components
protected boolean isAllEmpty(Name n) {
int count = n.size();
for (int i =0; i < count; i++ ) {
if (!n.get(i).equals("")) {
return false;
}
}
return true;
}
// ------ implementations of p_ Resolver and Context methods using
// ------ corresponding c_ and c_*_nns methods
/* implementation for Resolver method */
protected ResolveResult p_resolveToClass(Name name,
Class<?> contextType,
Continuation cont)
throws NamingException {
if (contextType.isInstance(this)) {
cont.setSuccess();
return (new ResolveResult(this, name));
}
ResolveResult ret = null;
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
Object obj = p_lookup(name, cont);
if (!cont.isContinue() && contextType.isInstance(obj)) {
ret = new ResolveResult(obj, _EMPTY_NAME);
}
break;
case TERMINAL_COMPONENT:
cont.setSuccess(); // no contextType found; return null
break;
default:
/* USE_CONTINUATION */
/* pcont already set or exception thrown */
break;
}
return ret;
}
/* implementations of p_ Context methods */
protected Object p_lookup(Name name, Continuation cont) throws NamingException {
Object ret = null;
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
ret = c_lookup_nns(res.getHead(), cont);
if (ret instanceof LinkRef) {
cont.setContinue(ret, res.getHead(), this);
ret = null;
}
break;
case TERMINAL_COMPONENT:
ret = c_lookup(res.getHead(), cont);
if (ret instanceof LinkRef) {
cont.setContinue(ret, res.getHead(), this);
ret = null;
}
break;
default:
/* USE_CONTINUATION */
/* pcont already set or exception thrown */
break;
}
return ret;
}
protected NamingEnumeration<NameClassPair> p_list(Name name, Continuation cont)
throws NamingException {
NamingEnumeration<NameClassPair> ret = null;
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
if (debug > 0)
System.out.println("c_list_nns(" + res.getHead() + ")");
ret = c_list_nns(res.getHead(), cont);
break;
case TERMINAL_COMPONENT:
if (debug > 0)
System.out.println("c_list(" + res.getHead() + ")");
ret = c_list(res.getHead(), cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
return ret;
}
protected NamingEnumeration<Binding> p_listBindings(Name name, Continuation cont) throws
NamingException {
NamingEnumeration<Binding> ret = null;
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
ret = c_listBindings_nns(res.getHead(), cont);
break;
case TERMINAL_COMPONENT:
ret = c_listBindings(res.getHead(), cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
return ret;
}
protected void p_bind(Name name, Object obj, Continuation cont) throws
NamingException {
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
c_bind_nns(res.getHead(), obj, cont);
break;
case TERMINAL_COMPONENT:
c_bind(res.getHead(), obj, cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
}
protected void p_rebind(Name name, Object obj, Continuation cont) throws
NamingException {
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
c_rebind_nns(res.getHead(), obj, cont);
break;
case TERMINAL_COMPONENT:
c_rebind(res.getHead(), obj, cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
}
protected void p_unbind(Name name, Continuation cont) throws
NamingException {
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
c_unbind_nns(res.getHead(), cont);
break;
case TERMINAL_COMPONENT:
c_unbind(res.getHead(), cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
}
protected void p_destroySubcontext(Name name, Continuation cont) throws
NamingException {
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
c_destroySubcontext_nns(res.getHead(), cont);
break;
case TERMINAL_COMPONENT:
c_destroySubcontext(res.getHead(), cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
}
protected Context p_createSubcontext(Name name, Continuation cont) throws
NamingException {
Context ret = null;
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
ret = c_createSubcontext_nns(res.getHead(), cont);
break;
case TERMINAL_COMPONENT:
ret = c_createSubcontext(res.getHead(), cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
return ret;
}
protected void p_rename(Name oldName, Name newName, Continuation cont) throws
NamingException {
HeadTail res = p_resolveIntermediate(oldName, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
c_rename_nns(res.getHead(), newName, cont);
break;
case TERMINAL_COMPONENT:
c_rename(res.getHead(), newName, cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
}
protected NameParser p_getNameParser(Name name, Continuation cont) throws
NamingException {
NameParser ret = null;
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
ret = c_getNameParser_nns(res.getHead(), cont);
break;
case TERMINAL_COMPONENT:
ret = c_getNameParser(res.getHead(), cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
return ret;
}
protected Object p_lookupLink(Name name, Continuation cont)
throws NamingException {
Object ret = null;
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
ret = c_lookupLink_nns(res.getHead(), cont);
break;
case TERMINAL_COMPONENT:
ret = c_lookupLink(res.getHead(), cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
return ret;
}
}
/*
* How p_resolveIntermediate() should behave for various test cases
a.b/x {a.b, x}
c_resolveIntermediate_nns(a.b)
continue(x)
{x,}
terminal(x)
a.b/ {a.b, ""}
terminal_nns(a.b);
a.b//
{a.b, ("", "")}
c_lookup_nns(a.b)
continue({""})
{,""}
terminal_nns({})
/x {{}, {"", x}}
c_lookup_nns({})
continue(x)
{x,}
terminal(x)
//y {{}, {"", "", y}}
c_lookup_nns({})
continue({"", y})
{{}, {"", y}}
c_lookup_nns({})
continue(y)
{y,}
terminal(y)
a.b//y {a.b, {"", y}}
c_resolveIntermediate_nns(a.b)
continue({"", y})
{{}, {"",y}}
c_lookup_nns({});
continue(y)
{y,}
terminal(y);
*
*/

View File

@@ -0,0 +1,470 @@
/*
* 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.toolkit.ctx;
import javax.naming.*;
import javax.naming.directory.*;
/* Direct subclasses of ComponentDirContext must provide implementations for
* the abstract c_ DirContext methods, and override the c_ Context methods
* (which are no longer abstract because they have been overriden by
* AtomicContext, the direct superclass of PartialDSCompositeContext).
*
* If the subclass is supports implicit nns, it must override all the
* c_*_nns methods corresponding to those in DirContext and Context.
* See ComponentContext for details.
*
* @author Rosanna Lee
*/
public abstract class ComponentDirContext extends PartialCompositeDirContext {
protected ComponentDirContext () {
_contextType = _COMPONENT;
}
// ------ Abstract methods whose implementations are provided by subclass
/* Equivalent to methods in DirContext */
protected abstract Attributes c_getAttributes(Name name,
String[] attrIds,
Continuation cont)
throws NamingException;
protected abstract void c_modifyAttributes(Name name, int mod_op,
Attributes attrs,
Continuation cont)
throws NamingException;
protected abstract void c_modifyAttributes(Name name,
ModificationItem[] mods,
Continuation cont)
throws NamingException;
protected abstract void c_bind(Name name, Object obj,
Attributes attrs,
Continuation cont)
throws NamingException;
protected abstract void c_rebind(Name name, Object obj,
Attributes attrs,
Continuation cont)
throws NamingException;
protected abstract DirContext c_createSubcontext(Name name,
Attributes attrs,
Continuation cont)
throws NamingException;
protected abstract NamingEnumeration<SearchResult> c_search(
Name name,
Attributes matchingAttributes,
String[] attributesToReturn,
Continuation cont)
throws NamingException;
protected abstract NamingEnumeration<SearchResult> c_search(
Name name,
String filter,
SearchControls cons,
Continuation cont)
throws NamingException;
protected abstract NamingEnumeration<SearchResult> c_search(
Name name,
String filterExpr,
Object[] filterArgs,
SearchControls cons,
Continuation cont)
throws NamingException;
protected abstract DirContext c_getSchema(Name name, Continuation cont)
throws NamingException;
protected abstract DirContext c_getSchemaClassDefinition(Name name,
Continuation cont)
throws NamingException;
// ------- default implementations of c_*_nns methods from DirContext
// The following methods are called when the DirContext methods
// are invoked with a name that has a trailing slash.
// For naming systems that support implicit nns,
// the trailing slash signifies the implicit nns.
// For such naming systems, override these c_*_nns methods.
//
// For naming systems that support junctions (explicit nns),
// the trailing slash is meaningless because a junction does not
// have an implicit nns. The default implementation here
// throws a NameNotFoundException for such names.
// If a context wants to accept a trailing slash as having
// the same meaning as the same name without a trailing slash,
// then it should override these c_*_nns methods.
// See ComponentContext for details.
protected Attributes c_getAttributes_nns(Name name,
String[] attrIds,
Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
return null;
}
protected void c_modifyAttributes_nns(Name name,
int mod_op,
Attributes attrs,
Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
}
protected void c_modifyAttributes_nns(Name name,
ModificationItem[] mods,
Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
}
protected void c_bind_nns(Name name,
Object obj,
Attributes attrs,
Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
}
protected void c_rebind_nns(Name name,
Object obj,
Attributes attrs,
Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
}
protected DirContext c_createSubcontext_nns(Name name,
Attributes attrs,
Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
return null;
}
protected NamingEnumeration<SearchResult> c_search_nns(
Name name,
Attributes matchingAttributes,
String[] attributesToReturn,
Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
return null;
}
protected NamingEnumeration<SearchResult> c_search_nns(
Name name,
String filter,
SearchControls cons,
Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
return null;
}
protected NamingEnumeration<SearchResult> c_search_nns(
Name name,
String filterExpr,
Object[] filterArgs,
SearchControls cons,
Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
return null;
}
protected DirContext c_getSchema_nns(Name name, Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
return null;
}
protected DirContext c_getSchemaClassDefinition_nns(Name name, Continuation cont)
throws NamingException {
c_processJunction_nns(name, cont);
return null;
}
// ------- implementations of p_ DirContext methods using corresponding
// ------- DirContext c_ and c_*_nns methods
/* Implements for abstract methods declared in PartialCompositeDirContext */
protected Attributes p_getAttributes(Name name,
String[] attrIds,
Continuation cont)
throws NamingException {
HeadTail res = p_resolveIntermediate(name, cont);
Attributes answer = null;
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
answer = c_getAttributes_nns(res.getHead(), attrIds, cont);
break;
case TERMINAL_COMPONENT:
answer = c_getAttributes(res.getHead(), attrIds, cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
return answer;
}
protected void p_modifyAttributes(Name name, int mod_op,
Attributes attrs,
Continuation cont)
throws NamingException {
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
c_modifyAttributes_nns(res.getHead(), mod_op, attrs, cont);
break;
case TERMINAL_COMPONENT:
c_modifyAttributes(res.getHead(), mod_op, attrs, cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
}
protected void p_modifyAttributes(Name name,
ModificationItem[] mods,
Continuation cont)
throws NamingException {
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
c_modifyAttributes_nns(res.getHead(), mods, cont);
break;
case TERMINAL_COMPONENT:
c_modifyAttributes(res.getHead(), mods, cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
}
protected void p_bind(Name name,
Object obj,
Attributes attrs,
Continuation cont)
throws NamingException {
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
c_bind_nns(res.getHead(), obj, attrs, cont);
break;
case TERMINAL_COMPONENT:
c_bind(res.getHead(), obj, attrs, cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
}
protected void p_rebind(Name name, Object obj,
Attributes attrs, Continuation cont)
throws NamingException {
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
c_rebind_nns(res.getHead(), obj, attrs, cont);
break;
case TERMINAL_COMPONENT:
c_rebind(res.getHead(), obj, attrs, cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
}
protected DirContext p_createSubcontext(Name name,
Attributes attrs,
Continuation cont)
throws NamingException {
HeadTail res = p_resolveIntermediate(name, cont);
DirContext answer = null;
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
answer = c_createSubcontext_nns(res.getHead(), attrs, cont);
break;
case TERMINAL_COMPONENT:
answer = c_createSubcontext(res.getHead(), attrs, cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
return answer;
}
protected NamingEnumeration<SearchResult> p_search(
Name name,
Attributes matchingAttributes,
String[] attributesToReturn,
Continuation cont)
throws NamingException {
HeadTail res = p_resolveIntermediate(name, cont);
NamingEnumeration<SearchResult> answer = null;
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
answer = c_search_nns(res.getHead(), matchingAttributes,
attributesToReturn, cont);
break;
case TERMINAL_COMPONENT:
answer = c_search(res.getHead(), matchingAttributes,
attributesToReturn, cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
return answer;
}
protected NamingEnumeration<SearchResult> p_search(Name name,
String filter,
SearchControls cons,
Continuation cont)
throws NamingException {
HeadTail res = p_resolveIntermediate(name, cont);
NamingEnumeration<SearchResult> answer = null;
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
answer = c_search_nns(res.getHead(), filter, cons, cont);
break;
case TERMINAL_COMPONENT:
answer = c_search(res.getHead(), filter, cons, cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
return answer;
}
protected NamingEnumeration<SearchResult> p_search(Name name,
String filterExpr,
Object[] filterArgs,
SearchControls cons,
Continuation cont)
throws NamingException {
HeadTail res = p_resolveIntermediate(name, cont);
NamingEnumeration<SearchResult> answer = null;
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
answer = c_search_nns(res.getHead(),
filterExpr, filterArgs, cons, cont);
break;
case TERMINAL_COMPONENT:
answer = c_search(res.getHead(), filterExpr, filterArgs, cons, cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
return answer;
}
protected DirContext p_getSchema(Name name, Continuation cont)
throws NamingException {
DirContext answer = null;
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
answer = c_getSchema_nns(res.getHead(), cont);
break;
case TERMINAL_COMPONENT:
answer = c_getSchema(res.getHead(), cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
return answer;
}
protected DirContext p_getSchemaClassDefinition(Name name, Continuation cont)
throws NamingException {
DirContext answer = null;
HeadTail res = p_resolveIntermediate(name, cont);
switch (res.getStatus()) {
case TERMINAL_NNS_COMPONENT:
answer = c_getSchemaClassDefinition_nns(res.getHead(), cont);
break;
case TERMINAL_COMPONENT:
answer = c_getSchemaClassDefinition(res.getHead(), cont);
break;
default:
/* USE_CONTINUATION */
/* cont already set or exception thrown */
break;
}
return answer;
}
}

View File

@@ -0,0 +1,442 @@
/*
* Copyright (c) 1999, 2013, 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.ctx;
import javax.naming.*;
import javax.naming.spi.ResolveResult;
import java.util.Hashtable;
/**
* This class contains information required to continue
* the method (place where it left off, and remaining name to
* continue).
*
* @author Rosanna Lee
*/
public class Continuation extends ResolveResult {
/**
* The name that we started out with. It is initialized by the constructor
* and used to calculate to "resolved name" in NamingException in
* fillInException().
* %%% Note that this approach does not always do the calculation
* correctly with respect to absence or presence of the trailing slash
* for resolved name.
*/
protected Name starter;
/**
* Whether links were encountered.
*/
protected Object followingLink = null;
/**
* The environment used by the caller. Initialized by constructor and
* used when filling out a CannotProceedException.
*/
protected Hashtable<?,?> environment = null;
/**
* Indicates whether the Continuation instance indicates that the operation
* should be continued using the data in the Continuation.
* Typically, this is only false if an error has been encountered or if
* the operation has succeeded.
*/
protected boolean continuing = false;
/**
* The last resolved context. Used to set the "AltNameCtx" in a
* CannotProceedException.
*/
protected Context resolvedContext = null;
/**
* The resolved name relative to resolvedContext. Used to set the
* "AltName" in a CannotProceedException.
*/
protected Name relativeResolvedName = null;
/**
* Constructs a new instance of Continuation.
* Used as dummy for contexts that do not do federation (e.g. for schema ops)
*/
public Continuation() {
}
/**
* Constructs a new instance of Continuation.
* @param top The name of the object that is to be resolved/operated upon.
* This becomes the Continuation's 'starter' and is used to
* calculate the "resolved name" when filling in a NamingException.
* @param environment The environment used by the caller. It is used
* when setting the "environment" of a CannotProceedException.
*/
@SuppressWarnings("unchecked") // For Hashtable clone: environment.clone()
public Continuation(Name top, Hashtable<?,?> environment) {
super();
starter = top;
this.environment = (Hashtable<?,?>)
((environment == null) ? null : environment.clone());
}
/**
* Determines whether this Continuation contains data that should be
* used to continue the operation.
*
* @return true if operation should continue; false if operation has
* completed (successfully or unsuccessfully).
*/
public boolean isContinue() {
return continuing;
}
/**
* Sets this Continuation to indicate successful completion.
* Subsequent calls to isContinue() will return false.
* This method is different from the setError() methods only from
* the standpoint that this method does not set any of the other
* fields such as resolved object or resolved context. This is because
* this method is typically called when the context recognizes that
* the operation has successfully completed and that the continuation
* already contains the appropriately set fields.
* @see setError
* @see setErrorNNS
*/
public void setSuccess() {
continuing = false;
}
/**
* Fills in an exception's fields using data from this Continuation.
* The resolved name is set by subtracting remainingName from starter.
* %%% This might not not always produce the correct answer wrt trailing "/".
* If the exception is a CannotProceedException, its environment,
* altName, and altNameCtx fields are set using this continuation's
* environment, relativeResolvedName, and resolvedContext.
*
* @param e The non-null naming exception to fill.
* @return The non-null naming exception with its fields set using
* data from this Continuation.
*/
public NamingException fillInException(NamingException e) {
e.setRemainingName(remainingName);
e.setResolvedObj(resolvedObj);
if (starter == null || starter.isEmpty())
e.setResolvedName(null);
else if (remainingName == null)
e.setResolvedName(starter);
else
e.setResolvedName(
starter.getPrefix(starter.size() -
remainingName.size()));
if ((e instanceof CannotProceedException)) {
CannotProceedException cpe = (CannotProceedException)e;
Hashtable<?,?> env = (environment == null ?
new Hashtable<>(11) : (Hashtable<?,?>)environment.clone());
cpe.setEnvironment(env);
cpe.setAltNameCtx(resolvedContext);
cpe.setAltName(relativeResolvedName);
}
return e;
}
/**
* Sets this Continuation to indicated that an error has occurred,
* and that the remaining name is rename + "/".
*
* This method is typically called by _nns methods that have been
* given a name to process. It might process part of that name but
* encountered some error. Consequenetly, it would call setErrorNNS()
* with the remaining name. Since the _nns method was expected to
* operate upon the "nns" of the original name, the remaining name
* must include the "nns". That's why this method adds a trailing "/".
*<p>
* After this method is called, isContinuing() returns false.
*
* @param resObj The possibly null object that was resolved to.
* @param remain The non-null remaining name.
*/
public void setErrorNNS(Object resObj, Name remain) {
Name nm = (Name)(remain.clone());
try {
nm.add("");
} catch (InvalidNameException e) {
// ignore; can't happen for composite name
}
setErrorAux(resObj, nm);
}
/**
* Form that accepts a String name instead of a Name name.
* @param resObj The possibly null object that was resolved to.
* @param remain The possibly String remaining name.
*
* @see #setErrorNNS(java.lang.Object, javax.naming.Name)
*/
public void setErrorNNS(Object resObj, String remain) {
CompositeName rname = new CompositeName();
try {
if (remain != null && !remain.equals(""))
rname.add(remain);
rname.add("");
} catch (InvalidNameException e) {
// ignore, can't happen for composite name
}
setErrorAux(resObj, rname);
}
/**
* Sets this Continuation to indicated that an error has occurred
* and supply resolved information.
*
* This method is typically called by methods that have been
* given a name to process. It might process part of that name but
* encountered some error. Consequenetly, it would call setError()
* with the resolved object and the remaining name.
*<p>
* After this method is called, isContinuing() returns false.
*
* @param resObj The possibly null object that was resolved to.
* @param remain The possibly null remaining name.
*/
public void setError(Object resObj, Name remain) {
if (remain != null)
remainingName = (Name)(remain.clone());
else
remainingName = null;
setErrorAux(resObj, remainingName);
}
/**
* Form that accepts a String name instead of a Name name.
* @param resObj The possibly null object that was resolved to.
* @param remain The possibly String remaining name.
*
* @see #setError(java.lang.Object, javax.naming.Name)
*/
public void setError(Object resObj, String remain) {
CompositeName rname = new CompositeName();
if (remain != null && !remain.equals("")) {
try {
rname.add(remain);
} catch (InvalidNameException e) {
// ignore; can't happen for composite name
}
}
setErrorAux(resObj, rname);
}
private void setErrorAux(Object resObj, Name rname) {
remainingName = rname;
resolvedObj = resObj;
continuing = false;
}
private void setContinueAux(Object resObj,
Name relResName, Context currCtx, Name remain) {
if (resObj instanceof LinkRef) {
setContinueLink(resObj, relResName, currCtx, remain);
} else {
remainingName = remain;
resolvedObj = resObj;
relativeResolvedName = relResName;
resolvedContext = currCtx;
continuing = true;
}
}
/**
* Sets this Continuation with the supplied data, and set remaining name
* to be "/".
* This method is typically called by _nns methods that have been
* given a name to process. It might the name (without the nns) and
* continue process of the nns elsewhere.
* Consequently, it would call this form of the setContinueNNS().
* This method supplies "/" as the remaining name.
*<p>
* After this method is called, isContinuing() returns true.
*
* @param resObj The possibly null resolved object.
* @param relResName The non-null resolved name relative to currCtx.
* @param currCtx The non-null context from which relResName is to be resolved.
*/
public void setContinueNNS(Object resObj, Name relResName, Context currCtx) {
CompositeName rname = new CompositeName();
setContinue(resObj, relResName, currCtx, PartialCompositeContext._NNS_NAME);
}
/**
* Overloaded form that accesses String names.
*
* @param resObj The possibly null resolved object.
* @param relResName The non-null resolved name relative to currCtx.
* @param currCtx The non-null context from which relResName is to be resolved.
* @see #setContinueNNS(java.lang.Object, javax.naming.Name, javax.naming.Context)
*/
public void setContinueNNS(Object resObj, String relResName, Context currCtx) {
CompositeName relname = new CompositeName();
try {
relname.add(relResName);
} catch (NamingException e) {}
setContinue(resObj, relname, currCtx, PartialCompositeContext._NNS_NAME);
}
/**
* Sets this Continuation with the supplied data, and set remaining name
* to be the empty name.
* This method is typically called by list-style methods
* in which the target context implementing list() expects an
* empty name. For example when c_list() is given a non-empty name to
* process, it would resolve that name, and then call setContinue()
* with the resolved object so that the target context to be listed
* would be called with the empty name (i.e. list the target context itself).
*<p>
* After this method is called, isContinuing() returns true.
*
* @param resObj The possibly null resolved object.
* @param relResName The non-null resolved name relative to currCtx.
* @param currCtx The non-null context from which relResName is to be resolved.
*/
public void setContinue(Object obj, Name relResName, Context currCtx) {
setContinueAux(obj, relResName, currCtx,
(Name)PartialCompositeContext._EMPTY_NAME.clone());
}
/**
* Sets this Continuation with the supplied data.
* This method is typically called by a method that has been asked
* to operate on a name. The method resolves part of the name
* (relResName) to obj and sets the unprocessed part to rename.
* It calls setContinue() so that the operation can be continued
* using this data.
*<p>
* After this method is called, isContinuing() returns true.
*
* @param resObj The possibly null resolved object.
* @param relResName The non-null resolved name relative to currCtx.
* @param currCtx The non-null context from which relResName is to be resolved.
* @param remain The non-null remaining name.
*/
public void setContinue(Object obj, Name relResName, Context currCtx, Name remain) {
if (remain != null)
this.remainingName = (Name)(remain.clone());
else
this.remainingName = new CompositeName();
setContinueAux(obj, relResName, currCtx, remainingName);
}
/**
* String overload.
*
* @param resObj The possibly null resolved object.
* @param relResName The non-null resolved name relative to currCtx.
* @param currCtx The non-null context from which relResName is to be resolved.
* @param remain The non-null remaining name.
* @see #setContinue(java.lang.Object, java.lang.String, javax.naming.Context, java.lang.String)
*/
public void setContinue(Object obj, String relResName,
Context currCtx, String remain) {
CompositeName relname = new CompositeName();
if (!relResName.equals("")) {
try {
relname.add(relResName);
} catch (NamingException e){}
}
CompositeName rname = new CompositeName();
if (!remain.equals("")) {
try {
rname.add(remain);
} catch (NamingException e) {
}
}
setContinueAux(obj, relname, currCtx, rname);
}
/**
* %%% This method is kept only for backward compatibility. Delete when
* old implementations updated.
*
* Replaced by setContinue(obj, relResName, (Context)currCtx);
*
* @deprecated
*/
@Deprecated
public void setContinue(Object obj, Object currCtx) {
setContinue(obj, null, (Context)currCtx);
}
/**
* Sets this Continuation to process a linkRef.
* %%% Not working yet.
*/
private void setContinueLink(Object linkRef, Name relResName,
Context resolvedCtx, Name rname) {
this.followingLink = linkRef;
this.remainingName = rname;
this.resolvedObj = resolvedCtx;
this.relativeResolvedName = PartialCompositeContext._EMPTY_NAME;
this.resolvedContext = resolvedCtx;
this.continuing = true;
}
public String toString() {
if (remainingName != null)
return starter.toString() + "; remainingName: '" + remainingName + "'";
else
return starter.toString();
}
public String toString(boolean detail) {
if (!detail || this.resolvedObj == null)
return this.toString();
return this.toString() + "; resolvedObj: " + this.resolvedObj +
"; relativeResolvedName: " + relativeResolvedName +
"; resolvedContext: " + resolvedContext;
}
private static final long serialVersionUID = 8162530656132624308L;
}

View File

@@ -0,0 +1,65 @@
/*
* 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.toolkit.ctx;
import javax.naming.Name;
/**
* A class for returning the result of p_parseComponent();
*
* @author Rosanna Lee
*/
public class HeadTail {
private int status;
private Name head;
private Name tail;
public HeadTail(Name head, Name tail) {
this(head, tail, 0);
}
public HeadTail(Name head, Name tail, int status) {
this.status = status;
this.head = head;
this.tail = tail;
}
public void setStatus(int status) {
this.status = status;
}
public Name getHead() {
return this.head;
}
public Name getTail() {
return this.tail;
}
public int getStatus() {
return this.status;
}
}

View File

@@ -0,0 +1,523 @@
/*
* Copyright (c) 1999, 2013, 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.ctx;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.naming.*;
import javax.naming.spi.Resolver;
import javax.naming.spi.ResolveResult;
import javax.naming.spi.NamingManager;
/**
* PartialCompositeContext implements Context operations on
* composite names using implementations of the p_ interfaces
* defined by its subclasses.
*
* The main purpose provided by this class is that it deals with
* partial resolutions and continuations, so that callers of the
* Context operation don't have to.
*
* Types of clients that will be direct subclasses of
* PartialCompositeContext may be service providers that implement
* one of the JNDI protocols, but which do not deal with
* continuations. Usually, service providers will be using
* one of the subclasses of PartialCompositeContext.
*
* @author Rosanna Lee
*/
public abstract class PartialCompositeContext implements Context, Resolver {
protected static final int _PARTIAL = 1;
protected static final int _COMPONENT = 2;
protected static final int _ATOMIC = 3;
protected int _contextType = _PARTIAL;
static final CompositeName _EMPTY_NAME = new CompositeName();
static CompositeName _NNS_NAME;
static {
try {
_NNS_NAME = new CompositeName("/");
} catch (InvalidNameException e) {
// Should never happen
}
}
protected PartialCompositeContext() {
}
// ------ Abstract methods whose implementations come from subclasses
/* Equivalent to method in Resolver interface */
protected abstract ResolveResult p_resolveToClass(Name name,
Class<?> contextType, Continuation cont) throws NamingException;
/* Equivalent to methods in Context interface */
protected abstract Object p_lookup(Name name, Continuation cont)
throws NamingException;
protected abstract Object p_lookupLink(Name name, Continuation cont)
throws NamingException;
protected abstract NamingEnumeration<NameClassPair> p_list(Name name,
Continuation cont) throws NamingException;
protected abstract NamingEnumeration<Binding> p_listBindings(Name name,
Continuation cont) throws NamingException;
protected abstract void p_bind(Name name, Object obj, Continuation cont)
throws NamingException;
protected abstract void p_rebind(Name name, Object obj, Continuation cont)
throws NamingException;
protected abstract void p_unbind(Name name, Continuation cont)
throws NamingException;
protected abstract void p_destroySubcontext(Name name, Continuation cont)
throws NamingException;
protected abstract Context p_createSubcontext(Name name, Continuation cont)
throws NamingException;
protected abstract void p_rename(Name oldname, Name newname,
Continuation cont)
throws NamingException;
protected abstract NameParser p_getNameParser(Name name, Continuation cont)
throws NamingException;
// ------ should be overridden by subclass;
// ------ not abstract only for backward compatibility
/**
* A cheap way of getting the environment.
* Default implementation is NOT cheap because it simply calls
* getEnvironment(), which most implementations clone before returning.
* Subclass should ALWAYS override this with the cheapest possible way.
* The toolkit knows to clone when necessary.
* @return The possibly null environment of the context.
*/
protected Hashtable<?,?> p_getEnvironment() throws NamingException {
return getEnvironment();
}
// ------ implementations of methods in Resolver and Context
// ------ using corresponding p_ methods provided by subclass
/* implementations for method in Resolver interface using p_ method */
public ResolveResult resolveToClass(String name,
Class<? extends Context> contextType)
throws NamingException
{
return resolveToClass(new CompositeName(name), contextType);
}
public ResolveResult resolveToClass(Name name,
Class<? extends Context> contextType)
throws NamingException
{
PartialCompositeContext ctx = this;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
ResolveResult answer;
Name nm = name;
try {
answer = ctx.p_resolveToClass(nm, contextType, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCContext(cont);
answer = ctx.p_resolveToClass(nm, contextType, cont);
}
} catch (CannotProceedException e) {
Context cctx = NamingManager.getContinuationContext(e);
if (!(cctx instanceof Resolver)) {
throw e;
}
answer = ((Resolver)cctx).resolveToClass(e.getRemainingName(),
contextType);
}
return answer;
}
/* implementations for methods in Context interface using p_ methods */
public Object lookup(String name) throws NamingException {
return lookup(new CompositeName(name));
}
public Object lookup(Name name) throws NamingException {
PartialCompositeContext ctx = this;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
Object answer;
Name nm = name;
try {
answer = ctx.p_lookup(nm, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCContext(cont);
answer = ctx.p_lookup(nm, cont);
}
} catch (CannotProceedException e) {
Context cctx = NamingManager.getContinuationContext(e);
answer = cctx.lookup(e.getRemainingName());
}
return answer;
}
public void bind(String name, Object newObj) throws NamingException {
bind(new CompositeName(name), newObj);
}
public void bind(Name name, Object newObj) throws NamingException {
PartialCompositeContext ctx = this;
Name nm = name;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
try {
ctx.p_bind(nm, newObj, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCContext(cont);
ctx.p_bind(nm, newObj, cont);
}
} catch (CannotProceedException e) {
Context cctx = NamingManager.getContinuationContext(e);
cctx.bind(e.getRemainingName(), newObj);
}
}
public void rebind(String name, Object newObj) throws NamingException {
rebind(new CompositeName(name), newObj);
}
public void rebind(Name name, Object newObj) throws NamingException {
PartialCompositeContext ctx = this;
Name nm = name;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
try {
ctx.p_rebind(nm, newObj, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCContext(cont);
ctx.p_rebind(nm, newObj, cont);
}
} catch (CannotProceedException e) {
Context cctx = NamingManager.getContinuationContext(e);
cctx.rebind(e.getRemainingName(), newObj);
}
}
public void unbind(String name) throws NamingException {
unbind(new CompositeName(name));
}
public void unbind(Name name) throws NamingException {
PartialCompositeContext ctx = this;
Name nm = name;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
try {
ctx.p_unbind(nm, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCContext(cont);
ctx.p_unbind(nm, cont);
}
} catch (CannotProceedException e) {
Context cctx = NamingManager.getContinuationContext(e);
cctx.unbind(e.getRemainingName());
}
}
public void rename(String oldName, String newName) throws NamingException {
rename(new CompositeName(oldName), new CompositeName(newName));
}
public void rename(Name oldName, Name newName)
throws NamingException
{
PartialCompositeContext ctx = this;
Name nm = oldName;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(oldName, env);
try {
ctx.p_rename(nm, newName, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCContext(cont);
ctx.p_rename(nm, newName, cont);
}
} catch (CannotProceedException e) {
Context cctx = NamingManager.getContinuationContext(e);
if (e.getRemainingNewName() != null) {
// %%% e.getRemainingNewName() should never be null
newName = e.getRemainingNewName();
}
cctx.rename(e.getRemainingName(), newName);
}
}
public NamingEnumeration<NameClassPair> list(String name)
throws NamingException
{
return list(new CompositeName(name));
}
public NamingEnumeration<NameClassPair> list(Name name)
throws NamingException
{
PartialCompositeContext ctx = this;
Name nm = name;
NamingEnumeration<NameClassPair> answer;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
try {
answer = ctx.p_list(nm, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCContext(cont);
answer = ctx.p_list(nm, cont);
}
} catch (CannotProceedException e) {
Context cctx = NamingManager.getContinuationContext(e);
answer = cctx.list(e.getRemainingName());
}
return answer;
}
public NamingEnumeration<Binding> listBindings(String name)
throws NamingException
{
return listBindings(new CompositeName(name));
}
public NamingEnumeration<Binding> listBindings(Name name)
throws NamingException
{
PartialCompositeContext ctx = this;
Name nm = name;
NamingEnumeration<Binding> answer;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
try {
answer = ctx.p_listBindings(nm, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCContext(cont);
answer = ctx.p_listBindings(nm, cont);
}
} catch (CannotProceedException e) {
Context cctx = NamingManager.getContinuationContext(e);
answer = cctx.listBindings(e.getRemainingName());
}
return answer;
}
public void destroySubcontext(String name) throws NamingException {
destroySubcontext(new CompositeName(name));
}
public void destroySubcontext(Name name) throws NamingException {
PartialCompositeContext ctx = this;
Name nm = name;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
try {
ctx.p_destroySubcontext(nm, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCContext(cont);
ctx.p_destroySubcontext(nm, cont);
}
} catch (CannotProceedException e) {
Context cctx = NamingManager.getContinuationContext(e);
cctx.destroySubcontext(e.getRemainingName());
}
}
public Context createSubcontext(String name) throws NamingException {
return createSubcontext(new CompositeName(name));
}
public Context createSubcontext(Name name) throws NamingException {
PartialCompositeContext ctx = this;
Name nm = name;
Context answer;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
try {
answer = ctx.p_createSubcontext(nm, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCContext(cont);
answer = ctx.p_createSubcontext(nm, cont);
}
} catch (CannotProceedException e) {
Context cctx = NamingManager.getContinuationContext(e);
answer = cctx.createSubcontext(e.getRemainingName());
}
return answer;
}
public Object lookupLink(String name) throws NamingException {
return lookupLink(new CompositeName(name));
}
public Object lookupLink(Name name) throws NamingException {
PartialCompositeContext ctx = this;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
Object answer;
Name nm = name;
try {
answer = ctx.p_lookupLink(nm, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCContext(cont);
answer = ctx.p_lookupLink(nm, cont);
}
} catch (CannotProceedException e) {
Context cctx = NamingManager.getContinuationContext(e);
answer = cctx.lookupLink(e.getRemainingName());
}
return answer;
}
public NameParser getNameParser(String name) throws NamingException {
return getNameParser(new CompositeName(name));
}
public NameParser getNameParser(Name name) throws NamingException {
PartialCompositeContext ctx = this;
Name nm = name;
NameParser answer;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
try {
answer = ctx.p_getNameParser(nm, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCContext(cont);
answer = ctx.p_getNameParser(nm, cont);
}
} catch (CannotProceedException e) {
Context cctx = NamingManager.getContinuationContext(e);
answer = cctx.getNameParser(e.getRemainingName());
}
return answer;
}
public String composeName(String name, String prefix)
throws NamingException {
Name fullName = composeName(new CompositeName(name),
new CompositeName(prefix));
return fullName.toString();
}
/**
* This default implementation simply concatenates the two names.
* There's one twist when the "java.naming.provider.compose.elideEmpty"
* environment setting is set to "true": if each name contains a
* nonempty component, and if 'prefix' ends with an empty component or
* 'name' starts with one, then one empty component is dropped.
* For example:
* <pre>
* elideEmpty=false elideEmpty=true
* {"a"} + {"b"} => {"a", "b"} {"a", "b"}
* {"a"} + {""} => {"a", ""} {"a", ""}
* {"a"} + {"", "b"} => {"a", "", "b"} {"a", "b"}
* {"a", ""} + {"b", ""} => {"a", "", "b", ""} {"a", "b", ""}
* {"a", ""} + {"", "b"} => {"a", "", "", "b"} {"a", "", "b"}
* </pre>
*/
public Name composeName(Name name, Name prefix) throws NamingException {
Name res = (Name)prefix.clone();
if (name == null) {
return res;
}
res.addAll(name);
String elide = (String)
p_getEnvironment().get("java.naming.provider.compose.elideEmpty");
if (elide == null || !elide.equalsIgnoreCase("true")) {
return res;
}
int len = prefix.size();
if (!allEmpty(prefix) && !allEmpty(name)) {
if (res.get(len - 1).equals("")) {
res.remove(len - 1);
} else if (res.get(len).equals("")) {
res.remove(len);
}
}
return res;
}
// ------ internal methods used by PartialCompositeContext
/**
* Tests whether a name contains a nonempty component.
*/
protected static boolean allEmpty(Name name) {
Enumeration<String> enum_ = name.getAll();
while (enum_.hasMoreElements()) {
if (!enum_.nextElement().isEmpty()) {
return false;
}
}
return true;
}
/**
* Retrieves a PartialCompositeContext for the resolved object in
* cont. Throws CannotProceedException if not successful.
*/
protected static PartialCompositeContext getPCContext(Continuation cont)
throws NamingException {
Object obj = cont.getResolvedObj();
PartialCompositeContext pctx = null;
if (obj instanceof PartialCompositeContext) {
// Just cast if octx already is PartialCompositeContext
// %%% ignoring environment for now
return (PartialCompositeContext)obj;
} else {
throw cont.fillInException(new CannotProceedException());
}
}
};

View File

@@ -0,0 +1,576 @@
/*
* 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.toolkit.ctx;
import java.util.Hashtable;
import javax.naming.*;
import javax.naming.directory.*;
import javax.naming.spi.DirectoryManager;
/*
* Inherit from AtomicContext so that subclasses of PartialCompositeDirContext
* can get the ns methods defined in subclasses of PartialCompositeContext.
*
* Direct subclasses of DirContext should provide implementations for
* the p_ abstract DirContext methods and override the p_ Context methods
* (not abstract anymore because they are overridden by ComponentContext
* (the superclass of AtomicContext)).
*
* @author Rosanna Lee
*/
public abstract class PartialCompositeDirContext
extends AtomicContext implements DirContext {
protected PartialCompositeDirContext() {
_contextType = _PARTIAL;
}
// ------ Abstract methods whose implementation come from subclasses
/* Equivalent to DirContext methods */
protected abstract Attributes p_getAttributes(Name name, String[] attrIds,
Continuation cont)
throws NamingException;
protected abstract void p_modifyAttributes(Name name, int mod_op,
Attributes attrs,
Continuation cont)
throws NamingException;
protected abstract void p_modifyAttributes(Name name,
ModificationItem[] mods,
Continuation cont)
throws NamingException;
protected abstract void p_bind(Name name, Object obj,
Attributes attrs,
Continuation cont)
throws NamingException;
protected abstract void p_rebind(Name name, Object obj,
Attributes attrs,
Continuation cont)
throws NamingException;
protected abstract DirContext p_createSubcontext(Name name,
Attributes attrs,
Continuation cont)
throws NamingException;
protected abstract NamingEnumeration<SearchResult> p_search(
Name name,
Attributes matchingAttributes,
String[] attributesToReturn,
Continuation cont)
throws NamingException;
protected abstract NamingEnumeration<SearchResult> p_search(
Name name,
String filter,
SearchControls cons,
Continuation cont)
throws NamingException;
protected abstract NamingEnumeration<SearchResult> p_search(
Name name,
String filterExpr,
Object[] filterArgs,
SearchControls cons,
Continuation cont)
throws NamingException;
protected abstract DirContext p_getSchema(Name name, Continuation cont)
throws NamingException;
protected abstract DirContext p_getSchemaClassDefinition(Name name,
Continuation cont)
throws NamingException;
// ------ implementation for DirContext methods using
// ------ corresponding p_ methods
public Attributes getAttributes(String name)
throws NamingException {
return getAttributes(name, null);
}
public Attributes getAttributes(Name name)
throws NamingException {
return getAttributes(name, null);
}
public Attributes getAttributes(String name, String[] attrIds)
throws NamingException {
return getAttributes(new CompositeName(name), attrIds);
}
public Attributes getAttributes(Name name, String[] attrIds)
throws NamingException {
PartialCompositeDirContext ctx = this;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
Attributes answer;
Name nm = name;
try {
answer = ctx.p_getAttributes(nm, attrIds, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCDirContext(cont);
answer = ctx.p_getAttributes(nm, attrIds, cont);
}
} catch (CannotProceedException e) {
DirContext cctx = DirectoryManager.getContinuationDirContext(e);
answer = cctx.getAttributes(e.getRemainingName(), attrIds);
}
return answer;
}
public void modifyAttributes(String name, int mod_op, Attributes attrs)
throws NamingException {
modifyAttributes(new CompositeName(name), mod_op, attrs);
}
public void modifyAttributes(Name name, int mod_op, Attributes attrs)
throws NamingException {
PartialCompositeDirContext ctx = this;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
Name nm = name;
try {
ctx.p_modifyAttributes(nm, mod_op, attrs, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCDirContext(cont);
ctx.p_modifyAttributes(nm, mod_op, attrs, cont);
}
} catch (CannotProceedException e) {
DirContext cctx = DirectoryManager.getContinuationDirContext(e);
cctx.modifyAttributes(e.getRemainingName(), mod_op, attrs);
}
}
public void modifyAttributes(String name, ModificationItem[] mods)
throws NamingException {
modifyAttributes(new CompositeName(name), mods);
}
public void modifyAttributes(Name name, ModificationItem[] mods)
throws NamingException {
PartialCompositeDirContext ctx = this;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
Name nm = name;
try {
ctx.p_modifyAttributes(nm, mods, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCDirContext(cont);
ctx.p_modifyAttributes(nm, mods, cont);
}
} catch (CannotProceedException e) {
DirContext cctx = DirectoryManager.getContinuationDirContext(e);
cctx.modifyAttributes(e.getRemainingName(), mods);
}
}
public void bind(String name, Object obj, Attributes attrs)
throws NamingException {
bind(new CompositeName(name), obj, attrs);
}
public void bind(Name name, Object obj, Attributes attrs)
throws NamingException {
PartialCompositeDirContext ctx = this;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
Name nm = name;
try {
ctx.p_bind(nm, obj, attrs, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCDirContext(cont);
ctx.p_bind(nm, obj, attrs, cont);
}
} catch (CannotProceedException e) {
DirContext cctx = DirectoryManager.getContinuationDirContext(e);
cctx.bind(e.getRemainingName(), obj, attrs);
}
}
public void rebind(String name, Object obj, Attributes attrs)
throws NamingException {
rebind(new CompositeName(name), obj, attrs);
}
public void rebind(Name name, Object obj, Attributes attrs)
throws NamingException {
PartialCompositeDirContext ctx = this;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
Name nm = name;
try {
ctx.p_rebind(nm, obj, attrs, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCDirContext(cont);
ctx.p_rebind(nm, obj, attrs, cont);
}
} catch (CannotProceedException e) {
DirContext cctx = DirectoryManager.getContinuationDirContext(e);
cctx.rebind(e.getRemainingName(), obj, attrs);
}
}
public DirContext createSubcontext(String name, Attributes attrs)
throws NamingException {
return createSubcontext(new CompositeName(name), attrs);
}
public DirContext createSubcontext(Name name, Attributes attrs)
throws NamingException {
PartialCompositeDirContext ctx = this;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
DirContext answer;
Name nm = name;
try {
answer = ctx.p_createSubcontext(nm, attrs, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCDirContext(cont);
answer = ctx.p_createSubcontext(nm, attrs, cont);
}
} catch (CannotProceedException e) {
DirContext cctx = DirectoryManager.getContinuationDirContext(e);
answer = cctx.createSubcontext(e.getRemainingName(), attrs);
}
return answer;
}
public NamingEnumeration<SearchResult>
search(String name, Attributes matchingAttributes)
throws NamingException
{
return search(name, matchingAttributes, null);
}
public NamingEnumeration<SearchResult>
search(Name name, Attributes matchingAttributes)
throws NamingException
{
return search(name, matchingAttributes, null);
}
public NamingEnumeration<SearchResult>
search(String name,
Attributes matchingAttributes,
String[] attributesToReturn)
throws NamingException
{
return search(new CompositeName(name),
matchingAttributes, attributesToReturn);
}
public NamingEnumeration<SearchResult>
search(Name name,
Attributes matchingAttributes,
String[] attributesToReturn)
throws NamingException
{
PartialCompositeDirContext ctx = this;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
NamingEnumeration<SearchResult> answer;
Name nm = name;
try {
answer = ctx.p_search(nm, matchingAttributes,
attributesToReturn, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCDirContext(cont);
answer = ctx.p_search(nm, matchingAttributes,
attributesToReturn, cont);
}
} catch (CannotProceedException e) {
DirContext cctx = DirectoryManager.getContinuationDirContext(e);
answer = cctx.search(e.getRemainingName(), matchingAttributes,
attributesToReturn);
}
return answer;
}
public NamingEnumeration<SearchResult>
search(String name,
String filter,
SearchControls cons)
throws NamingException
{
return search(new CompositeName(name), filter, cons);
}
public NamingEnumeration<SearchResult>
search(Name name,
String filter,
SearchControls cons)
throws NamingException
{
PartialCompositeDirContext ctx = this;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
NamingEnumeration<SearchResult> answer;
Name nm = name;
try {
answer = ctx.p_search(nm, filter, cons, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCDirContext(cont);
answer = ctx.p_search(nm, filter, cons, cont);
}
} catch (CannotProceedException e) {
DirContext cctx = DirectoryManager.getContinuationDirContext(e);
answer = cctx.search(e.getRemainingName(), filter, cons);
}
return answer;
}
public NamingEnumeration<SearchResult>
search(String name,
String filterExpr,
Object[] filterArgs,
SearchControls cons)
throws NamingException
{
return search(new CompositeName(name), filterExpr, filterArgs, cons);
}
public NamingEnumeration<SearchResult>
search(Name name,
String filterExpr,
Object[] filterArgs,
SearchControls cons)
throws NamingException
{
PartialCompositeDirContext ctx = this;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
NamingEnumeration<SearchResult> answer;
Name nm = name;
try {
answer = ctx.p_search(nm, filterExpr, filterArgs, cons, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCDirContext(cont);
answer = ctx.p_search(nm, filterExpr, filterArgs, cons, cont);
}
} catch (CannotProceedException e) {
DirContext cctx = DirectoryManager.getContinuationDirContext(e);
answer = cctx.search(e.getRemainingName(), filterExpr, filterArgs,
cons);
}
return answer;
}
public DirContext getSchema(String name) throws NamingException {
return getSchema(new CompositeName(name));
}
public DirContext getSchema(Name name) throws NamingException {
PartialCompositeDirContext ctx = this;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
DirContext answer;
Name nm = name;
try {
answer = ctx.p_getSchema(nm, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCDirContext(cont);
answer = ctx.p_getSchema(nm, cont);
}
} catch (CannotProceedException e) {
DirContext cctx = DirectoryManager.getContinuationDirContext(e);
answer = cctx.getSchema(e.getRemainingName());
}
return answer;
}
public DirContext getSchemaClassDefinition(String name)
throws NamingException {
return getSchemaClassDefinition(new CompositeName(name));
}
public DirContext getSchemaClassDefinition(Name name)
throws NamingException {
PartialCompositeDirContext ctx = this;
Hashtable<?,?> env = p_getEnvironment();
Continuation cont = new Continuation(name, env);
DirContext answer;
Name nm = name;
try {
answer = ctx.p_getSchemaClassDefinition(nm, cont);
while (cont.isContinue()) {
nm = cont.getRemainingName();
ctx = getPCDirContext(cont);
answer = ctx.p_getSchemaClassDefinition(nm, cont);
}
} catch (CannotProceedException e) {
DirContext cctx = DirectoryManager.getContinuationDirContext(e);
answer = cctx.getSchemaClassDefinition(e.getRemainingName());
}
return answer;
}
// ------ internal method used by PartialCompositeDirContext
/**
* Retrieves a PartialCompositeDirContext for the resolved object in
* cont. Throws CannotProceedException if not successful.
*/
protected static PartialCompositeDirContext getPCDirContext(Continuation cont)
throws NamingException {
PartialCompositeContext pctx =
PartialCompositeContext.getPCContext(cont);
if (!(pctx instanceof PartialCompositeDirContext)) {
throw cont.fillInException(
new NotContextException(
"Resolved object is not a DirContext."));
}
return (PartialCompositeDirContext)pctx;
}
//------ Compensation for inheriting from AtomicContext
/*
* Dummy implementations defined here so that direct subclasses
* of PartialCompositeDirContext or ComponentDirContext do not
* have to provide dummy implementations for these.
* Override these for subclasses of AtomicDirContext.
*/
protected StringHeadTail c_parseComponent(String inputName,
Continuation cont) throws NamingException {
OperationNotSupportedException e = new
OperationNotSupportedException();
throw cont.fillInException(e);
}
protected Object a_lookup(String name, Continuation cont)
throws NamingException {
OperationNotSupportedException e = new
OperationNotSupportedException();
throw cont.fillInException(e);
}
protected Object a_lookupLink(String name, Continuation cont)
throws NamingException {
OperationNotSupportedException e = new
OperationNotSupportedException();
throw cont.fillInException(e);
}
protected NamingEnumeration<NameClassPair> a_list(
Continuation cont) throws NamingException {
OperationNotSupportedException e = new
OperationNotSupportedException();
throw cont.fillInException(e);
}
protected NamingEnumeration<Binding> a_listBindings(
Continuation cont) throws NamingException {
OperationNotSupportedException e = new
OperationNotSupportedException();
throw cont.fillInException(e);
}
protected void a_bind(String name, Object obj, Continuation cont)
throws NamingException {
OperationNotSupportedException e = new
OperationNotSupportedException();
throw cont.fillInException(e);
}
protected void a_rebind(String name, Object obj, Continuation cont)
throws NamingException {
OperationNotSupportedException e = new
OperationNotSupportedException();
throw cont.fillInException(e);
}
protected void a_unbind(String name, Continuation cont)
throws NamingException {
OperationNotSupportedException e = new
OperationNotSupportedException();
throw cont.fillInException(e);
}
protected void a_destroySubcontext(String name, Continuation cont)
throws NamingException {
OperationNotSupportedException e = new
OperationNotSupportedException();
throw cont.fillInException(e);
}
protected Context a_createSubcontext(String name, Continuation cont)
throws NamingException {
OperationNotSupportedException e = new
OperationNotSupportedException();
throw cont.fillInException(e);
}
protected void a_rename(String oldname, Name newname,
Continuation cont) throws NamingException {
OperationNotSupportedException e = new
OperationNotSupportedException();
throw cont.fillInException(e);
}
protected NameParser a_getNameParser(Continuation cont)
throws NamingException {
OperationNotSupportedException e = new
OperationNotSupportedException();
throw cont.fillInException(e);
}
}

View File

@@ -0,0 +1,63 @@
/*
* 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.toolkit.ctx;
/**
* A class for returning the result of c_parseComponent().
*
* @author Rosanna Lee
*/
public class StringHeadTail {
private int status;
private String head;
private String tail;
public StringHeadTail(String head, String tail) {
this(head, tail, 0);
}
public StringHeadTail(String head, String tail, int status) {
this.status = status;
this.head = head;
this.tail = tail;
}
public void setStatus(int status) {
this.status = status;
}
public String getHead() {
return this.head;
}
public String getTail() {
return this.tail;
}
public int getStatus() {
return this.status;
}
}