Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2009-08-18 00:48:56 +0000
committerGreg Wilkins2009-08-18 00:48:56 +0000
commit800dfa288360cd02343b61f2878bc087b78084d6 (patch)
tree242bfa048e9d3f297a0b62785075ae8263dcf64b /jetty-jndi/src
parent8e7032aa424a7c78da63799803e0795e14263ed7 (diff)
downloadorg.eclipse.jetty.project-800dfa288360cd02343b61f2878bc087b78084d6.tar.gz
org.eclipse.jetty.project-800dfa288360cd02343b61f2878bc087b78084d6.tar.xz
org.eclipse.jetty.project-800dfa288360cd02343b61f2878bc087b78084d6.zip
moved to codehaus
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@733 7e9141cc-0065-0410-87d8-b60c137991c4
Diffstat (limited to 'jetty-jndi/src')
-rw-r--r--jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java192
-rw-r--r--jetty-jndi/src/main/java/org/eclipse/jetty/jndi/InitialContextFactory.java79
-rw-r--r--jetty-jndi/src/main/java/org/eclipse/jetty/jndi/NamingContext.java1446
-rw-r--r--jetty-jndi/src/main/java/org/eclipse/jetty/jndi/NamingUtil.java139
-rw-r--r--jetty-jndi/src/main/java/org/eclipse/jetty/jndi/factories/MailSessionReference.java183
-rw-r--r--jetty-jndi/src/main/java/org/eclipse/jetty/jndi/java/javaNameParser.java52
-rw-r--r--jetty-jndi/src/main/java/org/eclipse/jetty/jndi/java/javaRootURLContext.java329
-rw-r--r--jetty-jndi/src/main/java/org/eclipse/jetty/jndi/java/javaURLContextFactory.java103
-rw-r--r--jetty-jndi/src/main/java/org/eclipse/jetty/jndi/local/localContextRoot.java435
-rw-r--r--jetty-jndi/src/main/resources/jndi.properties2
-rw-r--r--jetty-jndi/src/test/java/org/eclipse/jetty/jndi/factories/TestMailSessionReference.java72
-rw-r--r--jetty-jndi/src/test/java/org/eclipse/jetty/jndi/java/TestJNDI.java295
-rw-r--r--jetty-jndi/src/test/java/org/eclipse/jetty/jndi/java/TestLocalJNDI.java88
13 files changed, 0 insertions, 3415 deletions
diff --git a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java
deleted file mode 100644
index ca00153e1b..0000000000
--- a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java
+++ /dev/null
@@ -1,192 +0,0 @@
-// ========================================================================
-// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-
-package org.eclipse.jetty.jndi;
-
-
-import java.util.Hashtable;
-import java.util.WeakHashMap;
-
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NameParser;
-import javax.naming.Reference;
-import javax.naming.StringRefAddr;
-import javax.naming.spi.ObjectFactory;
-
-import org.eclipse.jetty.server.handler.ContextHandler;
-import org.eclipse.jetty.util.log.Log;
-
-
-
-/**
- * ContextFactory.java
- *
- * This is an object factory that produces a jndi naming
- * context based on a classloader.
- *
- * It is used for the java:comp context.
- *
- * This object factory is bound at java:comp. When a
- * lookup arrives for java:comp, this object factory
- * is invoked and will return a context specific to
- * the caller's environment (so producing the java:comp/env
- * specific to a webapp).
- *
- * The context selected is based on classloaders. First
- * we try looking in at the classloader that is associated
- * with the current webapp context (if there is one). If
- * not, we use the thread context classloader.
- *
- * Created: Fri Jun 27 09:26:40 2003
- *
- *
- *
- */
-public class ContextFactory implements ObjectFactory
-{
- /**
- * Map of classloaders to contexts.
- */
- private static WeakHashMap _contextMap;
-
- /**
- * Threadlocal for injecting a context to use
- * instead of looking up the map.
- */
- private static ThreadLocal _threadContext;
-
- static
- {
- _contextMap = new WeakHashMap();
- _threadContext = new ThreadLocal();
- }
-
-
-
- /**
- * Find or create a context which pertains to a classloader.
- *
- * We use either the classloader for the current ContextHandler if
- * we are handling a request, OR we use the thread context classloader
- * if we are not processing a request.
- * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
- */
- public Object getObjectInstance (Object obj,
- Name name,
- Context nameCtx,
- Hashtable env)
- throws Exception
- {
- //First, see if we have had a context injected into us to use.
- Context ctx = (Context)_threadContext.get();
- if (ctx != null)
- {
- if(Log.isDebugEnabled()) Log.debug("Using the Context that is bound on the thread");
- return ctx;
- }
-
- // Next, see if we are in a webapp context, if we are, use
- // the classloader of the webapp to find the right jndi comp context
- ClassLoader loader = null;
- if (ContextHandler.getCurrentContext() != null)
- {
- loader = ContextHandler.getCurrentContext().getContextHandler().getClassLoader();
- }
-
-
- if (loader != null)
- {
- if (Log.isDebugEnabled()) Log.debug("Using classloader of current org.eclipse.jetty.server.handler.ContextHandler");
- }
- else
- {
- //Not already in a webapp context, in that case, we try the
- //curren't thread's classloader instead
- loader = Thread.currentThread().getContextClassLoader();
- if (Log.isDebugEnabled()) Log.debug("Using thread context classloader");
- }
-
- //Get the context matching the classloader
- ctx = (Context)_contextMap.get(loader);
-
- //The map does not contain an entry for this classloader
- if (ctx == null)
- {
- //Check if a parent classloader has created the context
- ctx = getParentClassLoaderContext(loader);
-
- //Didn't find a context to match any of the ancestors
- //of the classloader, so make a context
- if (ctx == null)
- {
- Reference ref = (Reference)obj;
- StringRefAddr parserAddr = (StringRefAddr)ref.get("parser");
- String parserClassName = (parserAddr==null?null:(String)parserAddr.getContent());
- NameParser parser = (NameParser)(parserClassName==null?null:loader.loadClass(parserClassName).newInstance());
-
- ctx = new NamingContext (env,
- name.get(0),
- nameCtx,
- parser);
- if(Log.isDebugEnabled())Log.debug("No entry for classloader: "+loader);
- _contextMap.put (loader, ctx);
- }
- }
-
- return ctx;
- }
-
- /**
- * Keep trying ancestors of the given classloader to find one to which
- * the context is bound.
- * @param loader
- * @return
- */
- public Context getParentClassLoaderContext (ClassLoader loader)
- {
- Context ctx = null;
- ClassLoader cl = loader;
- for (cl = cl.getParent(); (cl != null) && (ctx == null); cl = cl.getParent())
- {
- ctx = (Context)_contextMap.get(cl);
- }
-
- return ctx;
- }
-
-
- /**
- * Associate the given Context with the current thread.
- * resetComponentContext method should be called to reset the context.
- * @param ctx the context to associate to the current thread.
- * @return the previous context associated on the thread (can be null)
- */
- public static Context setComponentContext(final Context ctx)
- {
- Context previous = (Context)_threadContext.get();
- _threadContext.set(ctx);
- return previous;
- }
-
- /**
- * Set back the context with the given value.
- * Don't return the previous context, use setComponentContext() method for this.
- * @param ctx the context to associate to the current thread.
- */
- public static void resetComponentContext(final Context ctx)
- {
- _threadContext.set(ctx);
- }
-
-}
diff --git a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/InitialContextFactory.java b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/InitialContextFactory.java
deleted file mode 100644
index e72ad69545..0000000000
--- a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/InitialContextFactory.java
+++ /dev/null
@@ -1,79 +0,0 @@
-// ========================================================================
-// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-
-package org.eclipse.jetty.jndi;
-
-
-import java.util.Hashtable;
-import java.util.Properties;
-
-import javax.naming.CompoundName;
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NameParser;
-import javax.naming.NamingException;
-
-import org.eclipse.jetty.jndi.local.localContextRoot;
-import org.eclipse.jetty.util.log.Log;
-
-
-/*------------------------------------------------*/
-/**
- * InitialContextFactory.java
- *
- * Factory for the default InitialContext.
- * Created: Tue Jul 1 19:08:08 2003
- *
- *
- * @version 1.0
- */
-public class InitialContextFactory implements javax.naming.spi.InitialContextFactory
-{
- public static class DefaultParser implements NameParser
- {
- static Properties syntax = new Properties();
- static
- {
- syntax.put("jndi.syntax.direction", "left_to_right");
- syntax.put("jndi.syntax.separator", "/");
- syntax.put("jndi.syntax.ignorecase", "false");
- }
- public Name parse (String name)
- throws NamingException
- {
- return new CompoundName (name, syntax);
- }
- };
-
-
-
- /*------------------------------------------------*/
- /**
- * Get Context that has access to default Namespace.
- * This method won't be called if a name URL beginning
- * with java: is passed to an InitialContext.
- *
- * @see org.eclipse.jetty.jndi.java.javaURLContextFactory
- * @param env a <code>Hashtable</code> value
- * @return a <code>Context</code> value
- */
- public Context getInitialContext(Hashtable env)
- {
- Log.debug("InitialContextFactory.getInitialContext()");
-
- Context ctx = new localContextRoot(env);
- if(Log.isDebugEnabled())Log.debug("Created initial context delegate for local namespace:"+ctx);
-
- return ctx;
- }
-}
diff --git a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/NamingContext.java b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/NamingContext.java
deleted file mode 100644
index a8253a802c..0000000000
--- a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/NamingContext.java
+++ /dev/null
@@ -1,1446 +0,0 @@
-// ========================================================================
-// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-
-package org.eclipse.jetty.jndi;
-
-
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.NoSuchElementException;
-
-import javax.naming.Binding;
-import javax.naming.CompoundName;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.LinkRef;
-import javax.naming.Name;
-import javax.naming.NameAlreadyBoundException;
-import javax.naming.NameClassPair;
-import javax.naming.NameNotFoundException;
-import javax.naming.NameParser;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.NotContextException;
-import javax.naming.OperationNotSupportedException;
-import javax.naming.Reference;
-import javax.naming.Referenceable;
-import javax.naming.spi.NamingManager;
-
-import org.eclipse.jetty.util.log.Log;
-
-
-/*------------------------------------------------*/
-/** NamingContext
- * <p>Implementation of Context interface.
- *
- * <p><h4>Notes</h4>
- * <p>All Names are expected to be Compound, not Composite.
- *
- * <p><h4>Usage</h4>
- * <pre>
- */
-/*
-* </pre>
-*
-* @see
-*
-*
-* @version 1.0
-*/
-public class NamingContext implements Context, Cloneable
-{
-
- public static final String LOCK_PROPERTY = "org.eclipse.jndi.lock";
- public static final String UNLOCK_PROPERTY = "org.eclipse.jndi.unlock";
-
- public static final Enumeration EMPTY_ENUM = new Enumeration ()
- {
- public boolean hasMoreElements()
- {
- return false;
- }
-
- public Object nextElement ()
- {
- throw new NoSuchElementException();
- }
- };
-
-
- protected Context _parent = null;
- protected String _name = null;
- protected Hashtable _env = null;
- protected Hashtable _bindings = new Hashtable();
- protected NameParser _parser = null;
-
-
-
- /*------------------------------------------------*/
- /** NameEnumeration
- * <p>Implementation of NamingEnumeration interface.
- *
- * <p><h4>Notes</h4>
- * <p>Used for returning results of Context.list();
- *
- * <p><h4>Usage</h4>
- * <pre>
- */
- /*
- * </pre>
- *
- * @see
- *
- */
- public class NameEnumeration implements NamingEnumeration
- {
- Enumeration _delegate;
-
- public NameEnumeration (Enumeration e)
- {
- _delegate = e;
- }
-
- public void close()
- throws NamingException
- {
- }
-
- public boolean hasMore ()
- throws NamingException
- {
- return _delegate.hasMoreElements();
- }
-
- public Object next()
- throws NamingException
- {
- Binding b = (Binding)_delegate.nextElement();
- return new NameClassPair (b.getName(), b.getClassName(), true);
- }
-
- public boolean hasMoreElements()
- {
- return _delegate.hasMoreElements();
- }
-
- public Object nextElement()
- {
- Binding b = (Binding)_delegate.nextElement();
- return new NameClassPair (b.getName(), b.getClassName(), true);
- }
- }
-
-
-
-
-
-
- /*------------------------------------------------*/
- /** BindingEnumeration
- * <p>Implementation of NamingEnumeration
- *
- * <p><h4>Notes</h4>
- * <p>Used to return results of Context.listBindings();
- *
- * <p><h4>Usage</h4>
- * <pre>
- */
- /*
- * </pre>
- *
- * @see
- *
- */
- public class BindingEnumeration implements NamingEnumeration
- {
- Enumeration _delegate;
-
- public BindingEnumeration (Enumeration e)
- {
- _delegate = e;
- }
-
- public void close()
- throws NamingException
- {
- }
-
- public boolean hasMore ()
- throws NamingException
- {
- return _delegate.hasMoreElements();
- }
-
- public Object next()
- throws NamingException
- {
- Binding b = (Binding)_delegate.nextElement();
- return new Binding (b.getName(), b.getClassName(), b.getObject(), true);
- }
-
- public boolean hasMoreElements()
- {
- return _delegate.hasMoreElements();
- }
-
- public Object nextElement()
- {
- Binding b = (Binding)_delegate.nextElement();
- return new Binding (b.getName(), b.getClassName(), b.getObject(),true);
- }
- }
-
-
-
- /*------------------------------------------------*/
- /**
- * Constructor
- *
- * @param env environment properties
- * @param name relative name of this context
- * @param parent immediate ancestor Context (can be null)
- * @param parser NameParser for this Context
- */
- public NamingContext(Hashtable env,
- String name,
- Context parent,
- NameParser parser)
- {
- if (env == null)
- _env = new Hashtable();
- else
- _env = new Hashtable(env);
- _name = name;
- _parent = parent;
- _parser = parser;
- }
-
-
-
- /*------------------------------------------------*/
- /**
- * Creates a new <code>NamingContext</code> instance.
- *
- * @param env a <code>Hashtable</code> value
- */
- public NamingContext (Hashtable env)
- {
- if (env == null)
- _env = new Hashtable();
- else
- _env = new Hashtable(env);
- }
-
-
-
-
- /*------------------------------------------------*/
- /**
- * Constructor
- *
- */
- public NamingContext ()
- {
- _env = new Hashtable();
- }
-
-
- /*------------------------------------------------*/
- /**
- * Clone this NamingContext
- *
- * @return copy of this NamingContext
- * @exception CloneNotSupportedException if an error occurs
- */
- public Object clone ()
- throws CloneNotSupportedException
- {
- NamingContext ctx = (NamingContext)super.clone();
- ctx._env = (Hashtable)_env.clone();
- ctx._bindings = (Hashtable)_bindings.clone();
- return ctx;
- }
-
-
- /*------------------------------------------------*/
- /**
- * Getter for _name
- *
- * @return name of this Context (relative, not absolute)
- */
- public String getName ()
- {
- return _name;
- }
-
- /*------------------------------------------------*/
- /**
- * Getter for _parent
- *
- * @return parent Context
- */
- public Context getParent()
- {
- return _parent;
- }
-
- /*------------------------------------------------*/
- /**
- * Setter for _parser
- *
- *
- */
- public void setNameParser (NameParser parser)
- {
- _parser = parser;
- }
-
-
-
- /*------------------------------------------------*/
- /**
- * Bind a name to an object
- *
- * @param name Name of the object
- * @param obj object to bind
- * @exception NamingException if an error occurs
- */
- public void bind(Name name, Object obj)
- throws NamingException
- {
- if (isLocked())
- throw new NamingException ("This context is immutable");
-
- Name cname = toCanonicalName(name);
-
- if (cname == null)
- throw new NamingException ("Name is null");
-
- if (cname.size() == 0)
- throw new NamingException ("Name is empty");
-
-
- //if no subcontexts, just bind it
- if (cname.size() == 1)
- {
- //get the object to be bound
- Object objToBind = NamingManager.getStateToBind(obj, name,this, null);
- // Check for Referenceable
- if (objToBind instanceof Referenceable)
- {
- objToBind = ((Referenceable)objToBind).getReference();
- }
- //anything else we should be able to bind directly
-
- Binding binding = getBinding (cname);
- if (binding == null)
- addBinding (cname, objToBind);
- else
- throw new NameAlreadyBoundException (cname.toString());
- }
- else
- {
- if(Log.isDebugEnabled())Log.debug("Checking for existing binding for name="+cname+" for first element of name="+cname.get(0));
-
- //walk down the subcontext hierarchy
- //need to ignore trailing empty "" name components
-
- String firstComponent = cname.get(0);
- Object ctx = null;
-
- if (firstComponent.equals(""))
- ctx = this;
- else
- {
-
- Binding binding = getBinding (firstComponent);
- if (binding == null)
- throw new NameNotFoundException (firstComponent+ " is not bound");
-
- ctx = binding.getObject();
-
-
- if (ctx instanceof Reference)
- {
- //deference the object
- try
- {
- ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
- }
- catch (NamingException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- Log.warn("",e);
- throw new NamingException (e.getMessage());
- }
- }
- }
-
-
- if (ctx instanceof Context)
- {
- ((Context)ctx).bind (cname.getSuffix(1), obj);
- }
- else
- throw new NotContextException ("Object bound at "+firstComponent +" is not a Context");
- }
- }
-
-
-
- /*------------------------------------------------*/
- /**
- * Bind a name (as a String) to an object
- *
- * @param name a <code>String</code> value
- * @param obj an <code>Object</code> value
- * @exception NamingException if an error occurs
- */
- public void bind(String name, Object obj)
- throws NamingException
- {
- bind (_parser.parse(name), obj);
- }
-
-
- /*------------------------------------------------*/
- /**
- * Create a context as a child of this one
- *
- * @param name a <code>Name</code> value
- * @return a <code>Context</code> value
- * @exception NamingException if an error occurs
- */
- public Context createSubcontext (Name name)
- throws NamingException
- {
- if (isLocked())
- {
- NamingException ne = new NamingException ("This context is immutable");
- ne.setRemainingName(name);
- throw ne;
- }
-
-
-
- Name cname = toCanonicalName (name);
-
- if (cname == null)
- throw new NamingException ("Name is null");
- if (cname.size() == 0)
- throw new NamingException ("Name is empty");
-
- if (cname.size() == 1)
- {
- //not permitted to bind if something already bound at that name
- Binding binding = getBinding (cname);
- if (binding != null)
- throw new NameAlreadyBoundException (cname.toString());
-
- Context ctx = new NamingContext ((Hashtable)_env.clone(), cname.get(0), this, _parser);
- addBinding (cname, ctx);
- return ctx;
- }
-
-
- //If the name has multiple subcontexts, walk the hierarchy by
- //fetching the first one. All intermediate subcontexts in the
- //name must already exist.
- String firstComponent = cname.get(0);
- Object ctx = null;
-
- if (firstComponent.equals(""))
- ctx = this;
- else
- {
- Binding binding = getBinding (firstComponent);
- if (binding == null)
- throw new NameNotFoundException (firstComponent + " is not bound");
-
- ctx = binding.getObject();
-
- if (ctx instanceof Reference)
- {
- //deference the object
- if(Log.isDebugEnabled())Log.debug("Object bound at "+firstComponent +" is a Reference");
- try
- {
- ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
- }
- catch (NamingException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- Log.warn("",e);
- throw new NamingException (e.getMessage());
- }
- }
- }
-
- if (ctx instanceof Context)
- {
- return ((Context)ctx).createSubcontext (cname.getSuffix(1));
- }
- else
- throw new NotContextException (firstComponent +" is not a Context");
- }
-
-
- /*------------------------------------------------*/
- /**
- * Create a Context as a child of this one
- *
- * @param name a <code>String</code> value
- * @return a <code>Context</code> value
- * @exception NamingException if an error occurs
- */
- public Context createSubcontext (String name)
- throws NamingException
- {
- return createSubcontext(_parser.parse(name));
- }
-
-
-
- /*------------------------------------------------*/
- /**
- * Not supported
- *
- * @param name name of subcontext to remove
- * @exception NamingException if an error occurs
- */
- public void destroySubcontext (String name)
- throws NamingException
- {
- removeBinding(_parser.parse(name));
- }
-
-
-
- /*------------------------------------------------*/
- /**
- * Not supported
- *
- * @param name name of subcontext to remove
- * @exception NamingException if an error occurs
- */
- public void destroySubcontext (Name name)
- throws NamingException
- {
- removeBinding(name);
- }
-
- /*------------------------------------------------*/
- /**
- * Lookup a binding by name
- *
- * @param name name of bound object
- * @exception NamingException if an error occurs
- */
- public Object lookup(Name name)
- throws NamingException
- {
- if(Log.isDebugEnabled())Log.debug("Looking up name=\""+name+"\"");
- Name cname = toCanonicalName(name);
-
- if ((cname == null) || (cname.size() == 0))
- {
- Log.debug("Null or empty name, returning copy of this context");
- NamingContext ctx = new NamingContext (_env, _name, _parent, _parser);
- ctx._bindings = _bindings;
- return ctx;
- }
-
-
-
- if (cname.size() == 1)
- {
- Binding binding = getBinding (cname);
- if (binding == null)
- {
- NameNotFoundException nnfe = new NameNotFoundException();
- nnfe.setRemainingName(cname);
- throw nnfe;
- }
-
-
- Object o = binding.getObject();
-
- //handle links by looking up the link
- if (o instanceof LinkRef)
- {
- //if link name starts with ./ it is relative to current context
- String linkName = ((LinkRef)o).getLinkName();
- if (linkName.startsWith("./"))
- return this.lookup (linkName.substring(2));
- else
- {
- //link name is absolute
- InitialContext ictx = new InitialContext();
- return ictx.lookup (linkName);
- }
- }
- else if (o instanceof Reference)
- {
- //deference the object
- try
- {
- return NamingManager.getObjectInstance(o, cname, this, _env);
- }
- catch (NamingException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- Log.warn("",e);
- throw new NamingException (e.getMessage());
- }
- }
- else
- return o;
- }
-
- //it is a multipart name, recurse to the first subcontext
-
- String firstComponent = cname.get(0);
- Object ctx = null;
-
- if (firstComponent.equals(""))
- ctx = this;
- else
- {
-
- Binding binding = getBinding (firstComponent);
- if (binding == null)
- {
- NameNotFoundException nnfe = new NameNotFoundException();
- nnfe.setRemainingName(cname);
- throw nnfe;
- }
-
- //as we have bound a reference to an object factory
- //for the component specific contexts
- //at "comp" we need to resolve the reference
- ctx = binding.getObject();
-
- if (ctx instanceof Reference)
- {
- //deference the object
- try
- {
- ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
- }
- catch (NamingException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- Log.warn("",e);
- throw new NamingException (e.getMessage());
- }
- }
- }
- if (!(ctx instanceof Context))
- throw new NotContextException();
-
- return ((Context)ctx).lookup (cname.getSuffix(1));
- }
-
-
- /*------------------------------------------------*/
- /**
- * Lookup binding of an object by name
- *
- * @param name name of bound object
- * @return object bound to name
- * @exception NamingException if an error occurs
- */
- public Object lookup (String name)
- throws NamingException
- {
- return lookup (_parser.parse(name));
- }
-
-
-
- /*------------------------------------------------*/
- /**
- * Lookup link bound to name
- *
- * @param name name of link binding
- * @return LinkRef or plain object bound at name
- * @exception NamingException if an error occurs
- */
- public Object lookupLink (Name name)
- throws NamingException
- {
- Name cname = toCanonicalName(name);
-
- if (cname == null)
- {
- NamingContext ctx = new NamingContext (_env, _name, _parent, _parser);
- ctx._bindings = _bindings;
- return ctx;
- }
- if (cname.size() == 0)
- throw new NamingException ("Name is empty");
-
- if (cname.size() == 1)
- {
- Binding binding = getBinding (cname);
- if (binding == null)
- throw new NameNotFoundException();
-
- Object o = binding.getObject();
-
- //handle links by looking up the link
- if (o instanceof Reference)
- {
- //deference the object
- try
- {
- return NamingManager.getObjectInstance(o, cname.getPrefix(1), this, _env);
- }
- catch (NamingException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- Log.warn("",e);
- throw new NamingException (e.getMessage());
- }
- }
- else
- {
- //object is either a LinkRef which we don't dereference
- //or a plain object in which case spec says we return it
- return o;
- }
- }
-
-
- //it is a multipart name, recurse to the first subcontext
- String firstComponent = cname.get(0);
- Object ctx = null;
-
- if (firstComponent.equals(""))
- ctx = this;
- else
- {
- Binding binding = getBinding (firstComponent);
- if (binding == null)
- throw new NameNotFoundException ();
-
- ctx = binding.getObject();
-
- if (ctx instanceof Reference)
- {
- //deference the object
- try
- {
- ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
- }
- catch (NamingException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- Log.warn("",e);
- throw new NamingException (e.getMessage());
- }
- }
- }
-
- if (!(ctx instanceof Context))
- throw new NotContextException();
-
- return ((Context)ctx).lookup (cname.getSuffix(1));
- }
-
-
- /*------------------------------------------------*/
- /**
- * Lookup link bound to name
- *
- * @param name name of link binding
- * @return LinkRef or plain object bound at name
- * @exception NamingException if an error occurs
- */
- public Object lookupLink (String name)
- throws NamingException
- {
- return lookupLink (_parser.parse(name));
- }
-
-
- /*------------------------------------------------*/
- /**
- * List all names bound at Context named by Name
- *
- * @param name a <code>Name</code> value
- * @return a <code>NamingEnumeration</code> value
- * @exception NamingException if an error occurs
- */
- public NamingEnumeration list(Name name)
- throws NamingException
- {
- if(Log.isDebugEnabled())Log.debug("list() on Context="+getName()+" for name="+name);
- Name cname = toCanonicalName(name);
-
-
-
- if (cname == null)
- {
- return new NameEnumeration(EMPTY_ENUM);
- }
-
-
- if (cname.size() == 0)
- {
- return new NameEnumeration (_bindings.elements());
- }
-
-
-
- //multipart name
- String firstComponent = cname.get(0);
- Object ctx = null;
-
- if (firstComponent.equals(""))
- ctx = this;
- else
- {
- Binding binding = getBinding (firstComponent);
- if (binding == null)
- throw new NameNotFoundException ();
-
- ctx = binding.getObject();
-
- if (ctx instanceof Reference)
- {
- //deference the object
- if(Log.isDebugEnabled())Log.debug("Dereferencing Reference for "+name.get(0));
- try
- {
- ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
- }
- catch (NamingException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- Log.warn("",e);
- throw new NamingException (e.getMessage());
- }
- }
- }
-
- if (!(ctx instanceof Context))
- throw new NotContextException();
-
- return ((Context)ctx).list (cname.getSuffix(1));
- }
-
-
- /*------------------------------------------------*/
- /**
- * List all names bound at Context named by Name
- *
- * @param name a <code>Name</code> value
- * @return a <code>NamingEnumeration</code> value
- * @exception NamingException if an error occurs
- */
- public NamingEnumeration list(String name)
- throws NamingException
- {
- return list(_parser.parse(name));
- }
-
-
-
- /*------------------------------------------------*/
- /**
- * List all Bindings present at Context named by Name
- *
- * @param name a <code>Name</code> value
- * @return a <code>NamingEnumeration</code> value
- * @exception NamingException if an error occurs
- */
- public NamingEnumeration listBindings(Name name)
- throws NamingException
- {
- Name cname = toCanonicalName (name);
-
- if (cname == null)
- {
- return new BindingEnumeration(EMPTY_ENUM);
- }
-
- if (cname.size() == 0)
- {
- return new BindingEnumeration (_bindings.elements());
- }
-
-
-
- //multipart name
- String firstComponent = cname.get(0);
- Object ctx = null;
-
- //if a name has a leading "/" it is parsed as "" so ignore it by staying
- //at this level in the tree
- if (firstComponent.equals(""))
- ctx = this;
- else
- {
- //it is a non-empty name component
- Binding binding = getBinding (firstComponent);
- if (binding == null)
- throw new NameNotFoundException ();
-
- ctx = binding.getObject();
-
- if (ctx instanceof Reference)
- {
- //deference the object
- try
- {
- ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
- }
- catch (NamingException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- Log.warn("",e);
- throw new NamingException (e.getMessage());
- }
- }
- }
-
- if (!(ctx instanceof Context))
- throw new NotContextException();
-
- return ((Context)ctx).listBindings (cname.getSuffix(1));
- }
-
-
-
- /*------------------------------------------------*/
- /**
- * List all Bindings at Name
- *
- * @param name a <code>String</code> value
- * @return a <code>NamingEnumeration</code> value
- * @exception NamingException if an error occurs
- */
- public NamingEnumeration listBindings(String name)
- throws NamingException
- {
- return listBindings (_parser.parse(name));
- }
-
-
- /*------------------------------------------------*/
- /**
- * Overwrite or create a binding
- *
- * @param name a <code>Name</code> value
- * @param obj an <code>Object</code> value
- * @exception NamingException if an error occurs
- */
- public void rebind(Name name,
- Object obj)
- throws NamingException
- {
- if (isLocked())
- throw new NamingException ("This context is immutable");
-
- Name cname = toCanonicalName(name);
-
- if (cname == null)
- throw new NamingException ("Name is null");
-
- if (cname.size() == 0)
- throw new NamingException ("Name is empty");
-
-
- //if no subcontexts, just bind it
- if (cname.size() == 1)
- {
- //check if it is a Referenceable
- Object objToBind = NamingManager.getStateToBind(obj, name, this, null);
- if (objToBind instanceof Referenceable)
- {
- objToBind = ((Referenceable)objToBind).getReference();
- }
- addBinding (cname, objToBind);
- }
- else
- {
- //walk down the subcontext hierarchy
- if(Log.isDebugEnabled())Log.debug("Checking for existing binding for name="+cname+" for first element of name="+cname.get(0));
-
- String firstComponent = cname.get(0);
- Object ctx = null;
-
-
- if (firstComponent.equals(""))
- ctx = this;
- else
- {
- Binding binding = getBinding (name.get(0));
- if (binding == null)
- throw new NameNotFoundException (name.get(0)+ " is not bound");
-
- ctx = binding.getObject();
-
-
- if (ctx instanceof Reference)
- {
- //deference the object
- try
- {
- ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
- }
- catch (NamingException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- Log.warn("",e);
- throw new NamingException (e.getMessage());
- }
- }
- }
-
- if (ctx instanceof Context)
- {
- ((Context)ctx).rebind (cname.getSuffix(1), obj);
- }
- else
- throw new NotContextException ("Object bound at "+firstComponent +" is not a Context");
- }
- }
-
-
- /*------------------------------------------------*/
- /**
- * Overwrite or create a binding from Name to Object
- *
- * @param name a <code>String</code> value
- * @param obj an <code>Object</code> value
- * @exception NamingException if an error occurs
- */
- public void rebind (String name,
- Object obj)
- throws NamingException
- {
- rebind (_parser.parse(name), obj);
- }
-
- /*------------------------------------------------*/
- /**
- * Not supported.
- *
- * @param name a <code>String</code> value
- * @exception NamingException if an error occurs
- */
- public void unbind (String name)
- throws NamingException
- {
- unbind(_parser.parse(name));
- }
-
- /*------------------------------------------------*/
- /**
- * Not supported.
- *
- * @param name a <code>String</code> value
- * @exception NamingException if an error occurs
- */
- public void unbind (Name name)
- throws NamingException
- {
- if (name.size() == 0)
- return;
-
-
- if (isLocked())
- throw new NamingException ("This context is immutable");
-
- Name cname = toCanonicalName(name);
-
- if (cname == null)
- throw new NamingException ("Name is null");
-
- if (cname.size() == 0)
- throw new NamingException ("Name is empty");
-
-
- //if no subcontexts, just unbind it
- if (cname.size() == 1)
- {
- removeBinding (cname);
- }
- else
- {
- //walk down the subcontext hierarchy
- if(Log.isDebugEnabled())Log.debug("Checking for existing binding for name="+cname+" for first element of name="+cname.get(0));
-
- String firstComponent = cname.get(0);
- Object ctx = null;
-
-
- if (firstComponent.equals(""))
- ctx = this;
- else
- {
- Binding binding = getBinding (name.get(0));
- if (binding == null)
- throw new NameNotFoundException (name.get(0)+ " is not bound");
-
- ctx = binding.getObject();
-
-
- if (ctx instanceof Reference)
- {
- //deference the object
- try
- {
- ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
- }
- catch (NamingException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- Log.warn("",e);
- throw new NamingException (e.getMessage());
- }
- }
- }
-
- if (ctx instanceof Context)
- {
- ((Context)ctx).unbind (cname.getSuffix(1));
- }
- else
- throw new NotContextException ("Object bound at "+firstComponent +" is not a Context");
- }
-
- }
-
- /*------------------------------------------------*/
- /**
- * Not supported
- *
- * @param oldName a <code>Name</code> value
- * @param newName a <code>Name</code> value
- * @exception NamingException if an error occurs
- */
- public void rename(Name oldName,
- Name newName)
- throws NamingException
- {
- throw new OperationNotSupportedException();
- }
-
-
- /*------------------------------------------------*/
- /**
- * Not supported
- *
- * @param oldName a <code>Name</code> value
- * @param newName a <code>Name</code> value
- * @exception NamingException if an error occurs
- */ public void rename(String oldName,
- String newName)
- throws NamingException
- {
- throw new OperationNotSupportedException();
- }
-
-
-
- /*------------------------------------------------*/
- /** Join two names together. These are treated as
- * CompoundNames.
- *
- * @param name a <code>Name</code> value
- * @param prefix a <code>Name</code> value
- * @return a <code>Name</code> value
- * @exception NamingException if an error occurs
- */
- public Name composeName(Name name,
- Name prefix)
- throws NamingException
- {
- if (name == null)
- throw new NamingException ("Name cannot be null");
- if (prefix == null)
- throw new NamingException ("Prefix cannot be null");
-
- Name compoundName = (CompoundName)prefix.clone();
- compoundName.addAll (name);
- return compoundName;
- }
-
-
-
- /*------------------------------------------------*/
- /** Join two names together. These are treated as
- * CompoundNames.
- *
- * @param name a <code>Name</code> value
- * @param prefix a <code>Name</code> value
- * @return a <code>Name</code> value
- * @exception NamingException if an error occurs
- */
- public String composeName (String name,
- String prefix)
- throws NamingException
- {
- if (name == null)
- throw new NamingException ("Name cannot be null");
- if (prefix == null)
- throw new NamingException ("Prefix cannot be null");
-
- Name compoundName = _parser.parse(prefix);
- compoundName.add (name);
- return compoundName.toString();
- }
-
-
- /*------------------------------------------------*/
- /**
- * Do nothing
- *
- * @exception NamingException if an error occurs
- */
- public void close ()
- throws NamingException
- {
-
-
- }
-
-
- /*------------------------------------------------*/
- /**
- * Return a NameParser for this Context.
- *
- * @param name a <code>Name</code> value
- * @return a <code>NameParser</code> value
- */
- public NameParser getNameParser (Name name)
- {
- return _parser;
- }
-
- /*------------------------------------------------*/
- /**
- * Return a NameParser for this Context.
- *
- * @param name a <code>Name</code> value
- * @return a <code>NameParser</code> value
- */
- public NameParser getNameParser (String name)
- {
- return _parser;
- }
-
-
- /*------------------------------------------------*/
- /**
- * Get the full name of this Context node
- * by visiting it's ancestors back to root.
- *
- * NOTE: if this Context has a URL namespace then
- * the URL prefix will be missing
- *
- * @return the full name of this Context
- * @exception NamingException if an error occurs
- */
- public String getNameInNamespace ()
- throws NamingException
- {
- Name name = _parser.parse("");
-
- NamingContext c = this;
- while (c != null)
- {
- String str = c.getName();
- if (str != null)
- name.add(0, str);
- c = (NamingContext)c.getParent();
- }
- return name.toString();
- }
-
-
- /*------------------------------------------------*/
- /**
- * Add an environment setting to this Context
- *
- * @param propName name of the property to add
- * @param propVal value of the property to add
- * @return propVal or previous value of the property
- * @exception NamingException if an error occurs
- */
- public Object addToEnvironment(String propName,
- Object propVal)
- throws NamingException
- {
- if (isLocked() && !(propName.equals(UNLOCK_PROPERTY)))
- throw new NamingException ("This context is immutable");
-
- return _env.put (propName, propVal);
- }
-
-
- /*------------------------------------------------*/
- /**
- * Remove a property from this Context's environment.
- *
- * @param propName name of property to remove
- * @return value of property or null if it didn't exist
- * @exception NamingException if an error occurs
- */
- public Object removeFromEnvironment(String propName)
- throws NamingException
- {
- if (isLocked())
- throw new NamingException ("This context is immutable");
-
- return _env.remove (propName);
- }
-
-
- /*------------------------------------------------*/
- /**
- * Get the environment of this Context.
- *
- * @return a copy of the environment of this Context.
- */
- public Hashtable getEnvironment ()
- {
- return (Hashtable)_env.clone();
- }
-
-
- /*------------------------------------------------*/
- /**
- * Add a name to object binding to this Context.
- *
- * @param name a <code>Name</code> value
- * @param obj an <code>Object</code> value
- */
- protected void addBinding (Name name, Object obj)
- {
- String key = name.toString();
- if(Log.isDebugEnabled())Log.debug("Adding binding with key="+key+" obj="+obj+" for context="+_name);
- _bindings.put (key, new Binding (key, obj));
- }
-
- /*------------------------------------------------*/
- /**
- * Get a name to object binding from this Context
- *
- * @param name a <code>Name</code> value
- * @return a <code>Binding</code> value
- */
- protected Binding getBinding (Name name)
- {
- if(Log.isDebugEnabled())Log.debug("Looking up binding for "+name.toString()+" for context="+_name);
- return (Binding) _bindings.get(name.toString());
- }
-
-
- /*------------------------------------------------*/
- /**
- * Get a name to object binding from this Context
- *
- * @param name as a String
- * @return null or the Binding
- */
- protected Binding getBinding (String name)
- {
- if(Log.isDebugEnabled())Log.debug("Looking up binding for "+name+" for context="+_name);
- return (Binding) _bindings.get(name);
- }
-
-
- protected void removeBinding (Name name)
- {
- String key = name.toString();
- if (Log.isDebugEnabled()) Log.debug("Removing binding with key="+key);
- _bindings.remove(key);
- }
-
- /*------------------------------------------------*/
- /**
- * Remove leading or trailing empty components from
- * name. Eg "/comp/env/" -> "comp/env"
- *
- * @param name the name to normalize
- * @return normalized name
- */
- public Name toCanonicalName (Name name)
- {
- Name canonicalName = name;
-
- if (name != null)
- {
- if (canonicalName.size() > 1)
- {
- if (canonicalName.get(0).equals(""))
- canonicalName = canonicalName.getSuffix(1);
-
-
- if (canonicalName.get(canonicalName.size()-1).equals(""))
- canonicalName = canonicalName.getPrefix(canonicalName.size()-1);
-
- }
- }
-
- return canonicalName;
- }
-
- private boolean isLocked()
- {
- if ((_env.get(LOCK_PROPERTY) == null) && (_env.get(UNLOCK_PROPERTY) == null))
- return false;
-
- Object lockKey = _env.get(LOCK_PROPERTY);
- Object unlockKey = _env.get(UNLOCK_PROPERTY);
-
- if ((lockKey != null) && (unlockKey != null) && (lockKey.equals(unlockKey)))
- return false;
- return true;
- }
-
-}
diff --git a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/NamingUtil.java b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/NamingUtil.java
deleted file mode 100644
index df635a6eab..0000000000
--- a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/NamingUtil.java
+++ /dev/null
@@ -1,139 +0,0 @@
-// ========================================================================
-// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-
-package org.eclipse.jetty.jndi;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.naming.Binding;
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NameNotFoundException;
-import javax.naming.NameParser;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-
-import org.eclipse.jetty.util.log.Log;
-
-
-/**
- * Util.java
- *
- *
- * Created: Tue Jul 1 18:26:17 2003
- *
- *
- * @version 1.0
- */
-public class NamingUtil
-{
-
- /* ------------------------------------------------------------ */
- /**
- * Bind an object to a context ensuring all subcontexts
- * are created if necessary
- *
- * @param ctx the context into which to bind
- * @param name the name relative to context to bind
- * @param obj the object to be bound
- * @exception NamingException if an error occurs
- */
- public static Context bind (Context ctx, String nameStr, Object obj)
- throws NamingException
- {
- Name name = ctx.getNameParser("").parse(nameStr);
-
- //no name, nothing to do
- if (name.size() == 0)
- return null;
-
- Context subCtx = ctx;
-
- //last component of the name will be the name to bind
- for (int i=0; i < name.size() - 1; i++)
- {
- try
- {
- subCtx = (Context)subCtx.lookup (name.get(i));
- if(Log.isDebugEnabled())Log.debug("Subcontext "+name.get(i)+" already exists");
- }
- catch (NameNotFoundException e)
- {
- subCtx = subCtx.createSubcontext(name.get(i));
- if(Log.isDebugEnabled())Log.debug("Subcontext "+name.get(i)+" created");
- }
- }
-
- subCtx.rebind (name.get(name.size() - 1), obj);
- if(Log.isDebugEnabled())Log.debug("Bound object to "+name.get(name.size() - 1));
- return subCtx;
-
- }
-
-
- public static void unbind (Context ctx)
- throws NamingException
- {
- //unbind everything in the context and all of its subdirectories
- NamingEnumeration ne = ctx.listBindings(ctx.getNameInNamespace());
-
- while (ne.hasMoreElements())
- {
- Binding b = (Binding)ne.nextElement();
- if (b.getObject() instanceof Context)
- {
- unbind((Context)b.getObject());
- }
- else
- ctx.unbind(b.getName());
- }
- }
-
- /**
- * Do a deep listing of the bindings for a context.
- * @param ctx the context containing the name for which to list the bindings
- * @param name the name in the context to list
- * @return map: key is fully qualified name, value is the bound object
- * @throws NamingException
- */
- public static Map flattenBindings (Context ctx, String name)
- throws NamingException
- {
- HashMap map = new HashMap();
-
- //the context representation of name arg
- Context c = (Context)ctx.lookup (name);
- NameParser parser = c.getNameParser("");
- NamingEnumeration enm = ctx.listBindings(name);
- while (enm.hasMore())
- {
- Binding b = (Binding)enm.next();
-
- if (b.getObject() instanceof Context)
- {
- map.putAll(flattenBindings (c, b.getName()));
- }
- else
- {
- Name compoundName = parser.parse (c.getNameInNamespace());
- compoundName.add(b.getName());
- map.put (compoundName.toString(), b.getObject());
- }
-
- }
-
- return map;
- }
-
-}
diff --git a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/factories/MailSessionReference.java b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/factories/MailSessionReference.java
deleted file mode 100644
index 80e95d677b..0000000000
--- a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/factories/MailSessionReference.java
+++ /dev/null
@@ -1,183 +0,0 @@
-// ========================================================================
-// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-
-package org.eclipse.jetty.jndi.factories;
-
-
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.mail.Authenticator;
-import javax.mail.PasswordAuthentication;
-import javax.mail.Session;
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.RefAddr;
-import javax.naming.Reference;
-import javax.naming.StringRefAddr;
-import javax.naming.spi.ObjectFactory;
-
-import org.eclipse.jetty.http.security.Password;
-
-/**
- * MailSessionReference
- *
- * This is a subclass of javax.mail.Reference and an ObjectFactory for javax.mail.Session objects.
- *
- * The subclassing of Reference allows all of the setup for a javax.mail.Session
- * to be captured without necessitating first instantiating a Session object. The
- * reference is bound into JNDI and it is only when the reference is looked up that
- * this object factory will create an instance of javax.mail.Session using the
- * information captured in the Reference.
- *
- */
-public class MailSessionReference extends Reference implements ObjectFactory
-{
-
-
- public static class PasswordAuthenticator extends Authenticator
- {
- PasswordAuthentication passwordAuthentication;
- private String user;
- private String password;
-
- public PasswordAuthenticator()
- {
-
- }
-
- public PasswordAuthenticator(String user, String password)
- {
- passwordAuthentication = new PasswordAuthentication (user, (password.startsWith(Password.__OBFUSCATE)?Password.deobfuscate(password):password));
- }
-
- public PasswordAuthentication getPasswordAuthentication()
- {
- return passwordAuthentication;
- }
-
- public void setUser (String user)
- {
- this.user = user;
- }
- public String getUser ()
- {
- return this.user;
- }
-
- public String getPassword ()
- {
- return this.password;
- }
-
- public void setPassword(String password)
- {
- this.password = password;
- }
-
-
- };
-
-
-
-
-
- /**
- *
- */
- public MailSessionReference()
- {
- super ("javax.mail.Session", MailSessionReference.class.getName(), null);
- }
-
-
- /**
- * Create a javax.mail.Session instance based on the information passed in the Reference
- * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
- * @param ref the Reference
- * @param arg1 not used
- * @param arg2 not used
- * @param arg3 not used
- * @return
- * @throws Exception
- */
- public Object getObjectInstance(Object ref, Name arg1, Context arg2, Hashtable arg3) throws Exception
- {
- if (ref == null)
- return null;
-
- Reference reference = (Reference)ref;
-
-
- Properties props = new Properties();
- String user = null;
- String password = null;
-
- Enumeration refs = reference.getAll();
- while (refs.hasMoreElements())
- {
- RefAddr refAddr = (RefAddr)refs.nextElement();
- String name = refAddr.getType();
- String value = (String)refAddr.getContent();
- if (name.equalsIgnoreCase("user"))
- user = value;
- else if (name.equalsIgnoreCase("pwd"))
- password = value;
- else
- props.put(name, value);
- }
-
- if (password == null)
- return Session.getInstance(props);
- else
- return Session.getInstance(props, new PasswordAuthenticator(user, password));
- }
-
-
- public void setUser (String user)
- {
- StringRefAddr addr = (StringRefAddr)get("user");
- if (addr != null)
- {
- throw new RuntimeException ("user already set on SessionReference, can't be changed");
- }
- add(new StringRefAddr("user", user));
- }
-
- public void setPassword (String password)
- {
- StringRefAddr addr = (StringRefAddr)get("pwd");
- if (addr != null)
- throw new RuntimeException ("password already set on SessionReference, can't be changed");
- add(new StringRefAddr ("pwd", password));
- }
-
- public void setProperties (Properties properties)
- {
- Iterator entries = properties.entrySet().iterator();
- while (entries.hasNext())
- {
- Map.Entry e = (Map.Entry)entries.next();
- StringRefAddr sref = (StringRefAddr)get((String)e.getKey());
- if (sref != null)
- throw new RuntimeException ("property "+e.getKey()+" already set on Session reference, can't be changed");
- add(new StringRefAddr((String)e.getKey(), (String)e.getValue()));
- }
- }
-
-
-
-}
diff --git a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/java/javaNameParser.java b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/java/javaNameParser.java
deleted file mode 100644
index 8667207a74..0000000000
--- a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/java/javaNameParser.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// ========================================================================
-// Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-
-package org.eclipse.jetty.jndi.java;
-
-import java.util.Properties;
-
-import javax.naming.CompoundName;
-import javax.naming.Name;
-import javax.naming.NameParser;
-import javax.naming.NamingException;
-
-
-/**
- * javaNameParser
- *
- */
-public class javaNameParser implements NameParser
-{
-
- static Properties syntax = new Properties();
-
- static
- {
- syntax.put("jndi.syntax.direction", "left_to_right");
- syntax.put("jndi.syntax.separator", "/");
- syntax.put("jndi.syntax.ignorecase", "false");
- }
-
- /**
- * Parse a name into its components.
- * @param name The non-null string name to parse.
- * @return A non-null parsed form of the name using the naming convention
- * of this parser.
- * @exception NamingException If a naming exception was encountered.
- */
- public Name parse(String name) throws NamingException
- {
- return new CompoundName(name, syntax);
- }
-
-}
diff --git a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/java/javaRootURLContext.java b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/java/javaRootURLContext.java
deleted file mode 100644
index e2409e7368..0000000000
--- a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/java/javaRootURLContext.java
+++ /dev/null
@@ -1,329 +0,0 @@
-// ========================================================================
-// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-
-package org.eclipse.jetty.jndi.java;
-
-
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NameParser;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.Reference;
-import javax.naming.StringRefAddr;
-
-import org.eclipse.jetty.jndi.ContextFactory;
-import org.eclipse.jetty.jndi.NamingContext;
-import org.eclipse.jetty.util.log.Log;
-
-
-
-
-/** javaRootURLContext
- * <p>This is the root of the java: url namespace
- *
- * <p><h4>Notes</h4>
- * <p>Thanks to Rickard Oberg for the idea of binding an ObjectFactory at "comp".
- *
- * <p><h4>Usage</h4>
- * <pre>
- */
-/*
-* </pre>
-*
-* @see
-*
-*
-* @version 1.0
-*/
-public class javaRootURLContext implements Context
-{
- public static final String URL_PREFIX = "java:";
-
- protected Hashtable _env;
-
- protected static NamingContext _nameRoot;
-
- protected static NameParser _javaNameParser;
-
-
- static
- {
- try
- {
- _javaNameParser = new javaNameParser();
- _nameRoot = new NamingContext();
- _nameRoot.setNameParser(_javaNameParser);
-
- StringRefAddr parserAddr = new StringRefAddr("parser", _javaNameParser.getClass().getName());
-
- Reference ref = new Reference ("javax.naming.Context",
- parserAddr,
- ContextFactory.class.getName(),
- (String)null);
-
- //bind special object factory at comp
- _nameRoot.bind ("comp", ref);
- }
- catch (Exception e)
- {
- Log.warn(e);
- }
- }
-
-
-
- /*------------------------------------------------*/
- /**
- * Creates a new <code>javaRootURLContext</code> instance.
- *
- * @param env a <code>Hashtable</code> value
- */
- public javaRootURLContext(Hashtable env)
- {
- _env = env;
- }
-
-
- public Object lookup(Name name)
- throws NamingException
- {
- return getRoot().lookup(stripProtocol(name));
- }
-
-
- public Object lookup(String name)
- throws NamingException
- {
- return getRoot().lookup(stripProtocol(name));
- }
-
- public void bind(Name name, Object obj)
- throws NamingException
- {
- getRoot().bind(stripProtocol(name), obj);
- }
-
- public void bind(String name, Object obj)
- throws NamingException
- {
- getRoot().bind(stripProtocol(name), obj);
- }
-
- public void unbind (String name)
- throws NamingException
- {
- getRoot().unbind(stripProtocol(name));
- }
-
- public void unbind (Name name)
- throws NamingException
- {
- getRoot().unbind(stripProtocol(name));
- }
-
- public void rename (String oldStr, String newStr)
- throws NamingException
- {
- getRoot().rename (stripProtocol(oldStr), stripProtocol(newStr));
- }
-
- public void rename (Name oldName, Name newName)
- throws NamingException
- {
- getRoot().rename (stripProtocol(oldName), stripProtocol(newName));
- }
-
- public void rebind (Name name, Object obj)
- throws NamingException
- {
- getRoot().rebind(stripProtocol(name), obj);
- }
-
- public void rebind (String name, Object obj)
- throws NamingException
- {
- getRoot().rebind(stripProtocol(name), obj);
- }
-
-
- public Object lookupLink (Name name)
- throws NamingException
- {
- return getRoot().lookupLink(stripProtocol(name));
- }
-
- public Object lookupLink (String name)
- throws NamingException
- {
- return getRoot().lookupLink(stripProtocol(name));
- }
-
-
- public Context createSubcontext (Name name)
- throws NamingException
- {
- return getRoot().createSubcontext(stripProtocol(name));
- }
-
- public Context createSubcontext (String name)
- throws NamingException
- {
- return getRoot().createSubcontext(stripProtocol(name));
- }
-
-
- public void destroySubcontext (Name name)
- throws NamingException
- {
- getRoot().destroySubcontext(stripProtocol(name));
- }
-
- public void destroySubcontext (String name)
- throws NamingException
- {
- getRoot().destroySubcontext(stripProtocol(name));
- }
-
-
- public NamingEnumeration list(Name name)
- throws NamingException
- {
- return getRoot().list(stripProtocol(name));
- }
-
-
- public NamingEnumeration list(String name)
- throws NamingException
- {
- return getRoot().list(stripProtocol(name));
- }
-
- public NamingEnumeration listBindings(Name name)
- throws NamingException
- {
- return getRoot().listBindings(stripProtocol(name));
- }
-
- public NamingEnumeration listBindings(String name)
- throws NamingException
- {
- return getRoot().listBindings(stripProtocol(name));
- }
-
-
- public Name composeName (Name name,
- Name prefix)
- throws NamingException
- {
- return getRoot().composeName(name, prefix);
- }
-
- public String composeName (String name,
- String prefix)
- throws NamingException
- {
- return getRoot().composeName(name, prefix);
- }
-
-
- public void close ()
- throws NamingException
- {
- }
-
- public String getNameInNamespace ()
- throws NamingException
- {
- return URL_PREFIX;
- }
-
- public NameParser getNameParser (Name name)
- throws NamingException
- {
- return _javaNameParser;
- }
-
- public NameParser getNameParser (String name)
- throws NamingException
- {
- return _javaNameParser;
- }
-
-
- public Object addToEnvironment(String propName,
- Object propVal)
- throws NamingException
- {
- return _env.put (propName,propVal);
- }
-
- public Object removeFromEnvironment(String propName)
- throws NamingException
- {
- return _env.remove (propName);
- }
-
- public Hashtable getEnvironment ()
- {
- return _env;
- }
-
-
- protected NamingContext getRoot ()
- {
- return _nameRoot;
- }
-
-
- protected Name stripProtocol (Name name)
- throws NamingException
- {
- if ((name != null) && (name.size() > 0))
- {
- String head = name.get(0);
-
- if(Log.isDebugEnabled())Log.debug("Head element of name is: "+head);
-
- if (head.startsWith(URL_PREFIX))
- {
- head = head.substring (URL_PREFIX.length());
- name.remove(0);
- if (head.length() > 0)
- name.add(0, head);
-
- if(Log.isDebugEnabled())Log.debug("name modified to "+name.toString());
- }
- }
-
- return name;
- }
-
-
-
- protected String stripProtocol (String name)
- {
- String newName = name;
-
- if ((name != null) && (!name.equals("")))
- {
- if (name.startsWith(URL_PREFIX))
- newName = name.substring(URL_PREFIX.length());
- }
-
- return newName;
- }
-
-}
diff --git a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/java/javaURLContextFactory.java b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/java/javaURLContextFactory.java
deleted file mode 100644
index 59e7aceb9c..0000000000
--- a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/java/javaURLContextFactory.java
+++ /dev/null
@@ -1,103 +0,0 @@
-// ========================================================================
-// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-
-package org.eclipse.jetty.jndi.java;
-
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NamingException;
-import javax.naming.spi.ObjectFactory;
-
-import org.eclipse.jetty.util.log.Log;
-
-
-/** javaURLContextFactory
- * <p>This is the URL context factory for the java: URL.
- *
- * <p><h4>Notes</h4>
- * <p>
- *
- * <p><h4>Usage</h4>
- * <pre>
- */
-/*
-* </pre>
-*
-* @see
-*
-*
-* @version 1.0
-*/
-public class javaURLContextFactory implements ObjectFactory
-{
-
- /**
- * Either return a new context or the resolution of a url.
- *
- * @param url an <code>Object</code> value
- * @param name a <code>Name</code> value
- * @param ctx a <code>Context</code> value
- * @param env a <code>Hashtable</code> value
- * @return a new context or the resolved object for the url
- * @exception Exception if an error occurs
- */
- public Object getObjectInstance(Object url, Name name, Context ctx, Hashtable env)
- throws Exception
- {
- // null object means return a root context for doing resolutions
- if (url == null)
- {
- if(Log.isDebugEnabled())Log.debug(">>> new root context requested ");
- return new javaRootURLContext(env);
- }
-
- // return the resolution of the url
- if (url instanceof String)
- {
- if(Log.isDebugEnabled())Log.debug(">>> resolution of url "+url+" requested");
- Context rootctx = new javaRootURLContext (env);
- return rootctx.lookup ((String)url);
- }
-
- // return the resolution of at least one of the urls
- if (url instanceof String[])
- {
- if(Log.isDebugEnabled())Log.debug(">>> resolution of array of urls requested");
- String[] urls = (String[])url;
- Context rootctx = new javaRootURLContext (env);
- Object object = null;
- NamingException e = null;
- for (int i=0;(i< urls.length) && (object == null); i++)
- {
- try
- {
- object = rootctx.lookup (urls[i]);
- }
- catch (NamingException x)
- {
- e = x;
- }
- }
-
- if (object == null)
- throw e;
- else
- return object;
- }
-
- if(Log.isDebugEnabled())Log.debug(">>> No idea what to do, so return a new root context anyway");
- return new javaRootURLContext (env);
- }
-};
diff --git a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/local/localContextRoot.java b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/local/localContextRoot.java
deleted file mode 100644
index 0e5dc5a1c1..0000000000
--- a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/local/localContextRoot.java
+++ /dev/null
@@ -1,435 +0,0 @@
-// ========================================================================
-// Copyright (c) 2000-2009 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-
-package org.eclipse.jetty.jndi.local;
-
-import java.util.Hashtable;
-import java.util.Properties;
-
-import javax.naming.CompoundName;
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NameParser;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-
-import org.eclipse.jetty.jndi.NamingContext;
-
-/**
- *
- * localContext
- *
- *
- * @version $Revision: 4780 $ $Date: 2009-03-17 16:36:08 +0100 (Tue, 17 Mar 2009) $
- *
- */
-public class localContextRoot implements Context
-{
- private static final NamingContext _root;
-
- private final Hashtable _env;
-
- // make a root for the static namespace local:
- static
- {
- _root = new NamingContext();
- _root.setNameParser(new LocalNameParser());
- }
-
- static class LocalNameParser implements NameParser
- {
- Properties syntax = new Properties();
-
- LocalNameParser()
- {
- syntax.put("jndi.syntax.direction", "left_to_right");
- syntax.put("jndi.syntax.separator", "/");
- syntax.put("jndi.syntax.ignorecase", "false");
- }
-
- public Name parse(String name) throws NamingException
- {
- return new CompoundName(name, syntax);
- }
- }
-
- public localContextRoot(Hashtable env)
- {
- _env = new Hashtable(env);
- }
-
- /**
- *
- *
- * @see javax.naming.Context#close()
- */
- public void close() throws NamingException
- {
-
- }
-
- /**
- *
- *
- * @see javax.naming.Context#getNameInNamespace()
- */
- public String getNameInNamespace() throws NamingException
- {
- return "";
- }
-
- /**
- *
- *
- * @see javax.naming.Context#destroySubcontext(java.lang.String)
- */
- public void destroySubcontext(String name) throws NamingException
- {
- synchronized (_root)
- {
- _root.destroySubcontext(getSuffix(name));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#unbind(java.lang.String)
- */
- public void unbind(String name) throws NamingException
- {
- synchronized (_root)
- {
- _root.unbind(getSuffix(name));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#getEnvironment()
- */
- public Hashtable getEnvironment() throws NamingException
- {
- return _env;
- }
-
- /**
- *
- *
- * @see javax.naming.Context#destroySubcontext(javax.naming.Name)
- */
- public void destroySubcontext(Name name) throws NamingException
- {
- synchronized (_root)
- {
- _root.destroySubcontext(getSuffix(name));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#unbind(javax.naming.Name)
- */
- public void unbind(Name name) throws NamingException
- {
- synchronized (_root)
- {
- _root.unbind(getSuffix(name));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#lookup(java.lang.String)
- */
- public Object lookup(String name) throws NamingException
- {
- synchronized (_root)
- {
- return _root.lookup(getSuffix(name));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#lookupLink(java.lang.String)
- */
- public Object lookupLink(String name) throws NamingException
- {
- synchronized (_root)
- {
- return _root.lookupLink(getSuffix(name));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#removeFromEnvironment(java.lang.String)
- */
- public Object removeFromEnvironment(String propName) throws NamingException
- {
- return _env.remove(propName);
- }
-
- /**
- *
- *
- * @see javax.naming.Context#bind(java.lang.String, java.lang.Object)
- */
- public void bind(String name, Object obj) throws NamingException
- {
- synchronized (_root)
- {
- _root.bind(getSuffix(name), obj);
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#rebind(java.lang.String, java.lang.Object)
- */
- public void rebind(String name, Object obj) throws NamingException
- {
- synchronized (_root)
- {
- _root.rebind(getSuffix(name), obj);
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#lookup(javax.naming.Name)
- */
- public Object lookup(Name name) throws NamingException
- {
- synchronized (_root)
- {
- return _root.lookup(getSuffix(name));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#lookupLink(javax.naming.Name)
- */
- public Object lookupLink(Name name) throws NamingException
- {
- synchronized (_root)
- {
- return _root.lookupLink(getSuffix(name));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#bind(javax.naming.Name, java.lang.Object)
- */
- public void bind(Name name, Object obj) throws NamingException
- {
- synchronized (_root)
- {
- _root.bind(getSuffix(name), obj);
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#rebind(javax.naming.Name, java.lang.Object)
- */
- public void rebind(Name name, Object obj) throws NamingException
- {
- synchronized (_root)
- {
- _root.rebind(getSuffix(name), obj);
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#rename(java.lang.String, java.lang.String)
- */
- public void rename(String oldName, String newName) throws NamingException
- {
- synchronized (_root)
- {
- _root.rename(getSuffix(oldName), getSuffix(newName));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#createSubcontext(java.lang.String)
- */
- public Context createSubcontext(String name) throws NamingException
- {
- synchronized (_root)
- {
- return _root.createSubcontext(getSuffix(name));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#createSubcontext(javax.naming.Name)
- */
- public Context createSubcontext(Name name) throws NamingException
- {
- synchronized (_root)
- {
- return _root.createSubcontext(getSuffix(name));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#rename(javax.naming.Name, javax.naming.Name)
- */
- public void rename(Name oldName, Name newName) throws NamingException
- {
- synchronized (_root)
- {
- _root.rename(getSuffix(oldName), getSuffix(newName));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#getNameParser(java.lang.String)
- */
- public NameParser getNameParser(String name) throws NamingException
- {
- return _root.getNameParser(name);
- }
-
- /**
- *
- *
- * @see javax.naming.Context#getNameParser(javax.naming.Name)
- */
- public NameParser getNameParser(Name name) throws NamingException
- {
- return _root.getNameParser(name);
- }
-
- /**
- *
- *
- * @see javax.naming.Context#list(java.lang.String)
- */
- public NamingEnumeration list(String name) throws NamingException
- {
- synchronized (_root)
- {
- return _root.list(getSuffix(name));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#listBindings(java.lang.String)
- */
- public NamingEnumeration listBindings(String name) throws NamingException
- {
- synchronized (_root)
- {
- return _root.listBindings(getSuffix(name));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#list(javax.naming.Name)
- */
- public NamingEnumeration list(Name name) throws NamingException
- {
- synchronized (_root)
- {
- return _root.list(getSuffix(name));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#listBindings(javax.naming.Name)
- */
- public NamingEnumeration listBindings(Name name) throws NamingException
- {
- synchronized (_root)
- {
- return _root.listBindings(getSuffix(name));
- }
- }
-
- /**
- *
- *
- * @see javax.naming.Context#addToEnvironment(java.lang.String,
- * java.lang.Object)
- */
- public Object addToEnvironment(String propName, Object propVal)
- throws NamingException
- {
- return _env.put(propName, propVal);
- }
-
- /**
- *
- *
- * @see javax.naming.Context#composeName(java.lang.String, java.lang.String)
- */
- public String composeName(String name, String prefix)
- throws NamingException
- {
- return _root.composeName(name, prefix);
- }
-
- /**
- *
- *
- * @see javax.naming.Context#composeName(javax.naming.Name,
- * javax.naming.Name)
- */
- public Name composeName(Name name, Name prefix) throws NamingException
- {
- return _root.composeName(name, prefix);
- }
-
- protected String getSuffix(String url) throws NamingException
- {
- return url;
- }
-
- protected Name getSuffix(Name name) throws NamingException
- {
- return name;
- }
-
-}
diff --git a/jetty-jndi/src/main/resources/jndi.properties b/jetty-jndi/src/main/resources/jndi.properties
deleted file mode 100644
index 61a95a63ab..0000000000
--- a/jetty-jndi/src/main/resources/jndi.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-java.naming.factory.url.pkgs=org.eclipse.jetty.jndi
-java.naming.factory.initial=org.eclipse.jetty.jndi.InitialContextFactory
diff --git a/jetty-jndi/src/test/java/org/eclipse/jetty/jndi/factories/TestMailSessionReference.java b/jetty-jndi/src/test/java/org/eclipse/jetty/jndi/factories/TestMailSessionReference.java
deleted file mode 100644
index 6933005225..0000000000
--- a/jetty-jndi/src/test/java/org/eclipse/jetty/jndi/factories/TestMailSessionReference.java
+++ /dev/null
@@ -1,72 +0,0 @@
-// ========================================================================
-// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-
-package org.eclipse.jetty.jndi.factories;
-
-import java.util.Properties;
-
-import javax.mail.Session;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.LinkRef;
-import javax.naming.Name;
-import javax.naming.NameParser;
-
-import junit.framework.TestCase;
-
-import org.eclipse.jetty.jndi.NamingUtil;
-
-/**
- * TestMailSessionReference
- *
- *
- */
-public class TestMailSessionReference extends TestCase
-{
- public void testMailSessionReference ()
- throws Exception
- {
- InitialContext icontext = new InitialContext();
- MailSessionReference sref = new MailSessionReference();
- sref.setUser("janb");
- sref.setPassword("OBF:1xmk1w261z0f1w1c1xmq");
- Properties props = new Properties ();
- props.put("mail.smtp.host", "xxx");
- props.put("mail.debug", "true");
- sref.setProperties(props);
- NamingUtil.bind(icontext, "mail/Session", sref);
- Object x = icontext.lookup("mail/Session");
- assertNotNull(x);
- assertTrue(x instanceof javax.mail.Session);
- javax.mail.Session session = (javax.mail.Session)x;
- Properties sessionProps = session.getProperties();
- assertEquals(props, sessionProps);
- assertTrue (session.getDebug());
-
- Context foo = icontext.createSubcontext("foo");
- NameParser parser = icontext.getNameParser("");
- Name objectNameInNamespace = parser.parse(icontext.getNameInNamespace());
- objectNameInNamespace.addAll(parser.parse("mail/Session"));
-
- NamingUtil.bind(foo, "mail/Session", new LinkRef(objectNameInNamespace.toString()));
-
- Object o = foo.lookup("mail/Session");
- assertNotNull(o);
- Session fooSession = (Session)o;
- assertEquals(props, fooSession.getProperties());
- assertTrue(fooSession.getDebug());
-
- icontext.destroySubcontext("mail");
- icontext.destroySubcontext("foo");
- }
-}
diff --git a/jetty-jndi/src/test/java/org/eclipse/jetty/jndi/java/TestJNDI.java b/jetty-jndi/src/test/java/org/eclipse/jetty/jndi/java/TestJNDI.java
deleted file mode 100644
index 614a0ac3f4..0000000000
--- a/jetty-jndi/src/test/java/org/eclipse/jetty/jndi/java/TestJNDI.java
+++ /dev/null
@@ -1,295 +0,0 @@
-// ========================================================================
-// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-
-package org.eclipse.jetty.jndi.java;
-
-
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.HashMap;
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.LinkRef;
-import javax.naming.Name;
-import javax.naming.NameAlreadyBoundException;
-import javax.naming.NameClassPair;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.Reference;
-import javax.naming.StringRefAddr;
-import javax.naming.spi.ObjectFactory;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.eclipse.jetty.jndi.NamingContext;
-import org.eclipse.jetty.util.log.Log;
-
-
-
-public class TestJNDI extends TestCase
-{
-
-
- public static class MyObjectFactory implements ObjectFactory
- {
- public static String myString = "xxx";
-
- public Object getObjectInstance(Object obj,
- Name name,
- Context nameCtx,
- Hashtable environment)
- throws Exception
- {
- return myString;
- }
- }
-
- public TestJNDI (String name)
- {
- super (name);
- }
-
-
- public static Test suite ()
- {
- return new TestSuite (TestJNDI.class);
- }
-
- public void setUp ()
- throws Exception
- {
- }
-
-
- public void tearDown ()
- throws Exception
- {
- }
-
- public void testIt ()
- throws Exception
- {
- try
- {
- //set up some classloaders
- Thread currentThread = Thread.currentThread();
- ClassLoader currentLoader = currentThread.getContextClassLoader();
- ClassLoader childLoader1 = new URLClassLoader(new URL[0], currentLoader);
- ClassLoader childLoader2 = new URLClassLoader(new URL[0], currentLoader);
-
- //set the current thread's classloader
- currentThread.setContextClassLoader(childLoader1);
-
- InitialContext initCtxA = new InitialContext();
- initCtxA.bind ("blah", "123");
- assertEquals ("123", initCtxA.lookup("blah"));
-
-
-
-
- InitialContext initCtx = new InitialContext();
- Context sub0 = (Context)initCtx.lookup("java:");
-
- if(Log.isDebugEnabled())Log.debug("------ Looked up java: --------------");
-
- Name n = sub0.getNameParser("").parse("/red/green/");
-
-
- if(Log.isDebugEnabled())Log.debug("get(0)="+n.get(0));
- if(Log.isDebugEnabled())Log.debug("getPrefix(1)="+n.getPrefix(1));
- n = n.getSuffix(1);
- if(Log.isDebugEnabled())Log.debug("getSuffix(1)="+n);
- if(Log.isDebugEnabled())Log.debug("get(0)="+n.get(0));
- if(Log.isDebugEnabled())Log.debug("getPrefix(1)="+n.getPrefix(1));
- n = n.getSuffix(1);
- if(Log.isDebugEnabled())Log.debug("getSuffix(1)="+n);
- if(Log.isDebugEnabled())Log.debug("get(0)="+n.get(0));
- if(Log.isDebugEnabled())Log.debug("getPrefix(1)="+n.getPrefix(1));
- n = n.getSuffix(1);
- if(Log.isDebugEnabled())Log.debug("getSuffix(1)="+n);
-
- n = sub0.getNameParser("").parse("pink/purple/");
- if(Log.isDebugEnabled())Log.debug("get(0)="+n.get(0));
- if(Log.isDebugEnabled())Log.debug("getPrefix(1)="+n.getPrefix(1));
- n = n.getSuffix(1);
- if(Log.isDebugEnabled())Log.debug("getSuffix(1)="+n);
- if(Log.isDebugEnabled())Log.debug("get(0)="+n.get(0));
- if(Log.isDebugEnabled())Log.debug("getPrefix(1)="+n.getPrefix(1));
-
- NamingContext ncontext = (NamingContext)sub0;
-
- Name nn = ncontext.toCanonicalName(ncontext.getNameParser("").parse("/yellow/blue/"));
- Log.debug(nn.toString());
- assertEquals (2, nn.size());
-
- nn = ncontext.toCanonicalName(ncontext.getNameParser("").parse("/yellow/blue"));
- Log.debug(nn.toString());
- assertEquals (2, nn.size());
-
- nn = ncontext.toCanonicalName(ncontext.getNameParser("").parse("/"));
- if(Log.isDebugEnabled())Log.debug("/ parses as: "+nn+" with size="+nn.size());
- Log.debug(nn.toString());
- assertEquals (1, nn.size());
-
- nn = ncontext.toCanonicalName(ncontext.getNameParser("").parse(""));
- Log.debug(nn.toString());
- assertEquals (0, nn.size());
-
- Context fee = ncontext.createSubcontext("fee");
- fee.bind ("fi", "88");
- assertEquals("88", initCtxA.lookup("java:/fee/fi"));
- assertEquals("88", initCtxA.lookup("java:/fee/fi/"));
- assertTrue (initCtxA.lookup("java:/fee/") instanceof javax.naming.Context);
-
- try
- {
- Context sub1 = sub0.createSubcontext ("comp");
- fail("Comp should already be bound");
- }
- catch (NameAlreadyBoundException e)
- {
- //expected exception
- }
-
-
-
- //check bindings at comp
- Context sub1 = (Context)initCtx.lookup("java:comp");
-
- Context sub2 = sub1.createSubcontext ("env");
-
- initCtx.bind ("java:comp/env/rubbish", "abc");
- assertEquals ("abc", (String)initCtx.lookup("java:comp/env/rubbish"));
-
-
-
- //check binding LinkRefs
- LinkRef link = new LinkRef ("java:comp/env/rubbish");
- initCtx.bind ("java:comp/env/poubelle", link);
- assertEquals ("abc", (String)initCtx.lookup("java:comp/env/poubelle"));
-
- //check binding References
- StringRefAddr addr = new StringRefAddr("blah", "myReferenceable");
- Reference ref = new Reference (java.lang.String.class.getName(),
- addr,
- MyObjectFactory.class.getName(),
- (String)null);
-
- initCtx.bind ("java:comp/env/quatsch", ref);
- assertEquals (MyObjectFactory.myString, (String)initCtx.lookup("java:comp/env/quatsch"));
-
- //test binding something at java:
- Context sub3 = initCtx.createSubcontext("java:zero");
- initCtx.bind ("java:zero/one", "ONE");
- assertEquals ("ONE", initCtx.lookup("java:zero/one"));
-
-
-
-
- //change the current thread's classloader to check distinct naming
- currentThread.setContextClassLoader(childLoader2);
-
- Context otherSub1 = (Context)initCtx.lookup("java:comp");
- assertTrue (!(sub1 == otherSub1));
- try
- {
- initCtx.lookup("java:comp/env/rubbish");
- }
- catch (NameNotFoundException e)
- {
- //expected
- }
-
-
- //put the thread's classloader back
- currentThread.setContextClassLoader(childLoader1);
-
- //test rebind with existing binding
- initCtx.rebind("java:comp/env/rubbish", "xyz");
- assertEquals ("xyz", initCtx.lookup("java:comp/env/rubbish"));
-
- //test rebind with no existing binding
- initCtx.rebind ("java:comp/env/mullheim", "hij");
- assertEquals ("hij", initCtx.lookup("java:comp/env/mullheim"));
-
- //test that the other bindings are already there
- assertEquals ("xyz", (String)initCtx.lookup("java:comp/env/poubelle"));
-
- //test java:/comp/env/stuff
- assertEquals ("xyz", (String)initCtx.lookup("java:/comp/env/poubelle/"));
-
- //test list Names
- NamingEnumeration nenum = initCtx.list ("java:comp/env");
- HashMap results = new HashMap();
- while (nenum.hasMore())
- {
- NameClassPair ncp = (NameClassPair)nenum.next();
- results.put (ncp.getName(), ncp.getClassName());
- }
-
- assertEquals (4, results.size());
-
- assertEquals ("java.lang.String", (String)results.get("rubbish"));
- assertEquals ("javax.naming.LinkRef", (String)results.get("poubelle"));
- assertEquals ("java.lang.String", (String)results.get("mullheim"));
- assertEquals ("javax.naming.Reference", (String)results.get("quatsch"));
-
- //test list Bindings
- NamingEnumeration benum = initCtx.list("java:comp/env");
- assertEquals (4, results.size());
-
- //test NameInNamespace
- assertEquals ("comp/env", sub2.getNameInNamespace());
-
- //test close does nothing
- Context closeCtx = (Context)initCtx.lookup("java:comp/env");
- closeCtx.close();
-
-
- //test what happens when you close an initial context
- InitialContext closeInit = new InitialContext();
- closeInit.close();
-
-
-
- //check locking the context
- Context ectx = (Context)initCtx.lookup("java:comp");
- ectx.bind("crud", "xxx");
- ectx.addToEnvironment("org.eclipse.jndi.immutable", "TRUE");
- assertEquals ("xxx", (String)initCtx.lookup("java:comp/crud"));
- try
- {
- ectx.bind("crud2", "xxx2");
- }
- catch (NamingException ne)
- {
- //expected failure to modify immutable context
- }
-
- //test what happens when you close an initial context that was used
- initCtx.close();
- }
- finally
- {
- InitialContext ic = new InitialContext();
- Context comp = (Context)ic.lookup("java:comp");
- comp.destroySubcontext("env");
- }
- }
-
-}
diff --git a/jetty-jndi/src/test/java/org/eclipse/jetty/jndi/java/TestLocalJNDI.java b/jetty-jndi/src/test/java/org/eclipse/jetty/jndi/java/TestLocalJNDI.java
deleted file mode 100644
index 23a9955c43..0000000000
--- a/jetty-jndi/src/test/java/org/eclipse/jetty/jndi/java/TestLocalJNDI.java
+++ /dev/null
@@ -1,88 +0,0 @@
-// ========================================================================
-// Copyright (c) 2008-2009 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-package org.eclipse.jetty.jndi.java;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.Name;
-import javax.naming.NameNotFoundException;
-import javax.naming.NameParser;
-
-import junit.framework.TestCase;
-
-import org.eclipse.jetty.jndi.NamingUtil;
-
-
-public class TestLocalJNDI extends TestCase
-{
-
-
- public void setUp ()
- throws Exception
- {
- }
-
-
- public void tearDown ()
- throws Exception
- {
- InitialContext ic = new InitialContext();
- ic.destroySubcontext("a");
- }
-
-
- public void testLocal ()
- throws Exception
- {
-
- InitialContext ic = new InitialContext();
- NameParser parser = ic.getNameParser("");
- ic.bind("foo", "xxx");
-
- Object o = ic.lookup("foo");
- assertNotNull(o);
- assertEquals("xxx", (String)o);
-
- ic.unbind("foo");
- try
- {
- ic.lookup("foo");
- fail("Foo exists");
- }
- catch (NameNotFoundException e)
- {
- //expected
- }
- Name name = parser.parse("a");
- name.addAll(parser.parse("b/c/d"));
- NamingUtil.bind(ic, name.toString(), "333");
- assertNotNull(ic.lookup("a"));
- assertNotNull(ic.lookup("a/b"));
- assertNotNull(ic.lookup("a/b/c"));
- Context c = (Context)ic.lookup("a/b/c");
- o = c.lookup("d");
- assertNotNull(o);
- assertEquals("333", (String)o);
- assertEquals("333", ic.lookup(name));
- ic.destroySubcontext("a");
-
- name = parser.parse("");
- name.add("x");
- Name suffix = parser.parse("y/z");
- name.addAll(suffix);
- NamingUtil.bind(ic, name.toString(), "555");
- assertEquals("555", ic.lookup(name));
- ic.destroySubcontext("x");
- }
-
-}

Back to the top