harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r437433 [4/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/InitialContext.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/InitialContext.java?rev=437433&r1=437432&r2=437433&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/InitialContext.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/InitialContext.java Sun Aug 27 11:26:20 2006
@@ -1,495 +1,495 @@
-/* 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;
-
-import java.util.Hashtable;
-import javax.naming.spi.NamingManager;
-
-import org.apache.harmony.jndi.internal.UrlParser;
-import org.apache.harmony.jndi.internal.EnvironmentReader;
-
-/**
- * An <code>InitialContext</code> object is required as the starting context
- * for any naming operations.
- * Other contexts and subcontexts may be created later. Contexts may consist 
- * of different implementations according to the needs of the application. All
- * naming operations are performed relative to a context and names are resolved
- * beginning with the initial context.
- * <p>
- * When constructing an initial context, environment properties from a range
- * of sources may be used to initialize the environment. See the specification
- * of the {@link Context} interface for further details of environment 
- * properties.</p>
- * <p>
- * The environment at runtime determines the initial context implementation.
- * By default, the naming frameworks look for the initial context factory class
- * name in the property <code>Context.INITIAL_CONTEXT_FACTORY</code>. When URL 
- * strings must be resolved, a different policy is used which is described 
- * below.</p>
- * <p>
- * A <code>NoInitialContextException</code> is thrown when it cannot create an
- * initial context. The exception may occur not only during constructor
- * invocation, but may occur later. For example, when a subclass of <code>
- * InitialContext</code> uses the lazy initialization option, <code>
- * InitialContext</code> methods may be invoked later which require the 
- * initialization to be completed at that time using the <code>init</code> 
- * protected method. In these circumstances, <code>NoInitialContextException
- * </code> may be thrown some time after the constructor was invoked. JNDI 
- * applications should be written to be independent of when initial context 
- * is actually initialized.</p>
- * <p>
- * If environment property <code>Context.INITIAL_CONTEXT_FACTORY</code> has a 
- * non-null value, then the specified initial context factory may experience a
- * problem trying to instantiate an initial context and so throw an exception. 
- * It is a responsibility of the service provider implementation as to when an 
- * exception is thrown to report the problem to the JNDI application.</p>
- * <p>
- * URL names comprising a String format described by RFC1738 may be components
- * of names passed to naming operations. Typically, the URL is composed of the
- * "scheme" - such as one of http, ldap, dns - followed by additional text. If
- * the JNDI can identify the URL scheme from the specified name, then it is
- * used to construct a classname suffix in the following form:<br>
- * <pre>
- *     &lt;package_prefix&gt; . &lt;scheme&gt; . &lt;scheme&gt;URLContextFactory
- * </pre>
- * Several variants of the classname are constructed using each element of the
- * <code>Context.URL_PACKAGE_PREFIXES</code> environment property. Note that an
- * additional package prefix - "com.sun.jndi.url" - is always considered to be 
- * at the end of those already present in the value of that environment 
- * property. Although a service provider may also provide a URL context 
- * implementation as well as a context implementation, it is not required to do
- * so, and so an arbitrary service provider might not provide for creating URL
- * contexts.</p>
- * <p>
- * If a URL context is successfully created for a specified URL scheme, the
- * factory can create contexts for arbitrary URLs of the same scheme.
- * <code>NamingManager.setInitialContextFactoryBuilder</code> may be used to
- * specify an alternate policy for locating factories for initial contexts and
- * URL contexts.</p>
- * <p>
- * On successful completion of <code>InitialContext</code> initialization, the 
- * service provider implementation will have returned an appropriate <code>
- * Context</code> object which can be used for looking up and manipulating names
- * which may or may not be URL names. <code>InitialContext</code> methods other
- * than those dealing with environments should delegate context operations to 
- * that <code>Context</code> object.</p>
- *
- * @see Context
- * 
- */
-public class InitialContext implements Context {
-
-    /*
-     * -------------------------------------------------------------------
-     * Instance variables
-     * -------------------------------------------------------------------
-     */
-
-    /**
-     * Set to the result of the first successful invocation of <code>
-     * NamingManager.getInitialContext</code> by <code>getDefaultInitCtx
-     * </code>.
-     * Initially null. 
-     */
-    protected Context defaultInitCtx;
-
-    /**
-     * Set to true when <code>NamingManager.getInitialContext</code> has
-     * been invoked to obtain an initial context.
-     * Initially false.
-     */
-    protected boolean gotDefault;
-
-    /**
-     * Contains all those JNDI environment properties that were found in any
-     * of the the sources of JNDI environment properties.
-     * Initially null.
-     */
-    protected Hashtable<Object, Object> myProps;
-
-    /*
-     * -------------------------------------------------------------------
-     * Constructors
-     * -------------------------------------------------------------------
-     */
-
-    /**
-     * Constructs an <code>InitialContext</code> instance without using any
-     * environment properties.
-     * This constructor is effectively the same as using constructor
-     * <code>InitialContext((Hashtable)null)</code>.
-     * 
-     * @throws NamingException  If failed to create an <code>InitialContext</code>.
-     */
-    public InitialContext() throws NamingException {
-        this(null);
-    }
-
-    /**
-     * Constructs an <code>InitialContext</code> instance using environment
-     * properties in the supplied parameter which may be null.
-     *
-     * @param environment       the JNDI environment properties used to create
-     *                          the context 
-     * @throws NamingException  If failed to create an <code>InitialContext</code>.
-     */
-    public InitialContext(Hashtable<?, ?> environment) throws NamingException {
-        internalInit(environment);
-    }
-
-    /**
-     * Constructs an <code>InitialContext</code> instance by indicating whether
-     * a lazy initialization is desired.
-     * Effectively, this is the same as using constructor <code>InitialContext()
-     * </code> if lazy initialization is not indicated.
-     * <p>
-     * This constructor may be invoked with a parameter value of true and the
-     * implementation will defer initialization of the instance. This may be
-     * used in an <code>InitialContext</code> subclass constructor in which 
-     * later action will set up a <code>Hashtable</code> object with appropriate
-     * environment properties and pass that to the <code>init</code> method to
-     * complete initalization of the <code>InitialContext</code> object.</p>
-     *
-     * @param doNotInit         Specifies whether to initialize the new instance.
-     * @throws NamingException  If failed to create an <code>InitialContext</code>.
-     */
-    protected InitialContext(boolean doNotInit) throws NamingException {
-        if (!doNotInit) {
-            internalInit(null);
-        }
-    }
-
-    /*
-     * -------------------------------------------------------------------
-     * Methods
-     * -------------------------------------------------------------------
-     */
-
-    /*
-     * Does private initilaziation.
-     * 
-     * @param env               the JNDI environment properties used to create
-     *                          the context 
-     * @throws NamingException  If failed to create an InitialContext.
-     */
-    private void internalInit(Hashtable<?, ?> env) throws NamingException {
-
-        // 1. Read the environment parameter used to create this Context
-        if (null == env) {
-            myProps = new Hashtable<Object, Object>();
-        } else {
-            myProps = (Hashtable<Object, Object>) env.clone();
-        }
-
-        // 2. Read Applet parameters
-        EnvironmentReader.readAppletParameters(
-            myProps.get(Context.APPLET),
-            myProps);
-
-        // 3. Read System properties
-        EnvironmentReader.readSystemProperties(myProps);
-
-        // 4.1 Read application/applet resource files
-        EnvironmentReader.readApplicationResourceFiles(myProps);
-
-        // 4.2 Read "java.home"/lib/jndi.properties
-        EnvironmentReader.readLibraryResourceFile(myProps);
-
-        // 5. No need to read service provider resource files
-
-        // if JNDI standard property "java.naming.factory.initial" has a non-null value
-        if (myProps.containsKey(INITIAL_CONTEXT_FACTORY)) {
-            // call getDefaultInitCtx() to initialize gotDefault and defaultInitCtx
-            getDefaultInitCtx();
-        }
-    }
-
-    /**
-     * Uses the specified environment parameter together with other JNDI 
-     * properties to initialize this <code>InitialContext</code> object.
-     * The <code>myProps</code> field will be filled with found JNDI properties.
-     * If JNDI standard property "java.naming.factory.initial" has a non-null 
-     * value, then <code>getDefaultInitCtx</code> is invoked to try to 
-     * initialize fields <code>gotDefault</code> and <code>defaultInitCtx</code>
-     * of the <code>InitialContext</code> object.
-     * 
-     * @param env               the JNDI environment properties supplied to 
-     *                          create the context
-     * @throws NamingException  If naming problems are encountered during
-     *                          initialization of these fields.
-     */
-    protected void init(Hashtable<?, ?> env) throws NamingException {
-        this.internalInit(env);
-    }
-
-    /* 
-     * Initializes the default initial context.
-     * 
-     * @throws NamingException  If failed to initialize this InitialContext.
-     */
-    private void initializeDefaultInitCtx() throws NamingException {
-        if (!this.gotDefault) {
-            this.defaultInitCtx = NamingManager.getInitialContext(myProps);
-            if (null == this.defaultInitCtx) {
-                throw new NoInitialContextException("Failed to create an initial context."); //$NON-NLS-1$
-            }
-            this.gotDefault = true;
-        }
-    }
-
-    /**
-     * Gets the default underlying <code>Context</code> implementation.
-     * If <code>gotDefault</code> is true, returns the value of <code>
-     * defaultInitCtx</code>. Otherwise, calls <code>NamingManager.getInitialContext
-     * </code> to return an initial context for the current environment into 
-     * <code>defaultInitCtx</code>, then <code>gotDefault</code> is set true.
-     * If the resulting context object is null, a <code>NoInitialContextException
-     * </code> is thrown, otherwise the value of <code>defaultInitCtx</code> is
-     * returned.
-     *
-     * @return                  the default context
-     * @throws NoInitialContextException
-     *                          If <code>NamingManager.getInitialContext</code>
-     *                          returns null.
-     * @throws NamingException  If failed to create the default context.
-     */
-    protected Context getDefaultInitCtx() throws NamingException {
-        initializeDefaultInitCtx();
-        return this.defaultInitCtx;
-    }
-
-    /**
-     * Returns a non-null context for the specified name of Name representation.
-     * <p>
-     * If an initial context factory builder has been defined, then the
-     * specified <code>Name</code> parameter is ignored and the result of <code>
-     * getDefaultInitCtx</code> is returned. Otherwise, if the first component 
-     * of the name is not a URL string, then it returns the result of invoking
-     * <code>getDefaultInitCtx</code>. Otherwise, it attempts to return a URL 
-     * context {@link javax.naming.spi.NamingManager#getURLContext(String, Hashtable)},
-     * but if unsuccessful, returns the result of invoking 
-     * <code>getDefaultInitCtx</code>.</p>
-     *
-     * @param name              a name used in a naming operation which may not
-     *                          be null
-     * @return                  a context which may be a URL context
-     * @throws NamingException  If failed to get the desired context.
-     */
-    protected Context getURLOrDefaultInitCtx(Name name)
-        throws NamingException {
-        // If the name has components
-        if (0 < name.size()) {
-            return getURLOrDefaultInitCtx(name.get(0));
-        }
-		return getDefaultInitCtx();
-    }
-
-    /**
-     * Returns a non-null context for the specified name of string 
-     * representation.
-     * <p>
-     * If an initial context factory builder has been defined, then the
-     * specified name parameter is ignored and the result of <code>
-     * getDefaultInitCtx</code> is returned. Otherwise, if the name is not a URL
-     * string, then it returns the result of invoking <code>getDefaultInitCtx
-     * </code>. Otherwise, it attempts to return a URL context 
-     * {@link javax.naming.spi.NamingManager#getURLContext(String, Hashtable)}, 
-     * but if unsuccessful, returns the result of invoking <code>
-     * getDefaultInitCtx</code>.</p>
-     *
-     * @param name              a name used in a naming operation which may not
-     *                          be null
-     * @return                  a context which may be a URL context
-     * @throws NamingException  If failed to get the desired context.
-     */
-    protected Context getURLOrDefaultInitCtx(String name)
-        throws NamingException {
-
-        /*
-         * If an initial context factory builder has been defined, then the
-         * specified name parameter is ignored and the result of 
-         * getDefaultInitCtx() is returned.
-         */
-        if (NamingManager.hasInitialContextFactoryBuilder()) {
-            return getDefaultInitCtx();
-        }
-
-        if (null == name) {
-            throw new NullPointerException("null"); //$NON-NLS-1$
-        }
-
-        // If the name has components
-        String scheme = UrlParser.getScheme(name);
-        Context ctx = null;
-        if (null != scheme) {
-            // So the first componet is a valid URL
-            ctx = NamingManager.getURLContext(scheme, myProps);
-        }
-        return null == ctx ? getDefaultInitCtx() : ctx;
-    }
-
-    /*
-     * -------------------------------------------------------------------
-     * Methods of Interface Context
-     * -------------------------------------------------------------------
-     */
-
-    public Object lookup(Name name) throws NamingException {
-        return getURLOrDefaultInitCtx(name).lookup(name);
-    }
-
-    public Object lookup(String name) throws NamingException {
-        return getURLOrDefaultInitCtx(name).lookup(name);
-    }
-
-    public void bind(Name name, Object obj) throws NamingException {
-        getURLOrDefaultInitCtx(name).bind(name, obj);
-    }
-
-    public void bind(String name, Object obj) throws NamingException {
-        getURLOrDefaultInitCtx(name).bind(name, obj);
-    }
-
-    public void rebind(Name name, Object obj) throws NamingException {
-        getURLOrDefaultInitCtx(name).rebind(name, obj);
-    }
-
-    public void rebind(String name, Object obj) throws NamingException {
-        getURLOrDefaultInitCtx(name).rebind(name, obj);
-    }
-
-    public void unbind(Name name) throws NamingException {
-        getURLOrDefaultInitCtx(name).unbind(name);
-    }
-
-    public void unbind(String name) throws NamingException {
-        getURLOrDefaultInitCtx(name).unbind(name);
-    }
-
-    public void rename(Name oldName, Name newName) throws NamingException {
-        getURLOrDefaultInitCtx(oldName).rename(oldName, newName);
-    }
-
-    public void rename(String oldName, String newName) throws NamingException {
-        getURLOrDefaultInitCtx(oldName).rename(oldName, newName);
-    }
-
-    public NamingEnumeration<NameClassPair> list(Name name)
-        throws NamingException {
-        return getURLOrDefaultInitCtx(name).list(name);
-    }
-
-    public NamingEnumeration<NameClassPair> list(String name)
-        throws NamingException {
-        return getURLOrDefaultInitCtx(name).list(name);
-    }
-
-    public NamingEnumeration<Binding> listBindings(Name name)
-        throws NamingException {
-        return getURLOrDefaultInitCtx(name).listBindings(name);
-    }
-
-    public NamingEnumeration<Binding> listBindings(String name)
-            throws NamingException {
-        return getURLOrDefaultInitCtx(name).listBindings(name);
-    }
-
-    public void destroySubcontext(Name name) throws NamingException {
-        getURLOrDefaultInitCtx(name).destroySubcontext(name);
-    }
-
-    public void destroySubcontext(String name) throws NamingException {
-        getURLOrDefaultInitCtx(name).destroySubcontext(name);
-    }
-
-    public Context createSubcontext(Name name) throws NamingException {
-        return getURLOrDefaultInitCtx(name).createSubcontext(name);
-    }
-
-    public Context createSubcontext(String name) throws NamingException {
-        return getURLOrDefaultInitCtx(name).createSubcontext(name);
-    }
-
-    public Object lookupLink(Name name) throws NamingException {
-        return getURLOrDefaultInitCtx(name).lookupLink(name);
-    }
-
-    public Object lookupLink(String name) throws NamingException {
-        return getURLOrDefaultInitCtx(name).lookupLink(name);
-    }
-
-    public NameParser getNameParser(Name name) throws NamingException {
-        return getURLOrDefaultInitCtx(name).getNameParser(name);
-    }
-
-    public NameParser getNameParser(String name) throws NamingException {
-        return getURLOrDefaultInitCtx(name).getNameParser(name);
-    }
-
-    public Name composeName(Name name, Name prefix) throws NamingException {
-        if (null == name) {
-            throw new InvalidNameException("Invalid name."); //$NON-NLS-1$
-        }
-        if (prefix == null) {
-        	prefix = new CompositeName("");
-        }
-        Name comName = (Name) prefix.clone();
-        comName.addAll(name);
-        return comName;
-    }
-
-    public String composeName(String name, String prefix)
-        throws NamingException {
-        if (null == name) {
-            throw new InvalidNameException("Invalid name."); //$NON-NLS-1$
-        }
-        if (prefix == null) {
-        	prefix = "";
-        }
-        return composeName(new CompositeName(name), new CompositeName(prefix))
-            .toString();
-    }
-
-    public Object addToEnvironment(String propName, Object propVal)
-        throws NamingException {
-        this.myProps.put(propName, propVal);
-        return getDefaultInitCtx().addToEnvironment(propName, propVal);
-    }
-
-    public Object removeFromEnvironment(String propName)
-        throws NamingException {
-        this.myProps.remove(propName);
-        return getDefaultInitCtx().removeFromEnvironment(propName);
-    }
-
-    public Hashtable<?, ?> getEnvironment() throws NamingException {
-        return getDefaultInitCtx().getEnvironment();
-    }
-
-    public void close() throws NamingException {
-        if (this.gotDefault) {
-        	getDefaultInitCtx().close();
-        }
-    }
-
-    public String getNameInNamespace() throws NamingException {
-        return getDefaultInitCtx().getNameInNamespace();
-    }
-
-}
-
-
+/* 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;
+
+import java.util.Hashtable;
+import javax.naming.spi.NamingManager;
+
+import org.apache.harmony.jndi.internal.UrlParser;
+import org.apache.harmony.jndi.internal.EnvironmentReader;
+
+/**
+ * An <code>InitialContext</code> object is required as the starting context
+ * for any naming operations.
+ * Other contexts and subcontexts may be created later. Contexts may consist 
+ * of different implementations according to the needs of the application. All
+ * naming operations are performed relative to a context and names are resolved
+ * beginning with the initial context.
+ * <p>
+ * When constructing an initial context, environment properties from a range
+ * of sources may be used to initialize the environment. See the specification
+ * of the {@link Context} interface for further details of environment 
+ * properties.</p>
+ * <p>
+ * The environment at runtime determines the initial context implementation.
+ * By default, the naming frameworks look for the initial context factory class
+ * name in the property <code>Context.INITIAL_CONTEXT_FACTORY</code>. When URL 
+ * strings must be resolved, a different policy is used which is described 
+ * below.</p>
+ * <p>
+ * A <code>NoInitialContextException</code> is thrown when it cannot create an
+ * initial context. The exception may occur not only during constructor
+ * invocation, but may occur later. For example, when a subclass of <code>
+ * InitialContext</code> uses the lazy initialization option, <code>
+ * InitialContext</code> methods may be invoked later which require the 
+ * initialization to be completed at that time using the <code>init</code> 
+ * protected method. In these circumstances, <code>NoInitialContextException
+ * </code> may be thrown some time after the constructor was invoked. JNDI 
+ * applications should be written to be independent of when initial context 
+ * is actually initialized.</p>
+ * <p>
+ * If environment property <code>Context.INITIAL_CONTEXT_FACTORY</code> has a 
+ * non-null value, then the specified initial context factory may experience a
+ * problem trying to instantiate an initial context and so throw an exception. 
+ * It is a responsibility of the service provider implementation as to when an 
+ * exception is thrown to report the problem to the JNDI application.</p>
+ * <p>
+ * URL names comprising a String format described by RFC1738 may be components
+ * of names passed to naming operations. Typically, the URL is composed of the
+ * "scheme" - such as one of http, ldap, dns - followed by additional text. If
+ * the JNDI can identify the URL scheme from the specified name, then it is
+ * used to construct a classname suffix in the following form:<br>
+ * <pre>
+ *     &lt;package_prefix&gt; . &lt;scheme&gt; . &lt;scheme&gt;URLContextFactory
+ * </pre>
+ * Several variants of the classname are constructed using each element of the
+ * <code>Context.URL_PACKAGE_PREFIXES</code> environment property. Note that an
+ * additional package prefix - "com.sun.jndi.url" - is always considered to be 
+ * at the end of those already present in the value of that environment 
+ * property. Although a service provider may also provide a URL context 
+ * implementation as well as a context implementation, it is not required to do
+ * so, and so an arbitrary service provider might not provide for creating URL
+ * contexts.</p>
+ * <p>
+ * If a URL context is successfully created for a specified URL scheme, the
+ * factory can create contexts for arbitrary URLs of the same scheme.
+ * <code>NamingManager.setInitialContextFactoryBuilder</code> may be used to
+ * specify an alternate policy for locating factories for initial contexts and
+ * URL contexts.</p>
+ * <p>
+ * On successful completion of <code>InitialContext</code> initialization, the 
+ * service provider implementation will have returned an appropriate <code>
+ * Context</code> object which can be used for looking up and manipulating names
+ * which may or may not be URL names. <code>InitialContext</code> methods other
+ * than those dealing with environments should delegate context operations to 
+ * that <code>Context</code> object.</p>
+ *
+ * @see Context
+ * 
+ */
+public class InitialContext implements Context {
+
+    /*
+     * -------------------------------------------------------------------
+     * Instance variables
+     * -------------------------------------------------------------------
+     */
+
+    /**
+     * Set to the result of the first successful invocation of <code>
+     * NamingManager.getInitialContext</code> by <code>getDefaultInitCtx
+     * </code>.
+     * Initially null. 
+     */
+    protected Context defaultInitCtx;
+
+    /**
+     * Set to true when <code>NamingManager.getInitialContext</code> has
+     * been invoked to obtain an initial context.
+     * Initially false.
+     */
+    protected boolean gotDefault;
+
+    /**
+     * Contains all those JNDI environment properties that were found in any
+     * of the the sources of JNDI environment properties.
+     * Initially null.
+     */
+    protected Hashtable<Object, Object> myProps;
+
+    /*
+     * -------------------------------------------------------------------
+     * Constructors
+     * -------------------------------------------------------------------
+     */
+
+    /**
+     * Constructs an <code>InitialContext</code> instance without using any
+     * environment properties.
+     * This constructor is effectively the same as using constructor
+     * <code>InitialContext((Hashtable)null)</code>.
+     * 
+     * @throws NamingException  If failed to create an <code>InitialContext</code>.
+     */
+    public InitialContext() throws NamingException {
+        this(null);
+    }
+
+    /**
+     * Constructs an <code>InitialContext</code> instance using environment
+     * properties in the supplied parameter which may be null.
+     *
+     * @param environment       the JNDI environment properties used to create
+     *                          the context 
+     * @throws NamingException  If failed to create an <code>InitialContext</code>.
+     */
+    public InitialContext(Hashtable<?, ?> environment) throws NamingException {
+        internalInit(environment);
+    }
+
+    /**
+     * Constructs an <code>InitialContext</code> instance by indicating whether
+     * a lazy initialization is desired.
+     * Effectively, this is the same as using constructor <code>InitialContext()
+     * </code> if lazy initialization is not indicated.
+     * <p>
+     * This constructor may be invoked with a parameter value of true and the
+     * implementation will defer initialization of the instance. This may be
+     * used in an <code>InitialContext</code> subclass constructor in which 
+     * later action will set up a <code>Hashtable</code> object with appropriate
+     * environment properties and pass that to the <code>init</code> method to
+     * complete initalization of the <code>InitialContext</code> object.</p>
+     *
+     * @param doNotInit         Specifies whether to initialize the new instance.
+     * @throws NamingException  If failed to create an <code>InitialContext</code>.
+     */
+    protected InitialContext(boolean doNotInit) throws NamingException {
+        if (!doNotInit) {
+            internalInit(null);
+        }
+    }
+
+    /*
+     * -------------------------------------------------------------------
+     * Methods
+     * -------------------------------------------------------------------
+     */
+
+    /*
+     * Does private initilaziation.
+     * 
+     * @param env               the JNDI environment properties used to create
+     *                          the context 
+     * @throws NamingException  If failed to create an InitialContext.
+     */
+    private void internalInit(Hashtable<?, ?> env) throws NamingException {
+
+        // 1. Read the environment parameter used to create this Context
+        if (null == env) {
+            myProps = new Hashtable<Object, Object>();
+        } else {
+            myProps = (Hashtable<Object, Object>) env.clone();
+        }
+
+        // 2. Read Applet parameters
+        EnvironmentReader.readAppletParameters(
+            myProps.get(Context.APPLET),
+            myProps);
+
+        // 3. Read System properties
+        EnvironmentReader.readSystemProperties(myProps);
+
+        // 4.1 Read application/applet resource files
+        EnvironmentReader.readApplicationResourceFiles(myProps);
+
+        // 4.2 Read "java.home"/lib/jndi.properties
+        EnvironmentReader.readLibraryResourceFile(myProps);
+
+        // 5. No need to read service provider resource files
+
+        // if JNDI standard property "java.naming.factory.initial" has a non-null value
+        if (myProps.containsKey(INITIAL_CONTEXT_FACTORY)) {
+            // call getDefaultInitCtx() to initialize gotDefault and defaultInitCtx
+            getDefaultInitCtx();
+        }
+    }
+
+    /**
+     * Uses the specified environment parameter together with other JNDI 
+     * properties to initialize this <code>InitialContext</code> object.
+     * The <code>myProps</code> field will be filled with found JNDI properties.
+     * If JNDI standard property "java.naming.factory.initial" has a non-null 
+     * value, then <code>getDefaultInitCtx</code> is invoked to try to 
+     * initialize fields <code>gotDefault</code> and <code>defaultInitCtx</code>
+     * of the <code>InitialContext</code> object.
+     * 
+     * @param env               the JNDI environment properties supplied to 
+     *                          create the context
+     * @throws NamingException  If naming problems are encountered during
+     *                          initialization of these fields.
+     */
+    protected void init(Hashtable<?, ?> env) throws NamingException {
+        this.internalInit(env);
+    }
+
+    /* 
+     * Initializes the default initial context.
+     * 
+     * @throws NamingException  If failed to initialize this InitialContext.
+     */
+    private void initializeDefaultInitCtx() throws NamingException {
+        if (!this.gotDefault) {
+            this.defaultInitCtx = NamingManager.getInitialContext(myProps);
+            if (null == this.defaultInitCtx) {
+                throw new NoInitialContextException("Failed to create an initial context."); //$NON-NLS-1$
+            }
+            this.gotDefault = true;
+        }
+    }
+
+    /**
+     * Gets the default underlying <code>Context</code> implementation.
+     * If <code>gotDefault</code> is true, returns the value of <code>
+     * defaultInitCtx</code>. Otherwise, calls <code>NamingManager.getInitialContext
+     * </code> to return an initial context for the current environment into 
+     * <code>defaultInitCtx</code>, then <code>gotDefault</code> is set true.
+     * If the resulting context object is null, a <code>NoInitialContextException
+     * </code> is thrown, otherwise the value of <code>defaultInitCtx</code> is
+     * returned.
+     *
+     * @return                  the default context
+     * @throws NoInitialContextException
+     *                          If <code>NamingManager.getInitialContext</code>
+     *                          returns null.
+     * @throws NamingException  If failed to create the default context.
+     */
+    protected Context getDefaultInitCtx() throws NamingException {
+        initializeDefaultInitCtx();
+        return this.defaultInitCtx;
+    }
+
+    /**
+     * Returns a non-null context for the specified name of Name representation.
+     * <p>
+     * If an initial context factory builder has been defined, then the
+     * specified <code>Name</code> parameter is ignored and the result of <code>
+     * getDefaultInitCtx</code> is returned. Otherwise, if the first component 
+     * of the name is not a URL string, then it returns the result of invoking
+     * <code>getDefaultInitCtx</code>. Otherwise, it attempts to return a URL 
+     * context {@link javax.naming.spi.NamingManager#getURLContext(String, Hashtable)},
+     * but if unsuccessful, returns the result of invoking 
+     * <code>getDefaultInitCtx</code>.</p>
+     *
+     * @param name              a name used in a naming operation which may not
+     *                          be null
+     * @return                  a context which may be a URL context
+     * @throws NamingException  If failed to get the desired context.
+     */
+    protected Context getURLOrDefaultInitCtx(Name name)
+        throws NamingException {
+        // If the name has components
+        if (0 < name.size()) {
+            return getURLOrDefaultInitCtx(name.get(0));
+        }
+		return getDefaultInitCtx();
+    }
+
+    /**
+     * Returns a non-null context for the specified name of string 
+     * representation.
+     * <p>
+     * If an initial context factory builder has been defined, then the
+     * specified name parameter is ignored and the result of <code>
+     * getDefaultInitCtx</code> is returned. Otherwise, if the name is not a URL
+     * string, then it returns the result of invoking <code>getDefaultInitCtx
+     * </code>. Otherwise, it attempts to return a URL context 
+     * {@link javax.naming.spi.NamingManager#getURLContext(String, Hashtable)}, 
+     * but if unsuccessful, returns the result of invoking <code>
+     * getDefaultInitCtx</code>.</p>
+     *
+     * @param name              a name used in a naming operation which may not
+     *                          be null
+     * @return                  a context which may be a URL context
+     * @throws NamingException  If failed to get the desired context.
+     */
+    protected Context getURLOrDefaultInitCtx(String name)
+        throws NamingException {
+
+        /*
+         * If an initial context factory builder has been defined, then the
+         * specified name parameter is ignored and the result of 
+         * getDefaultInitCtx() is returned.
+         */
+        if (NamingManager.hasInitialContextFactoryBuilder()) {
+            return getDefaultInitCtx();
+        }
+
+        if (null == name) {
+            throw new NullPointerException("null"); //$NON-NLS-1$
+        }
+
+        // If the name has components
+        String scheme = UrlParser.getScheme(name);
+        Context ctx = null;
+        if (null != scheme) {
+            // So the first componet is a valid URL
+            ctx = NamingManager.getURLContext(scheme, myProps);
+        }
+        return null == ctx ? getDefaultInitCtx() : ctx;
+    }
+
+    /*
+     * -------------------------------------------------------------------
+     * Methods of Interface Context
+     * -------------------------------------------------------------------
+     */
+
+    public Object lookup(Name name) throws NamingException {
+        return getURLOrDefaultInitCtx(name).lookup(name);
+    }
+
+    public Object lookup(String name) throws NamingException {
+        return getURLOrDefaultInitCtx(name).lookup(name);
+    }
+
+    public void bind(Name name, Object obj) throws NamingException {
+        getURLOrDefaultInitCtx(name).bind(name, obj);
+    }
+
+    public void bind(String name, Object obj) throws NamingException {
+        getURLOrDefaultInitCtx(name).bind(name, obj);
+    }
+
+    public void rebind(Name name, Object obj) throws NamingException {
+        getURLOrDefaultInitCtx(name).rebind(name, obj);
+    }
+
+    public void rebind(String name, Object obj) throws NamingException {
+        getURLOrDefaultInitCtx(name).rebind(name, obj);
+    }
+
+    public void unbind(Name name) throws NamingException {
+        getURLOrDefaultInitCtx(name).unbind(name);
+    }
+
+    public void unbind(String name) throws NamingException {
+        getURLOrDefaultInitCtx(name).unbind(name);
+    }
+
+    public void rename(Name oldName, Name newName) throws NamingException {
+        getURLOrDefaultInitCtx(oldName).rename(oldName, newName);
+    }
+
+    public void rename(String oldName, String newName) throws NamingException {
+        getURLOrDefaultInitCtx(oldName).rename(oldName, newName);
+    }
+
+    public NamingEnumeration<NameClassPair> list(Name name)
+        throws NamingException {
+        return getURLOrDefaultInitCtx(name).list(name);
+    }
+
+    public NamingEnumeration<NameClassPair> list(String name)
+        throws NamingException {
+        return getURLOrDefaultInitCtx(name).list(name);
+    }
+
+    public NamingEnumeration<Binding> listBindings(Name name)
+        throws NamingException {
+        return getURLOrDefaultInitCtx(name).listBindings(name);
+    }
+
+    public NamingEnumeration<Binding> listBindings(String name)
+            throws NamingException {
+        return getURLOrDefaultInitCtx(name).listBindings(name);
+    }
+
+    public void destroySubcontext(Name name) throws NamingException {
+        getURLOrDefaultInitCtx(name).destroySubcontext(name);
+    }
+
+    public void destroySubcontext(String name) throws NamingException {
+        getURLOrDefaultInitCtx(name).destroySubcontext(name);
+    }
+
+    public Context createSubcontext(Name name) throws NamingException {
+        return getURLOrDefaultInitCtx(name).createSubcontext(name);
+    }
+
+    public Context createSubcontext(String name) throws NamingException {
+        return getURLOrDefaultInitCtx(name).createSubcontext(name);
+    }
+
+    public Object lookupLink(Name name) throws NamingException {
+        return getURLOrDefaultInitCtx(name).lookupLink(name);
+    }
+
+    public Object lookupLink(String name) throws NamingException {
+        return getURLOrDefaultInitCtx(name).lookupLink(name);
+    }
+
+    public NameParser getNameParser(Name name) throws NamingException {
+        return getURLOrDefaultInitCtx(name).getNameParser(name);
+    }
+
+    public NameParser getNameParser(String name) throws NamingException {
+        return getURLOrDefaultInitCtx(name).getNameParser(name);
+    }
+
+    public Name composeName(Name name, Name prefix) throws NamingException {
+        if (null == name) {
+            throw new InvalidNameException("Invalid name."); //$NON-NLS-1$
+        }
+        if (prefix == null) {
+        	prefix = new CompositeName("");
+        }
+        Name comName = (Name) prefix.clone();
+        comName.addAll(name);
+        return comName;
+    }
+
+    public String composeName(String name, String prefix)
+        throws NamingException {
+        if (null == name) {
+            throw new InvalidNameException("Invalid name."); //$NON-NLS-1$
+        }
+        if (prefix == null) {
+        	prefix = "";
+        }
+        return composeName(new CompositeName(name), new CompositeName(prefix))
+            .toString();
+    }
+
+    public Object addToEnvironment(String propName, Object propVal)
+        throws NamingException {
+        this.myProps.put(propName, propVal);
+        return getDefaultInitCtx().addToEnvironment(propName, propVal);
+    }
+
+    public Object removeFromEnvironment(String propName)
+        throws NamingException {
+        this.myProps.remove(propName);
+        return getDefaultInitCtx().removeFromEnvironment(propName);
+    }
+
+    public Hashtable<?, ?> getEnvironment() throws NamingException {
+        return getDefaultInitCtx().getEnvironment();
+    }
+
+    public void close() throws NamingException {
+        if (this.gotDefault) {
+        	getDefaultInitCtx().close();
+        }
+    }
+
+    public String getNameInNamespace() throws NamingException {
+        return getDefaultInitCtx().getNameInNamespace();
+    }
+
+}
+
+

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

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

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

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

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

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

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

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

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/Name.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/Name.java?rev=437433&r1=437432&r2=437433&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/Name.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/Name.java Sun Aug 27 11:26:20 2006
@@ -1,216 +1,216 @@
-/* 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;
-
-import java.io.Serializable;
-import java.util.Enumeration;
-
-/**
- * A <code>Name</code> interface represents a name in a naming service.
- * <p>
- * A name which implements this interface has a sequence of zero or more 
- * elements delimited by separators. Each element can be accessed using its
- * position. The first element is at position 0.</p>
- * <p>
- * This interface is implemented by 2 classes - <code>CompoundName</code> 
- * and <code>CompositeName</code>.</p>
- * <p>
- * Examples of names are:
- * <pre>
- * File system name - for example /home/jenningm/.profile
- * DNS hostname     - for example www.apache.org
- * Internet URL     - for example http://www.eclipse.org/org/index.html
- * </pre></p>
- * 
- * @see CompositeName
- * @see CompoundName
- */
-public interface Name extends Cloneable, Serializable, Comparable<Object> {
-
-    /*
-     * SUID declared publically in the spec.
-     */
-    public static final long serialVersionUID = -3617482732056931635L;
-    
-    /*
-     * -------------------------------------------------------------------
-     * Methods
-     * -------------------------------------------------------------------
-     */
-
-    /**
-     * Get all the elements of this <code>Name</code>.
-     * If the <code>Name</code> is empty then return an empty 
-     * <code>Enumeration</code>.
-     * 
-     * @return an enumeration of <code>Name</code> elements - cannot be null
-     */
-    public Enumeration<String> getAll();
-
-    /**
-     * Get an element of this <code>Name</code>.
-     * 
-     * @param i the index of the required element - must be greater
-     *          than or equal to 0 and less than size().
-     * @return  the element at the specified position
-     * @throws ArrayIndexOutOfBoundsException when the position is invalid. 
-     *          If the <code>Name</code> is empty this always returns 
-     *          <code>ArrayIndexOutOfBoundsException</code>
-     */
-    public String get(int i);
-
-    /**
-     * Create a new <code>Name</code> which comprises the first several 
-     * elements of this <code>Name</code>.
-     * 
-     * @param i the index of the first element not to be included - must be 
-     *          greater than or equal to 0 and less than or equal to size. 
-     *          If 0 then an empty name is returned.
-     * @return  a new <code>Name</code> which comprises the first several 
-     *          elements of this <code>Name</code>
-     * @throws ArrayIndexOutOfBoundsException when the position is invalid.
-     */
-    public Name getPrefix(int i);
-    
-    /**
-     * Create a new <code>Name</code> which comprises the last 
-     * (<code>size() - i</code>) elements of this <code>Name</code>.
-     * 
-     * @param i the index of the first element to be included - must be 
-     *          greater than or equal to 0 and less than size.
-     * @return  a new <code>Name</code> which comprises the last 
-     *          (<code>size() - i</code>) elements of this 
-     *          <code>Name</code>
-     * @throws ArrayIndexOutOfBoundsException when the position is invalid.
-     */
-    public Name getSuffix(int i);
-    
-    /**
-     * Append a name to this <code>Name</code>. The name itself may have a 
-     * number of elements.
-     * 
-     * @param name  the name to append onto this <code>Name</code>.
-     * @return      this <code>Name</code>
-     * @throws InvalidNameException if name is invalid or the addition of the
-     *              name results in this <code>Name</code> becoming invalid.
-     */
-    public Name addAll(Name name) throws InvalidNameException;
-    
-    /**
-     * Insert a name within this <code>Name</code> at the specified position. 
-     * The name itself may have a number of elements.
-     * 
-     * @param i     the index of the element where to start inserting the name
-     *              - must be greater than or equal to 0 and less than or equal
-     *              to size.
-     * @param name  the name to insert into this <code>Name</code>.
-     * @return      this <code>Name</code>
-     * @throws InvalidNameException  if name is invalid or the addition of the
-     *              name results in this <code>Name</code> becoming invalid.
-     */
-    public Name addAll(int i, Name name) throws InvalidNameException;
-
-    /**
-     * Append an element to this <code>Name</code>.
-     * 
-     * @param s the string to append
-     * @return  this <code>Name</code>
-     * @throws InvalidNameException if the addition of the element results in
-     *          this <code>Name</code> becoming invalid.
-     */
-    public Name add(String s) throws InvalidNameException;
-    
-    /**
-     * Insert an element within this <code>Name</code> at the specified 
-     * position.
-     * 
-     * @param i the index of the element where to insert the element - 
-     *          must be greater than or equal to 0 and less than or equal to
-     *          size.
-     * @param s the String to insert
-     * @return  this <code>Name</code>.
-     * @throws InvalidNameException if the insertion of the element results in
-     *          this Name becoming invalid.
-     */
-    public Name add(int i, String s) throws InvalidNameException;
-
-    /**
-     * Delete an element from this <code>Name</code>.
-     * 
-     * @param i the index of the element to delete - must be greater
-     *          than or equal to 0 and less than size.
-     * @return  the deleted element
-     * @throws InvalidNameException if the deletion of the element results in
-     *          this <code>Name</code> becoming invalid.
-     */
-    public Object remove(int i) throws InvalidNameException;
-
-    /**
-     * Create a copy of this <code>Name</code>.
-     * 
-     * @return a complete (deep) copy of the object.
-     */
-    public Object clone();
-    
-    /**
-     * Compare this <code>Name</code> with the one supplied as a parameter. 
-     * Each class which implements this interface will have a specification 
-     * of how to do the comparison.
-     * 
-     * @param o the object to compare - cannot be null.
-     * @return  a negative number means this is less than the supplied object.
-     *          a positive number means this is greater than the supplied 
-     *          object. Zero means the two objects are equal. 
-     */
-    public int compareTo(Object o);
-    
-    /**
-     * Get the size of this <code>Name</code>. The size of a <code>Name</code>
-     * is its number of elements.
-     * 
-     * @return the size of this name - cannot be null - can be zero
-     */
-    public int size();
-    
-    /**
-     * Check if this <code>Name</code> is empty. A <code>Name</code> is empty
-     * when it has no elements.
-     * 
-     * @return true if empty, else returns false
-     */
-    public boolean isEmpty();
-
-    /**
-     * Check if this <code>Name</code> starts with the elements in the 
-     * supplied name. The supplied name itself may have a number of elements.
-     * 
-     * @param name  the name to check against this name
-     * @return      true when the supplied name matches else returns false
-     */
-    public boolean startsWith(Name name);
-
-    /**
-     * Check if this <code>Name</code> ends with the elements in the supplied 
-     * name. The supplied name itself may have a number of elements.
-     * 
-     * @param name  the name to check against this name.
-     * @return      true when the supplied name matches else returns false.
-     */
-    public boolean endsWith(Name name);
-}
-
-
+/* 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;
+
+import java.io.Serializable;
+import java.util.Enumeration;
+
+/**
+ * A <code>Name</code> interface represents a name in a naming service.
+ * <p>
+ * A name which implements this interface has a sequence of zero or more 
+ * elements delimited by separators. Each element can be accessed using its
+ * position. The first element is at position 0.</p>
+ * <p>
+ * This interface is implemented by 2 classes - <code>CompoundName</code> 
+ * and <code>CompositeName</code>.</p>
+ * <p>
+ * Examples of names are:
+ * <pre>
+ * File system name - for example /home/jenningm/.profile
+ * DNS hostname     - for example www.apache.org
+ * Internet URL     - for example http://www.eclipse.org/org/index.html
+ * </pre></p>
+ * 
+ * @see CompositeName
+ * @see CompoundName
+ */
+public interface Name extends Cloneable, Serializable, Comparable<Object> {
+
+    /*
+     * SUID declared publically in the spec.
+     */
+    public static final long serialVersionUID = -3617482732056931635L;
+    
+    /*
+     * -------------------------------------------------------------------
+     * Methods
+     * -------------------------------------------------------------------
+     */
+
+    /**
+     * Get all the elements of this <code>Name</code>.
+     * If the <code>Name</code> is empty then return an empty 
+     * <code>Enumeration</code>.
+     * 
+     * @return an enumeration of <code>Name</code> elements - cannot be null
+     */
+    public Enumeration<String> getAll();
+
+    /**
+     * Get an element of this <code>Name</code>.
+     * 
+     * @param i the index of the required element - must be greater
+     *          than or equal to 0 and less than size().
+     * @return  the element at the specified position
+     * @throws ArrayIndexOutOfBoundsException when the position is invalid. 
+     *          If the <code>Name</code> is empty this always returns 
+     *          <code>ArrayIndexOutOfBoundsException</code>
+     */
+    public String get(int i);
+
+    /**
+     * Create a new <code>Name</code> which comprises the first several 
+     * elements of this <code>Name</code>.
+     * 
+     * @param i the index of the first element not to be included - must be 
+     *          greater than or equal to 0 and less than or equal to size. 
+     *          If 0 then an empty name is returned.
+     * @return  a new <code>Name</code> which comprises the first several 
+     *          elements of this <code>Name</code>
+     * @throws ArrayIndexOutOfBoundsException when the position is invalid.
+     */
+    public Name getPrefix(int i);
+    
+    /**
+     * Create a new <code>Name</code> which comprises the last 
+     * (<code>size() - i</code>) elements of this <code>Name</code>.
+     * 
+     * @param i the index of the first element to be included - must be 
+     *          greater than or equal to 0 and less than size.
+     * @return  a new <code>Name</code> which comprises the last 
+     *          (<code>size() - i</code>) elements of this 
+     *          <code>Name</code>
+     * @throws ArrayIndexOutOfBoundsException when the position is invalid.
+     */
+    public Name getSuffix(int i);
+    
+    /**
+     * Append a name to this <code>Name</code>. The name itself may have a 
+     * number of elements.
+     * 
+     * @param name  the name to append onto this <code>Name</code>.
+     * @return      this <code>Name</code>
+     * @throws InvalidNameException if name is invalid or the addition of the
+     *              name results in this <code>Name</code> becoming invalid.
+     */
+    public Name addAll(Name name) throws InvalidNameException;
+    
+    /**
+     * Insert a name within this <code>Name</code> at the specified position. 
+     * The name itself may have a number of elements.
+     * 
+     * @param i     the index of the element where to start inserting the name
+     *              - must be greater than or equal to 0 and less than or equal
+     *              to size.
+     * @param name  the name to insert into this <code>Name</code>.
+     * @return      this <code>Name</code>
+     * @throws InvalidNameException  if name is invalid or the addition of the
+     *              name results in this <code>Name</code> becoming invalid.
+     */
+    public Name addAll(int i, Name name) throws InvalidNameException;
+
+    /**
+     * Append an element to this <code>Name</code>.
+     * 
+     * @param s the string to append
+     * @return  this <code>Name</code>
+     * @throws InvalidNameException if the addition of the element results in
+     *          this <code>Name</code> becoming invalid.
+     */
+    public Name add(String s) throws InvalidNameException;
+    
+    /**
+     * Insert an element within this <code>Name</code> at the specified 
+     * position.
+     * 
+     * @param i the index of the element where to insert the element - 
+     *          must be greater than or equal to 0 and less than or equal to
+     *          size.
+     * @param s the String to insert
+     * @return  this <code>Name</code>.
+     * @throws InvalidNameException if the insertion of the element results in
+     *          this Name becoming invalid.
+     */
+    public Name add(int i, String s) throws InvalidNameException;
+
+    /**
+     * Delete an element from this <code>Name</code>.
+     * 
+     * @param i the index of the element to delete - must be greater
+     *          than or equal to 0 and less than size.
+     * @return  the deleted element
+     * @throws InvalidNameException if the deletion of the element results in
+     *          this <code>Name</code> becoming invalid.
+     */
+    public Object remove(int i) throws InvalidNameException;
+
+    /**
+     * Create a copy of this <code>Name</code>.
+     * 
+     * @return a complete (deep) copy of the object.
+     */
+    public Object clone();
+    
+    /**
+     * Compare this <code>Name</code> with the one supplied as a parameter. 
+     * Each class which implements this interface will have a specification 
+     * of how to do the comparison.
+     * 
+     * @param o the object to compare - cannot be null.
+     * @return  a negative number means this is less than the supplied object.
+     *          a positive number means this is greater than the supplied 
+     *          object. Zero means the two objects are equal. 
+     */
+    public int compareTo(Object o);
+    
+    /**
+     * Get the size of this <code>Name</code>. The size of a <code>Name</code>
+     * is its number of elements.
+     * 
+     * @return the size of this name - cannot be null - can be zero
+     */
+    public int size();
+    
+    /**
+     * Check if this <code>Name</code> is empty. A <code>Name</code> is empty
+     * when it has no elements.
+     * 
+     * @return true if empty, else returns false
+     */
+    public boolean isEmpty();
+
+    /**
+     * Check if this <code>Name</code> starts with the elements in the 
+     * supplied name. The supplied name itself may have a number of elements.
+     * 
+     * @param name  the name to check against this name
+     * @return      true when the supplied name matches else returns false
+     */
+    public boolean startsWith(Name name);
+
+    /**
+     * Check if this <code>Name</code> ends with the elements in the supplied 
+     * name. The supplied name itself may have a number of elements.
+     * 
+     * @param name  the name to check against this name.
+     * @return      true when the supplied name matches else returns false.
+     */
+    public boolean endsWith(Name name);
+}
+
+

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

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/NameClassPair.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/NameClassPair.java?rev=437433&r1=437432&r2=437433&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/NameClassPair.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/NameClassPair.java Sun Aug 27 11:26:20 2006
@@ -1,233 +1,233 @@
-/* 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;
-
-import java.io.Serializable;
-
-/**
- * <code>NameClassPair</code> associates a name in a naming service with a 
- * specified class name and also with a relative flag. In JNDI, 
- * <code>NameClassPair</code> is extended by <code>javax.naming.Binding</code>;
- * <code>Binding</code> objects are used in <code>javax.naming.Context</code>
- * implementations.
- * <p>
- * A <code>NameClassPair</code> object is not thread-safe unless appropriate 
- * synchronization is applied to any code manipulating these objects.</p>
- * <p>
- * As this class implements the <code>Serializable</code> interface, it is 
- * important that fields below are declared with the same names.</p>
- * 
- */
-public class NameClassPair implements Serializable {
-
-    /*
-     * -------------------------------------------------------------------
-     * Constants
-     * -------------------------------------------------------------------
-     */
-
-    // J2SE 1.5.0
-    private static final long serialVersionUID = 5620776610160863339L;
-
-    /*
-     * -------------------------------------------------------------------
-     * Instance variables
-     * -------------------------------------------------------------------
-     */
-
-    /**
-     * The name used in a naming service. This field may be null and has default
-     * value of null.
-     * 
-     * @serial
-     */
-    private String name;
-
-    /**
-     * The class of an object represented by this name in a naming service.
-     * This field may be null and has default value null.
-     * 
-     * @serial
-     */
-    private String className;
-
-    /**
-     *
-     * @serial
-     */
-    private String fullName;
-
-    /**
-     * This flag indicates whether the name s used in a naming service is relative
-     * to the context. It is set by setRelative and is not derived. This field has
-     * default value true. If this is set to false then the name is not relative and
-     * is actually a URL.
-     * 
-     * @serial
-     */
-    private boolean isRel;
-
-    /*
-     * -------------------------------------------------------------------
-     * Constructors
-     * -------------------------------------------------------------------
-     */
-
-    /**
-     * Construct a <code>NameClassPair</code> from a name and a class.
-     * Both arguments can be null.
-     * Relative flag is true.
-     * 
-     * @param name      a name used in naming service
-     * @param className a class name
-     */
-    public NameClassPair(String name, String className) {
-        this(name, className, true);
-    }
-
-    /**
-     * Construct a <code>NameClassPair</code> from a name, a class and a 
-     * relative flag. The name and class arguments can be null.
-     * 
-     * @param name      a name used in naming service
-     * @param className a class name
-     * @param relative  a relative flag
-     */
-    public NameClassPair(String name, String className, boolean relative) {
-        if (name == null) {
-            throw new IllegalArgumentException("name must not be null");
-        }
-        this.name = name;
-        this.className = className;
-        this.isRel = relative;
-        this.fullName = null;
-    }
-
-    /*
-     * -------------------------------------------------------------------
-     * Methods
-     * -------------------------------------------------------------------
-     */
-
-    /**
-     * Returns the value of the class which may be null.
-     * 
-     * @return the value of the class which may be null.
-     */
-    public String getClassName() {
-        return className;
-    }
-
-    /**
-     * Returns the value of the name field which may be null.
-     * 
-     * @return the value of the name field which may be null.
-     */
-    public String getName() {
-        return name;
-    }
-
-    /**
-     * Returns the value of the relative flag.
-     * 
-     * @return the value of the relative flag.
-     */
-    public boolean isRelative() {
-        return isRel;
-    }
-
-    /**
-     * Set the class of this object. The argument can be null.
-     * 
-     * @param className a class name
-     */
-    public void setClassName(String className) {
-        this.className = className;
-    }
-
-    /**
-     * Set the name of this object. The argument can be null.
-     * 
-     * @param name  a name used in naming service
-     */
-    public void setName(String name) {
-        if (name == null) {
-            throw new IllegalArgumentException("name must not be null");
-        }
-        this.name = name;
-    }
-
-    /**
-     * Set the isRelative flag field of this object.
-     * 
-     * @param relative  a relative flag
-     */
-    public void setRelative(boolean relative) {
-        this.isRel = relative;
-    }
-
-    /**
-     * Returns the value of the full name field which may be null.
-     * 
-     * @return the value of the full name field which may be null.
-     *
-     * @throws UnsupportedOperationException
-     */
-    public String getNameInNamespace() {
-        if (fullName == null) {
-            throw new UnsupportedOperationException(
-                    "full name doesn't apply to this binding");
-        }
-        return fullName;
-    }
-
-    /**
-     * Set the full name of this object. The argument can be null.
-     * 
-     * @param fullName  a full name
-     */
-    public void setNameInNamespace(String fullName) {
-        this.fullName = fullName;
-    }
-
-    /*
-     * -------------------------------------------------------------------
-     * Methods override parent class Object
-     * -------------------------------------------------------------------
-     */
-
-    /**
-     * If the flag is set to false then the string is preceded with
-     * "(not relative)" and then has the name value, ": " and the class
-     * value.
-     * 
-     * @return a string representation of this object
-     */
-    public String toString() {
-        StringBuffer buf = new StringBuffer();
-        if (!isRel) {
-            buf.append("(not relative)"); //$NON-NLS-1$
-        }
-        buf.append(getName());
-        buf.append(": "); //$NON-NLS-1$
-        buf.append(getClassName()); // getClassName() is overrided by subclass
-        return buf.toString();
-    }
-
-}
-
-
+/* 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;
+
+import java.io.Serializable;
+
+/**
+ * <code>NameClassPair</code> associates a name in a naming service with a 
+ * specified class name and also with a relative flag. In JNDI, 
+ * <code>NameClassPair</code> is extended by <code>javax.naming.Binding</code>;
+ * <code>Binding</code> objects are used in <code>javax.naming.Context</code>
+ * implementations.
+ * <p>
+ * A <code>NameClassPair</code> object is not thread-safe unless appropriate 
+ * synchronization is applied to any code manipulating these objects.</p>
+ * <p>
+ * As this class implements the <code>Serializable</code> interface, it is 
+ * important that fields below are declared with the same names.</p>
+ * 
+ */
+public class NameClassPair implements Serializable {
+
+    /*
+     * -------------------------------------------------------------------
+     * Constants
+     * -------------------------------------------------------------------
+     */
+
+    // J2SE 1.5.0
+    private static final long serialVersionUID = 5620776610160863339L;
+
+    /*
+     * -------------------------------------------------------------------
+     * Instance variables
+     * -------------------------------------------------------------------
+     */
+
+    /**
+     * The name used in a naming service. This field may be null and has default
+     * value of null.
+     * 
+     * @serial
+     */
+    private String name;
+
+    /**
+     * The class of an object represented by this name in a naming service.
+     * This field may be null and has default value null.
+     * 
+     * @serial
+     */
+    private String className;
+
+    /**
+     *
+     * @serial
+     */
+    private String fullName;
+
+    /**
+     * This flag indicates whether the name s used in a naming service is relative
+     * to the context. It is set by setRelative and is not derived. This field has
+     * default value true. If this is set to false then the name is not relative and
+     * is actually a URL.
+     * 
+     * @serial
+     */
+    private boolean isRel;
+
+    /*
+     * -------------------------------------------------------------------
+     * Constructors
+     * -------------------------------------------------------------------
+     */
+
+    /**
+     * Construct a <code>NameClassPair</code> from a name and a class.
+     * Both arguments can be null.
+     * Relative flag is true.
+     * 
+     * @param name      a name used in naming service
+     * @param className a class name
+     */
+    public NameClassPair(String name, String className) {
+        this(name, className, true);
+    }
+
+    /**
+     * Construct a <code>NameClassPair</code> from a name, a class and a 
+     * relative flag. The name and class arguments can be null.
+     * 
+     * @param name      a name used in naming service
+     * @param className a class name
+     * @param relative  a relative flag
+     */
+    public NameClassPair(String name, String className, boolean relative) {
+        if (name == null) {
+            throw new IllegalArgumentException("name must not be null");
+        }
+        this.name = name;
+        this.className = className;
+        this.isRel = relative;
+        this.fullName = null;
+    }
+
+    /*
+     * -------------------------------------------------------------------
+     * Methods
+     * -------------------------------------------------------------------
+     */
+
+    /**
+     * Returns the value of the class which may be null.
+     * 
+     * @return the value of the class which may be null.
+     */
+    public String getClassName() {
+        return className;
+    }
+
+    /**
+     * Returns the value of the name field which may be null.
+     * 
+     * @return the value of the name field which may be null.
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Returns the value of the relative flag.
+     * 
+     * @return the value of the relative flag.
+     */
+    public boolean isRelative() {
+        return isRel;
+    }
+
+    /**
+     * Set the class of this object. The argument can be null.
+     * 
+     * @param className a class name
+     */
+    public void setClassName(String className) {
+        this.className = className;
+    }
+
+    /**
+     * Set the name of this object. The argument can be null.
+     * 
+     * @param name  a name used in naming service
+     */
+    public void setName(String name) {
+        if (name == null) {
+            throw new IllegalArgumentException("name must not be null");
+        }
+        this.name = name;
+    }
+
+    /**
+     * Set the isRelative flag field of this object.
+     * 
+     * @param relative  a relative flag
+     */
+    public void setRelative(boolean relative) {
+        this.isRel = relative;
+    }
+
+    /**
+     * Returns the value of the full name field which may be null.
+     * 
+     * @return the value of the full name field which may be null.
+     *
+     * @throws UnsupportedOperationException
+     */
+    public String getNameInNamespace() {
+        if (fullName == null) {
+            throw new UnsupportedOperationException(
+                    "full name doesn't apply to this binding");
+        }
+        return fullName;
+    }
+
+    /**
+     * Set the full name of this object. The argument can be null.
+     * 
+     * @param fullName  a full name
+     */
+    public void setNameInNamespace(String fullName) {
+        this.fullName = fullName;
+    }
+
+    /*
+     * -------------------------------------------------------------------
+     * Methods override parent class Object
+     * -------------------------------------------------------------------
+     */
+
+    /**
+     * If the flag is set to false then the string is preceded with
+     * "(not relative)" and then has the name value, ": " and the class
+     * value.
+     * 
+     * @return a string representation of this object
+     */
+    public String toString() {
+        StringBuffer buf = new StringBuffer();
+        if (!isRel) {
+            buf.append("(not relative)"); //$NON-NLS-1$
+        }
+        buf.append(getName());
+        buf.append(": "); //$NON-NLS-1$
+        buf.append(getClassName()); // getClassName() is overrided by subclass
+        return buf.toString();
+    }
+
+}
+
+

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

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

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

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



Mime
View raw message