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,246 @@
/*
* 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 javax.naming.spi;
import java.util.Hashtable;
import javax.naming.*;
/**
* This class is for dealing with federations/continuations.
*
* @author Rosanna Lee
* @author Scott Seligman
* @since 1.3
*/
class ContinuationContext implements Context, Resolver {
protected CannotProceedException cpe;
protected Hashtable<?,?> env;
protected Context contCtx = null;
protected ContinuationContext(CannotProceedException cpe,
Hashtable<?,?> env) {
this.cpe = cpe;
this.env = env;
}
protected Context getTargetContext() throws NamingException {
if (contCtx == null) {
if (cpe.getResolvedObj() == null)
throw (NamingException)cpe.fillInStackTrace();
contCtx = NamingManager.getContext(cpe.getResolvedObj(),
cpe.getAltName(),
cpe.getAltNameCtx(),
env);
if (contCtx == null)
throw (NamingException)cpe.fillInStackTrace();
}
return contCtx;
}
public Object lookup(Name name) throws NamingException {
Context ctx = getTargetContext();
return ctx.lookup(name);
}
public Object lookup(String name) throws NamingException {
Context ctx = getTargetContext();
return ctx.lookup(name);
}
public void bind(Name name, Object newObj) throws NamingException {
Context ctx = getTargetContext();
ctx.bind(name, newObj);
}
public void bind(String name, Object newObj) throws NamingException {
Context ctx = getTargetContext();
ctx.bind(name, newObj);
}
public void rebind(Name name, Object newObj) throws NamingException {
Context ctx = getTargetContext();
ctx.rebind(name, newObj);
}
public void rebind(String name, Object newObj) throws NamingException {
Context ctx = getTargetContext();
ctx.rebind(name, newObj);
}
public void unbind(Name name) throws NamingException {
Context ctx = getTargetContext();
ctx.unbind(name);
}
public void unbind(String name) throws NamingException {
Context ctx = getTargetContext();
ctx.unbind(name);
}
public void rename(Name name, Name newName) throws NamingException {
Context ctx = getTargetContext();
ctx.rename(name, newName);
}
public void rename(String name, String newName) throws NamingException {
Context ctx = getTargetContext();
ctx.rename(name, newName);
}
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
Context ctx = getTargetContext();
return ctx.list(name);
}
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
Context ctx = getTargetContext();
return ctx.list(name);
}
public NamingEnumeration<Binding> listBindings(Name name)
throws NamingException
{
Context ctx = getTargetContext();
return ctx.listBindings(name);
}
public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
Context ctx = getTargetContext();
return ctx.listBindings(name);
}
public void destroySubcontext(Name name) throws NamingException {
Context ctx = getTargetContext();
ctx.destroySubcontext(name);
}
public void destroySubcontext(String name) throws NamingException {
Context ctx = getTargetContext();
ctx.destroySubcontext(name);
}
public Context createSubcontext(Name name) throws NamingException {
Context ctx = getTargetContext();
return ctx.createSubcontext(name);
}
public Context createSubcontext(String name) throws NamingException {
Context ctx = getTargetContext();
return ctx.createSubcontext(name);
}
public Object lookupLink(Name name) throws NamingException {
Context ctx = getTargetContext();
return ctx.lookupLink(name);
}
public Object lookupLink(String name) throws NamingException {
Context ctx = getTargetContext();
return ctx.lookupLink(name);
}
public NameParser getNameParser(Name name) throws NamingException {
Context ctx = getTargetContext();
return ctx.getNameParser(name);
}
public NameParser getNameParser(String name) throws NamingException {
Context ctx = getTargetContext();
return ctx.getNameParser(name);
}
public Name composeName(Name name, Name prefix)
throws NamingException
{
Context ctx = getTargetContext();
return ctx.composeName(name, prefix);
}
public String composeName(String name, String prefix)
throws NamingException {
Context ctx = getTargetContext();
return ctx.composeName(name, prefix);
}
public Object addToEnvironment(String propName, Object value)
throws NamingException {
Context ctx = getTargetContext();
return ctx.addToEnvironment(propName, value);
}
public Object removeFromEnvironment(String propName)
throws NamingException {
Context ctx = getTargetContext();
return ctx.removeFromEnvironment(propName);
}
public Hashtable<?,?> getEnvironment() throws NamingException {
Context ctx = getTargetContext();
return ctx.getEnvironment();
}
public String getNameInNamespace() throws NamingException {
Context ctx = getTargetContext();
return ctx.getNameInNamespace();
}
public ResolveResult
resolveToClass(Name name, Class<? extends Context> contextType)
throws NamingException
{
if (cpe.getResolvedObj() == null)
throw (NamingException)cpe.fillInStackTrace();
Resolver res = NamingManager.getResolver(cpe.getResolvedObj(),
cpe.getAltName(),
cpe.getAltNameCtx(),
env);
if (res == null)
throw (NamingException)cpe.fillInStackTrace();
return res.resolveToClass(name, contextType);
}
public ResolveResult
resolveToClass(String name, Class<? extends Context> contextType)
throws NamingException
{
if (cpe.getResolvedObj() == null)
throw (NamingException)cpe.fillInStackTrace();
Resolver res = NamingManager.getResolver(cpe.getResolvedObj(),
cpe.getAltName(),
cpe.getAltNameCtx(),
env);
if (res == null)
throw (NamingException)cpe.fillInStackTrace();
return res.resolveToClass(name, contextType);
}
public void close() throws NamingException {
cpe = null;
env = null;
if (contCtx != null) {
contCtx.close();
contCtx = null;
}
}
}

View File

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

View File

@@ -0,0 +1,132 @@
/*
* 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 javax.naming.spi;
import java.util.Hashtable;
import javax.naming.*;
import javax.naming.directory.Attributes;
/**
* This interface represents a factory for creating an object given
* an object and attributes about the object.
*<p>
* The JNDI framework allows for object implementations to
* be loaded in dynamically via <em>object factories</em>. See
* <tt>ObjectFactory</tt> for details.
* <p>
* A <tt>DirObjectFactory</tt> extends <tt>ObjectFactory</tt> by allowing
* an <tt>Attributes</tt> instance
* to be supplied to the <tt>getObjectInstance()</tt> method.
* <tt>DirObjectFactory</tt> implementations are intended to be used by <tt>DirContext</tt>
* service providers. The service provider, in addition reading an
* object from the directory, might already have attributes that
* are useful for the object factory to check to see whether the
* factory is supposed to process the object. For instance, an LDAP-style
* service provider might have read the "objectclass" of the object.
* A CORBA object factory might be interested only in LDAP entries
* with "objectclass=corbaObject". By using the attributes supplied by
* the LDAP service provider, the CORBA object factory can quickly
* eliminate objects that it need not worry about, and non-CORBA object
* factories can quickly eliminate CORBA-related LDAP entries.
*
* @author Rosanna Lee
* @author Scott Seligman
*
* @see NamingManager#getObjectInstance
* @see DirectoryManager#getObjectInstance
* @see ObjectFactory
* @since 1.3
*/
public interface DirObjectFactory extends ObjectFactory {
/**
* Creates an object using the location or reference information, and attributes
* specified.
* <p>
* Special requirements of this object are supplied
* using <code>environment</code>.
* An example of such an environment property is user identity
* information.
*<p>
* <tt>DirectoryManager.getObjectInstance()</tt>
* successively loads in object factories. If it encounters a <tt>DirObjectFactory</tt>,
* it will invoke <tt>DirObjectFactory.getObjectInstance()</tt>;
* otherwise, it invokes
* <tt>ObjectFactory.getObjectInstance()</tt>. It does this until a factory
* produces a non-null answer.
* <p> When an exception
* is thrown by an object factory, the exception is passed on to the caller
* of <tt>DirectoryManager.getObjectInstance()</tt>. The search for other factories
* that may produce a non-null answer is halted.
* An object factory should only throw an exception if it is sure that
* it is the only intended factory and that no other object factories
* should be tried.
* If this factory cannot create an object using the arguments supplied,
* it should return null.
*<p>Since <tt>DirObjectFactory</tt> extends <tt>ObjectFactory</tt>, it
* effectively
* has two <tt>getObjectInstance()</tt> methods, where one differs from the other by
* the attributes argument. Given a factory that implements <tt>DirObjectFactory</tt>,
* <tt>DirectoryManager.getObjectInstance()</tt> will only
* use the method that accepts the attributes argument, while
* <tt>NamingManager.getObjectInstance()</tt> will only use the one that does not accept
* the attributes argument.
*<p>
* See <tt>ObjectFactory</tt> for a description URL context factories and other
* properties of object factories that apply equally to <tt>DirObjectFactory</tt>.
*<p>
* The <tt>name</tt>, <tt>attrs</tt>, and <tt>environment</tt> parameters
* are owned by the caller.
* The implementation will not modify these objects or keep references
* to them, although it may keep references to clones or copies.
*
* @param obj The possibly null object containing location or reference
* information that can be used in creating an object.
* @param name The name of this object relative to <code>nameCtx</code>,
* or null if no name is specified.
* @param nameCtx The context relative to which the <code>name</code>
* parameter is specified, or null if <code>name</code> is
* relative to the default initial context.
* @param environment The possibly null environment that is used in
* creating the object.
* @param attrs The possibly null attributes containing some of <tt>obj</tt>'s
* attributes. <tt>attrs</tt> might not necessarily have all of <tt>obj</tt>'s
* attributes. If the object factory requires more attributes, it needs
* to get it, either using <tt>obj</tt>, or <tt>name</tt> and <tt>nameCtx</tt>.
* The factory must not modify attrs.
* @return The object created; null if an object cannot be created.
* @exception Exception If this object factory encountered an exception
* while attempting to create an object, and no other object factories are
* to be tried.
*
* @see DirectoryManager#getObjectInstance
* @see NamingManager#getURLContext
*/
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
Hashtable<?,?> environment,
Attributes attrs)
throws Exception;
}

