0N/A/*
2362N/A * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.jndi.toolkit.ctx;
0N/A
0N/Aimport java.util.Hashtable;
0N/A
0N/Aimport javax.naming.*;
0N/Aimport javax.naming.directory.*;
0N/Aimport javax.naming.spi.NamingManager;
0N/Aimport javax.naming.spi.DirectoryManager;
0N/A
0N/A/*
0N/A * Inherit from AtomicContext so that subclasses of PartialCompositeDirContext
0N/A * can get the ns methods defined in subclasses of PartialCompositeContext.
0N/A *
0N/A * Direct subclasses of DirContext should provide implementations for
0N/A * the p_ abstract DirContext methods and override the p_ Context methods
0N/A * (not abstract anymore because they are overridden by ComponentContext
0N/A * (the superclass of AtomicContext)).
0N/A *
0N/A * @author Rosanna Lee
0N/A */
0N/A
0N/Apublic abstract class PartialCompositeDirContext
0N/A extends AtomicContext implements DirContext {
0N/A
0N/A protected PartialCompositeDirContext() {
0N/A _contextType = _PARTIAL;
0N/A }
0N/A
0N/A// ------ Abstract methods whose implementation come from subclasses
0N/A
0N/A /* Equivalent to DirContext methods */
0N/A protected abstract Attributes p_getAttributes(Name name, String[] attrIds,
0N/A Continuation cont)
0N/A throws NamingException;
0N/A
0N/A protected abstract void p_modifyAttributes(Name name, int mod_op,
0N/A Attributes attrs,
0N/A Continuation cont)
0N/A throws NamingException;
0N/A
0N/A protected abstract void p_modifyAttributes(Name name,
0N/A ModificationItem[] mods,
0N/A Continuation cont)
0N/A throws NamingException;
0N/A
0N/A protected abstract void p_bind(Name name, Object obj,
0N/A Attributes attrs,
0N/A Continuation cont)
0N/A throws NamingException;
0N/A
0N/A protected abstract void p_rebind(Name name, Object obj,
0N/A Attributes attrs,
0N/A Continuation cont)
0N/A throws NamingException;
0N/A
0N/A protected abstract DirContext p_createSubcontext(Name name,
0N/A Attributes attrs,
0N/A Continuation cont)
0N/A throws NamingException;
0N/A
0N/A protected abstract NamingEnumeration p_search(Name name,
0N/A Attributes matchingAttributes,
0N/A String[] attributesToReturn,
0N/A Continuation cont)
0N/A throws NamingException;
0N/A
0N/A protected abstract NamingEnumeration p_search(Name name,
0N/A String filter,
0N/A SearchControls cons,
0N/A Continuation cont)
0N/A throws NamingException;
0N/A
0N/A protected abstract NamingEnumeration p_search(Name name,
0N/A String filterExpr,
0N/A Object[] filterArgs,
0N/A SearchControls cons,
0N/A Continuation cont)
0N/A throws NamingException;
0N/A
0N/A protected abstract DirContext p_getSchema(Name name, Continuation cont)
0N/A throws NamingException;
0N/A
0N/A protected abstract DirContext p_getSchemaClassDefinition(Name name,
0N/A Continuation cont)
0N/A throws NamingException;
0N/A
0N/A// ------ implementation for DirContext methods using
0N/A// ------ corresponding p_ methods
0N/A
0N/A public Attributes getAttributes(String name)
0N/A throws NamingException {
0N/A return getAttributes(name, null);
0N/A }
0N/A
0N/A public Attributes getAttributes(Name name)
0N/A throws NamingException {
0N/A return getAttributes(name, null);
0N/A }
0N/A
0N/A public Attributes getAttributes(String name, String[] attrIds)
0N/A throws NamingException {
0N/A return getAttributes(new CompositeName(name), attrIds);
0N/A }
0N/A
0N/A public Attributes getAttributes(Name name, String[] attrIds)
0N/A throws NamingException {
0N/A PartialCompositeDirContext ctx = this;
0N/A Hashtable env = p_getEnvironment();
0N/A Continuation cont = new Continuation(name, env);
0N/A Attributes answer;
0N/A Name nm = name;
0N/A
0N/A try {
0N/A answer = ctx.p_getAttributes(nm, attrIds, cont);
0N/A while (cont.isContinue()) {
0N/A nm = cont.getRemainingName();
0N/A ctx = getPCDirContext(cont);
0N/A answer = ctx.p_getAttributes(nm, attrIds, cont);
0N/A }
0N/A } catch (CannotProceedException e) {
0N/A DirContext cctx = DirectoryManager.getContinuationDirContext(e);
0N/A answer = cctx.getAttributes(e.getRemainingName(), attrIds);
0N/A }
0N/A return answer;
0N/A }
0N/A
0N/A public void modifyAttributes(String name, int mod_op, Attributes attrs)
0N/A throws NamingException {
0N/A modifyAttributes(new CompositeName(name), mod_op, attrs);
0N/A }
0N/A
0N/A public void modifyAttributes(Name name, int mod_op, Attributes attrs)
0N/A throws NamingException {
0N/A PartialCompositeDirContext ctx = this;
0N/A Hashtable env = p_getEnvironment();
0N/A Continuation cont = new Continuation(name, env);
0N/A Name nm = name;
0N/A
0N/A try {
0N/A ctx.p_modifyAttributes(nm, mod_op, attrs, cont);
0N/A while (cont.isContinue()) {
0N/A nm = cont.getRemainingName();
0N/A ctx = getPCDirContext(cont);
0N/A ctx.p_modifyAttributes(nm, mod_op, attrs, cont);
0N/A }
0N/A } catch (CannotProceedException e) {
0N/A DirContext cctx = DirectoryManager.getContinuationDirContext(e);
0N/A cctx.modifyAttributes(e.getRemainingName(), mod_op, attrs);
0N/A }
0N/A }
0N/A
0N/A public void modifyAttributes(String name, ModificationItem[] mods)
0N/A throws NamingException {
0N/A modifyAttributes(new CompositeName(name), mods);
0N/A }
0N/A
0N/A public void modifyAttributes(Name name, ModificationItem[] mods)
0N/A throws NamingException {
0N/A PartialCompositeDirContext ctx = this;
0N/A Hashtable env = p_getEnvironment();
0N/A Continuation cont = new Continuation(name, env);
0N/A Name nm = name;
0N/A
0N/A try {
0N/A ctx.p_modifyAttributes(nm, mods, cont);
0N/A while (cont.isContinue()) {
0N/A nm = cont.getRemainingName();
0N/A ctx = getPCDirContext(cont);
0N/A ctx.p_modifyAttributes(nm, mods, cont);
0N/A }
0N/A } catch (CannotProceedException e) {
0N/A DirContext cctx = DirectoryManager.getContinuationDirContext(e);
0N/A cctx.modifyAttributes(e.getRemainingName(), mods);
0N/A }
0N/A }
0N/A
0N/A public void bind(String name, Object obj, Attributes attrs)
0N/A throws NamingException {
0N/A bind(new CompositeName(name), obj, attrs);
0N/A }
0N/A
0N/A public void bind(Name name, Object obj, Attributes attrs)
0N/A throws NamingException {
0N/A PartialCompositeDirContext ctx = this;
0N/A Hashtable env = p_getEnvironment();
0N/A Continuation cont = new Continuation(name, env);
0N/A Name nm = name;
0N/A
0N/A try {
0N/A ctx.p_bind(nm, obj, attrs, cont);
0N/A while (cont.isContinue()) {
0N/A nm = cont.getRemainingName();
0N/A ctx = getPCDirContext(cont);
0N/A ctx.p_bind(nm, obj, attrs, cont);
0N/A }
0N/A } catch (CannotProceedException e) {
0N/A DirContext cctx = DirectoryManager.getContinuationDirContext(e);
0N/A cctx.bind(e.getRemainingName(), obj, attrs);
0N/A }
0N/A }
0N/A
0N/A public void rebind(String name, Object obj, Attributes attrs)
0N/A throws NamingException {
0N/A rebind(new CompositeName(name), obj, attrs);
0N/A }
0N/A
0N/A public void rebind(Name name, Object obj, Attributes attrs)
0N/A throws NamingException {
0N/A PartialCompositeDirContext ctx = this;
0N/A Hashtable env = p_getEnvironment();
0N/A Continuation cont = new Continuation(name, env);
0N/A Name nm = name;
0N/A
0N/A try {
0N/A ctx.p_rebind(nm, obj, attrs, cont);
0N/A while (cont.isContinue()) {
0N/A nm = cont.getRemainingName();
0N/A ctx = getPCDirContext(cont);
0N/A ctx.p_rebind(nm, obj, attrs, cont);
0N/A }
0N/A } catch (CannotProceedException e) {
0N/A DirContext cctx = DirectoryManager.getContinuationDirContext(e);
0N/A cctx.rebind(e.getRemainingName(), obj, attrs);
0N/A }
0N/A }
0N/A
0N/A public DirContext createSubcontext(String name, Attributes attrs)
0N/A throws NamingException {
0N/A return createSubcontext(new CompositeName(name), attrs);
0N/A }
0N/A
0N/A public DirContext createSubcontext(Name name, Attributes attrs)
0N/A throws NamingException {
0N/A PartialCompositeDirContext ctx = this;
0N/A Hashtable env = p_getEnvironment();
0N/A Continuation cont = new Continuation(name, env);
0N/A DirContext answer;
0N/A Name nm = name;
0N/A
0N/A try {
0N/A answer = ctx.p_createSubcontext(nm, attrs, cont);
0N/A while (cont.isContinue()) {
0N/A nm = cont.getRemainingName();
0N/A ctx = getPCDirContext(cont);
0N/A answer = ctx.p_createSubcontext(nm, attrs, cont);
0N/A }
0N/A } catch (CannotProceedException e) {
0N/A DirContext cctx = DirectoryManager.getContinuationDirContext(e);
0N/A answer = cctx.createSubcontext(e.getRemainingName(), attrs);
0N/A }
0N/A return answer;
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(String name, Attributes matchingAttributes)
0N/A throws NamingException
0N/A {
0N/A return search(name, matchingAttributes, null);
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(Name name, Attributes matchingAttributes)
0N/A throws NamingException
0N/A {
0N/A return search(name, matchingAttributes, null);
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(String name,
0N/A Attributes matchingAttributes,
0N/A String[] attributesToReturn)
0N/A throws NamingException
0N/A {
0N/A return search(new CompositeName(name),
0N/A matchingAttributes, attributesToReturn);
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(Name name,
0N/A Attributes matchingAttributes,
0N/A String[] attributesToReturn)
0N/A throws NamingException
0N/A {
0N/A
0N/A PartialCompositeDirContext ctx = this;
0N/A Hashtable env = p_getEnvironment();
0N/A Continuation cont = new Continuation(name, env);
0N/A NamingEnumeration answer;
0N/A Name nm = name;
0N/A
0N/A try {
0N/A answer = ctx.p_search(nm, matchingAttributes,
0N/A attributesToReturn, cont);
0N/A while (cont.isContinue()) {
0N/A nm = cont.getRemainingName();
0N/A ctx = getPCDirContext(cont);
0N/A answer = ctx.p_search(nm, matchingAttributes,
0N/A attributesToReturn, cont);
0N/A }
0N/A } catch (CannotProceedException e) {
0N/A DirContext cctx = DirectoryManager.getContinuationDirContext(e);
0N/A answer = cctx.search(e.getRemainingName(), matchingAttributes,
0N/A attributesToReturn);
0N/A }
0N/A return answer;
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(String name,
0N/A String filter,
0N/A SearchControls cons)
0N/A throws NamingException
0N/A {
0N/A return search(new CompositeName(name), filter, cons);
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(Name name,
0N/A String filter,
0N/A SearchControls cons)
0N/A throws NamingException
0N/A {
0N/A
0N/A PartialCompositeDirContext ctx = this;
0N/A Hashtable env = p_getEnvironment();
0N/A Continuation cont = new Continuation(name, env);
0N/A NamingEnumeration answer;
0N/A Name nm = name;
0N/A
0N/A try {
0N/A answer = ctx.p_search(nm, filter, cons, cont);
0N/A while (cont.isContinue()) {
0N/A nm = cont.getRemainingName();
0N/A ctx = getPCDirContext(cont);
0N/A answer = ctx.p_search(nm, filter, cons, cont);
0N/A }
0N/A } catch (CannotProceedException e) {
0N/A DirContext cctx = DirectoryManager.getContinuationDirContext(e);
0N/A answer = cctx.search(e.getRemainingName(), filter, cons);
0N/A }
0N/A return answer;
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(String name,
0N/A String filterExpr,
0N/A Object[] filterArgs,
0N/A SearchControls cons)
0N/A throws NamingException
0N/A {
0N/A return search(new CompositeName(name), filterExpr, filterArgs, cons);
0N/A }
0N/A
0N/A public NamingEnumeration<SearchResult>
0N/A search(Name name,
0N/A String filterExpr,
0N/A Object[] filterArgs,
0N/A SearchControls cons)
0N/A throws NamingException
0N/A {
0N/A
0N/A PartialCompositeDirContext ctx = this;
0N/A Hashtable env = p_getEnvironment();
0N/A Continuation cont = new Continuation(name, env);
0N/A NamingEnumeration answer;
0N/A Name nm = name;
0N/A
0N/A try {
0N/A answer = ctx.p_search(nm, filterExpr, filterArgs, cons, cont);
0N/A while (cont.isContinue()) {
0N/A nm = cont.getRemainingName();
0N/A ctx = getPCDirContext(cont);
0N/A answer = ctx.p_search(nm, filterExpr, filterArgs, cons, cont);
0N/A }
0N/A } catch (CannotProceedException e) {
0N/A DirContext cctx = DirectoryManager.getContinuationDirContext(e);
0N/A answer = cctx.search(e.getRemainingName(), filterExpr, filterArgs,
0N/A cons);
0N/A }
0N/A return answer;
0N/A }
0N/A
0N/A public DirContext getSchema(String name) throws NamingException {
0N/A return getSchema(new CompositeName(name));
0N/A }
0N/A
0N/A public DirContext getSchema(Name name) throws NamingException {
0N/A PartialCompositeDirContext ctx = this;
0N/A Hashtable env = p_getEnvironment();
0N/A Continuation cont = new Continuation(name, env);
0N/A DirContext answer;
0N/A Name nm = name;
0N/A
0N/A try {
0N/A answer = ctx.p_getSchema(nm, cont);
0N/A while (cont.isContinue()) {
0N/A nm = cont.getRemainingName();
0N/A ctx = getPCDirContext(cont);
0N/A answer = ctx.p_getSchema(nm, cont);
0N/A }
0N/A } catch (CannotProceedException e) {
0N/A DirContext cctx = DirectoryManager.getContinuationDirContext(e);
0N/A answer = cctx.getSchema(e.getRemainingName());
0N/A }
0N/A return answer;
0N/A }
0N/A
0N/A public DirContext getSchemaClassDefinition(String name)
0N/A throws NamingException {
0N/A return getSchemaClassDefinition(new CompositeName(name));
0N/A }
0N/A
0N/A public DirContext getSchemaClassDefinition(Name name)
0N/A throws NamingException {
0N/A PartialCompositeDirContext ctx = this;
0N/A Hashtable env = p_getEnvironment();
0N/A Continuation cont = new Continuation(name, env);
0N/A DirContext answer;
0N/A Name nm = name;
0N/A
0N/A try {
0N/A answer = ctx.p_getSchemaClassDefinition(nm, cont);
0N/A while (cont.isContinue()) {
0N/A nm = cont.getRemainingName();
0N/A ctx = getPCDirContext(cont);
0N/A answer = ctx.p_getSchemaClassDefinition(nm, cont);
0N/A }
0N/A } catch (CannotProceedException e) {
0N/A DirContext cctx = DirectoryManager.getContinuationDirContext(e);
0N/A answer = cctx.getSchemaClassDefinition(e.getRemainingName());
0N/A }
0N/A return answer;
0N/A }
0N/A
0N/A// ------ internal method used by PartialCompositeDirContext
0N/A
0N/A /**
0N/A * Retrieves a PartialCompositeDirContext for the resolved object in
0N/A * cont. Throws CannotProceedException if not successful.
0N/A */
0N/A protected static PartialCompositeDirContext getPCDirContext(Continuation cont)
0N/A throws NamingException {
0N/A
0N/A PartialCompositeContext pctx =
0N/A PartialCompositeContext.getPCContext(cont);
0N/A
0N/A if (!(pctx instanceof PartialCompositeDirContext)) {
0N/A throw cont.fillInException(
0N/A new NotContextException(
0N/A "Resolved object is not a DirContext."));
0N/A }
0N/A
0N/A return (PartialCompositeDirContext)pctx;
0N/A }
0N/A
0N/A
0N/A//------ Compensation for inheriting from AtomicContext
0N/A
0N/A /*
0N/A * Dummy implementations defined here so that direct subclasses
0N/A * of PartialCompositeDirContext or ComponentDirContext do not
0N/A * have to provide dummy implementations for these.
0N/A * Override these for subclasses of AtomicDirContext.
0N/A */
0N/A
0N/A protected StringHeadTail c_parseComponent(String inputName,
0N/A Continuation cont) throws NamingException {
0N/A OperationNotSupportedException e = new
0N/A OperationNotSupportedException();
0N/A throw cont.fillInException(e);
0N/A }
0N/A
0N/A protected Object a_lookup(String name, Continuation cont)
0N/A throws NamingException {
0N/A OperationNotSupportedException e = new
0N/A OperationNotSupportedException();
0N/A throw cont.fillInException(e);
0N/A }
0N/A
0N/A protected Object a_lookupLink(String name, Continuation cont)
0N/A throws NamingException {
0N/A OperationNotSupportedException e = new
0N/A OperationNotSupportedException();
0N/A throw cont.fillInException(e);
0N/A }
0N/A
0N/A protected NamingEnumeration a_list(
0N/A Continuation cont) throws NamingException {
0N/A OperationNotSupportedException e = new
0N/A OperationNotSupportedException();
0N/A throw cont.fillInException(e);
0N/A }
0N/A
0N/A protected NamingEnumeration a_listBindings(
0N/A Continuation cont) throws NamingException {
0N/A OperationNotSupportedException e = new
0N/A OperationNotSupportedException();
0N/A throw cont.fillInException(e);
0N/A }
0N/A
0N/A protected void a_bind(String name, Object obj, Continuation cont)
0N/A throws NamingException {
0N/A OperationNotSupportedException e = new
0N/A OperationNotSupportedException();
0N/A throw cont.fillInException(e);
0N/A }
0N/A
0N/A protected void a_rebind(String name, Object obj, Continuation cont)
0N/A throws NamingException {
0N/A OperationNotSupportedException e = new
0N/A OperationNotSupportedException();
0N/A throw cont.fillInException(e);
0N/A }
0N/A
0N/A protected void a_unbind(String name, Continuation cont)
0N/A throws NamingException {
0N/A OperationNotSupportedException e = new
0N/A OperationNotSupportedException();
0N/A throw cont.fillInException(e);
0N/A }
0N/A
0N/A protected void a_destroySubcontext(String name, Continuation cont)
0N/A throws NamingException {
0N/A OperationNotSupportedException e = new
0N/A OperationNotSupportedException();
0N/A throw cont.fillInException(e);
0N/A }
0N/A
0N/A protected Context a_createSubcontext(String name, Continuation cont)
0N/A throws NamingException {
0N/A OperationNotSupportedException e = new
0N/A OperationNotSupportedException();
0N/A throw cont.fillInException(e);
0N/A }
0N/A
0N/A protected void a_rename(String oldname, Name newname,
0N/A Continuation cont) throws NamingException {
0N/A OperationNotSupportedException e = new
0N/A OperationNotSupportedException();
0N/A throw cont.fillInException(e);
0N/A }
0N/A
0N/A protected NameParser a_getNameParser(Continuation cont)
0N/A throws NamingException {
0N/A OperationNotSupportedException e = new
0N/A OperationNotSupportedException();
0N/A throw cont.fillInException(e);
0N/A }
0N/A}