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 javax.naming.spi;
0N/A
0N/Aimport java.util.Hashtable;
0N/A
0N/Aimport javax.naming.Name;
0N/Aimport javax.naming.NamingEnumeration;
0N/Aimport javax.naming.CompositeName;
0N/Aimport javax.naming.NamingException;
0N/Aimport javax.naming.CannotProceedException;
0N/Aimport javax.naming.OperationNotSupportedException;
0N/Aimport javax.naming.Context;
0N/A
0N/Aimport javax.naming.directory.DirContext;
0N/Aimport javax.naming.directory.Attributes;
0N/Aimport javax.naming.directory.SearchControls;
0N/Aimport javax.naming.directory.ModificationItem;
0N/A
0N/A/**
0N/A * This class is the continuation context for invoking DirContext methods.
0N/A *
0N/A * @author Rosanna Lee
0N/A * @author Scott Seligman
0N/A * @since 1.3
0N/A */
0N/A
0N/Aclass ContinuationDirContext extends ContinuationContext implements DirContext {
0N/A
0N/A ContinuationDirContext(CannotProceedException cpe, Hashtable env) {
0N/A super(cpe, env);
0N/A }
0N/A
0N/A protected DirContextNamePair getTargetContext(Name name)
0N/A throws NamingException {
0N/A
0N/A if (cpe.getResolvedObj() == null)
0N/A throw (NamingException)cpe.fillInStackTrace();
0N/A
0N/A Context ctx = NamingManager.getContext(cpe.getResolvedObj(),
0N/A cpe.getAltName(),
0N/A cpe.getAltNameCtx(),
0N/A env);
0N/A if (ctx == null)
0N/A throw (NamingException)cpe.fillInStackTrace();
0N/A
0N/A if (ctx instanceof DirContext)
0N/A return new DirContextNamePair((DirContext)ctx, name);
0N/A
0N/A if (ctx instanceof Resolver) {
0N/A Resolver res = (Resolver)ctx;
0N/A ResolveResult rr = res.resolveToClass(name, DirContext.class);
0N/A
0N/A // Reached a DirContext; return result.
0N/A DirContext dctx = (DirContext)rr.getResolvedObj();
0N/A return (new DirContextNamePair(dctx, rr.getRemainingName()));
0N/A }
0N/A
0N/A // Resolve all the way using lookup(). This may allow the operation
0N/A // to succeed if it doesn't require the penultimate context.
0N/A Object ultimate = ctx.lookup(name);
0N/A if (ultimate instanceof DirContext) {
0N/A return (new DirContextNamePair((DirContext)ultimate,
0N/A new CompositeName()));
0N/A }
0N/A
0N/A throw (NamingException)cpe.fillInStackTrace();
0N/A }
0N/A
0N/A protected DirContextStringPair getTargetContext(String name)
0N/A throws NamingException {
0N/A
0N/A if (cpe.getResolvedObj() == null)
0N/A throw (NamingException)cpe.fillInStackTrace();
0N/A
0N/A Context ctx = NamingManager.getContext(cpe.getResolvedObj(),
0N/A cpe.getAltName(),
0N/A cpe.getAltNameCtx(),
0N/A env);
0N/A
0N/A if (ctx instanceof DirContext)
0N/A return new DirContextStringPair((DirContext)ctx, name);
0N/A
0N/A if (ctx instanceof Resolver) {
0N/A Resolver res = (Resolver)ctx;
0N/A ResolveResult rr = res.resolveToClass(name, DirContext.class);
0N/A
0N/A // Reached a DirContext; return result.
0N/A DirContext dctx = (DirContext)rr.getResolvedObj();
0N/A Name tmp = rr.getRemainingName();
0N/A String remains = (tmp != null) ? tmp.toString() : "";
0N/A return (new DirContextStringPair(dctx, remains));
0N/A }
0N/A
0N/A // Resolve all the way using lookup(). This may allow the operation
0N/A // to succeed if it doesn't require the penultimate context.
0N/A Object ultimate = ctx.lookup(name);
0N/A if (ultimate instanceof DirContext) {
0N/A return (new DirContextStringPair((DirContext)ultimate, ""));
0N/A }
0N/A
0N/A throw (NamingException)cpe.fillInStackTrace();
0N/A }
0N/A
0N/A public Attributes getAttributes(String name) throws NamingException {
0N/A DirContextStringPair res = getTargetContext(name);
0N/A return res.getDirContext().getAttributes(res.getString());
0N/A }
0N/A
0N/A public Attributes getAttributes(String name, String[] attrIds)
0N/A throws NamingException {
0N/A DirContextStringPair res = getTargetContext(name);
0N/A return res.getDirContext().getAttributes(res.getString(), attrIds);
0N/A }
0N/A
0N/A public Attributes getAttributes(Name name) throws NamingException {
0N/A DirContextNamePair res = getTargetContext(name);
0N/A return res.getDirContext().getAttributes(res.getName());
0N/A }
0N/A
0N/A public Attributes getAttributes(Name name, String[] attrIds)
0N/A throws NamingException {
0N/A DirContextNamePair res = getTargetContext(name);
0N/A return res.getDirContext().getAttributes(res.getName(), attrIds);
0N/A }
0N/A
0N/A public void modifyAttributes(Name name, int mod_op, Attributes attrs)
0N/A throws NamingException {
0N/A DirContextNamePair res = getTargetContext(name);
0N/A res.getDirContext().modifyAttributes(res.getName(), mod_op, attrs);
0N/A }
0N/A public void modifyAttributes(String name, int mod_op, Attributes attrs)
0N/A throws NamingException {
0N/A DirContextStringPair res = getTargetContext(name);
0N/A res.getDirContext().modifyAttributes(res.getString(), mod_op, attrs);
0N/A }
0N/A
0N/A public void modifyAttributes(Name name, ModificationItem[] mods)
0N/A throws NamingException {
0N/A DirContextNamePair res = getTargetContext(name);
0N/A res.getDirContext().modifyAttributes(res.getName(), mods);
0N/A }
0N/A public void modifyAttributes(String name, ModificationItem[] mods)
0N/A throws NamingException {
0N/A DirContextStringPair res = getTargetContext(name);
0N/A res.getDirContext().modifyAttributes(res.getString(), mods);
0N/A }
0N/A
0N/A public void bind(Name name, Object obj, Attributes attrs)
0N/A throws NamingException {
0N/A DirContextNamePair res = getTargetContext(name);
0N/A res.getDirContext().bind(res.getName(), obj, attrs);
0N/A }
0N/A public void bind(String name, Object obj, Attributes attrs)
0N/A throws NamingException {
0N/A DirContextStringPair res = getTargetContext(name);
0N/A res.getDirContext().bind(res.getString(), obj, attrs);
0N/A }
0N/A
0N/A public void rebind(Name name, Object obj, Attributes attrs)
0N/A throws NamingException {
0N/A DirContextNamePair res = getTargetContext(name);
0N/A res.getDirContext().rebind(res.getName(), obj, attrs);
0N/A }
0N/A public void rebind(String name, Object obj, Attributes attrs)
0N/A throws NamingException {
0N/A DirContextStringPair res = getTargetContext(name);
0N/A res.getDirContext().rebind(res.getString(), obj, attrs);
0N/A }
0N/A
0N/A public DirContext createSubcontext(Name name, Attributes attrs)
0N/A throws NamingException {
0N/A DirContextNamePair res = getTargetContext(name);
0N/A return res.getDirContext().createSubcontext(res.getName(), attrs);
0N/A }
0N/A
0N/A public DirContext createSubcontext(String name, Attributes attrs)
0N/A throws NamingException {
0N/A DirContextStringPair res = getTargetContext(name);
0N/A return
0N/A res.getDirContext().createSubcontext(res.getString(), attrs);
0N/A }
0N/A
0N/A public NamingEnumeration search(Name name,
0N/A Attributes matchingAttributes,
0N/A String[] attributesToReturn)
0N/A throws NamingException {
0N/A DirContextNamePair res = getTargetContext(name);
0N/A return res.getDirContext().search(res.getName(), matchingAttributes,
0N/A attributesToReturn);
0N/A }
0N/A
0N/A public NamingEnumeration search(String name,
0N/A Attributes matchingAttributes,
0N/A String[] attributesToReturn)
0N/A throws NamingException {
0N/A DirContextStringPair res = getTargetContext(name);
0N/A return res.getDirContext().search(res.getString(),
0N/A matchingAttributes,
0N/A attributesToReturn);
0N/A }
0N/A
0N/A public NamingEnumeration search(Name name,
0N/A Attributes matchingAttributes)
0N/A throws NamingException {
0N/A DirContextNamePair res = getTargetContext(name);
0N/A return res.getDirContext().search(res.getName(), matchingAttributes);
0N/A }
0N/A public NamingEnumeration search(String name,
0N/A Attributes matchingAttributes)
0N/A throws NamingException {
0N/A DirContextStringPair res = getTargetContext(name);
0N/A return res.getDirContext().search(res.getString(),
0N/A matchingAttributes);
0N/A }
0N/A
0N/A public NamingEnumeration search(Name name,
0N/A String filter,
0N/A SearchControls cons)
0N/A throws NamingException {
0N/A DirContextNamePair res = getTargetContext(name);
0N/A return res.getDirContext().search(res.getName(), filter, cons);
0N/A }
0N/A
0N/A public NamingEnumeration search(String name,
0N/A String filter,
0N/A SearchControls cons)
0N/A throws NamingException {
0N/A DirContextStringPair res = getTargetContext(name);
0N/A return res.getDirContext().search(res.getString(), filter, cons);
0N/A }
0N/A
0N/A public NamingEnumeration search(Name name,
0N/A String filterExpr,
0N/A Object[] args,
0N/A SearchControls cons)
0N/A throws NamingException {
0N/A DirContextNamePair res = getTargetContext(name);
0N/A return res.getDirContext().search(res.getName(), filterExpr, args,
0N/A cons);
0N/A }
0N/A
0N/A public NamingEnumeration search(String name,
0N/A String filterExpr,
0N/A Object[] args,
0N/A SearchControls cons)
0N/A throws NamingException {
0N/A DirContextStringPair res = getTargetContext(name);
0N/A return res.getDirContext().search(res.getString(), filterExpr, args,
0N/A cons);
0N/A }
0N/A
0N/A public DirContext getSchema(String name) throws NamingException {
0N/A DirContextStringPair res = getTargetContext(name);
0N/A return res.getDirContext().getSchema(res.getString());
0N/A }
0N/A
0N/A public DirContext getSchema(Name name) throws NamingException {
0N/A DirContextNamePair res = getTargetContext(name);
0N/A return res.getDirContext().getSchema(res.getName());
0N/A }
0N/A
0N/A public DirContext getSchemaClassDefinition(String name)
0N/A throws NamingException {
0N/A DirContextStringPair res = getTargetContext(name);
0N/A return res.getDirContext().getSchemaClassDefinition(res.getString());
0N/A }
0N/A
0N/A public DirContext getSchemaClassDefinition(Name name)
0N/A throws NamingException {
0N/A DirContextNamePair res = getTargetContext(name);
0N/A return res.getDirContext().getSchemaClassDefinition(res.getName());
0N/A }
0N/A}
0N/A
0N/Aclass DirContextNamePair {
0N/A DirContext ctx;
0N/A Name name;
0N/A
0N/A DirContextNamePair(DirContext ctx, Name name) {
0N/A this.ctx = ctx;
0N/A this.name = name;
0N/A }
0N/A
0N/A DirContext getDirContext() {
0N/A return ctx;
0N/A }
0N/A
0N/A Name getName() {
0N/A return name;
0N/A }
0N/A}
0N/A
0N/Aclass DirContextStringPair {
0N/A DirContext ctx;
0N/A String str;
0N/A
0N/A DirContextStringPair(DirContext ctx, String str) {
0N/A this.ctx = ctx;
0N/A this.str = str;
0N/A }
0N/A
0N/A DirContext getDirContext() {
0N/A return ctx;
0N/A }
0N/A
0N/A String getString() {
0N/A return str;
0N/A }
0N/A}