View File

@@ -0,0 +1,188 @@
/*
* 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 javax.naming.spi;
import javax.naming.*;
import javax.naming.directory.Attributes;
import java.util.Hashtable;
/**
* This interface represents a factory for obtaining the state of an
* object and corresponding attributes for binding.
*<p>
* The JNDI framework allows for object implementations to
* be loaded in dynamically via <tt>object factories</tt>.
* <p>
* A <tt>DirStateFactory</tt> extends <tt>StateFactory</tt>
* by allowing an <tt>Attributes</tt> instance
* to be supplied to and be returned by the <tt>getStateToBind()</tt> method.
* <tt>DirStateFactory</tt> implementations are intended to be used by
* <tt>DirContext</tt> service providers.
* When a caller binds an object using <tt>DirContext.bind()</tt>,
* he might also specify a set of attributes to be bound with the object.
* The object and attributes to be bound are passed to
* the <tt>getStateToBind()</tt> method of a factory.
* If the factory processes the object and attributes, it returns
* a corresponding pair of object and attributes to be bound.
* If the factory does not process the object, it must return null.
*<p>
* For example, a caller might bind a printer object with some printer-related
* attributes.
*<blockquote><pre>
* ctx.rebind("inky", printer, printerAttrs);
*</pre></blockquote>
* An LDAP service provider for <tt>ctx</tt> uses a <tt>DirStateFactory</tt>
* (indirectly via <tt>DirectoryManager.getStateToBind()</tt>)
* and gives it <tt>printer</tt> and <tt>printerAttrs</tt>. A factory for
* an LDAP directory might turn <tt>printer</tt> into a set of attributes
* and merge that with <tt>printerAttrs</tt>. The service provider then
* uses the resulting attributes to create an LDAP entry and updates
* the directory.
*
* <p> Since <tt>DirStateFactory</tt> extends <tt>StateFactory</tt>, it
* has two <tt>getStateToBind()</tt> methods, where one
* differs from the other by the attributes
* argument. <tt>DirectoryManager.getStateToBind()</tt> will only use
* the form that accepts the attributes argument, while
* <tt>NamingManager.getStateToBind()</tt> will only use the form that
* does not accept the attributes argument.
*
* <p> Either form of the <tt>getStateToBind()</tt> method of a
* DirStateFactory may be invoked multiple times, possibly using different
* parameters. The implementation is thread-safe.
*
* @author Rosanna Lee
* @author Scott Seligman
*
* @see DirectoryManager#getStateToBind
* @see DirObjectFactory
* @since 1.3
*/
public interface DirStateFactory extends StateFactory {
/**
* Retrieves the state of an object for binding given the object and attributes
* to be transformed.
*<p>
* <tt>DirectoryManager.getStateToBind()</tt>
* successively loads in state factories. If a factory implements
* <tt>DirStateFactory</tt>, <tt>DirectoryManager</tt> invokes this method;
* otherwise, it invokes <tt>StateFactory.getStateToBind()</tt>.
* It does this until a factory produces a non-null answer.
*<p>
* When an exception is thrown by a factory,
* the exception is passed on to the caller
* of <tt>DirectoryManager.getStateToBind()</tt>. The search for other factories
* that may produce a non-null answer is halted.
* A factory should only throw an exception if it is sure that
* it is the only intended factory and that no other factories
* should be tried.
* If this factory cannot create an object using the arguments supplied,
* it should return null.
* <p>
* The <code>name</code> and <code>nameCtx</code> parameters may
* optionally be used to specify the name of the object being created.
* See the description of "Name and Context Parameters" in
* {@link ObjectFactory#getObjectInstance ObjectFactory.getObjectInstance()}
* for details.
* If a factory uses <code>nameCtx</code> it should synchronize its use
* against concurrent access, since context implementations are not
* guaranteed to be thread-safe.
*<p>
* The <tt>name</tt>, <tt>inAttrs</tt>, and <tt>environment</tt> parameters
* are owned by the caller.
* The implementation will not modify these objects or keep references
* to them, although it may keep references to clones or copies.
* The object returned by this method is owned by the caller.
* The implementation will not subsequently modify it.
* It will contain either a new <tt>Attributes</tt> object that is
* likewise owned by the caller, or a reference to the original
* <tt>inAttrs</tt> parameter.
*
* @param obj A possibly null object whose state is to be retrieved.
* @param name The name of this object relative to <code>nameCtx</code>,
* or null if no name is specified.
* @param nameCtx The context relative to which the <code>name</code>
* parameter is specified, or null if <code>name</code> is
* relative to the default initial context.
* @param environment The possibly null environment to
* be used in the creation of the object's state.
* @param inAttrs The possibly null attributes to be bound with the object.
* The factory must not modify <tt>inAttrs</tt>.
* @return A <tt>Result</tt> containing the object's state for binding
* and the corresponding
* attributes to be bound; null if the object don't use this factory.
* @exception NamingException If this factory encountered an exception
* while attempting to get the object's state, and no other factories are
* to be tried.
*
* @see DirectoryManager#getStateToBind
*/
public Result getStateToBind(Object obj, Name name, Context nameCtx,
Hashtable<?,?> environment,
Attributes inAttrs)
throws NamingException;
/**
* An object/attributes pair for returning the result of
* DirStateFactory.getStateToBind().
*/
public static class Result {
/**
* The possibly null object to be bound.
*/
private Object obj;
/**
* The possibly null attributes to be bound.
*/
private Attributes attrs;
/**
* Constructs an instance of Result.
*
* @param obj The possibly null object to be bound.
* @param outAttrs The possibly null attributes to be bound.
*/
public Result(Object obj, Attributes outAttrs) {
this.obj = obj;
this.attrs = outAttrs;
}
/**
* Retrieves the object to be bound.
* @return The possibly null object to be bound.
*/
public Object getObject() { return obj; };
/**
* Retrieves the attributes to be bound.
* @return The possibly null attributes to be bound.
*/
public Attributes getAttributes() { return attrs; };
}
}

View File

