harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r437433 [11/17] - in /incubator/harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/javax/naming/ main/java/javax/naming/directory/ main/java/javax/naming/event/ main/java/javax/naming/ldap/ main/java/javax/naming/spi/ main/java/org...
Date Sun, 27 Aug 2006 18:26:28 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/Resolver.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/Resolver.java?rev=437433&r1=437432&r2=437433&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/Resolver.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/Resolver.java Sun Aug 27 11:26:20 2006
@@ -1,77 +1,77 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package javax.naming.spi;
-
-import javax.naming.Name;
-import javax.naming.NamingException;
-
-/**
- * The <code>Resolver</code> interface describes an intermediate context which
- * may be used in name resolution. In some context implementations, it is 
- * possible that subtypes of <code>Context</code> may not be supported; in such
- * cases, a class implementing the <code>Resolver</code> interface becomes 
- * useful to obtain a context which is of a specified subtype of 
- * <code>Context</code>.
- * 
- */
-public interface Resolver {
-
-    /*
-     * -------------------------------------------------------------------
-     * Methods
-     * -------------------------------------------------------------------
-     */
-
-    /**
-     * Partially resolves the name specified by name <code>n</code> stopping 
-     * at the first context object which is of the <code>Context</code> subtype 
-     * specified by class <code>c</code>.
-     * 
-     * @param n a name
-     * @param c a context
-     * @return  details of the resolved context object and the part of the name
-     *          remaining to be resolved in a non-null <code>ResolveResult</code>
-     *          object.
-     * @throws javax.naming.NotContextException if no context of the specified subtype is 
-     *          found.
-     * @throws NamingException if other naming errors occur
-     */
-    ResolveResult resolveToClass(Name n,
-                                 Class<? extends javax.naming.Context> c)
-        throws NamingException;
-
-    /**
-     * Partially resolves the name specified by name <code>n</code> stopping 
-     * at the first context object which is of the <code>Context</code> subtype 
-     * specified by class <code>c</code>.
-     * 
-     * @param n a name in string
-     * @param c a context
-     * @return  details of the resolved context object and the part of the name
-     *          remaining to be resolved in a non-null <code>ResolveResult</code>
-     *          object.
-     * @throws javax.naming.NotContextException if no context of the specified subtype is 
-     *          found.
-     * @throws NamingException if other naming errors occur
-     */
-    ResolveResult resolveToClass(String n,
-                                 Class<? extends javax.naming.Context> c)
-        throws NamingException;
-
-}
-
-
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package javax.naming.spi;
+
+import javax.naming.Name;
+import javax.naming.NamingException;
+
+/**
+ * The <code>Resolver</code> interface describes an intermediate context which
+ * may be used in name resolution. In some context implementations, it is 
+ * possible that subtypes of <code>Context</code> may not be supported; in such
+ * cases, a class implementing the <code>Resolver</code> interface becomes 
+ * useful to obtain a context which is of a specified subtype of 
+ * <code>Context</code>.
+ * 
+ */
+public interface Resolver {
+
+    /*
+     * -------------------------------------------------------------------
+     * Methods
+     * -------------------------------------------------------------------
+     */
+
+    /**
+     * Partially resolves the name specified by name <code>n</code> stopping 
+     * at the first context object which is of the <code>Context</code> subtype 
+     * specified by class <code>c</code>.
+     * 
+     * @param n a name
+     * @param c a context
+     * @return  details of the resolved context object and the part of the name
+     *          remaining to be resolved in a non-null <code>ResolveResult</code>
+     *          object.
+     * @throws javax.naming.NotContextException if no context of the specified subtype is 
+     *          found.
+     * @throws NamingException if other naming errors occur
+     */
+    ResolveResult resolveToClass(Name n,
+                                 Class<? extends javax.naming.Context> c)
+        throws NamingException;
+
+    /**
+     * Partially resolves the name specified by name <code>n</code> stopping 
+     * at the first context object which is of the <code>Context</code> subtype 
+     * specified by class <code>c</code>.
+     * 
+     * @param n a name in string
+     * @param c a context
+     * @return  details of the resolved context object and the part of the name
+     *          remaining to be resolved in a non-null <code>ResolveResult</code>
+     *          object.
+     * @throws javax.naming.NotContextException if no context of the specified subtype is 
+     *          found.
+     * @throws NamingException if other naming errors occur
+     */
+    ResolveResult resolveToClass(String n,
+                                 Class<? extends javax.naming.Context> c)
+        throws NamingException;
+
+}
+
+

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/Resolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/StateFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/StateFactory.java?rev=437433&r1=437432&r2=437433&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/StateFactory.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/StateFactory.java Sun Aug 27 11:26:20 2006
@@ -1,98 +1,98 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package javax.naming.spi;
-
-import java.util.Hashtable;
-import javax.naming.Name;
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-/**
- * The <code>StateFactory</code> interface describes a factory used to get 
- * the state of an object to be bound. Using a <code>lookup()</code> on a 
- * suitable context, an class may be found representing, say, a printer; 
- * an <code>ObjectFactory</code> may be used to create an instance of the 
- * printer object class and methods defined by the printer class may be used 
- * to inspect and manipulate the printer. There is a reverse mechanism in 
- * which a <code>StateFactory</code> is used by the service provider
- * to obtain the state of the (in this case) printer for storing in the 
- * naming system. In addition to implementing this interface, a 
- * <code>StateFactory</code> class must be public and have a public 
- * constructor taking no parameters.
- * <p>
- * Note that while <code>StateFactory</code> is meant to be used in 
- * <code>Context</code> service providers, whereas <code>DirStateFactory</code>
- * is meant to be used in <code>DirContext</code> service providers.</p>
- *
- */
-public interface StateFactory {
-
-    /*
-     * -------------------------------------------------------------------
-     * Methods
-     * -------------------------------------------------------------------
-     */
-
-    /**
-     * Returns a new instance of the specified object <code>o</code> 
-     * containing the state of the object to be bound, customised by the 
-     * specified <code>envmt</code> parameter. The name and context 
-     * parameters optionally specify the name of the object being created. 
-     * 
-     * Object and state factories are specified via environment properties 
-     * from several sources including provider properties files (see the 
-     * specification of the <code>Context</code> interface) and may comprise 
-     * a list of factories. When the service provider looks to obtain the list
-     * of state factories, the environment and provider properties files are 
-     * search for the property name specified by constant
-     * <code>Context.STATE_FACTORIES</code>. Each state factory in the
-     * resulting list is used by <code>NamingManager.getStateToBind()</code> 
-     * which invokes this method on each of them until a non-null result is 
-     * achieved or until the list is exhausted. If a <code>StatetFactory</code>
-     * throws an exception, it should be passed back to the code that 
-     * invoked <code>NamingManager.getStateToBind()</code> and no further 
-     * state factories in the list are examined. An exception should only be 
-     * thrown by a state factory if it is intended that no other state 
-     * factories be examined. Usually, if an state factory is unable to
-     * return the state of an object, then null should be returned.
-     * 
-     * @param o     may be null, or specifies the returning instance
-     * @param n     may be null, or specifies the name relative to the 
-     *              specified context <code>c</code>. The implementation 
-     *              may clone or copy this object, but will not modify the 
-     *              original.
-     * @param c     the context to which the name parameter is relative, or 
-     *              may be null when using a name relative the the default 
-     *              initial context. If a factory uses this context object, 
-     *              synchronization should be used as context objects are 
-     *              not thread-safe.
-     * @param envmt may be null; the implementation may clone or copy this 
-     *              object, but will not modify the original.
-     * @return      either a new instance of the specified object 
-     *              <code>o</code> containing the state of the object to be 
-     *              bound, customised by the specified 
-     *              <code>envmt</code> parameter. Or null if no object could 
-     *              be created.
-     * @throws NamingException if it is intended that no other state 
-     *              factories be examined.
-     */
-    Object getStateToBind(Object o, Name n, Context c, Hashtable<?, ?> envmt)
-        throws NamingException;
-
-}
-
-
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package javax.naming.spi;
+
+import java.util.Hashtable;
+import javax.naming.Name;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+/**
+ * The <code>StateFactory</code> interface describes a factory used to get 
+ * the state of an object to be bound. Using a <code>lookup()</code> on a 
+ * suitable context, an class may be found representing, say, a printer; 
+ * an <code>ObjectFactory</code> may be used to create an instance of the 
+ * printer object class and methods defined by the printer class may be used 
+ * to inspect and manipulate the printer. There is a reverse mechanism in 
+ * which a <code>StateFactory</code> is used by the service provider
+ * to obtain the state of the (in this case) printer for storing in the 
+ * naming system. In addition to implementing this interface, a 
+ * <code>StateFactory</code> class must be public and have a public 
+ * constructor taking no parameters.
+ * <p>
+ * Note that while <code>StateFactory</code> is meant to be used in 
+ * <code>Context</code> service providers, whereas <code>DirStateFactory</code>
+ * is meant to be used in <code>DirContext</code> service providers.</p>
+ *
+ */
+public interface StateFactory {
+
+    /*
+     * -------------------------------------------------------------------
+     * Methods
+     * -------------------------------------------------------------------
+     */
+
+    /**
+     * Returns a new instance of the specified object <code>o</code> 
+     * containing the state of the object to be bound, customised by the 
+     * specified <code>envmt</code> parameter. The name and context 
+     * parameters optionally specify the name of the object being created. 
+     * 
+     * Object and state factories are specified via environment properties 
+     * from several sources including provider properties files (see the 
+     * specification of the <code>Context</code> interface) and may comprise 
+     * a list of factories. When the service provider looks to obtain the list
+     * of state factories, the environment and provider properties files are 
+     * search for the property name specified by constant
+     * <code>Context.STATE_FACTORIES</code>. Each state factory in the
+     * resulting list is used by <code>NamingManager.getStateToBind()</code> 
+     * which invokes this method on each of them until a non-null result is 
+     * achieved or until the list is exhausted. If a <code>StatetFactory</code>
+     * throws an exception, it should be passed back to the code that 
+     * invoked <code>NamingManager.getStateToBind()</code> and no further 
+     * state factories in the list are examined. An exception should only be 
+     * thrown by a state factory if it is intended that no other state 
+     * factories be examined. Usually, if an state factory is unable to
+     * return the state of an object, then null should be returned.
+     * 
+     * @param o     may be null, or specifies the returning instance
+     * @param n     may be null, or specifies the name relative to the 
+     *              specified context <code>c</code>. The implementation 
+     *              may clone or copy this object, but will not modify the 
+     *              original.
+     * @param c     the context to which the name parameter is relative, or 
+     *              may be null when using a name relative the the default 
+     *              initial context. If a factory uses this context object, 
+     *              synchronization should be used as context objects are 
+     *              not thread-safe.
+     * @param envmt may be null; the implementation may clone or copy this 
+     *              object, but will not modify the original.
+     * @return      either a new instance of the specified object 
+     *              <code>o</code> containing the state of the object to be 
+     *              bound, customised by the specified 
+     *              <code>envmt</code> parameter. Or null if no object could 
+     *              be created.
+     * @throws NamingException if it is intended that no other state 
+     *              factories be examined.
+     */
+    Object getStateToBind(Object o, Name n, Context c, Hashtable<?, ?> envmt)
+        throws NamingException;
+
+}
+
+

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/spi/StateFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/EnvironmentReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/internal/UrlParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLContext.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLContext.java?rev=437433&r1=437432&r2=437433&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLContext.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLContext.java Sun Aug 27 11:26:20 2006
@@ -1,787 +1,787 @@
-/*
- * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * @author  Vasily Zakharov
- * @version $Revision: 1.1.2.3 $
- */
-package org.apache.harmony.jndi.provider;
-
-import java.util.Hashtable;
-
-import javax.naming.CannotProceedException;
-import javax.naming.CompositeName;
-import javax.naming.Context;
-import javax.naming.InvalidNameException;
-import javax.naming.Name;
-import javax.naming.NameParser;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.OperationNotSupportedException;
-
-import javax.naming.spi.NamingManager;
-import javax.naming.spi.ResolveResult;
-
-
-/**
- * Base class for URL naming context implementations.
- *
- * In many cases, subclasses should only override
- * {@link #getRootURLContext(String, Hashtable)} method
- * and provide a public constructor calling
- * {@link GenericURLContext#GenericURLContext(Hashtable) super(environment)}.
- *
- * @author  Vasily Zakharov
- * @version $Revision: 1.1.2.3 $
- */
-public abstract class GenericURLContext implements Context {
-
-    /**
-     * Local environment.
-     */
-    protected Hashtable environment;
-
-    /**
-     * Creates instance of this context with empty environment.
-     */
-    protected GenericURLContext() {
-        this(null);
-    }
-
-    /**
-     * Creates instance of this context with specified environment.
-     *
-     * @param   environment
-     *          Environment to copy.
-     */
-    protected GenericURLContext(Hashtable environment) {
-        this.environment = ((environment != null)
-                ? (Hashtable) environment.clone()
-                : new Hashtable());
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Object lookup(Name name) throws NamingException {
-        if (!(name instanceof CompositeName)) {
-            throw new InvalidNameException(
-                    "URL context can't accept non-composite name: " + name);
-        }
-
-        if (name.size() == 1) {
-            return lookup(name.get(0));
-        } else {
-            Context context = getContinuationContext(name);
-
-            try {
-                return context.lookup(name.getSuffix(1));
-            } finally {
-                context.close();
-            }
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Object lookup(String name) throws NamingException {
-        ResolveResult result = getRootURLContext(name, environment);
-        Context context = (Context) result.getResolvedObj();
-
-        try {
-            return context.lookup(result.getRemainingName());
-        } finally {
-            context.close();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Object lookupLink(Name name) throws NamingException {
-        if (!(name instanceof CompositeName)) {
-            throw new InvalidNameException(
-                    "URL context can't accept non-composite name: " + name);
-        }
-
-        if (name.size() == 1) {
-            return lookupLink(name.get(0));
-        } else {
-            Context context = getContinuationContext(name);
-
-            try {
-                return context.lookupLink(name.getSuffix(1));
-            } finally {
-                context.close();
-            }
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Object lookupLink(String name) throws NamingException {
-        ResolveResult result = getRootURLContext(name, environment);
-        Context context = (Context) result.getResolvedObj();
-
-        try {
-            return context.lookupLink(result.getRemainingName());
-        } finally {
-            context.close();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void bind(Name name, Object obj) throws NamingException {
-        if (!(name instanceof CompositeName)) {
-            throw new InvalidNameException(
-                    "URL context can't accept non-composite name: " + name);
-        }
-
-        if (name.size() == 1) {
-            bind(name.get(0), obj);
-        } else {
-            Context context = getContinuationContext(name);
-
-            try {
-                context.bind(name.getSuffix(1), obj);
-            } finally {
-                context.close();
-            }
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void bind(String name, Object obj) throws NamingException {
-        ResolveResult result = getRootURLContext(name, environment);
-        Context context = (Context) result.getResolvedObj();
-
-        try {
-            context.bind(result.getRemainingName(), obj);
-        } finally {
-            context.close();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void rebind(Name name, Object obj) throws NamingException {
-        if (!(name instanceof CompositeName)) {
-            throw new InvalidNameException(
-                    "URL context can't accept non-composite name: " + name);
-        }
-
-        if (name.size() == 1) {
-            rebind(name.get(0), obj);
-        } else {
-            Context context = getContinuationContext(name);
-
-            try {
-                context.rebind(name.getSuffix(1), obj);
-            } finally {
-                context.close();
-            }
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void rebind(String name, Object obj) throws NamingException {
-        ResolveResult result = getRootURLContext(name, environment);
-        Context context = (Context) result.getResolvedObj();
-
-        try {
-            context.rebind(result.getRemainingName(), obj);
-        } finally {
-            context.close();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void unbind(Name name) throws NamingException {
-        if (!(name instanceof CompositeName)) {
-            throw new InvalidNameException(
-                    "URL context can't accept non-composite name: " + name);
-        }
-
-        if (name.size() == 1) {
-            unbind(name.get(0));
-        } else {
-            Context context = getContinuationContext(name);
-
-            try {
-                context.unbind(name.getSuffix(1));
-            } finally {
-                context.close();
-            }
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void unbind(String name) throws NamingException {
-        ResolveResult result = getRootURLContext(name, environment);
-        Context context = (Context) result.getResolvedObj();
-
-        try {
-            context.unbind(result.getRemainingName());
-        } finally {
-            context.close();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Context createSubcontext(Name name) throws NamingException {
-        if (!(name instanceof CompositeName)) {
-            throw new InvalidNameException(
-                    "URL context can't accept non-composite name: " + name);
-        }
-
-        if (name.size() == 1) {
-            return createSubcontext(name.get(0));
-        } else {
-            Context context = getContinuationContext(name);
-
-            try {
-                return context.createSubcontext(name.getSuffix(1));
-            } finally {
-                context.close();
-            }
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Context createSubcontext(String name) throws NamingException {
-        ResolveResult result = getRootURLContext(name, environment);
-        Context context = (Context) result.getResolvedObj();
-
-        try {
-            return context.createSubcontext(result.getRemainingName());
-        } finally {
-            context.close();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void destroySubcontext(Name name) throws NamingException {
-        if (!(name instanceof CompositeName)) {
-            throw new InvalidNameException(
-                    "URL context can't accept non-composite name: " + name);
-        }
-
-        if (name.size() == 1) {
-            destroySubcontext(name.get(0));
-        } else {
-            Context context = getContinuationContext(name);
-
-            try {
-                context.destroySubcontext(name.getSuffix(1));
-            } finally {
-                context.close();
-            }
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void destroySubcontext(String name) throws NamingException {
-        ResolveResult result = getRootURLContext(name, environment);
-        Context context = (Context) result.getResolvedObj();
-
-        try {
-            context.destroySubcontext(result.getRemainingName());
-        } finally {
-            context.close();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     *
-     * This method uses {@link #urlEquals(String, String)} to compare
-     * URL prefixes of the names.
-     */
-    public void rename(Name oldName, Name newName) throws NamingException {
-        if (!(oldName instanceof CompositeName)) {
-            throw new InvalidNameException(
-                    "URL context can't accept non-composite name: " + oldName);
-        }
-
-        if (!(newName instanceof CompositeName)) {
-            throw new InvalidNameException(
-                    "URL context can't accept non-composite name: " + newName);
-        }
-
-        if ((oldName.size() == 1) ^ (newName.size() != 1)) {
-            throw new OperationNotSupportedException("Renaming of names "
-                    + "of which one has only one component, and another "
-                    + "has more than one component is not supported: "
-                    + oldName + " -> " + newName);
-        }
-
-        if (oldName.size() == 1) {
-             rename(oldName.get(0), newName.get(0));
-        } else {
-            if (!urlEquals(oldName.get(0), oldName.get(0))) {
-                throw new OperationNotSupportedException("Renaming of names "
-                        + "using different URLs as their first components "
-                        + "is not supported: " + oldName + " -> " + newName);
-            }
-            Context context = getContinuationContext(oldName);
-
-            try {
-                context.rename(oldName.getSuffix(1), newName.getSuffix(1));
-            } finally {
-                context.close();
-            }
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     *
-     * This method uses {@link #getURLPrefix(String)} and
-     * {@link #getURLSuffix(String, String)} methods to parse string names,
-     * and also uses  {@link #urlEquals(String, String)}
-     * to compare URL prefixes of the names.
-     */
-    public void rename(String oldName, String newName) throws NamingException {
-        String oldPrefix = getURLPrefix(oldName);
-        String newPrefix = getURLPrefix(newName);
-
-        if(!urlEquals(oldPrefix, newPrefix)) {
-            throw new OperationNotSupportedException("Renaming of names "
-                    + "using different URL prefixes is not supported: "
-                    + oldName + " -> " + newName);
-        }
-        ResolveResult result = getRootURLContext(oldName, environment);
-        Context context = (Context) result.getResolvedObj();
-
-        try {
-            context.rename(result.getRemainingName(),
-                    getURLSuffix(newPrefix, newName));
-        } finally {
-            context.close();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public NamingEnumeration list(Name name) throws NamingException {
-        if (!(name instanceof CompositeName)) {
-            throw new InvalidNameException(
-                    "URL context can't accept non-composite name: " + name);
-        }
-
-        if (name.size() == 1) {
-            return list(name.get(0));
-        } else {
-            Context context = getContinuationContext(name);
-
-            try {
-                return context.list(name.getSuffix(1));
-            } finally {
-                context.close();
-            }
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public NamingEnumeration list(String name) throws NamingException {
-        ResolveResult result = getRootURLContext(name, environment);
-        Context context = (Context) result.getResolvedObj();
-
-        try {
-            return context.list(result.getRemainingName());
-        } finally {
-            context.close();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public NamingEnumeration listBindings(Name name) throws NamingException {
-        if (!(name instanceof CompositeName)) {
-            throw new InvalidNameException(
-                    "URL context can't accept non-composite name: " + name);
-        }
-
-        if (name.size() == 1) {
-            return listBindings(name.get(0));
-        } else {
-            Context context = getContinuationContext(name);
-
-            try {
-                return context.listBindings(name.getSuffix(1));
-            } finally {
-                context.close();
-            }
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public NamingEnumeration listBindings(String name) throws NamingException {
-        ResolveResult result = getRootURLContext(name, environment);
-        Context context = (Context) result.getResolvedObj();
-
-        try {
-            return context.listBindings(result.getRemainingName());
-        } finally {
-            context.close();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public NameParser getNameParser(Name name) throws NamingException {
-        if (!(name instanceof CompositeName)) {
-            throw new InvalidNameException(
-                    "URL context can't accept non-composite name: " + name);
-        }
-
-        if (name.size() == 1) {
-            return getNameParser(name.get(0));
-        } else {
-            Context context = getContinuationContext(name);
-
-            try {
-                return context.getNameParser(name.getSuffix(1));
-            } finally {
-                context.close();
-            }
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public NameParser getNameParser(String name) throws NamingException {
-        ResolveResult result = getRootURLContext(name, environment);
-        Context context = (Context) result.getResolvedObj();
-
-        try {
-            return context.getNameParser(result.getRemainingName());
-        } finally {
-            context.close();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Name composeName(Name name, Name prefix) throws NamingException {
-        return ((Name) prefix.clone()).addAll(name);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public String composeName(String name, String prefix) {
-        return ((prefix.length() < 1) ? name
-                : (name.length() < 1) ? prefix
-                : (prefix + '/' + name));
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public String getNameInNamespace() {
-        return "";
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Hashtable getEnvironment() {
-        return (Hashtable) environment.clone();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Object addToEnvironment(String propName, Object propVal) {
-        return environment.put(propName, propVal);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Object removeFromEnvironment(String propName) {
-        return environment.remove(propName);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void close() {
-        environment = null;
-    }
-
-    /**
-     * Lookups the first component (considered a URL)
-     * of the specified name using {@link #lookup(String)},
-     * wraps it into {@link CannotProceedException}, passes it to
-     * {@link NamingManager#getContinuationContext(CannotProceedException)}
-     * method and returns the result.
-     *
-     * This method is used by {@link #lookup(Name)} and other public methods
-     * taking {@link Name} as a parameter.
-     *
-     * This method uses {@link #createCannotProceedException(Name)} method.
-     *
-     * @param   name
-     *          Name to parse.
-     *
-     * @return  Continuation context.
-     *
-     * @throws  NamingException
-     *          If some naming error occurs.
-     */
-    protected Context getContinuationContext(Name name) throws NamingException {
-        return NamingManager.getContinuationContext(
-                createCannotProceedException(name));
-    }
-
-    /**
-     * Lookups the first component (considered a URL)
-     * of the specified name using {@link #lookup(String)}
-     * and wraps it into {@link CannotProceedException}.
-     *
-     * @param   name
-     *          Name to parse.
-     *
-     * @return  Created {@link CannotProceedException}.
-     *
-     * @throws  NamingException
-     *          If some naming error occurs.
-     */
-    protected final CannotProceedException createCannotProceedException(
-            Name name) throws NamingException {
-        CannotProceedException cpe = new CannotProceedException();
-        cpe.setResolvedObj(lookup(name.get(0)));
-        cpe.setEnvironment(environment);
-        return cpe;
-    }
-
-    /**
-     * Determines the proper context from the specified URL and returns
-     * the {@link ResolveResult} object with that context as resolved object
-     * and the rest of the URL as remaining name.
-     *
-     * This method is used by {@link #lookup(String)} and other public methods
-     * taking {@link String} name as a parameter.
-     *
-     * This method must be overridden by particular URL context implementations.
-     *
-     * When overriding make sure that
-     * {@link #getURLPrefix(String)},
-     * {@link #getURLSuffix(String, String)} and
-     * {@link #getRootURLContext(String, Hashtable)}
-     * methods are in sync in how they parse URLs.
-     *
-     * @param   url
-     *          URL.
-     *
-     * @param   environment
-     *          Environment.
-     *
-     * @return  {@link ResolveResult} object with resolved context
-     *          as resolved object the rest of the URL as remaining name.
-     *
-     * @throws  NamingException
-     *          If some naming error occurs.
-     */
-    protected abstract ResolveResult getRootURLContext(
-            String url, Hashtable environment) throws NamingException;
-
-    /**
-     * Compares two URLs for equality.
-     *
-     * Implemented here as <code>url1.equals(url2)</code>.
-     * Subclasses may provide different implementation.
-     *
-     * This method is only used by {@link #rename(Name, Name)}
-     * and {@link #rename(String, String)} methods.
-     *
-     * @param   url1
-     *          First URL to compare.
-     *
-     * @param   url2
-     *          Second URL to compare.
-     *
-     * @return  <code>true</code> if specified URLs are equal,
-     *          <code>false</code> otherwise.
-     */
-    protected boolean urlEquals(String url1, String url2) {
-        return url1.equals(url2);
-    }
-
-    /**
-     * Returns URL prefix, containing scheme name, hostname and port.
-     *
-     * This method is only used by {@link #rename(String, String)} method
-     * and may be overridden by subclasses.
-     *
-     * When overriding make sure that
-     * {@link #getURLPrefix(String)},
-     * {@link #getURLSuffix(String, String)} and
-     * {@link #getRootURLContext(String, Hashtable)}
-     * methods are in sync in how they parse URLs.
-     *
-     * @param   url
-     *          URL to parse.
-     *
-     * @return  URL prefix.
-     *
-     * @throws  NamingException
-     *          If some naming error occurs.
-     */
-    protected String getURLPrefix(String url) throws NamingException {
-        int index = url.indexOf(':');
-        if (index < 0) {
-            throw new OperationNotSupportedException("Invalid URL: " + url);
-        }
-        index++;
-
-        if (url.startsWith("//", index)) {
-            int slashPos = url.indexOf('/', index + 2);
-            index = ((slashPos >= 0) ? slashPos : url.length());
-        }
-        return url.substring(0, index);
-    }
-
-    /**
-     * Returns URL suffix, containing everything but the
-     * {@linkplain #getURLPrefix(String) prefix} and separating slash,
-     * as a single-component {@link CompositeName}.
-     *
-     * This method is only used by {@link #rename(String, String)} method
-     * and may be overridden by subclasses.
-     *
-     * This method uses {@link #decodeURLString(String)}
-     * to decode the suffix string.
-     *
-     * When overriding make sure that
-     * {@link #getURLPrefix(String)},
-     * {@link #getURLSuffix(String, String)} and
-     * {@link #getRootURLContext(String, Hashtable)}
-     * methods are in sync in how they parse URLs.
-     *
-     * @param   prefix
-     *          URL prefix, returned by {@link #getURLPrefix(String)}
-     *          previously called on the same URL.
-     *
-     * @param   url
-     *          URL to parse.
-     *
-     * @return  URL suffix as a single-component {@link CompositeName}.
-     *
-     * @throws  NamingException
-     *          If some naming error occurs.
-     */
-    protected Name getURLSuffix(String prefix, String url)
-            throws NamingException {
-        int length = prefix.length();
-
-        if (length >= (url.length() - 1)) {
-            // If prefix is only 1 character shorter than URL,
-            // that character is slash and can be ignored.
-            return new CompositeName();
-        }
-
-        String suffix = url.substring(
-                (url.charAt(length) == '/') ? (length + 1) : length);
-
-        try {
-            return new CompositeName().add(decodeURLString(suffix));
-        } catch (IllegalArgumentException e) {
-            throw (InvalidNameException)
-                    new InvalidNameException().initCause(e);
-        }
-    }
-
-    /**
-     * Decodes URL string by transforming URL-encoded characters
-     * into their Unicode character representations.
-     *
-     * This method is used by {@link #getURLSuffix(String, String)}.
-     *
-     * @param   str
-     *          URL or part of URL string.
-     *
-     * @return  Decoded string.
-     *
-     * @throws  IllegalArgumentException
-     *          If URL format is incorrect.
-     */
-    protected static final String decodeURLString(String str)
-            throws IllegalArgumentException {
-        int length = str.length();
-        byte bytes[] = new byte[length];
-        int index = 0;
-
-        for(int i = 0; i < length; ) {
-            char c = str.charAt(i++);
-
-            if (c == '%') {
-                int next = i + 2;
-
-                if (next > length) {
-                    new IllegalArgumentException("Invalid URL format: " + str);
-                }
-
-                try {
-                    bytes[index++] = (byte)
-                            Integer.parseInt(str.substring(i, next), 16);
-                } catch (NumberFormatException e) {
-                    throw (IllegalArgumentException)
-                            new IllegalArgumentException(
-                                    "Invalid URL format: " + str).initCause(e);
-                }
-
-                i = next;
-            } else {
-                bytes[index++] = (byte) c;
-            }
-        }
-        return new String(bytes, 0, index);
-    }
-}
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.3 $
+ */
+package org.apache.harmony.jndi.provider;
+
+import java.util.Hashtable;
+
+import javax.naming.CannotProceedException;
+import javax.naming.CompositeName;
+import javax.naming.Context;
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.OperationNotSupportedException;
+
+import javax.naming.spi.NamingManager;
+import javax.naming.spi.ResolveResult;
+
+
+/**
+ * Base class for URL naming context implementations.
+ *
+ * In many cases, subclasses should only override
+ * {@link #getRootURLContext(String, Hashtable)} method
+ * and provide a public constructor calling
+ * {@link GenericURLContext#GenericURLContext(Hashtable) super(environment)}.
+ *
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.3 $
+ */
+public abstract class GenericURLContext implements Context {
+
+    /**
+     * Local environment.
+     */
+    protected Hashtable environment;
+
+    /**
+     * Creates instance of this context with empty environment.
+     */
+    protected GenericURLContext() {
+        this(null);
+    }
+
+    /**
+     * Creates instance of this context with specified environment.
+     *
+     * @param   environment
+     *          Environment to copy.
+     */
+    protected GenericURLContext(Hashtable environment) {
+        this.environment = ((environment != null)
+                ? (Hashtable) environment.clone()
+                : new Hashtable());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object lookup(Name name) throws NamingException {
+        if (!(name instanceof CompositeName)) {
+            throw new InvalidNameException(
+                    "URL context can't accept non-composite name: " + name);
+        }
+
+        if (name.size() == 1) {
+            return lookup(name.get(0));
+        } else {
+            Context context = getContinuationContext(name);
+
+            try {
+                return context.lookup(name.getSuffix(1));
+            } finally {
+                context.close();
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object lookup(String name) throws NamingException {
+        ResolveResult result = getRootURLContext(name, environment);
+        Context context = (Context) result.getResolvedObj();
+
+        try {
+            return context.lookup(result.getRemainingName());
+        } finally {
+            context.close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object lookupLink(Name name) throws NamingException {
+        if (!(name instanceof CompositeName)) {
+            throw new InvalidNameException(
+                    "URL context can't accept non-composite name: " + name);
+        }
+
+        if (name.size() == 1) {
+            return lookupLink(name.get(0));
+        } else {
+            Context context = getContinuationContext(name);
+
+            try {
+                return context.lookupLink(name.getSuffix(1));
+            } finally {
+                context.close();
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object lookupLink(String name) throws NamingException {
+        ResolveResult result = getRootURLContext(name, environment);
+        Context context = (Context) result.getResolvedObj();
+
+        try {
+            return context.lookupLink(result.getRemainingName());
+        } finally {
+            context.close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void bind(Name name, Object obj) throws NamingException {
+        if (!(name instanceof CompositeName)) {
+            throw new InvalidNameException(
+                    "URL context can't accept non-composite name: " + name);
+        }
+
+        if (name.size() == 1) {
+            bind(name.get(0), obj);
+        } else {
+            Context context = getContinuationContext(name);
+
+            try {
+                context.bind(name.getSuffix(1), obj);
+            } finally {
+                context.close();
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void bind(String name, Object obj) throws NamingException {
+        ResolveResult result = getRootURLContext(name, environment);
+        Context context = (Context) result.getResolvedObj();
+
+        try {
+            context.bind(result.getRemainingName(), obj);
+        } finally {
+            context.close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void rebind(Name name, Object obj) throws NamingException {
+        if (!(name instanceof CompositeName)) {
+            throw new InvalidNameException(
+                    "URL context can't accept non-composite name: " + name);
+        }
+
+        if (name.size() == 1) {
+            rebind(name.get(0), obj);
+        } else {
+            Context context = getContinuationContext(name);
+
+            try {
+                context.rebind(name.getSuffix(1), obj);
+            } finally {
+                context.close();
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void rebind(String name, Object obj) throws NamingException {
+        ResolveResult result = getRootURLContext(name, environment);
+        Context context = (Context) result.getResolvedObj();
+
+        try {
+            context.rebind(result.getRemainingName(), obj);
+        } finally {
+            context.close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void unbind(Name name) throws NamingException {
+        if (!(name instanceof CompositeName)) {
+            throw new InvalidNameException(
+                    "URL context can't accept non-composite name: " + name);
+        }
+
+        if (name.size() == 1) {
+            unbind(name.get(0));
+        } else {
+            Context context = getContinuationContext(name);
+
+            try {
+                context.unbind(name.getSuffix(1));
+            } finally {
+                context.close();
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void unbind(String name) throws NamingException {
+        ResolveResult result = getRootURLContext(name, environment);
+        Context context = (Context) result.getResolvedObj();
+
+        try {
+            context.unbind(result.getRemainingName());
+        } finally {
+            context.close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Context createSubcontext(Name name) throws NamingException {
+        if (!(name instanceof CompositeName)) {
+            throw new InvalidNameException(
+                    "URL context can't accept non-composite name: " + name);
+        }
+
+        if (name.size() == 1) {
+            return createSubcontext(name.get(0));
+        } else {
+            Context context = getContinuationContext(name);
+
+            try {
+                return context.createSubcontext(name.getSuffix(1));
+            } finally {
+                context.close();
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Context createSubcontext(String name) throws NamingException {
+        ResolveResult result = getRootURLContext(name, environment);
+        Context context = (Context) result.getResolvedObj();
+
+        try {
+            return context.createSubcontext(result.getRemainingName());
+        } finally {
+            context.close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void destroySubcontext(Name name) throws NamingException {
+        if (!(name instanceof CompositeName)) {
+            throw new InvalidNameException(
+                    "URL context can't accept non-composite name: " + name);
+        }
+
+        if (name.size() == 1) {
+            destroySubcontext(name.get(0));
+        } else {
+            Context context = getContinuationContext(name);
+
+            try {
+                context.destroySubcontext(name.getSuffix(1));
+            } finally {
+                context.close();
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void destroySubcontext(String name) throws NamingException {
+        ResolveResult result = getRootURLContext(name, environment);
+        Context context = (Context) result.getResolvedObj();
+
+        try {
+            context.destroySubcontext(result.getRemainingName());
+        } finally {
+            context.close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * This method uses {@link #urlEquals(String, String)} to compare
+     * URL prefixes of the names.
+     */
+    public void rename(Name oldName, Name newName) throws NamingException {
+        if (!(oldName instanceof CompositeName)) {
+            throw new InvalidNameException(
+                    "URL context can't accept non-composite name: " + oldName);
+        }
+
+        if (!(newName instanceof CompositeName)) {
+            throw new InvalidNameException(
+                    "URL context can't accept non-composite name: " + newName);
+        }
+
+        if ((oldName.size() == 1) ^ (newName.size() != 1)) {
+            throw new OperationNotSupportedException("Renaming of names "
+                    + "of which one has only one component, and another "
+                    + "has more than one component is not supported: "
+                    + oldName + " -> " + newName);
+        }
+
+        if (oldName.size() == 1) {
+             rename(oldName.get(0), newName.get(0));
+        } else {
+            if (!urlEquals(oldName.get(0), oldName.get(0))) {
+                throw new OperationNotSupportedException("Renaming of names "
+                        + "using different URLs as their first components "
+                        + "is not supported: " + oldName + " -> " + newName);
+            }
+            Context context = getContinuationContext(oldName);
+
+            try {
+                context.rename(oldName.getSuffix(1), newName.getSuffix(1));
+            } finally {
+                context.close();
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * This method uses {@link #getURLPrefix(String)} and
+     * {@link #getURLSuffix(String, String)} methods to parse string names,
+     * and also uses  {@link #urlEquals(String, String)}
+     * to compare URL prefixes of the names.
+     */
+    public void rename(String oldName, String newName) throws NamingException {
+        String oldPrefix = getURLPrefix(oldName);
+        String newPrefix = getURLPrefix(newName);
+
+        if(!urlEquals(oldPrefix, newPrefix)) {
+            throw new OperationNotSupportedException("Renaming of names "
+                    + "using different URL prefixes is not supported: "
+                    + oldName + " -> " + newName);
+        }
+        ResolveResult result = getRootURLContext(oldName, environment);
+        Context context = (Context) result.getResolvedObj();
+
+        try {
+            context.rename(result.getRemainingName(),
+                    getURLSuffix(newPrefix, newName));
+        } finally {
+            context.close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public NamingEnumeration list(Name name) throws NamingException {
+        if (!(name instanceof CompositeName)) {
+            throw new InvalidNameException(
+                    "URL context can't accept non-composite name: " + name);
+        }
+
+        if (name.size() == 1) {
+            return list(name.get(0));
+        } else {
+            Context context = getContinuationContext(name);
+
+            try {
+                return context.list(name.getSuffix(1));
+            } finally {
+                context.close();
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public NamingEnumeration list(String name) throws NamingException {
+        ResolveResult result = getRootURLContext(name, environment);
+        Context context = (Context) result.getResolvedObj();
+
+        try {
+            return context.list(result.getRemainingName());
+        } finally {
+            context.close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public NamingEnumeration listBindings(Name name) throws NamingException {
+        if (!(name instanceof CompositeName)) {
+            throw new InvalidNameException(
+                    "URL context can't accept non-composite name: " + name);
+        }
+
+        if (name.size() == 1) {
+            return listBindings(name.get(0));
+        } else {
+            Context context = getContinuationContext(name);
+
+            try {
+                return context.listBindings(name.getSuffix(1));
+            } finally {
+                context.close();
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public NamingEnumeration listBindings(String name) throws NamingException {
+        ResolveResult result = getRootURLContext(name, environment);
+        Context context = (Context) result.getResolvedObj();
+
+        try {
+            return context.listBindings(result.getRemainingName());
+        } finally {
+            context.close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public NameParser getNameParser(Name name) throws NamingException {
+        if (!(name instanceof CompositeName)) {
+            throw new InvalidNameException(
+                    "URL context can't accept non-composite name: " + name);
+        }
+
+        if (name.size() == 1) {
+            return getNameParser(name.get(0));
+        } else {
+            Context context = getContinuationContext(name);
+
+            try {
+                return context.getNameParser(name.getSuffix(1));
+            } finally {
+                context.close();
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public NameParser getNameParser(String name) throws NamingException {
+        ResolveResult result = getRootURLContext(name, environment);
+        Context context = (Context) result.getResolvedObj();
+
+        try {
+            return context.getNameParser(result.getRemainingName());
+        } finally {
+            context.close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name composeName(Name name, Name prefix) throws NamingException {
+        return ((Name) prefix.clone()).addAll(name);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String composeName(String name, String prefix) {
+        return ((prefix.length() < 1) ? name
+                : (name.length() < 1) ? prefix
+                : (prefix + '/' + name));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getNameInNamespace() {
+        return "";
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Hashtable getEnvironment() {
+        return (Hashtable) environment.clone();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object addToEnvironment(String propName, Object propVal) {
+        return environment.put(propName, propVal);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object removeFromEnvironment(String propName) {
+        return environment.remove(propName);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void close() {
+        environment = null;
+    }
+
+    /**
+     * Lookups the first component (considered a URL)
+     * of the specified name using {@link #lookup(String)},
+     * wraps it into {@link CannotProceedException}, passes it to
+     * {@link NamingManager#getContinuationContext(CannotProceedException)}
+     * method and returns the result.
+     *
+     * This method is used by {@link #lookup(Name)} and other public methods
+     * taking {@link Name} as a parameter.
+     *
+     * This method uses {@link #createCannotProceedException(Name)} method.
+     *
+     * @param   name
+     *          Name to parse.
+     *
+     * @return  Continuation context.
+     *
+     * @throws  NamingException
+     *          If some naming error occurs.
+     */
+    protected Context getContinuationContext(Name name) throws NamingException {
+        return NamingManager.getContinuationContext(
+                createCannotProceedException(name));
+    }
+
+    /**
+     * Lookups the first component (considered a URL)
+     * of the specified name using {@link #lookup(String)}
+     * and wraps it into {@link CannotProceedException}.
+     *
+     * @param   name
+     *          Name to parse.
+     *
+     * @return  Created {@link CannotProceedException}.
+     *
+     * @throws  NamingException
+     *          If some naming error occurs.
+     */
+    protected final CannotProceedException createCannotProceedException(
+            Name name) throws NamingException {
+        CannotProceedException cpe = new CannotProceedException();
+        cpe.setResolvedObj(lookup(name.get(0)));
+        cpe.setEnvironment(environment);
+        return cpe;
+    }
+
+    /**
+     * Determines the proper context from the specified URL and returns
+     * the {@link ResolveResult} object with that context as resolved object
+     * and the rest of the URL as remaining name.
+     *
+     * This method is used by {@link #lookup(String)} and other public methods
+     * taking {@link String} name as a parameter.
+     *
+     * This method must be overridden by particular URL context implementations.
+     *
+     * When overriding make sure that
+     * {@link #getURLPrefix(String)},
+     * {@link #getURLSuffix(String, String)} and
+     * {@link #getRootURLContext(String, Hashtable)}
+     * methods are in sync in how they parse URLs.
+     *
+     * @param   url
+     *          URL.
+     *
+     * @param   environment
+     *          Environment.
+     *
+     * @return  {@link ResolveResult} object with resolved context
+     *          as resolved object the rest of the URL as remaining name.
+     *
+     * @throws  NamingException
+     *          If some naming error occurs.
+     */
+    protected abstract ResolveResult getRootURLContext(
+            String url, Hashtable environment) throws NamingException;
+
+    /**
+     * Compares two URLs for equality.
+     *
+     * Implemented here as <code>url1.equals(url2)</code>.
+     * Subclasses may provide different implementation.
+     *
+     * This method is only used by {@link #rename(Name, Name)}
+     * and {@link #rename(String, String)} methods.
+     *
+     * @param   url1
+     *          First URL to compare.
+     *
+     * @param   url2
+     *          Second URL to compare.
+     *
+     * @return  <code>true</code> if specified URLs are equal,
+     *          <code>false</code> otherwise.
+     */
+    protected boolean urlEquals(String url1, String url2) {
+        return url1.equals(url2);
+    }
+
+    /**
+     * Returns URL prefix, containing scheme name, hostname and port.
+     *
+     * This method is only used by {@link #rename(String, String)} method
+     * and may be overridden by subclasses.
+     *
+     * When overriding make sure that
+     * {@link #getURLPrefix(String)},
+     * {@link #getURLSuffix(String, String)} and
+     * {@link #getRootURLContext(String, Hashtable)}
+     * methods are in sync in how they parse URLs.
+     *
+     * @param   url
+     *          URL to parse.
+     *
+     * @return  URL prefix.
+     *
+     * @throws  NamingException
+     *          If some naming error occurs.
+     */
+    protected String getURLPrefix(String url) throws NamingException {
+        int index = url.indexOf(':');
+        if (index < 0) {
+            throw new OperationNotSupportedException("Invalid URL: " + url);
+        }
+        index++;
+
+        if (url.startsWith("//", index)) {
+            int slashPos = url.indexOf('/', index + 2);
+            index = ((slashPos >= 0) ? slashPos : url.length());
+        }
+        return url.substring(0, index);
+    }
+
+    /**
+     * Returns URL suffix, containing everything but the
+     * {@linkplain #getURLPrefix(String) prefix} and separating slash,
+     * as a single-component {@link CompositeName}.
+     *
+     * This method is only used by {@link #rename(String, String)} method
+     * and may be overridden by subclasses.
+     *
+     * This method uses {@link #decodeURLString(String)}
+     * to decode the suffix string.
+     *
+     * When overriding make sure that
+     * {@link #getURLPrefix(String)},
+     * {@link #getURLSuffix(String, String)} and
+     * {@link #getRootURLContext(String, Hashtable)}
+     * methods are in sync in how they parse URLs.
+     *
+     * @param   prefix
+     *          URL prefix, returned by {@link #getURLPrefix(String)}
+     *          previously called on the same URL.
+     *
+     * @param   url
+     *          URL to parse.
+     *
+     * @return  URL suffix as a single-component {@link CompositeName}.
+     *
+     * @throws  NamingException
+     *          If some naming error occurs.
+     */
+    protected Name getURLSuffix(String prefix, String url)
+            throws NamingException {
+        int length = prefix.length();
+
+        if (length >= (url.length() - 1)) {
+            // If prefix is only 1 character shorter than URL,
+            // that character is slash and can be ignored.
+            return new CompositeName();
+        }
+
+        String suffix = url.substring(
+                (url.charAt(length) == '/') ? (length + 1) : length);
+
+        try {
+            return new CompositeName().add(decodeURLString(suffix));
+        } catch (IllegalArgumentException e) {
+            throw (InvalidNameException)
+                    new InvalidNameException().initCause(e);
+        }
+    }
+
+    /**
+     * Decodes URL string by transforming URL-encoded characters
+     * into their Unicode character representations.
+     *
+     * This method is used by {@link #getURLSuffix(String, String)}.
+     *
+     * @param   str
+     *          URL or part of URL string.
+     *
+     * @return  Decoded string.
+     *
+     * @throws  IllegalArgumentException
+     *          If URL format is incorrect.
+     */
+    protected static final String decodeURLString(String str)
+            throws IllegalArgumentException {
+        int length = str.length();
+        byte bytes[] = new byte[length];
+        int index = 0;
+
+        for(int i = 0; i < length; ) {
+            char c = str.charAt(i++);
+
+            if (c == '%') {
+                int next = i + 2;
+
+                if (next > length) {
+                    new IllegalArgumentException("Invalid URL format: " + str);
+                }
+
+                try {
+                    bytes[index++] = (byte)
+                            Integer.parseInt(str.substring(i, next), 16);
+                } catch (NumberFormatException e) {
+                    throw (IllegalArgumentException)
+                            new IllegalArgumentException(
+                                    "Invalid URL format: " + str).initCause(e);
+                }
+
+                i = next;
+            } else {
+                bytes[index++] = (byte) c;
+            }
+        }
+        return new String(bytes, 0, index);
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLContextFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLContextFactory.java?rev=437433&r1=437432&r2=437433&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLContextFactory.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLContextFactory.java Sun Aug 27 11:26:20 2006
@@ -1,156 +1,156 @@
-/*
- * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * @author  Vasily Zakharov
- * @version $Revision: 1.1.2.3 $
- */
-package org.apache.harmony.jndi.provider;
-
-import java.util.Hashtable;
-
-import javax.naming.ConfigurationException;
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NamingException;
-
-import javax.naming.spi.ObjectFactory;
-
-
-/**
- * Base class for URL naming context factory implementations.
- *
- * In many cases, subclasses should only override
- * {@link #createURLContext(Hashtable)} method
- * and provide public no-args constructor.
- *
- * @author  Vasily Zakharov
- * @version $Revision: 1.1.2.3 $
- */
-public abstract class GenericURLContextFactory implements ObjectFactory {
-
-    /**
-     * Default constructor for subclasses.
-     */
-    protected GenericURLContextFactory() {}
-
-    /**
-     * Lookups the specified object in the underlying context.
-     * Underlying context instance is provided by
-     * {@link #createURLContext(Hashtable)}.
-     *
-     * Follows the guidelines for URL context factories described in
-     * {@link ObjectFactory#getObjectInstance(Object, Name, Context, Hashtable)}
-     * specification.
-     *
-     * If <code>obj</code> is <code>null</code>,
-     * just creates and returns an underlying context.
-     *
-     * If <code>obj</code> is a proper URL string,
-     * lookups and returns an object specified by that string.
-     *
-     * If <code>obj</code> is an array of URL strings,
-     * tries to lookup each of them sequentially until lookup succeeds,
-     * then returns the result. If no lookup succeeds, throws
-     * {@link NamingException} describing the fail of a last lookup.
-     *
-     * <code>name</code> and <code>nameCtx</code> parameters are ignored.
-     *
-     * @param   obj
-     *          Object to lookup, can be <code>null</code>.
-     *
-     * @param   name
-     *          Ignored.
-     *
-     * @param   nameCtx
-     *          Ignored.
-     *
-     * @param   environment
-     *          Environment to use in creating the underlying context,
-     *          can be <code>null</code>.
-     *
-     * @return  The object created.
-     *
-     * @throws  ConfigurationException
-     *          If <code>obj</code> is neither <code>null</code>
-     *          nor a string, nor a string array, or is an empty string array.
-     *
-     * @throws  NamingException
-     *          If lookup attempt failed.
-     */
-    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
-            Hashtable environment) throws NamingException {
-        Context context = createURLContext(environment);
-
-        if (obj == null) {
-            // For null object - just return context.
-            return context;
-        }
-
-        try {
-            if (obj instanceof String) {
-                // For string object - return the object it names.
-                return context.lookup((String) obj);
-            }
-
-            if (obj instanceof String[]) {
-                // For string array object - search it through.
-                String[] strings = (String[]) obj;
-
-                if (strings.length < 1) {
-                    throw new ConfigurationException(
-                            "obj is an empty string array");
-                }
-
-                NamingException exception = null;
-
-                for (int i = 0; i < strings.length; i++) {
-                    try {
-                        // If the valid object is found - return it.
-                        return context.lookup(strings[i]);
-                    } catch (NamingException e) {
-                        // Invalid object, store the exception
-                        // to throw it later if no valid object is found.
-                        exception = e;
-                    }
-                }
-
-                // No valid object is found.
-                throw exception;
-            }
-
-            // Unknown object type.
-            throw new IllegalArgumentException("obj is neither null, "
-                    + "nor a string, nor a string array: " + obj);
-        } finally {
-            context.close();
-        }
-    }
-
-    /**
-     * Returns new instance of the necessary context.
-     * Used by {@link #getObjectInstance(Object, Name, Context, Hashtable)}.
-     *
-     * Must be overridden by particular URL context factory implementations.
-     *
-     * @param   environment
-     *          Environment.
-     *
-     * @return  New context instance.
-     */
-    protected abstract Context createURLContext(Hashtable environment);
-}
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.3 $
+ */
+package org.apache.harmony.jndi.provider;
+
+import java.util.Hashtable;
+
+import javax.naming.ConfigurationException;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+
+import javax.naming.spi.ObjectFactory;
+
+
+/**
+ * Base class for URL naming context factory implementations.
+ *
+ * In many cases, subclasses should only override
+ * {@link #createURLContext(Hashtable)} method
+ * and provide public no-args constructor.
+ *
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.3 $
+ */
+public abstract class GenericURLContextFactory implements ObjectFactory {
+
+    /**
+     * Default constructor for subclasses.
+     */
+    protected GenericURLContextFactory() {}
+
+    /**
+     * Lookups the specified object in the underlying context.
+     * Underlying context instance is provided by
+     * {@link #createURLContext(Hashtable)}.
+     *
+     * Follows the guidelines for URL context factories described in
+     * {@link ObjectFactory#getObjectInstance(Object, Name, Context, Hashtable)}
+     * specification.
+     *
+     * If <code>obj</code> is <code>null</code>,
+     * just creates and returns an underlying context.
+     *
+     * If <code>obj</code> is a proper URL string,
+     * lookups and returns an object specified by that string.
+     *
+     * If <code>obj</code> is an array of URL strings,
+     * tries to lookup each of them sequentially until lookup succeeds,
+     * then returns the result. If no lookup succeeds, throws
+     * {@link NamingException} describing the fail of a last lookup.
+     *
+     * <code>name</code> and <code>nameCtx</code> parameters are ignored.
+     *
+     * @param   obj
+     *          Object to lookup, can be <code>null</code>.
+     *
+     * @param   name
+     *          Ignored.
+     *
+     * @param   nameCtx
+     *          Ignored.
+     *
+     * @param   environment
+     *          Environment to use in creating the underlying context,
+     *          can be <code>null</code>.
+     *
+     * @return  The object created.
+     *
+     * @throws  ConfigurationException
+     *          If <code>obj</code> is neither <code>null</code>
+     *          nor a string, nor a string array, or is an empty string array.
+     *
+     * @throws  NamingException
+     *          If lookup attempt failed.
+     */
+    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
+            Hashtable environment) throws NamingException {
+        Context context = createURLContext(environment);
+
+        if (obj == null) {
+            // For null object - just return context.
+            return context;
+        }
+
+        try {
+            if (obj instanceof String) {
+                // For string object - return the object it names.
+                return context.lookup((String) obj);
+            }
+
+            if (obj instanceof String[]) {
+                // For string array object - search it through.
+                String[] strings = (String[]) obj;
+
+                if (strings.length < 1) {
+                    throw new ConfigurationException(
+                            "obj is an empty string array");
+                }
+
+                NamingException exception = null;
+
+                for (int i = 0; i < strings.length; i++) {
+                    try {
+                        // If the valid object is found - return it.
+                        return context.lookup(strings[i]);
+                    } catch (NamingException e) {
+                        // Invalid object, store the exception
+                        // to throw it later if no valid object is found.
+                        exception = e;
+                    }
+                }
+
+                // No valid object is found.
+                throw exception;
+            }
+
+            // Unknown object type.
+            throw new IllegalArgumentException("obj is neither null, "
+                    + "nor a string, nor a string array: " + obj);
+        } finally {
+            context.close();
+        }
+    }
+
+    /**
+     * Returns new instance of the necessary context.
+     * Used by {@link #getObjectInstance(Object, Name, Context, Hashtable)}.
+     *
+     * Must be overridden by particular URL context factory implementations.
+     *
+     * @param   environment
+     *          Environment.
+     *
+     * @return  New context instance.
+     */
+    protected abstract Context createURLContext(Hashtable environment);
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLContextFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message