Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 8509 invoked from network); 27 Aug 2006 18:28:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 27 Aug 2006 18:28:07 -0000 Received: (qmail 28730 invoked by uid 500); 27 Aug 2006 18:28:07 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 28676 invoked by uid 500); 27 Aug 2006 18:28:07 -0000 Mailing-List: contact harmony-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-commits@incubator.apache.org Received: (qmail 28654 invoked by uid 99); 27 Aug 2006 18:28:07 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Aug 2006 11:28:07 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Aug 2006 11:27:53 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 9B8491A983A; Sun, 27 Aug 2006 11:26:43 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r437433 [12/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 -0000 To: harmony-commits@incubator.apache.org From: ndbeyer@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060827182643.9B8491A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLDirContext.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLDirContext.java?rev=437433&r1=437432&r2=437433&view=diff ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLDirContext.java (original) +++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLDirContext.java Sun Aug 27 11:26:20 2006 @@ -1,594 +1,594 @@ -/* - * 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.InvalidNameException; -import javax.naming.Name; -import javax.naming.NamingEnumeration; -import javax.naming.NamingException; - -import javax.naming.directory.Attributes; -import javax.naming.directory.DirContext; -import javax.naming.directory.ModificationItem; -import javax.naming.directory.SearchControls; - -import javax.naming.spi.DirectoryManager; -import javax.naming.spi.ResolveResult; - - -/** - * Base class for URL directory context implementations. - * - * In many cases, subclasses should only override - * {@link GenericURLContext#getRootURLContext(String, Hashtable)} method - * and provide a public constructor calling - * {@link GenericURLDirContext#GenericURLDirContext(Hashtable) super(environment)}. - * - * @author Vasily Zakharov - * @version $Revision: 1.1.2.3 $ - */ -public abstract class GenericURLDirContext - extends GenericURLContext implements DirContext { - - /** - * Creates instance of this context with empty environment. - */ - protected GenericURLDirContext() { - super(null); - } - - /** - * Creates instance of this context with specified environment. - * - * @param environment - * Environment to copy. - */ - protected GenericURLDirContext(Hashtable environment) { - super(environment); - } - - /** - * {@inheritDoc} - */ - public void bind(Name name, Object obj, Attributes attrs) - 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, attrs); - } else { - DirContext context = getContinuationDirContext(name); - - try { - context.bind(name.getSuffix(1), obj, attrs); - } finally { - context.close(); - } - } - } - - /** - * {@inheritDoc} - */ - public void bind(String name, Object obj, Attributes attrs) - throws NamingException { - ResolveResult result = getRootURLContext(name, environment); - DirContext context = (DirContext) result.getResolvedObj(); - - try { - context.bind(result.getRemainingName(), obj, attrs); - } finally { - context.close(); - } - } - - /** - * {@inheritDoc} - */ - public void rebind(Name name, Object obj, Attributes attrs) - 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, attrs); - } else { - DirContext context = getContinuationDirContext(name); - - try { - context.rebind(name.getSuffix(1), obj, attrs); - } finally { - context.close(); - } - } - } - - /** - * {@inheritDoc} - */ - public void rebind(String name, Object obj, Attributes attrs) - throws NamingException { - ResolveResult result = getRootURLContext(name, environment); - DirContext context = (DirContext) result.getResolvedObj(); - - try { - context.rebind(result.getRemainingName(), obj, attrs); - } finally { - context.close(); - } - } - - /** - * {@inheritDoc} - */ - public DirContext createSubcontext(Name name, Attributes attrs) - 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), attrs); - } else { - DirContext context = getContinuationDirContext(name); - - try { - return context.createSubcontext(name.getSuffix(1), attrs); - } finally { - context.close(); - } - } - } - - /** - * {@inheritDoc} - */ - public DirContext createSubcontext(String name, Attributes attrs) - throws NamingException { - ResolveResult result = getRootURLContext(name, environment); - DirContext context = (DirContext) result.getResolvedObj(); - - try { - return context.createSubcontext(result.getRemainingName(), attrs); - } finally { - context.close(); - } - } - - /** - * {@inheritDoc} - */ - public Attributes getAttributes(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 getAttributes(name.get(0)); - } else { - DirContext context = getContinuationDirContext(name); - - try { - return context.getAttributes(name.getSuffix(1)); - } finally { - context.close(); - } - } - } - - /** - * {@inheritDoc} - */ - public Attributes getAttributes(String name) throws NamingException { - ResolveResult result = getRootURLContext(name, environment); - DirContext context = (DirContext) result.getResolvedObj(); - - try { - return context.getAttributes(result.getRemainingName()); - } finally { - context.close(); - } - } - - /** - * {@inheritDoc} - */ - public Attributes getAttributes(Name name, String[] attrIds) - throws NamingException { - if (!(name instanceof CompositeName)) { - throw new InvalidNameException( - "URL context can't accept non-composite name: " + name); - } - - if (name.size() == 1) { - return getAttributes(name.get(0), attrIds); - } else { - DirContext context = getContinuationDirContext(name); - - try { - return context.getAttributes(name.getSuffix(1), attrIds); - } finally { - context.close(); - } - } - } - - /** - * {@inheritDoc} - */ - public Attributes getAttributes(String name, String[] attrIds) - throws NamingException { - ResolveResult result = getRootURLContext(name, environment); - DirContext context = (DirContext) result.getResolvedObj(); - - try { - return context.getAttributes(result.getRemainingName(), attrIds); - } finally { - context.close(); - } - } - - /** - * {@inheritDoc} - */ - public void modifyAttributes(Name name, int mod_op, Attributes attrs) - throws NamingException { - if (!(name instanceof CompositeName)) { - throw new InvalidNameException( - "URL context can't accept non-composite name: " + name); - } - - if (name.size() == 1) { - modifyAttributes(name.get(0), mod_op, attrs); - } else { - DirContext context = getContinuationDirContext(name); - - try { - context.modifyAttributes(name.getSuffix(1), mod_op, attrs); - } finally { - context.close(); - } - } - } - - /** - * {@inheritDoc} - */ - public void modifyAttributes(String name, int mod_op, Attributes attrs) - throws NamingException { - ResolveResult result = getRootURLContext(name, environment); - DirContext context = (DirContext) result.getResolvedObj(); - - try { - context.modifyAttributes(result.getRemainingName(), mod_op, attrs); - } finally { - context.close(); - } - } - - /** - * {@inheritDoc} - */ - public void modifyAttributes(Name name, ModificationItem[] mods) - throws NamingException { - if (!(name instanceof CompositeName)) { - throw new InvalidNameException( - "URL context can't accept non-composite name: " + name); - } - - if (name.size() == 1) { - modifyAttributes(name.get(0), mods); - } else { - DirContext context = getContinuationDirContext(name); - - try { - context.modifyAttributes(name.getSuffix(1), mods); - } finally { - context.close(); - } - } - } - - /** - * {@inheritDoc} - */ - public void modifyAttributes(String name, ModificationItem[] mods) - throws NamingException { - ResolveResult result = getRootURLContext(name, environment); - DirContext context = (DirContext) result.getResolvedObj(); - - try { - context.modifyAttributes(result.getRemainingName(), mods); - } finally { - context.close(); - } - } - - /** - * {@inheritDoc} - */ - public DirContext getSchema(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 getSchema(name.get(0)); - } else { - DirContext context = getContinuationDirContext(name); - - try { - return context.getSchema(name.getSuffix(1)); - } finally { - context.close(); - } - } - } - - /** - * {@inheritDoc} - */ - public DirContext getSchema(String name) throws NamingException { - ResolveResult result = getRootURLContext(name, environment); - DirContext context = (DirContext) result.getResolvedObj(); - - try { - return context.getSchema(result.getRemainingName()); - } finally { - context.close(); - } - } - - /** - * {@inheritDoc} - */ - public DirContext getSchemaClassDefinition(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 getSchemaClassDefinition(name.get(0)); - } else { - DirContext context = getContinuationDirContext(name); - - try { - return context.getSchemaClassDefinition(name.getSuffix(1)); - } finally { - context.close(); - } - } - } - - /** - * {@inheritDoc} - */ - public DirContext getSchemaClassDefinition(String name) - throws NamingException { - ResolveResult result = getRootURLContext(name, environment); - DirContext context = (DirContext) result.getResolvedObj(); - - try { - return context.getSchemaClassDefinition(result.getRemainingName()); - } finally { - context.close(); - } - } - - /** - * {@inheritDoc} - */ - public NamingEnumeration search(Name name, Attributes matchingAttributes) - throws NamingException { - if (!(name instanceof CompositeName)) { - throw new InvalidNameException( - "URL context can't accept non-composite name: " + name); - } - - if (name.size() == 1) { - return search(name.get(0), matchingAttributes); - } else { - DirContext context = getContinuationDirContext(name); - - try { - return context.search(name.getSuffix(1), matchingAttributes); - } finally { - context.close(); - } - } - } - - /** - * {@inheritDoc} - */ - public NamingEnumeration search(String name, Attributes matchingAttributes) - throws NamingException { - ResolveResult result = getRootURLContext(name, environment); - DirContext context = (DirContext) result.getResolvedObj(); - - try { - return context.search(result.getRemainingName(), - matchingAttributes); - } finally { - context.close(); - } - } - - /** - * {@inheritDoc} - */ - public NamingEnumeration search(Name name, Attributes matchingAttributes, - String[] attributesToReturn) throws NamingException { - if (!(name instanceof CompositeName)) { - throw new InvalidNameException( - "URL context can't accept non-composite name: " + name); - } - - if (name.size() == 1) { - return search(name.get(0), matchingAttributes, attributesToReturn); - } else { - DirContext context = getContinuationDirContext(name); - - try { - return context.search(name.getSuffix(1), - matchingAttributes, attributesToReturn); - } finally { - context.close(); - } - } - } - - /** - * {@inheritDoc} - */ - public NamingEnumeration search(String name, Attributes matchingAttributes, - String[] attributesToReturn) throws NamingException { - ResolveResult result = getRootURLContext(name, environment); - DirContext context = (DirContext) result.getResolvedObj(); - - try { - return context.search(result.getRemainingName(), - matchingAttributes, attributesToReturn); - } finally { - context.close(); - } - } - - /** - * {@inheritDoc} - */ - public NamingEnumeration search(Name name, String filter, - SearchControls cons) throws NamingException { - if (!(name instanceof CompositeName)) { - throw new InvalidNameException( - "URL context can't accept non-composite name: " + name); - } - - if (name.size() == 1) { - return search(name.get(0), filter, cons); - } else { - DirContext context = getContinuationDirContext(name); - - try { - return context.search(name.getSuffix(1), filter, cons); - } finally { - context.close(); - } - } - } - - /** - * {@inheritDoc} - */ - public NamingEnumeration search(String name, String filter, - SearchControls cons) throws NamingException { - ResolveResult result = getRootURLContext(name, environment); - DirContext context = (DirContext) result.getResolvedObj(); - - try { - return context.search(result.getRemainingName(), filter, cons); - } finally { - context.close(); - } - } - - /** - * {@inheritDoc} - */ - public NamingEnumeration search(Name name, String filterExpr, - Object[] filterArgs, SearchControls cons) throws NamingException { - if (!(name instanceof CompositeName)) { - throw new InvalidNameException( - "URL context can't accept non-composite name: " + name); - } - - if (name.size() == 1) { - return search(name.get(0), filterExpr, filterArgs, cons); - } else { - DirContext context = getContinuationDirContext(name); - - try { - return context.search(name.getSuffix(1), - filterExpr, filterArgs, cons); - } finally { - context.close(); - } - } - } - - /** - * {@inheritDoc} - */ - public NamingEnumeration search(String name, String filterExpr, - Object[] filterArgs, SearchControls cons) throws NamingException { - ResolveResult result = getRootURLContext(name, environment); - DirContext context = (DirContext) result.getResolvedObj(); - - try { - return context.search(result.getRemainingName(), - filterExpr, filterArgs, cons); - } finally { - context.close(); - } - } - - /** - * Lookups the first component (considered a URL) - * of the specified name using {@link #lookup(String)}, - * wraps it into {@link CannotProceedException}, passes it to - * {@link DirectoryManager#getContinuationDirContext(CannotProceedException)} - * method and returns the result. - * - * This method is used by {@link #getAttributes(Name)} - * and other public methods taking {@link Name} as a parameter. - * - * This method uses - * {@link GenericURLContext#createCannotProceedException(Name)} method. - * - * @param name - * Name to parse. - * - * @return Continuation context. - * - * @throws NamingException - * If some naming error occurs. - */ - protected DirContext getContinuationDirContext(Name name) - throws NamingException { - return DirectoryManager.getContinuationDirContext( - createCannotProceedException(name)); - } -} +/* + * 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.InvalidNameException; +import javax.naming.Name; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; + +import javax.naming.directory.Attributes; +import javax.naming.directory.DirContext; +import javax.naming.directory.ModificationItem; +import javax.naming.directory.SearchControls; + +import javax.naming.spi.DirectoryManager; +import javax.naming.spi.ResolveResult; + + +/** + * Base class for URL directory context implementations. + * + * In many cases, subclasses should only override + * {@link GenericURLContext#getRootURLContext(String, Hashtable)} method + * and provide a public constructor calling + * {@link GenericURLDirContext#GenericURLDirContext(Hashtable) super(environment)}. + * + * @author Vasily Zakharov + * @version $Revision: 1.1.2.3 $ + */ +public abstract class GenericURLDirContext + extends GenericURLContext implements DirContext { + + /** + * Creates instance of this context with empty environment. + */ + protected GenericURLDirContext() { + super(null); + } + + /** + * Creates instance of this context with specified environment. + * + * @param environment + * Environment to copy. + */ + protected GenericURLDirContext(Hashtable environment) { + super(environment); + } + + /** + * {@inheritDoc} + */ + public void bind(Name name, Object obj, Attributes attrs) + 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, attrs); + } else { + DirContext context = getContinuationDirContext(name); + + try { + context.bind(name.getSuffix(1), obj, attrs); + } finally { + context.close(); + } + } + } + + /** + * {@inheritDoc} + */ + public void bind(String name, Object obj, Attributes attrs) + throws NamingException { + ResolveResult result = getRootURLContext(name, environment); + DirContext context = (DirContext) result.getResolvedObj(); + + try { + context.bind(result.getRemainingName(), obj, attrs); + } finally { + context.close(); + } + } + + /** + * {@inheritDoc} + */ + public void rebind(Name name, Object obj, Attributes attrs) + 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, attrs); + } else { + DirContext context = getContinuationDirContext(name); + + try { + context.rebind(name.getSuffix(1), obj, attrs); + } finally { + context.close(); + } + } + } + + /** + * {@inheritDoc} + */ + public void rebind(String name, Object obj, Attributes attrs) + throws NamingException { + ResolveResult result = getRootURLContext(name, environment); + DirContext context = (DirContext) result.getResolvedObj(); + + try { + context.rebind(result.getRemainingName(), obj, attrs); + } finally { + context.close(); + } + } + + /** + * {@inheritDoc} + */ + public DirContext createSubcontext(Name name, Attributes attrs) + 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), attrs); + } else { + DirContext context = getContinuationDirContext(name); + + try { + return context.createSubcontext(name.getSuffix(1), attrs); + } finally { + context.close(); + } + } + } + + /** + * {@inheritDoc} + */ + public DirContext createSubcontext(String name, Attributes attrs) + throws NamingException { + ResolveResult result = getRootURLContext(name, environment); + DirContext context = (DirContext) result.getResolvedObj(); + + try { + return context.createSubcontext(result.getRemainingName(), attrs); + } finally { + context.close(); + } + } + + /** + * {@inheritDoc} + */ + public Attributes getAttributes(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 getAttributes(name.get(0)); + } else { + DirContext context = getContinuationDirContext(name); + + try { + return context.getAttributes(name.getSuffix(1)); + } finally { + context.close(); + } + } + } + + /** + * {@inheritDoc} + */ + public Attributes getAttributes(String name) throws NamingException { + ResolveResult result = getRootURLContext(name, environment); + DirContext context = (DirContext) result.getResolvedObj(); + + try { + return context.getAttributes(result.getRemainingName()); + } finally { + context.close(); + } + } + + /** + * {@inheritDoc} + */ + public Attributes getAttributes(Name name, String[] attrIds) + throws NamingException { + if (!(name instanceof CompositeName)) { + throw new InvalidNameException( + "URL context can't accept non-composite name: " + name); + } + + if (name.size() == 1) { + return getAttributes(name.get(0), attrIds); + } else { + DirContext context = getContinuationDirContext(name); + + try { + return context.getAttributes(name.getSuffix(1), attrIds); + } finally { + context.close(); + } + } + } + + /** + * {@inheritDoc} + */ + public Attributes getAttributes(String name, String[] attrIds) + throws NamingException { + ResolveResult result = getRootURLContext(name, environment); + DirContext context = (DirContext) result.getResolvedObj(); + + try { + return context.getAttributes(result.getRemainingName(), attrIds); + } finally { + context.close(); + } + } + + /** + * {@inheritDoc} + */ + public void modifyAttributes(Name name, int mod_op, Attributes attrs) + throws NamingException { + if (!(name instanceof CompositeName)) { + throw new InvalidNameException( + "URL context can't accept non-composite name: " + name); + } + + if (name.size() == 1) { + modifyAttributes(name.get(0), mod_op, attrs); + } else { + DirContext context = getContinuationDirContext(name); + + try { + context.modifyAttributes(name.getSuffix(1), mod_op, attrs); + } finally { + context.close(); + } + } + } + + /** + * {@inheritDoc} + */ + public void modifyAttributes(String name, int mod_op, Attributes attrs) + throws NamingException { + ResolveResult result = getRootURLContext(name, environment); + DirContext context = (DirContext) result.getResolvedObj(); + + try { + context.modifyAttributes(result.getRemainingName(), mod_op, attrs); + } finally { + context.close(); + } + } + + /** + * {@inheritDoc} + */ + public void modifyAttributes(Name name, ModificationItem[] mods) + throws NamingException { + if (!(name instanceof CompositeName)) { + throw new InvalidNameException( + "URL context can't accept non-composite name: " + name); + } + + if (name.size() == 1) { + modifyAttributes(name.get(0), mods); + } else { + DirContext context = getContinuationDirContext(name); + + try { + context.modifyAttributes(name.getSuffix(1), mods); + } finally { + context.close(); + } + } + } + + /** + * {@inheritDoc} + */ + public void modifyAttributes(String name, ModificationItem[] mods) + throws NamingException { + ResolveResult result = getRootURLContext(name, environment); + DirContext context = (DirContext) result.getResolvedObj(); + + try { + context.modifyAttributes(result.getRemainingName(), mods); + } finally { + context.close(); + } + } + + /** + * {@inheritDoc} + */ + public DirContext getSchema(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 getSchema(name.get(0)); + } else { + DirContext context = getContinuationDirContext(name); + + try { + return context.getSchema(name.getSuffix(1)); + } finally { + context.close(); + } + } + } + + /** + * {@inheritDoc} + */ + public DirContext getSchema(String name) throws NamingException { + ResolveResult result = getRootURLContext(name, environment); + DirContext context = (DirContext) result.getResolvedObj(); + + try { + return context.getSchema(result.getRemainingName()); + } finally { + context.close(); + } + } + + /** + * {@inheritDoc} + */ + public DirContext getSchemaClassDefinition(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 getSchemaClassDefinition(name.get(0)); + } else { + DirContext context = getContinuationDirContext(name); + + try { + return context.getSchemaClassDefinition(name.getSuffix(1)); + } finally { + context.close(); + } + } + } + + /** + * {@inheritDoc} + */ + public DirContext getSchemaClassDefinition(String name) + throws NamingException { + ResolveResult result = getRootURLContext(name, environment); + DirContext context = (DirContext) result.getResolvedObj(); + + try { + return context.getSchemaClassDefinition(result.getRemainingName()); + } finally { + context.close(); + } + } + + /** + * {@inheritDoc} + */ + public NamingEnumeration search(Name name, Attributes matchingAttributes) + throws NamingException { + if (!(name instanceof CompositeName)) { + throw new InvalidNameException( + "URL context can't accept non-composite name: " + name); + } + + if (name.size() == 1) { + return search(name.get(0), matchingAttributes); + } else { + DirContext context = getContinuationDirContext(name); + + try { + return context.search(name.getSuffix(1), matchingAttributes); + } finally { + context.close(); + } + } + } + + /** + * {@inheritDoc} + */ + public NamingEnumeration search(String name, Attributes matchingAttributes) + throws NamingException { + ResolveResult result = getRootURLContext(name, environment); + DirContext context = (DirContext) result.getResolvedObj(); + + try { + return context.search(result.getRemainingName(), + matchingAttributes); + } finally { + context.close(); + } + } + + /** + * {@inheritDoc} + */ + public NamingEnumeration search(Name name, Attributes matchingAttributes, + String[] attributesToReturn) throws NamingException { + if (!(name instanceof CompositeName)) { + throw new InvalidNameException( + "URL context can't accept non-composite name: " + name); + } + + if (name.size() == 1) { + return search(name.get(0), matchingAttributes, attributesToReturn); + } else { + DirContext context = getContinuationDirContext(name); + + try { + return context.search(name.getSuffix(1), + matchingAttributes, attributesToReturn); + } finally { + context.close(); + } + } + } + + /** + * {@inheritDoc} + */ + public NamingEnumeration search(String name, Attributes matchingAttributes, + String[] attributesToReturn) throws NamingException { + ResolveResult result = getRootURLContext(name, environment); + DirContext context = (DirContext) result.getResolvedObj(); + + try { + return context.search(result.getRemainingName(), + matchingAttributes, attributesToReturn); + } finally { + context.close(); + } + } + + /** + * {@inheritDoc} + */ + public NamingEnumeration search(Name name, String filter, + SearchControls cons) throws NamingException { + if (!(name instanceof CompositeName)) { + throw new InvalidNameException( + "URL context can't accept non-composite name: " + name); + } + + if (name.size() == 1) { + return search(name.get(0), filter, cons); + } else { + DirContext context = getContinuationDirContext(name); + + try { + return context.search(name.getSuffix(1), filter, cons); + } finally { + context.close(); + } + } + } + + /** + * {@inheritDoc} + */ + public NamingEnumeration search(String name, String filter, + SearchControls cons) throws NamingException { + ResolveResult result = getRootURLContext(name, environment); + DirContext context = (DirContext) result.getResolvedObj(); + + try { + return context.search(result.getRemainingName(), filter, cons); + } finally { + context.close(); + } + } + + /** + * {@inheritDoc} + */ + public NamingEnumeration search(Name name, String filterExpr, + Object[] filterArgs, SearchControls cons) throws NamingException { + if (!(name instanceof CompositeName)) { + throw new InvalidNameException( + "URL context can't accept non-composite name: " + name); + } + + if (name.size() == 1) { + return search(name.get(0), filterExpr, filterArgs, cons); + } else { + DirContext context = getContinuationDirContext(name); + + try { + return context.search(name.getSuffix(1), + filterExpr, filterArgs, cons); + } finally { + context.close(); + } + } + } + + /** + * {@inheritDoc} + */ + public NamingEnumeration search(String name, String filterExpr, + Object[] filterArgs, SearchControls cons) throws NamingException { + ResolveResult result = getRootURLContext(name, environment); + DirContext context = (DirContext) result.getResolvedObj(); + + try { + return context.search(result.getRemainingName(), + filterExpr, filterArgs, cons); + } finally { + context.close(); + } + } + + /** + * Lookups the first component (considered a URL) + * of the specified name using {@link #lookup(String)}, + * wraps it into {@link CannotProceedException}, passes it to + * {@link DirectoryManager#getContinuationDirContext(CannotProceedException)} + * method and returns the result. + * + * This method is used by {@link #getAttributes(Name)} + * and other public methods taking {@link Name} as a parameter. + * + * This method uses + * {@link GenericURLContext#createCannotProceedException(Name)} method. + * + * @param name + * Name to parse. + * + * @return Continuation context. + * + * @throws NamingException + * If some naming error occurs. + */ + protected DirContext getContinuationDirContext(Name name) + throws NamingException { + return DirectoryManager.getContinuationDirContext( + createCannotProceedException(name)); + } +} Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLDirContext.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLDirContextFactory.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLDirContextFactory.java?rev=437433&r1=437432&r2=437433&view=diff ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLDirContextFactory.java (original) +++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLDirContextFactory.java Sun Aug 27 11:26:20 2006 @@ -1,134 +1,134 @@ -/* - * 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.2 $ - */ -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.directory.Attributes; -import javax.naming.directory.DirContext; - -import javax.naming.spi.DirObjectFactory; -import javax.naming.spi.ObjectFactory; - - -/** - * Base class for URL directory context factory implementations. - * - * In many cases, subclasses should only override - * {@link #createURLDirContext(Hashtable)} method. - * and provide public no-args constructor. - * - * @author Vasily Zakharov - * @version $Revision: 1.1.2.2 $ - */ -public abstract class GenericURLDirContextFactory - extends GenericURLContextFactory implements DirObjectFactory { - - /** - * Default constructor for subclasses. - */ - protected GenericURLDirContextFactory() {} - - /** - * 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 obj is null, - * just creates and returns an underlying context. - * - * If obj is a proper URL string, - * lookups and returns an object specified by that string. - * - * If obj 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. - * - * name, nameCtx, and attrs - * parameters are ignored. - * - * This implementation just calls - * {@link #getObjectInstance(Object, Name, Context, Hashtable)}. - * - * @param obj - * Object to lookup, can be null. - * - * @param name - * Ignored. - * - * @param nameCtx - * Ignored. - * - * @param environment - * Environment to use in creating the underlying context, - * can be null. - * - * @param attrs - * Ignored. - * - * @return The object created. - * - * @throws ConfigurationException - * If obj is neither null - * 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, Attributes attrs) throws Exception { - return getObjectInstance(obj, name, nameCtx, environment); - } - - /** - * {@inheritDoc} - * - * This implementation just calls {@link #createURLDirContext(Hashtable)}. - */ - protected final Context createURLContext(Hashtable environment) { - return createURLDirContext(environment); - } - - /** - * Returns new instance of the necessary context. Used by - * {@link #getObjectInstance(Object, Name, Context, Hashtable)} and - * {@link #getObjectInstance(Object, Name, Context, Hashtable, Attributes)}. - * - * Must be overridden by particular URL context factory implementations. - * - * @param environment - * Environment. - * - * @return New context instance. - */ - protected abstract DirContext createURLDirContext(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.2 $ + */ +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.directory.Attributes; +import javax.naming.directory.DirContext; + +import javax.naming.spi.DirObjectFactory; +import javax.naming.spi.ObjectFactory; + + +/** + * Base class for URL directory context factory implementations. + * + * In many cases, subclasses should only override + * {@link #createURLDirContext(Hashtable)} method. + * and provide public no-args constructor. + * + * @author Vasily Zakharov + * @version $Revision: 1.1.2.2 $ + */ +public abstract class GenericURLDirContextFactory + extends GenericURLContextFactory implements DirObjectFactory { + + /** + * Default constructor for subclasses. + */ + protected GenericURLDirContextFactory() {} + + /** + * 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 obj is null, + * just creates and returns an underlying context. + * + * If obj is a proper URL string, + * lookups and returns an object specified by that string. + * + * If obj 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. + * + * name, nameCtx, and attrs + * parameters are ignored. + * + * This implementation just calls + * {@link #getObjectInstance(Object, Name, Context, Hashtable)}. + * + * @param obj + * Object to lookup, can be null. + * + * @param name + * Ignored. + * + * @param nameCtx + * Ignored. + * + * @param environment + * Environment to use in creating the underlying context, + * can be null. + * + * @param attrs + * Ignored. + * + * @return The object created. + * + * @throws ConfigurationException + * If obj is neither null + * 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, Attributes attrs) throws Exception { + return getObjectInstance(obj, name, nameCtx, environment); + } + + /** + * {@inheritDoc} + * + * This implementation just calls {@link #createURLDirContext(Hashtable)}. + */ + protected final Context createURLContext(Hashtable environment) { + return createURLDirContext(environment); + } + + /** + * Returns new instance of the necessary context. Used by + * {@link #getObjectInstance(Object, Name, Context, Hashtable)} and + * {@link #getObjectInstance(Object, Name, Context, Hashtable, Attributes)}. + * + * Must be overridden by particular URL context factory implementations. + * + * @param environment + * Environment. + * + * @return New context instance. + */ + protected abstract DirContext createURLDirContext(Hashtable environment); +} Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/GenericURLDirContextFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/package.html URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/package.html?rev=437433&r1=437432&r2=437433&view=diff ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/package.html (original) +++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/package.html Sun Aug 27 11:26:20 2006 @@ -1,27 +1,27 @@ - - - - -Root package for JNDI service providers. - -This package also contains some abstract classes used as basic implementation for URL contexts. - - + + + + +Root package for JNDI service providers. + +This package also contains some abstract classes used as basic implementation for URL contexts. + + Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/package.html ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/package.html URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/package.html?rev=437433&r1=437432&r2=437433&view=diff ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/package.html (original) +++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/package.html Sun Aug 27 11:26:20 2006 @@ -1,25 +1,25 @@ - - - - -URL context classes for RMI Registry Service Provider for JNDI. - - + + + + +URL context classes for RMI Registry Service Provider for JNDI. + + Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/package.html ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/AtomicNameParser.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/AtomicNameParser.java?rev=437433&r1=437432&r2=437433&view=diff ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/AtomicNameParser.java (original) +++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/AtomicNameParser.java Sun Aug 27 11:26:20 2006 @@ -1,72 +1,72 @@ -/* - * 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.rmi.registry; - -import java.util.Properties; - -import javax.naming.CompoundName; -import javax.naming.Name; -import javax.naming.NameParser; -import javax.naming.NamingException; - - -/** - * Parser for flat case-sensitive atomic names used by {@link RegistryContext}. - * - * @author Vasily Zakharov - * @version $Revision: 1.1.2.3 $ - */ -public class AtomicNameParser implements NameParser { - - /** - * Syntax, defines a flat case-sensitive context, - * initialized in static initialization block. - */ - private static final Properties syntax = new Properties(); - - /** - * Static initializer for {@link #syntax}. - */ - static { - syntax.put("jndi.syntax.direction", "flat"); - } - - /** - * Creates instance of this class. - */ - public AtomicNameParser() {} - - /** - * Returns flat {@link CompoundName} constructed from the specified string. - * - * @param name - * Name to parse, cannot be null. - * - * @return Flat {@link CompoundName} constructed from the specified string. - * - * @throws NamingException - * If some error occured. - */ - public Name parse(String name) throws NamingException { - return new CompoundName(name, syntax); - } -} +/* + * 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.rmi.registry; + +import java.util.Properties; + +import javax.naming.CompoundName; +import javax.naming.Name; +import javax.naming.NameParser; +import javax.naming.NamingException; + + +/** + * Parser for flat case-sensitive atomic names used by {@link RegistryContext}. + * + * @author Vasily Zakharov + * @version $Revision: 1.1.2.3 $ + */ +public class AtomicNameParser implements NameParser { + + /** + * Syntax, defines a flat case-sensitive context, + * initialized in static initialization block. + */ + private static final Properties syntax = new Properties(); + + /** + * Static initializer for {@link #syntax}. + */ + static { + syntax.put("jndi.syntax.direction", "flat"); + } + + /** + * Creates instance of this class. + */ + public AtomicNameParser() {} + + /** + * Returns flat {@link CompoundName} constructed from the specified string. + * + * @param name + * Name to parse, cannot be null. + * + * @return Flat {@link CompoundName} constructed from the specified string. + * + * @throws NamingException + * If some error occured. + */ + public Name parse(String name) throws NamingException { + return new CompoundName(name, syntax); + } +} Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/AtomicNameParser.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/BindingEnumeration.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/BindingEnumeration.java?rev=437433&r1=437432&r2=437433&view=diff ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/BindingEnumeration.java (original) +++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/BindingEnumeration.java Sun Aug 27 11:26:20 2006 @@ -1,101 +1,101 @@ -/* - * 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.2 $ - */ -package org.apache.harmony.jndi.provider.rmi.registry; - -import java.rmi.registry.Registry; - -import java.util.NoSuchElementException; - -import javax.naming.Binding; -import javax.naming.Name; -import javax.naming.NamingException; - - -/** - * Enumeration of {@link Binding} objects, - * used by {@link RegistryContext#listBindings(Name)} method. - * - * @author Vasily Zakharov - * @version $Revision: 1.1.2.2 $ - */ -class BindingEnumeration extends NameClassPairEnumeration { - - /** - * Registry context. - */ - protected RegistryContext context; - - /** - * Creates this enumeration. - * - * @param names - * Binding names returned from {@link Registry#list()} method. - * - * @param context - * RegistryContext to extract bindings from. - */ - public BindingEnumeration(String[] names, RegistryContext context) { - super(names); - this.context = context.cloneContext(); - } - - /** - * {@inheritDoc} - */ - public boolean hasMore() { - if (super.hasMore()) { - return true; - } else { - close(); - return false; - } - } - - /** - * {@inheritDoc} - */ - public Object next() throws NoSuchElementException, NamingException { - if (!hasMore()) { - throw new NoSuchElementException(); - } - - String name = names[index++]; - Binding binding = new Binding(name, context.lookup(name)); - binding.setNameInNamespace(name); - return binding; - } - - /** - * {@inheritDoc} - */ - public void close() { - super.close(); - finalize(); - } - - /** - * {@inheritDoc} - */ - protected void finalize() { - context.close(); - } -} +/* + * 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.2 $ + */ +package org.apache.harmony.jndi.provider.rmi.registry; + +import java.rmi.registry.Registry; + +import java.util.NoSuchElementException; + +import javax.naming.Binding; +import javax.naming.Name; +import javax.naming.NamingException; + + +/** + * Enumeration of {@link Binding} objects, + * used by {@link RegistryContext#listBindings(Name)} method. + * + * @author Vasily Zakharov + * @version $Revision: 1.1.2.2 $ + */ +class BindingEnumeration extends NameClassPairEnumeration { + + /** + * Registry context. + */ + protected RegistryContext context; + + /** + * Creates this enumeration. + * + * @param names + * Binding names returned from {@link Registry#list()} method. + * + * @param context + * RegistryContext to extract bindings from. + */ + public BindingEnumeration(String[] names, RegistryContext context) { + super(names); + this.context = context.cloneContext(); + } + + /** + * {@inheritDoc} + */ + public boolean hasMore() { + if (super.hasMore()) { + return true; + } else { + close(); + return false; + } + } + + /** + * {@inheritDoc} + */ + public Object next() throws NoSuchElementException, NamingException { + if (!hasMore()) { + throw new NoSuchElementException(); + } + + String name = names[index++]; + Binding binding = new Binding(name, context.lookup(name)); + binding.setNameInNamespace(name); + return binding; + } + + /** + * {@inheritDoc} + */ + public void close() { + super.close(); + finalize(); + } + + /** + * {@inheritDoc} + */ + protected void finalize() { + context.close(); + } +} Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/BindingEnumeration.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/NameClassPairEnumeration.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/NameClassPairEnumeration.java?rev=437433&r1=437432&r2=437433&view=diff ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/NameClassPairEnumeration.java (original) +++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/NameClassPairEnumeration.java Sun Aug 27 11:26:20 2006 @@ -1,109 +1,109 @@ -/* - * 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.2 $ - */ -package org.apache.harmony.jndi.provider.rmi.registry; - -import java.rmi.registry.Registry; - -import java.util.NoSuchElementException; - -import javax.naming.Name; -import javax.naming.NameClassPair; -import javax.naming.NamingEnumeration; -import javax.naming.NamingException; - - -/** - * Enumeration of {@link NameClassPair} objects, - * used by {@link RegistryContext#list(Name)} method. - * - * @author Vasily Zakharov - * @version $Revision: 1.1.2.2 $ - */ -class NameClassPairEnumeration implements NamingEnumeration { - - /** - * Binding names returned from {@link Registry#list()} method. - */ - protected final String[] names; - - /** - * Index of the next name to return. - */ - protected int index = 0; - - /** - * Creates this enumeration. - * - * @param names - * Binding names returned from {@link Registry#list()} method. - */ - public NameClassPairEnumeration(String[] names) { - this.names = names; - } - - /** - * {@inheritDoc} - */ - public boolean hasMore() { - return (index < names.length); - } - - /** - * {@inheritDoc} - */ - public Object next() throws NamingException, NoSuchElementException { - if (!hasMore()) { - throw new NoSuchElementException(); - } - - String name = names[index++]; - NameClassPair pair = new NameClassPair(name, Object.class.getName()); - pair.setNameInNamespace(name); - return pair; - } - - /** - * {@inheritDoc} - */ - public boolean hasMoreElements() { - return hasMore(); - } - - /** - * {@inheritDoc} - */ - public Object nextElement() { - try { - return next(); - } catch (NamingException e) { - throw (NoSuchElementException) - new NoSuchElementException().initCause(e); - } - } - - /** - * {@inheritDoc} - */ - public void close() { - index = names.length; - } -} +/* + * 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.2 $ + */ +package org.apache.harmony.jndi.provider.rmi.registry; + +import java.rmi.registry.Registry; + +import java.util.NoSuchElementException; + +import javax.naming.Name; +import javax.naming.NameClassPair; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; + + +/** + * Enumeration of {@link NameClassPair} objects, + * used by {@link RegistryContext#list(Name)} method. + * + * @author Vasily Zakharov + * @version $Revision: 1.1.2.2 $ + */ +class NameClassPairEnumeration implements NamingEnumeration { + + /** + * Binding names returned from {@link Registry#list()} method. + */ + protected final String[] names; + + /** + * Index of the next name to return. + */ + protected int index = 0; + + /** + * Creates this enumeration. + * + * @param names + * Binding names returned from {@link Registry#list()} method. + */ + public NameClassPairEnumeration(String[] names) { + this.names = names; + } + + /** + * {@inheritDoc} + */ + public boolean hasMore() { + return (index < names.length); + } + + /** + * {@inheritDoc} + */ + public Object next() throws NamingException, NoSuchElementException { + if (!hasMore()) { + throw new NoSuchElementException(); + } + + String name = names[index++]; + NameClassPair pair = new NameClassPair(name, Object.class.getName()); + pair.setNameInNamespace(name); + return pair; + } + + /** + * {@inheritDoc} + */ + public boolean hasMoreElements() { + return hasMore(); + } + + /** + * {@inheritDoc} + */ + public Object nextElement() { + try { + return next(); + } catch (NamingException e) { + throw (NoSuchElementException) + new NoSuchElementException().initCause(e); + } + } + + /** + * {@inheritDoc} + */ + public void close() { + index = names.length; + } +} Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/rmi/registry/NameClassPairEnumeration.java ------------------------------------------------------------------------------ svn:eol-style = native