@@ -0,0 +1,338 @@
/*
* 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 javax.naming.spi;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.Reference;
import javax.naming.Referenceable;
import javax.naming.NamingException;
import javax.naming.CannotProceedException;
import javax.naming.directory.DirContext;
import javax.naming.directory.Attributes;
import com.sun.naming.internal.ResourceManager;
import com.sun.naming.internal.FactoryEnumeration;
/**
* This class contains methods for supporting <tt>DirContext</tt>
* implementations.
*<p>
* This class is an extension of <tt>NamingManager</tt>. It contains methods
* for use by service providers for accessing object factories and
* state factories, and for getting continuation contexts for
* supporting federation.
*<p>
* <tt>DirectoryManager</tt> is safe for concurrent access by multiple threads.
*<p>
* Except as otherwise noted,
* a <tt>Name</tt>, <tt>Attributes</tt>, or environment parameter
* passed to any method is owned by the caller.
* The implementation will not modify the object or keep a reference
* to it, although it may keep a reference to a clone or copy.
*
* @author Rosanna Lee
* @author Scott Seligman
*
* @see DirObjectFactory
* @see DirStateFactory
* @since 1.3
*/
public class DirectoryManager extends NamingManager {
/*
* Disallow anyone from creating one of these.
*/
DirectoryManager() {}
/**
* Creates a context in which to continue a <tt>DirContext</tt> operation.
* Operates just like <tt>NamingManager.getContinuationContext()</tt>,
* only the continuation context returned is a <tt>DirContext</tt>.
*
* @param cpe
* The non-null exception that triggered this continuation.
* @return A non-null <tt>DirContext</tt> object for continuing the operation.
* @exception NamingException If a naming exception occurred.
*
* @see NamingManager#getContinuationContext(CannotProceedException)
*/
@SuppressWarnings("unchecked")
public static DirContext getContinuationDirContext(
CannotProceedException cpe) throws NamingException {
Hashtable<Object,Object> env = (Hashtable<Object,Object>)cpe.getEnvironment();
if (env == null) {
env = new Hashtable<>(7);
} else {
// Make a (shallow) copy of the environment.
env = (Hashtable<Object,Object>) env.clone();
}
env.put(CPE, cpe);
return (new ContinuationDirContext(cpe, env));
}
/**
* Creates an instance of an object for the specified object,
* attributes, and environment.
* <p>
* This method is the same as <tt>NamingManager.getObjectInstance</tt>
* except for the following differences:
*<ul>
*<li>
* It accepts an <tt>Attributes</tt> parameter that contains attributes
* associated with the object. The <tt>DirObjectFactory</tt> might use these
* attributes to save having to look them up from the directory.
*<li>
* The object factories tried must implement either
* <tt>ObjectFactory</tt> or <tt>DirObjectFactory</tt>.
* If it implements <tt>DirObjectFactory</tt>,
* <tt>DirObjectFactory.getObjectInstance()</tt> is used, otherwise,
* <tt>ObjectFactory.getObjectInstance()</tt> is used.
*</ul>
* Service providers that implement the <tt>DirContext</tt> interface
* should use this method, not <tt>NamingManager.getObjectInstance()</tt>.
*<p>
*
* @param refInfo The possibly null object for which to create an object.
* @param name The name of this object relative to <code>nameCtx</code>.
* Specifying a name is optional; if it is
* omitted, <code>name</code> should be null.
* @param nameCtx The context relative to which the <code>name</code>
* parameter is specified. If null, <code>name</code> is
* relative to the default initial context.
* @param environment The possibly null environment to
* be used in the creation of the object factory and the object.
* @param attrs The possibly null attributes associated with refInfo.
* This might not be the complete set of attributes for refInfo;
* you might be able to read more attributes from the directory.
* @return An object created using <code>refInfo</code> and <tt>attrs</tt>; or
* <code>refInfo</code> if an object cannot be created by
* a factory.
* @exception NamingException If a naming exception was encountered
* while attempting to get a URL context, or if one of the
* factories accessed throws a NamingException.
* @exception Exception If one of the factories accessed throws an
* exception, or if an error was encountered while loading
* and instantiating the factory and object classes.
* A factory should only throw an exception if it does not want
* other factories to be used in an attempt to create an object.
* See <tt>DirObjectFactory.getObjectInstance()</tt>.
* @see NamingManager#getURLContext
* @see DirObjectFactory
* @see DirObjectFactory#getObjectInstance
* @since 1.3
*/
public static Object
getObjectInstance(Object refInfo, Name name, Context nameCtx,
Hashtable<?,?> environment, Attributes attrs)
throws Exception {
ObjectFactory factory;
ObjectFactoryBuilder builder = getObjectFactoryBuilder();
if (builder != null) {
// builder must return non-null factory
factory = builder.createObjectFactory(refInfo, environment);
if (factory instanceof DirObjectFactory) {
return ((DirObjectFactory)factory).getObjectInstance(
refInfo, name, nameCtx, environment, attrs);
} else {
return factory.getObjectInstance(refInfo, name, nameCtx,
environment);
}
}
// use reference if possible
Reference ref = null;
if (refInfo instanceof Reference) {
ref = (Reference) refInfo;
} else if (refInfo instanceof Referenceable) {
ref = ((Referenceable)(refInfo)).getReference();
}
Object answer;
if (ref != null) {
String f = ref.getFactoryClassName();
if (f != null) {
// if reference identifies a factory, use exclusively
factory = getObjectFactoryFromReference(ref, f);
if (factory instanceof DirObjectFactory) {
return ((DirObjectFactory)factory).getObjectInstance(
ref, name, nameCtx, environment, attrs);
} else if (factory != null) {
return factory.getObjectInstance(ref, name, nameCtx,
environment);
}
// No factory found, so return original refInfo.
// Will reach this point if factory class is not in
// class path and reference does not contain a URL for it
return refInfo;
} else {
// if reference has no factory, check for addresses
// containing URLs
// ignore name & attrs params; not used in URL factory
answer = processURLAddrs(ref, name, nameCtx, environment);
if (answer != null) {
return answer;
}
}
}
// try using any specified factories
answer = createObjectFromFactories(refInfo, name, nameCtx,
environment, attrs);
return (answer != null) ? answer : refInfo;
}
private static Object createObjectFromFactories(Object obj, Name name,
Context nameCtx, Hashtable<?,?> environment, Attributes attrs)
throws Exception {
FactoryEnumeration factories = ResourceManager.getFactories(
Context.OBJECT_FACTORIES, environment, nameCtx);
if (factories == null)
return null;
ObjectFactory factory;
Object answer = null;
// Try each factory until one succeeds
while (answer == null && factories.hasMore()) {
factory = (ObjectFactory)factories.next();
if (factory instanceof DirObjectFactory) {
answer = ((DirObjectFactory)factory).
getObjectInstance(obj, name, nameCtx, environment, attrs);
} else {
answer =
factory.getObjectInstance(obj, name, nameCtx, environment);
}
}
return answer;
}
/**
* Retrieves the state of an object for binding when given the original
* object and its attributes.
* <p>
* This method is like <tt>NamingManager.getStateToBind</tt> except
* for the following differences:
*<ul>
*<li>It accepts an <tt>Attributes</tt> parameter containing attributes
* that were passed to the <tt>DirContext.bind()</tt> method.
*<li>It returns a non-null <tt>DirStateFactory.Result</tt> instance
* containing the object to be bound, and the attributes to
* accompany the binding. Either the object or the attributes may be null.
*<li>
* The state factories tried must each implement either
* <tt>StateFactory</tt> or <tt>DirStateFactory</tt>.
* If it implements <tt>DirStateFactory</tt>, then
* <tt>DirStateFactory.getStateToBind()</tt> is called; otherwise,
* <tt>StateFactory.getStateToBind()</tt> is called.
*</ul>
*
* Service providers that implement the <tt>DirContext</tt> interface
* should use this method, not <tt>NamingManager.getStateToBind()</tt>.
*<p>
* See NamingManager.getStateToBind() for a description of how
* the list of state factories to be tried is determined.
*<p>
* The object returned by this method is owned by the caller.
* The implementation will not subsequently modify it.
* It will contain either a new <tt>Attributes</tt> object that is
* likewise owned by the caller, or a reference to the original
* <tt>attrs</tt> parameter.
*
* @param obj The non-null object for which to get state to bind.
* @param name The name of this object relative to <code>nameCtx</code>,
* or null if no name is specified.
* @param nameCtx The context relative to which the <code>name</code>
* parameter is specified, or null if <code>name</code> is
* relative to the default initial context.
* @param environment The possibly null environment to
* be used in the creation of the state factory and
* the object's state.
* @param attrs The possibly null Attributes that is to be bound with the
* object.
* @return A non-null DirStateFactory.Result containing
* the object and attributes to be bound.
* If no state factory returns a non-null answer, the result will contain
* the object (<tt>obj</tt>) itself with the original attributes.
* @exception NamingException If a naming exception was encountered
* while using the factories.
* A factory should only throw an exception if it does not want
* other factories to be used in an attempt to create an object.
* See <tt>DirStateFactory.getStateToBind()</tt>.
* @see DirStateFactory
* @see DirStateFactory#getStateToBind
* @see NamingManager#getStateToBind
* @since 1.3
*/
public static DirStateFactory.Result
getStateToBind(Object obj, Name name, Context nameCtx,
Hashtable<?,?> environment, Attributes attrs)
throws NamingException {
// Get list of state factories
FactoryEnumeration factories = ResourceManager.getFactories(
Context.STATE_FACTORIES, environment, nameCtx);
if (factories == null) {
// no factories to try; just return originals
return new DirStateFactory.Result(obj, attrs);
}
// Try each factory until one succeeds
StateFactory factory;
Object objanswer;
DirStateFactory.Result answer = null;
while (answer == null && factories.hasMore()) {
factory = (StateFactory)factories.next();
if (factory instanceof DirStateFactory) {
answer = ((DirStateFactory)factory).
getStateToBind(obj, name, nameCtx, environment, attrs);
} else {
objanswer =
factory.getStateToBind(obj, name, nameCtx, environment);
if (objanswer != null) {
answer = new DirStateFactory.Result(objanswer, attrs);
}
}
}
return (answer != null) ? answer :
new DirStateFactory.Result(obj, attrs); // nothing new
}
}

View File

@@ -0,0 +1,72 @@
/*
* 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 javax.naming.spi;
import java.util.Hashtable;
import javax.naming.*;
/**
* This interface represents a factory that creates an initial context.
*<p>
* The JNDI framework allows for different initial context implementations
* to be specified at runtime. The initial context is created using
* an <em>initial context factory</em>.
* An initial context factory must implement the InitialContextFactory
* interface, which provides a method for creating instances of initial
* context that implement the Context interface.
* In addition, the factory class must be public and must have a public
* constructor that accepts no arguments.
*
* @author Rosanna Lee
* @author Scott Seligman
*
* @see InitialContextFactoryBuilder
* @see NamingManager#getInitialContext
* @see javax.naming.InitialContext
* @see javax.naming.directory.InitialDirContext
* @since 1.3
*/
public interface InitialContextFactory {
/**
* Creates an Initial Context for beginning name resolution.
* Special requirements of this context are supplied
* using <code>environment</code>.
*<p>
* The environment parameter is owned by the caller.
* The implementation will not modify the object or keep a reference
* to it, although it may keep a reference to a clone or copy.
*
* @param environment The possibly null environment
* specifying information to be used in the creation
* of the initial context.
* @return A non-null initial context object that implements the Context
* interface.
* @exception NamingException If cannot create an initial context.
*/
public Context getInitialContext(Hashtable<?,?> environment)
throws NamingException;
}

View File

@@ -0,0 +1,71 @@
/*
* 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 javax.naming.spi;
import java.util.Hashtable;
import javax.naming.NamingException;
/**
* This interface represents a builder that creates initial context factories.
*<p>
* The JNDI framework allows for different initial context implementations
* to be specified at runtime. An initial context is created using
* an initial context factory. A program can install its own builder
* that creates initial context factories, thereby overriding the
* default policies used by the framework, by calling
* NamingManager.setInitialContextFactoryBuilder().
* The InitialContextFactoryBuilder interface must be implemented by
* such a builder.
*
* @author Rosanna Lee
* @author Scott Seligman
*
* @see InitialContextFactory
* @see NamingManager#getInitialContext
* @see NamingManager#setInitialContextFactoryBuilder
* @see NamingManager#hasInitialContextFactoryBuilder
* @see javax.naming.InitialContext
* @see javax.naming.directory.InitialDirContext
* @since 1.3
*/
public interface InitialContextFactoryBuilder {
/**
* Creates an initial context factory using the specified
* environment.
*<p>
* The environment parameter is owned by the caller.
* The implementation will not modify the object or keep a reference
* to it, although it may keep a reference to a clone or copy.
*
* @param environment Environment used in creating an initial
* context implementation. Can be null.
* @return A non-null initial context factory.
* @exception NamingException If an initial context factory could not be created.
*/
public InitialContextFactory
createInitialContextFactory(Hashtable<?,?> environment)
throws NamingException;
}

View File

@@ -0,0 +1,886 @@
/*
* Copyright (c) 1999, 2012, 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 javax.naming.spi;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.net.MalformedURLException;
import javax.naming.*;
import com.sun.naming.internal.ObjectFactoriesFilter;
import com.sun.naming.internal.VersionHelper;
import com.sun.naming.internal.ResourceManager;
import com.sun.naming.internal.FactoryEnumeration;
/**
* This class contains methods for creating context objects
* and objects referred to by location information in the naming
* or directory service.
*<p>
* This class cannot be instantiated. It has only static methods.
*<p>
* The mention of URL in the documentation for this class refers to
* a URL string as defined by RFC 1738 and its related RFCs. It is
* any string that conforms to the syntax described therein, and
* may not always have corresponding support in the java.net.URL
* class or Web browsers.
*<p>
* NamingManager is safe for concurrent access by multiple threads.
*<p>
* Except as otherwise noted,
* a <tt>Name</tt> or environment parameter
* passed to any method is owned by the caller.
* The implementation will not modify the object or keep a reference
* to it, although it may keep a reference to a clone or copy.
*
* @author Rosanna Lee
* @author Scott Seligman
* @since 1.3
*/
public class NamingManager {
/*
* Disallow anyone from creating one of these.
* Made package private so that DirectoryManager can subclass.
*/
NamingManager() {}
// should be protected and package private
static final VersionHelper helper = VersionHelper.getVersionHelper();
// --------- object factory stuff
/**
* Package-private; used by DirectoryManager and NamingManager.
*/
private static ObjectFactoryBuilder object_factory_builder = null;
/**
* The ObjectFactoryBuilder determines the policy used when
* trying to load object factories.
* See getObjectInstance() and class ObjectFactory for a description
* of the default policy.
* setObjectFactoryBuilder() overrides this default policy by installing
* an ObjectFactoryBuilder. Subsequent object factories will
* be loaded and created using the installed builder.
*<p>
* The builder can only be installed if the executing thread is allowed
* (by the security manager's checkSetFactory() method) to do so.
* Once installed, the builder cannot be replaced.
*<p>
* @param builder The factory builder to install. If null, no builder
* is installed.
* @exception SecurityException builder cannot be installed
* for security reasons.
* @exception NamingException builder cannot be installed for
* a non-security-related reason.
* @exception IllegalStateException If a factory has already been installed.
* @see #getObjectInstance
* @see ObjectFactory
* @see ObjectFactoryBuilder
* @see java.lang.SecurityManager#checkSetFactory
*/
public static synchronized void setObjectFactoryBuilder(
ObjectFactoryBuilder builder) throws NamingException {
if (object_factory_builder != null)
throw new IllegalStateException("ObjectFactoryBuilder already set");
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkSetFactory();
}
object_factory_builder = builder;
}
/**
* Used for accessing object factory builder.
*/
static synchronized ObjectFactoryBuilder getObjectFactoryBuilder() {
return object_factory_builder;
}
/**
* Retrieves the ObjectFactory for the object identified by a reference,
* using the reference's factory class name and factory codebase
* to load in the factory's class.
* @param ref The non-null reference to use.
* @param factoryName The non-null class name of the factory.
* @return The object factory for the object identified by ref; null
* if unable to load the factory.
*/
static ObjectFactory getObjectFactoryFromReference(
Reference ref, String factoryName)
throws IllegalAccessException,
InstantiationException,
MalformedURLException {
Class<?> clas = null;
// Try to use current class loader
try {
clas = helper.loadClassWithoutInit(factoryName);
// Validate factory's class with the objects factory serial filter
if (!ObjectFactoriesFilter.canInstantiateObjectsFactory(clas)) {
return null;
}
} catch (ClassNotFoundException e) {
// ignore and continue
// e.printStackTrace();
}
// All other exceptions are passed up.
// Not in class path; try to use codebase
String codebase;
if (clas == null &&
(codebase = ref.getFactoryClassLocation()) != null) {
try {
clas = helper.loadClass(factoryName, codebase);
// Validate factory's class with the objects factory serial filter
if (clas == null ||
!ObjectFactoriesFilter.canInstantiateObjectsFactory(clas)) {
return null;
}
} catch (ClassNotFoundException e) {
}
}
return (clas != null) ? (ObjectFactory) clas.newInstance() : null;
}
/**
* Creates an object using the factories specified in the
* <tt>Context.OBJECT_FACTORIES</tt> property of the environment
* or of the provider resource file associated with <tt>nameCtx</tt>.
*
* @return factory created; null if cannot create
*/
private static Object createObjectFromFactories(Object obj, Name name,
Context nameCtx, Hashtable<?,?> environment) throws Exception {
FactoryEnumeration factories = ResourceManager.getFactories(
Context.OBJECT_FACTORIES, environment, nameCtx);
if (factories == null)
return null;
// Try each factory until one succeeds
ObjectFactory factory;
Object answer = null;
while (answer == null && factories.hasMore()) {
factory = (ObjectFactory)factories.next();
answer = factory.getObjectInstance(obj, name, nameCtx, environment);
}
return answer;
}
private static String getURLScheme(String str) {
int colon_posn = str.indexOf(':');
int slash_posn = str.indexOf('/');
if (colon_posn > 0 && (slash_posn == -1 || colon_posn < slash_posn))
return str.substring(0, colon_posn);
return null;
}
/**
* Creates an instance of an object for the specified object
* and environment.
* <p>
* If an object factory builder has been installed, it is used to
* create a factory for creating the object.
* Otherwise, the following rules are used to create the object:
*<ol>
* <li>If <code>refInfo</code> is a <code>Reference</code>
* or <code>Referenceable</code> containing a factory class name,
* use the named factory to create the object.
* Return <code>refInfo</code> if the factory cannot be created.
* Under JDK 1.1, if the factory class must be loaded from a location
* specified in the reference, a <tt>SecurityManager</tt> must have
* been installed or the factory creation will fail.
* If an exception is encountered while creating the factory,
* it is passed up to the caller.
* <li>If <tt>refInfo</tt> is a <tt>Reference</tt> or
* <tt>Referenceable</tt> with no factory class name,
* and the address or addresses are <tt>StringRefAddr</tt>s with
* address type "URL",
* try the URL context factory corresponding to each URL's scheme id
* to create the object (see <tt>getURLContext()</tt>).
* If that fails, continue to the next step.
* <li> Use the object factories specified in
* the <tt>Context.OBJECT_FACTORIES</tt> property of the environment,
* and of the provider resource file associated with
* <tt>nameCtx</tt>, in that order.
* The value of this property is a colon-separated list of factory
* class names that are tried in order, and the first one that succeeds
* in creating an object is the one used.
* If none of the factories can be loaded,
* return <code>refInfo</code>.
* If an exception is encountered while creating the object, the
* exception is passed up to the caller.
*</ol>
*<p>
* Service providers that implement the <tt>DirContext</tt>
* interface should use
* <tt>DirectoryManager.getObjectInstance()</tt>, not this method.
* Service providers that implement only the <tt>Context</tt>
* interface should use this method.
* <p>
* Note that an object factory (an object that implements the ObjectFactory
* interface) must be public and must have a public constructor that
* accepts no arguments.
* <p>
* The <code>name</code> and <code>nameCtx</code> parameters may
* optionally be used to specify the name of the object being created.
* <code>name</code> is the name of the object, relative to context
* <code>nameCtx</code>. This information could be useful to the object
* factory or to the object implementation.
* If there are several possible contexts from which the object
* could be named -- as will often be the case -- it is up to
* the caller to select one. A good rule of thumb is to select the
* "deepest" context available.
* If <code>nameCtx</code> is null, <code>name</code> is relative
* to the default initial context. If no name is being specified, the
* <code>name</code> parameter should be null.
*
* @param refInfo The possibly null object for which to create an object.
* @param name The name of this object relative to <code>nameCtx</code>.
* Specifying a name is optional; if it is
* omitted, <code>name</code> should be null.
* @param nameCtx The context relative to which the <code>name</code>
* parameter is specified. If null, <code>name</code> is
* relative to the default initial context.
* @param environment The possibly null environment to
* be used in the creation of the object factory and the object.
* @return An object created using <code>refInfo</code>; or
* <code>refInfo</code> if an object cannot be created using
* the algorithm described above.
* @exception NamingException if a naming exception was encountered
* while attempting to get a URL context, or if one of the
* factories accessed throws a NamingException.
* @exception Exception if one of the factories accessed throws an
* exception, or if an error was encountered while loading
* and instantiating the factory and object classes.
* A factory should only throw an exception if it does not want
* other factories to be used in an attempt to create an object.
* See ObjectFactory.getObjectInstance().
* @see #getURLContext
* @see ObjectFactory
* @see ObjectFactory#getObjectInstance
*/
public static Object
getObjectInstance(Object refInfo, Name name, Context nameCtx,
Hashtable<?,?> environment)
throws Exception
{
ObjectFactory factory;
// Use builder if installed
ObjectFactoryBuilder builder = getObjectFactoryBuilder();
if (builder != null) {
// builder must return non-null factory
factory = builder.createObjectFactory(refInfo, environment);
return factory.getObjectInstance(refInfo, name, nameCtx,
environment);
}
// Use reference if possible
Reference ref = null;
if (refInfo instanceof Reference) {
ref = (Reference) refInfo;
} else if (refInfo instanceof Referenceable) {
ref = ((Referenceable)(refInfo)).getReference();
}
Object answer;
if (ref != null) {
String f = ref.getFactoryClassName();
if (f != null) {
// if reference identifies a factory, use exclusively
factory = getObjectFactoryFromReference(ref, f);
if (factory != null) {
return factory.getObjectInstance(ref, name, nameCtx,
environment);
}
// No factory found, so return original refInfo.
// Will reach this point if factory class is not in
// class path and reference does not contain a URL for it
return refInfo;
} else {
// if reference has no factory, check for addresses
// containing URLs
answer = processURLAddrs(ref, name, nameCtx, environment);
if (answer != null) {
return answer;
}
}
}
// try using any specified factories
answer =
createObjectFromFactories(refInfo, name, nameCtx, environment);
return (answer != null) ? answer : refInfo;
}
/*
* Ref has no factory. For each address of type "URL", try its URL
* context factory. Returns null if unsuccessful in creating and
* invoking a factory.
*/
static Object processURLAddrs(Reference ref, Name name, Context nameCtx,
Hashtable<?,?> environment)
throws NamingException {
for (int i = 0; i < ref.size(); i++) {
RefAddr addr = ref.get(i);
if (addr instanceof StringRefAddr &&
addr.getType().equalsIgnoreCase("URL")) {
String url = (String)addr.getContent();
Object answer = processURL(url, name, nameCtx, environment);
if (answer != null) {
return answer;
}
}
}
return null;
}
private static Object processURL(Object refInfo, Name name,
Context nameCtx, Hashtable<?,?> environment)
throws NamingException {
Object answer;
// If refInfo is a URL string, try to use its URL context factory
// If no context found, continue to try object factories.
if (refInfo instanceof String) {
String url = (String)refInfo;
String scheme = getURLScheme(url);
if (scheme != null) {
answer = getURLObject(scheme, refInfo, name, nameCtx,
environment);
if (answer != null) {
return answer;
}
}
}
// If refInfo is an array of URL strings,
// try to find a context factory for any one of its URLs.
// If no context found, continue to try object factories.
if (refInfo instanceof String[]) {
String[] urls = (String[])refInfo;
for (int i = 0; i <urls.length; i++) {
String scheme = getURLScheme(urls[i]);
if (scheme != null) {
answer = getURLObject(scheme, refInfo, name, nameCtx,
environment);
if (answer != null)
return answer;
}
}
}
return null;
}
/**
* Retrieves a context identified by <code>obj</code>, using the specified
* environment.
* Used by ContinuationContext.
*
* @param obj The object identifying the context.
* @param name The name of the context being returned, relative to
* <code>nameCtx</code>, or null if no name is being
* specified.
* See the <code>getObjectInstance</code> method for
* details.
* @param nameCtx The context relative to which <code>name</code> is
* specified, or null for the default initial context.
* See the <code>getObjectInstance</code> method for
* details.
* @param environment Environment specifying characteristics of the
* resulting context.
* @return A context identified by <code>obj</code>.
*
* @see #getObjectInstance
*/
static Context getContext(Object obj, Name name, Context nameCtx,
Hashtable<?,?> environment) throws NamingException {
Object answer;
if (obj instanceof Context) {
// %%% Ignore environment for now. OK since method not public.
return (Context)obj;
}
try {
answer = getObjectInstance(obj, name, nameCtx, environment);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
NamingException ne = new NamingException();
ne.setRootCause(e);
throw ne;
}
return (answer instanceof Context)
? (Context)answer
: null;
}
// Used by ContinuationContext
static Resolver getResolver(Object obj, Name name, Context nameCtx,
Hashtable<?,?> environment) throws NamingException {
Object answer;
if (obj instanceof Resolver) {
// %%% Ignore environment for now. OK since method not public.
return (Resolver)obj;
}
try {
answer = getObjectInstance(obj, name, nameCtx, environment);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
NamingException ne = new NamingException();
ne.setRootCause(e);
throw ne;
}
return (answer instanceof Resolver)
? (Resolver)answer
: null;
}
/***************** URL Context implementations ***************/
/**
* Creates a context for the given URL scheme id.
* <p>
* The resulting context is for resolving URLs of the
* scheme <code>scheme</code>. The resulting context is not tied
* to a specific URL. It is able to handle arbitrary URLs with
* the specified scheme.
*<p>
* The class name of the factory that creates the resulting context
* has the naming convention <i>scheme-id</i>URLContextFactory
* (e.g. "ftpURLContextFactory" for the "ftp" scheme-id),
* in the package specified as follows.
* The <tt>Context.URL_PKG_PREFIXES</tt> environment property (which
* may contain values taken from applet parameters, system properties,
* or application resource files)
* contains a colon-separated list of package prefixes.
* Each package prefix in
* the property is tried in the order specified to load the factory class.
* The default package prefix is "com.sun.jndi.url" (if none of the
* specified packages work, this default is tried).
* The complete package name is constructed using the package prefix,
* concatenated with the scheme id.
*<p>
* For example, if the scheme id is "ldap", and the
* <tt>Context.URL_PKG_PREFIXES</tt> property
* contains "com.widget:com.wiz.jndi",
* the naming manager would attempt to load the following classes
* until one is successfully instantiated:
*<ul>
* <li>com.widget.ldap.ldapURLContextFactory
* <li>com.wiz.jndi.ldap.ldapURLContextFactory
* <li>com.sun.jndi.url.ldap.ldapURLContextFactory
*</ul>
* If none of the package prefixes work, null is returned.
*<p>
* If a factory is instantiated, it is invoked with the following
* parameters to produce the resulting context.
* <p>
* <code>factory.getObjectInstance(null, environment);</code>
* <p>
* For example, invoking getObjectInstance() as shown above
* on a LDAP URL context factory would return a
* context that can resolve LDAP urls
* (e.g. "ldap://ldap.wiz.com/o=wiz,c=us",
* "ldap://ldap.umich.edu/o=umich,c=us", ...).
*<p>
* Note that an object factory (an object that implements the ObjectFactory
* interface) must be public and must have a public constructor that
* accepts no arguments.
*
* @param scheme The non-null scheme-id of the URLs supported by the context.
* @param environment The possibly null environment properties to be
* used in the creation of the object factory and the context.
* @return A context for resolving URLs with the
* scheme id <code>scheme</code>;
* <code>null</code> if the factory for creating the
* context is not found.
* @exception NamingException If a naming exception occurs while creating
* the context.
* @see #getObjectInstance
* @see ObjectFactory#getObjectInstance
*/
public static Context getURLContext(String scheme,
Hashtable<?,?> environment)
throws NamingException
{
// pass in 'null' to indicate creation of generic context for scheme
// (i.e. not specific to a URL).
Object answer = getURLObject(scheme, null, null, null, environment);
if (answer instanceof Context) {
return (Context)answer;
} else {
return null;
}
}
private static final String defaultPkgPrefix = "com.sun.jndi.url";
/**
* Creates an object for the given URL scheme id using
* the supplied urlInfo.
* <p>
* If urlInfo is null, the result is a context for resolving URLs
* with the scheme id 'scheme'.
* If urlInfo is a URL, the result is a context named by the URL.
* Names passed to this context is assumed to be relative to this
* context (i.e. not a URL). For example, if urlInfo is
* "ldap://ldap.wiz.com/o=Wiz,c=us", the resulting context will
* be that pointed to by "o=Wiz,c=us" on the server 'ldap.wiz.com'.
* Subsequent names that can be passed to this context will be
* LDAP names relative to this context (e.g. cn="Barbs Jensen").
* If urlInfo is an array of URLs, the URLs are assumed
* to be equivalent in terms of the context to which they refer.
* The resulting context is like that of the single URL case.
* If urlInfo is of any other type, that is handled by the
* context factory for the URL scheme.
* @param scheme the URL scheme id for the context
* @param urlInfo information used to create the context
* @param name name of this object relative to <code>nameCtx</code>
* @param nameCtx Context whose provider resource file will be searched
* for package prefix values (or null if none)
* @param environment Environment properties for creating the context
* @see javax.naming.InitialContext
*/
private static Object getURLObject(String scheme, Object urlInfo,
Name name, Context nameCtx,
Hashtable<?,?> environment)
throws NamingException {
// e.g. "ftpURLContextFactory"
ObjectFactory factory = (ObjectFactory)ResourceManager.getFactory(
Context.URL_PKG_PREFIXES, environment, nameCtx,
"." + scheme + "." + scheme + "URLContextFactory", defaultPkgPrefix);
if (factory == null)
return null;
// Found object factory
try {
return factory.getObjectInstance(urlInfo, name, nameCtx, environment);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
NamingException ne = new NamingException();
ne.setRootCause(e);
throw ne;
}
}
// ------------ Initial Context Factory Stuff
private static InitialContextFactoryBuilder initctx_factory_builder = null;
/**
* Use this method for accessing initctx_factory_builder while
* inside an unsynchronized method.
*/
private static synchronized InitialContextFactoryBuilder
getInitialContextFactoryBuilder() {
return initctx_factory_builder;
}
/**
* Creates an initial context using the specified environment
* properties.
*<p>
* If an InitialContextFactoryBuilder has been installed,
* it is used to create the factory for creating the initial context.
* Otherwise, the class specified in the
* <tt>Context.INITIAL_CONTEXT_FACTORY</tt> environment property is used.
* Note that an initial context factory (an object that implements the
* InitialContextFactory interface) must be public and must have a
* public constructor that accepts no arguments.
*
* @param env The possibly null environment properties used when
* creating the context.
* @return A non-null initial context.
* @exception NoInitialContextException If the
* <tt>Context.INITIAL_CONTEXT_FACTORY</tt> property
* is not found or names a nonexistent
* class or a class that cannot be instantiated,
* or if the initial context could not be created for some other
* reason.
* @exception NamingException If some other naming exception was encountered.
* @see javax.naming.InitialContext
* @see javax.naming.directory.InitialDirContext
*/
public static Context getInitialContext(Hashtable<?,?> env)
throws NamingException {
InitialContextFactory factory;
InitialContextFactoryBuilder builder = getInitialContextFactoryBuilder();
if (builder == null) {
// No factory installed, use property
// Get initial context factory class name
String className = env != null ?
(String)env.get(Context.INITIAL_CONTEXT_FACTORY) : null;
if (className == null) {
NoInitialContextException ne = new NoInitialContextException(
"Need to specify class name in environment or system " +
"property, or as an applet parameter, or in an " +
"application resource file: " +
Context.INITIAL_CONTEXT_FACTORY);
throw ne;
}
try {
factory = (InitialContextFactory)
helper.loadClass(className).newInstance();
} catch(Exception e) {
NoInitialContextException ne =
new NoInitialContextException(
"Cannot instantiate class: " + className);
ne.setRootCause(e);
throw ne;
}
} else {
factory = builder.createInitialContextFactory(env);
}
return factory.getInitialContext(env);
}
/**
* Sets the InitialContextFactory builder to be builder.
*
*<p>
* The builder can only be installed if the executing thread is allowed by
* the security manager to do so. Once installed, the builder cannot
* be replaced.
* @param builder The initial context factory builder to install. If null,
* no builder is set.
* @exception SecurityException builder cannot be installed for security
* reasons.
* @exception NamingException builder cannot be installed for
* a non-security-related reason.
* @exception IllegalStateException If a builder was previous installed.
* @see #hasInitialContextFactoryBuilder
* @see java.lang.SecurityManager#checkSetFactory
*/
public static synchronized void setInitialContextFactoryBuilder(
InitialContextFactoryBuilder builder)
throws NamingException {
if (initctx_factory_builder != null)
throw new IllegalStateException(
"InitialContextFactoryBuilder already set");
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkSetFactory();
}
initctx_factory_builder = builder;
}
/**
* Determines whether an initial context factory builder has
* been set.
* @return true if an initial context factory builder has
* been set; false otherwise.
* @see #setInitialContextFactoryBuilder
*/
public static boolean hasInitialContextFactoryBuilder() {
return (getInitialContextFactoryBuilder() != null);
}
// ----- Continuation Context Stuff
/**
* Constant that holds the name of the environment property into
* which <tt>getContinuationContext()</tt> stores the value of its
* <tt>CannotProceedException</tt> parameter.
* This property is inherited by the continuation context, and may
* be used by that context's service provider to inspect the
* fields of the exception.
*<p>
* The value of this constant is "java.naming.spi.CannotProceedException".
*
* @see #getContinuationContext
* @since 1.3
*/
public static final String CPE = "java.naming.spi.CannotProceedException";
/**
* Creates a context in which to continue a context operation.
*<p>
* In performing an operation on a name that spans multiple
* namespaces, a context from one naming system may need to pass
* the operation on to the next naming system. The context
* implementation does this by first constructing a
* <code>CannotProceedException</code> containing information
* pinpointing how far it has proceeded. It then obtains a
* continuation context from JNDI by calling
* <code>getContinuationContext</code>. The context
* implementation should then resume the context operation by
* invoking the same operation on the continuation context, using
* the remainder of the name that has not yet been resolved.
*<p>
* Before making use of the <tt>cpe</tt> parameter, this method
* updates the environment associated with that object by setting
* the value of the property <a href="#CPE"><tt>CPE</tt></a>
* to <tt>cpe</tt>. This property will be inherited by the
* continuation context, and may be used by that context's
* service provider to inspect the fields of this exception.
*
* @param cpe
* The non-null exception that triggered this continuation.
* @return A non-null Context object for continuing the operation.
* @exception NamingException If a naming exception occurred.
*/
@SuppressWarnings("unchecked")
public static Context getContinuationContext(CannotProceedException cpe)
throws NamingException {
Hashtable<Object,Object> env = (Hashtable<Object,Object>)cpe.getEnvironment();
if (env == null) {
env = new Hashtable<>(7);
} else {
// Make a (shallow) copy of the environment.
env = (Hashtable<Object,Object>)env.clone();
}
env.put(CPE, cpe);
ContinuationContext cctx = new ContinuationContext(cpe, env);
return cctx.getTargetContext();
}
// ------------ State Factory Stuff
/**
* Retrieves the state of an object for binding.
* <p>
* Service providers that implement the <tt>DirContext</tt> interface
* should use <tt>DirectoryManager.getStateToBind()</tt>, not this method.
* Service providers that implement only the <tt>Context</tt> interface
* should use this method.
*<p>
* This method uses the specified state factories in
* the <tt>Context.STATE_FACTORIES</tt> property from the environment
* properties, and from the provider resource file associated with
* <tt>nameCtx</tt>, in that order.
* The value of this property is a colon-separated list of factory
* class names that are tried in order, and the first one that succeeds
* in returning the object's state is the one used.
* If no object's state can be retrieved in this way, return the
* object itself.
* If an exception is encountered while retrieving the state, the
* exception is passed up to the caller.
* <p>
* Note that a state factory
* (an object that implements the StateFactory
* interface) must be public and must have a public constructor that
* accepts no arguments.
* <p>
* The <code>name</code> and <code>nameCtx</code> parameters may
* optionally be used to specify the name of the object being created.
* See the description of "Name and Context Parameters" in
* {@link ObjectFactory#getObjectInstance
* ObjectFactory.getObjectInstance()}
* for details.
* <p>
* This method may return a <tt>Referenceable</tt> object. The
* service provider obtaining this object may choose to store it
* directly, or to extract its reference (using
* <tt>Referenceable.getReference()</tt>) and store that instead.
*
* @param obj The non-null object for which to get state to bind.
* @param name The name of this object relative to <code>nameCtx</code>,
* or null if no name is specified.
* @param nameCtx The context relative to which the <code>name</code>
* parameter is specified, or null if <code>name</code> is
* relative to the default initial context.
* @param environment The possibly null environment to
* be used in the creation of the state factory and
* the object's state.
* @return The non-null object representing <tt>obj</tt>'s state for
* binding. It could be the object (<tt>obj</tt>) itself.
* @exception NamingException If one of the factories accessed throws an
* exception, or if an error was encountered while loading
* and instantiating the factory and object classes.
* A factory should only throw an exception if it does not want
* other factories to be used in an attempt to create an object.
* See <tt>StateFactory.getStateToBind()</tt>.
* @see StateFactory
* @see StateFactory#getStateToBind
* @see DirectoryManager#getStateToBind
* @since 1.3
*/
public static Object
getStateToBind(Object obj, Name name, Context nameCtx,
Hashtable<?,?> environment)
throws NamingException
{
FactoryEnumeration factories = ResourceManager.getFactories(
Context.STATE_FACTORIES, environment, nameCtx);
if (factories == null) {
return obj;
}
// Try each factory until one succeeds
StateFactory factory;
Object answer = null;
while (answer == null && factories.hasMore()) {
factory = (StateFactory)factories.next();
answer = factory.getStateToBind(obj, name, nameCtx, environment);
}
return (answer != null) ? answer : obj;
}
}

View File

@@ -0,0 +1,174 @@
/*
* 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 javax.naming.spi;
import java.util.Hashtable;
import javax.naming.*;
/**
* This interface represents a factory for creating an object.
*<p>
* The JNDI framework allows for object implementations to
* be loaded in dynamically via <em>object factories</em>.
* For example, when looking up a printer bound in the name space,
* if the print service binds printer names to References, the printer
* Reference could be used to create a printer object, so that
* the caller of lookup can directly operate on the printer object
* after the lookup.
* <p>An <tt>ObjectFactory</tt> is responsible
* for creating objects of a specific type. In the above example,
* you may have a PrinterObjectFactory for creating Printer objects.
*<p>
* An object factory must implement the <tt>ObjectFactory</tt> interface.
* In addition, the factory class must be public and must have a
* public constructor that accepts no parameters.
*<p>
* The <tt>getObjectInstance()</tt> method of an object factory may
* be invoked multiple times, possibly using different parameters.
* The implementation is thread-safe.
*<p>
* The mention of URL in the documentation for this class refers to
* a URL string as defined by RFC 1738 and its related RFCs. It is
* any string that conforms to the syntax described therein, and
* may not always have corresponding support in the java.net.URL
* class or Web browsers.
*
* @author Rosanna Lee
* @author Scott Seligman
*
* @see NamingManager#getObjectInstance
* @see NamingManager#getURLContext
* @see ObjectFactoryBuilder
* @see StateFactory
* @since 1.3
*/
public interface ObjectFactory {
/**
* Creates an object using the location or reference information
* specified.
* <p>
* Special requirements of this object are supplied
* using <code>environment</code>.
* An example of such an environment property is user identity
* information.
*<p>
* <tt>NamingManager.getObjectInstance()</tt>
* successively loads in object factories and invokes this method
* on them until one produces a non-null answer. When an exception
* is thrown by an object factory, the exception is passed on to the caller
* of <tt>NamingManager.getObjectInstance()</tt>
* (and no search is made for other factories
* that may produce a non-null answer).
* An object factory should only throw an exception if it is sure that
* it is the only intended factory and that no other object factories
* should be tried.
* If this factory cannot create an object using the arguments supplied,
* it should return null.
*<p>
* A <em>URL context factory</em> is a special ObjectFactory that
* creates contexts for resolving URLs or objects whose locations
* are specified by URLs. The <tt>getObjectInstance()</tt> method
* of a URL context factory will obey the following rules.
* <ol>
* <li>If <code>obj</code> is null, create a context for resolving URLs of the
* scheme associated with this factory. The resulting context is not tied
* to a specific URL: it is able to handle arbitrary URLs with this factory's
* scheme id. For example, invoking <tt>getObjectInstance()</tt> with
* <code>obj</code> set to null on an LDAP URL context factory would return a
* context that can resolve LDAP URLs
* such as "ldap://ldap.wiz.com/o=wiz,c=us" and
* "ldap://ldap.umich.edu/o=umich,c=us".
* <li>
* If <code>obj</code> is a URL string, create an object (typically a context)
* identified by the URL. For example, suppose this is an LDAP URL context
* factory. If <code>obj</code> is "ldap://ldap.wiz.com/o=wiz,c=us",
* getObjectInstance() would return the context named by the distinguished
* name "o=wiz, c=us" at the LDAP server ldap.wiz.com. This context can
* then be used to resolve LDAP names (such as "cn=George")
* relative to that context.
* <li>
* If <code>obj</code> is an array of URL strings, the assumption is that the
* URLs are equivalent in terms of the context to which they refer.
* Verification of whether the URLs are, or need to be, equivalent is up
* to the context factory. The order of the URLs in the array is
* not significant.
* The object returned by getObjectInstance() is like that of the single
* URL case. It is the object named by the URLs.
* <li>
* If <code>obj</code> is of any other type, the behavior of
* <tt>getObjectInstance()</tt> is determined by the context factory
* implementation.
* </ol>
*
* <p>
* The <tt>name</tt> and <tt>environment</tt> parameters
* are owned by the caller.
* The implementation will not modify these objects or keep references
* to them, although it may keep references to clones or copies.
*
* <p>
* <b>Name and Context Parameters.</b> &nbsp;&nbsp;&nbsp;
* <a name=NAMECTX></a>
*
* The <code>name</code> and <code>nameCtx</code> parameters may
* optionally be used to specify the name of the object being created.
* <code>name</code> is the name of the object, relative to context
* <code>nameCtx</code>.
* If there are several possible contexts from which the object
* could be named -- as will often be the case -- it is up to
* the caller to select one. A good rule of thumb is to select the
* "deepest" context available.
* If <code>nameCtx</code> is null, <code>name</code> is relative
* to the default initial context. If no name is being specified, the
* <code>name</code> parameter should be null.
* If a factory uses <code>nameCtx</code> it should synchronize its use
* against concurrent access, since context implementations are not
* guaranteed to be thread-safe.
* <p>
*
* @param obj The possibly null object containing location or reference
* information that can be used in creating an object.
* @param name The name of this object relative to <code>nameCtx</code>,
* or null if no name is specified.
* @param nameCtx The context relative to which the <code>name</code>
* parameter is specified, or null if <code>name</code> is
* relative to the default initial context.
* @param environment The possibly null environment that is used in
* creating the object.
* @return The object created; null if an object cannot be created.
* @exception Exception if this object factory encountered an exception
* while attempting to create an object, and no other object factories are
* to be tried.
*
* @see NamingManager#getObjectInstance
* @see NamingManager#getURLContext
*/
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
Hashtable<?,?> environment)
throws Exception;
}

View File

@@ -0,0 +1,75 @@
/*
* 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 javax.naming.spi;
import java.util.Hashtable;
import javax.naming.NamingException;
/**
* This interface represents a builder that creates object factories.
*<p>
* The JNDI framework allows for object implementations to
* be loaded in dynamically via <em>object factories</em>.
* For example, when looking up a printer bound in the name space,
* if the print service binds printer names to References, the printer
* Reference could be used to create a printer object, so that
* the caller of lookup can directly operate on the printer object
* after the lookup. An ObjectFactory is responsible for creating
* objects of a specific type. JNDI uses a default policy for using
* and loading object factories. You can override this default policy
* by calling <tt>NamingManager.setObjectFactoryBuilder()</tt> with an ObjectFactoryBuilder,
* which contains the program-defined way of creating/loading
* object factories.
* Any <tt>ObjectFactoryBuilder</tt> implementation must implement this
* interface that for creating object factories.
*
* @author Rosanna Lee
* @author Scott Seligman
*
* @see ObjectFactory
* @see NamingManager#getObjectInstance
* @see NamingManager#setObjectFactoryBuilder
* @since 1.3
*/
public interface ObjectFactoryBuilder {
/**
* Creates a new object factory using the environment supplied.
*<p>
* The environment parameter is owned by the caller.
* The implementation will not modify the object or keep a reference
* to it, although it may keep a reference to a clone or copy.
*
* @param obj The possibly null object for which to create a factory.
* @param environment Environment to use when creating the factory.
* Can be null.
* @return A non-null new instance of an ObjectFactory.
* @exception NamingException If an object factory cannot be created.
*
*/
public ObjectFactory createObjectFactory(Object obj,
Hashtable<?,?> environment)
throws NamingException;
}

View File

@@ -0,0 +1,201 @@
/*
* 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 javax.naming.spi;
import javax.naming.Name;
import javax.naming.Context;
import javax.naming.CompositeName;
import javax.naming.InvalidNameException;
/**
* This class represents the result of resolution of a name.
* It contains the object to which name was resolved, and the portion
* of the name that has not been resolved.
*<p>
* A ResolveResult instance is not synchronized against concurrent
* multithreaded access. Multiple threads trying to access and modify
* a single ResolveResult instance should lock the object.
*
* @author Rosanna Lee
* @author Scott Seligman
* @since 1.3
*/
public class ResolveResult implements java.io.Serializable {
/**
* Field containing the Object that was resolved to successfully.
* It can be null only when constructed using a subclass.
* Constructors should always initialize this.
* @serial
*/
protected Object resolvedObj;
/**
* Field containing the remaining name yet to be resolved.
* It can be null only when constructed using a subclass.
* Constructors should always initialize this.
* @serial
*/
protected Name remainingName;
/**
* Constructs an instance of ResolveResult with the
* resolved object and remaining name both initialized to null.
*/
protected ResolveResult() {
resolvedObj = null;
remainingName = null;
}
/**
* Constructs a new instance of ResolveResult consisting of
* the resolved object and the remaining unresolved component.
*
* @param robj The non-null object resolved to.
* @param rcomp The single remaining name component that has yet to be
* resolved. Cannot be null (but can be empty).
*/
public ResolveResult(Object robj, String rcomp) {
resolvedObj = robj;
try {
remainingName = new CompositeName(rcomp);
// remainingName.appendComponent(rcomp);
} catch (InvalidNameException e) {
// ignore; shouldn't happen
}
}
/**
* Constructs a new instance of ResolveResult consisting of
* the resolved Object and the remaining name.
*
* @param robj The non-null Object resolved to.
* @param rname The non-null remaining name that has yet to be resolved.
*/
public ResolveResult(Object robj, Name rname) {
resolvedObj = robj;
setRemainingName(rname);
}
/**
* Retrieves the remaining unresolved portion of the name.
*
* @return The remaining unresolved portion of the name.
* Cannot be null but empty OK.
* @see #appendRemainingName
* @see #appendRemainingComponent
* @see #setRemainingName
*/
public Name getRemainingName() {
return this.remainingName;
}
/**
* Retrieves the Object to which resolution was successful.
*
* @return The Object to which resolution was successful. Cannot be null.
* @see #setResolvedObj
*/
public Object getResolvedObj() {
return this.resolvedObj;
}
/**
* Sets the remaining name field of this result to name.
* A copy of name is made so that modifying the copy within
* this ResolveResult does not affect <code>name</code> and
* vice versa.
*
* @param name The name to set remaining name to. Cannot be null.
* @see #getRemainingName
* @see #appendRemainingName
* @see #appendRemainingComponent
*/
public void setRemainingName(Name name) {
if (name != null)
this.remainingName = (Name)(name.clone());
else {
// ??? should throw illegal argument exception
this.remainingName = null;
}
}
/**
* Adds components to the end of remaining name.
*
* @param name The components to add. Can be null.
* @see #getRemainingName
* @see #setRemainingName
* @see #appendRemainingComponent
*/
public void appendRemainingName(Name name) {
// System.out.println("appendingRemainingName: " + name.toString());
// Exception e = new Exception();
// e.printStackTrace();
if (name != null) {
if (this.remainingName != null) {
try {
this.remainingName.addAll(name);
} catch (InvalidNameException e) {
// ignore; shouldn't happen for composite name
}
} else {
this.remainingName = (Name)(name.clone());
}
}
}
/**
* Adds a single component to the end of remaining name.
*
* @param name The component to add. Can be null.
* @see #getRemainingName
* @see #appendRemainingName
*/
public void appendRemainingComponent(String name) {
if (name != null) {
CompositeName rname = new CompositeName();
try {
rname.add(name);
} catch (InvalidNameException e) {
// ignore; shouldn't happen for empty composite name
}
appendRemainingName(rname);
}
}
/**
* Sets the resolved Object field of this result to obj.
*
* @param obj The object to use for setting the resolved obj field.
* Cannot be null.
* @see #getResolvedObj
*/
public void setResolvedObj(Object obj) {
this.resolvedObj = obj;
// ??? should check for null?
}
private static final long serialVersionUID = -4552108072002407559L;
}

View File

@@ -0,0 +1,96 @@
/*
* 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 javax.naming.spi;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
/**
* This interface represents an "intermediate context" for name resolution.
*<p>
* The Resolver interface contains methods that are implemented by contexts
* that do not support subtypes of Context, but which can act as
* intermediate contexts for resolution purposes.
*<p>
* A <tt>Name</tt> parameter passed to any method is owned
* by the caller. The service provider will not modify the object
* or keep a reference to it.
* A <tt>ResolveResult</tt> object returned by any
* method is owned by the caller. The caller may subsequently modify it;
* the service provider may not.
*
* @author Rosanna Lee
* @author Scott Seligman
* @since 1.3
*/
public interface Resolver {
/**
* Partially resolves a name. Stops at the first
* context that is an instance of a given subtype of
* <code>Context</code>.
*
* @param name
* the name to resolve
* @param contextType
* the type of object to resolve. This should
* be a subtype of <code>Context</code>.
* @return the object that was found, along with the unresolved
* suffix of <code>name</code>. Cannot be null.
*
* @throws javax.naming.NotContextException
* if no context of the appropriate type is found
* @throws NamingException if a naming exception was encountered
*
* @see #resolveToClass(String, Class)
*/
public ResolveResult resolveToClass(Name name,
Class<? extends Context> contextType)
throws NamingException;
/**
* Partially resolves a name.
* See {@link #resolveToClass(Name, Class)} for details.
*
* @param name
* the name to resolve
* @param contextType
* the type of object to resolve. This should
* be a subtype of <code>Context</code>.
* @return the object that was found, along with the unresolved
* suffix of <code>name</code>. Cannot be null.
*
* @throws javax.naming.NotContextException
* if no context of the appropriate type is found
* @throws NamingException if a naming exception was encountered
*/
public ResolveResult resolveToClass(String name,
Class<? extends Context> contextType)
throws NamingException;
};

View File

@@ -0,0 +1,138 @@
/*
* 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 javax.naming.spi;
import javax.naming.*;
import java.util.Hashtable;
/**
* This interface represents a factory for obtaining the state of an
* object for binding.
*<p>
* The JNDI framework allows for object implementations to
* be loaded in dynamically via <em>object factories</em>.
* For example, when looking up a printer bound in the name space,
* if the print service binds printer names to <tt>Reference</tt>s, the printer
* <tt>Reference</tt> could be used to create a printer object, so that
* the caller of lookup can directly operate on the printer object
* after the lookup.
* <p>An <tt>ObjectFactory</tt> is responsible
* for creating objects of a specific type. In the above example,
* you may have a <tt>PrinterObjectFactory</tt> for creating
* <tt>Printer</tt> objects.
* <p>
* For the reverse process, when an object is bound into the namespace,
* JNDI provides <em>state factories</em>.
* Continuing with the printer example, suppose the printer object is
* updated and rebound:
* <blockquote><pre>
* ctx.rebind("inky", printer);
* </pre></blockquote>
* The service provider for <tt>ctx</tt> uses a state factory
* to obtain the state of <tt>printer</tt> for binding into its namespace.
* A state factory for the <tt>Printer</tt> type object might return
* a more compact object for storage in the naming system.
*<p>
* A state factory must implement the <tt>StateFactory</tt> interface.
* In addition, the factory class must be public and must have a
* public constructor that accepts no parameters.
*<p>
* The <tt>getStateToBind()</tt> method of a state factory may
* be invoked multiple times, possibly using different parameters.
* The implementation is thread-safe.
*<p>
* <tt>StateFactory</tt> is intended for use with service providers
* that implement only the <tt>Context</tt> interface.
* <tt>DirStateFactory</tt> is intended for use with service providers
* that implement the <tt>DirContext</tt> interface.
*
* @author Rosanna Lee
* @author Scott Seligman
*
* @see NamingManager#getStateToBind
* @see DirectoryManager#getStateToBind
* @see ObjectFactory
* @see DirStateFactory
* @since 1.3
*/
public interface StateFactory {
/**
* Retrieves the state of an object for binding.
*<p>
* <tt>NamingManager.getStateToBind()</tt>
* successively loads in state factories and invokes this method
* on them until one produces a non-null answer.
* <tt>DirectoryManager.getStateToBind()</tt>
* successively loads in state factories. If a factory implements
* <tt>DirStateFactory</tt>, then <tt>DirectoryManager</tt>
* invokes <tt>DirStateFactory.getStateToBind()</tt>; otherwise
* it invokes <tt>StateFactory.getStateToBind()</tt>.
*<p> When an exception
* is thrown by a factory, the exception is passed on to the caller
* of <tt>NamingManager.getStateToBind()</tt> and
* <tt>DirectoryManager.getStateToBind()</tt>.
* The search for other factories
* that may produce a non-null answer is halted.
* A factory should only throw an exception if it is sure that
* it is the only intended factory and that no other factories
* should be tried.
* If this factory cannot create an object using the arguments supplied,
* it should return null.
* <p>
* The <code>name</code> and <code>nameCtx</code> parameters may
* optionally be used to specify the name of the object being created.
* See the description of "Name and Context Parameters" in
* {@link ObjectFactory#getObjectInstance ObjectFactory.getObjectInstance()}
* for details.
* If a factory uses <code>nameCtx</code> it should synchronize its use
* against concurrent access, since context implementations are not
* guaranteed to be thread-safe.
* <p>
* The <tt>name</tt> and <tt>environment</tt> parameters
* are owned by the caller.
* The implementation will not modify these objects or keep references
* to them, although it may keep references to clones or copies.
*
* @param obj A non-null object whose state is to be retrieved.
* @param name The name of this object relative to <code>nameCtx</code>,
* or null if no name is specified.
* @param nameCtx The context relative to which the <code>name</code>
* parameter is specified, or null if <code>name</code> is
* relative to the default initial context.
* @param environment The possibly null environment to
* be used in the creation of the object's state.
* @return The object's state for binding;
* null if the factory is not returning any changes.
* @exception NamingException if this factory encountered an exception
* while attempting to get the object's state, and no other factories are
* to be tried.
*
* @see NamingManager#getStateToBind
* @see DirectoryManager#getStateToBind
*/
public Object getStateToBind(Object obj, Name name, Context nameCtx,
Hashtable<?,?> environment)
throws NamingException;
}