You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tr...@apache.org on 2006/01/20 14:48:55 UTC

svn commit: r370807 [2/22] - in /directory/sandbox/trustin/mina-spi: ./ core/src/main/java/org/apache/mina/common/ core/src/main/java/org/apache/mina/common/support/ core/src/main/java/org/apache/mina/common/support/discovery/ core/src/main/java/org/ap...

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/JDK12Hooks.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/JDK12Hooks.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/JDK12Hooks.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/JDK12Hooks.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,221 @@
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.mina.common.support.discovery.jdk;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+
+
+/**
+ * @author Richard A. Sitze
+ */
+class JDK12Hooks extends JDKHooks {
+    private static final ClassLoader systemClassLoader
+        = findSystemClassLoader();
+
+    /**
+     * The thread context class loader is available for JDK 1.2
+     * or later, if certain security conditions are met.
+     * 
+     * @return The thread context class loader, if available.
+     *         Otherwise return null.
+     */
+    public ClassLoader getThreadContextClassLoader() {
+        ClassLoader classLoader;
+        
+        try {
+            classLoader = Thread.currentThread().getContextClassLoader();
+        } catch (SecurityException e) {
+            /**
+             * SecurityException is thrown when
+             * a) the context class loader isn't an ancestor of the
+             *    calling class's class loader, or
+             * b) if security permissions are restricted.
+             * 
+             * For (a), ignore and keep going.  We cannot help but also
+             * ignore (b) with the logic below, but other calls elsewhere
+             * (to obtain a class loader) will re-trigger this exception
+             * where we can make a distinction.
+             */
+            classLoader = null;  // ignore
+        }
+        
+        // Return the selected class loader
+        return classLoader;
+    }
+    
+    /**
+     * The system class loader is available for JDK 1.2
+     * or later, if certain security conditions are met.
+     * 
+     * @return The system class loader, if available.
+     *         Otherwise return null.
+     */
+    public ClassLoader getSystemClassLoader() {
+        return systemClassLoader;
+    }
+
+    /**
+     * Implement ClassLoader.getResources for JDK 1.2
+     */
+    public Enumeration getResources(ClassLoader loader,
+                                    String resourceName)
+        throws IOException
+    {
+        /**
+         * The simple answer is/was:
+         *    return loader.getResources(resourceName);
+         * 
+         * However, some classloaders overload the behavior of getResource
+         * (loadClass, etc) such that the order of returned results changes
+         * from normally expected behavior.
+         * 
+         * Example: locate classes/resources from child ClassLoaders first,
+         *          parents last (in some J2EE environs).
+         * 
+         * The resource returned by getResource() should be the same as the
+         * first resource returned by getResources().  Unfortunately, this
+         * is not, and cannot be: getResources() is 'final' in the current
+         * JDK's (1.2, 1.3, 1.4).
+         * 
+         * To address this, the implementation of this method will
+         * return an Enumeration such that the first element is the
+         * results of getResource, and all trailing elements are
+         * from getResources.  On each iteration, we check so see
+         * if the resource (from getResources) matches the first resource,
+         * and eliminate the redundent element.
+         */
+        
+        final URL first = (URL)loader.getResource(resourceName);
+        final Enumeration rest = loader.getResources(resourceName);
+        
+        return new Enumeration() {
+            private boolean firstDone = (first == null);
+            private URL next = getNext();
+            
+            public Object nextElement() {
+                URL o = next;
+                next = getNext();
+                return o;
+            }
+
+            public boolean hasMoreElements() {
+                return next != null;
+            }
+            
+            private URL getNext() {
+                URL n;
+                
+                if (!firstDone) {
+                    /**
+                     * First time through, use results of getReference()
+                     * if they were non-null.
+                     */
+                    firstDone = true;
+                    n = first;
+                } else {
+                    /**
+                     * Subsequent times through,
+                     * use results of getReferences()
+                     * but take out anything that matches 'first'.
+                     * 
+                     * Iterate through list until we find one that
+                     * doesn't match 'first'.
+                     */
+                    n = null;
+                    while (rest.hasMoreElements()  &&  n == null) {
+                        n = (URL)rest.nextElement();
+                        if (first != null &&
+                            n != null &&
+                            n.equals(first))
+                        {
+                            n = null;
+                        }
+                    }
+                }
+                
+                return n;
+            }
+        };
+    }
+    
+    static private ClassLoader findSystemClassLoader() {
+        ClassLoader classLoader;
+        
+        try {
+            classLoader = ClassLoader.getSystemClassLoader();
+        } catch (SecurityException e) {
+            /**
+             * Ignore and keep going.
+             */
+            classLoader = null;
+        }
+
+        if (classLoader == null) {
+            classLoader = new PsuedoSystemClassLoader();
+        }
+        
+        // Return the selected class loader
+        return classLoader;
+    }
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/JDK12Hooks.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/JDKHooks.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/JDKHooks.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/JDKHooks.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/JDKHooks.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,110 @@
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.mina.common.support.discovery.jdk;
+
+import java.util.Enumeration;
+import java.io.IOException;
+
+
+/**
+ * @author Richard A. Sitze
+ */
+public abstract class JDKHooks {
+    private static final JDKHooks jdkHooks;
+    
+    static {
+        jdkHooks = new JDK12Hooks();
+    }
+    
+    protected JDKHooks() { }
+    
+    /**
+     * Return singleton object representing JVM hooks/tools.
+     * 
+     * TODO: add logic to detect JDK level.
+     */
+    public static final JDKHooks getJDKHooks() {
+        return jdkHooks;
+    }
+
+    /**
+     * The thread context class loader is available for JDK 1.2
+     * or later, if certain security conditions are met.
+     * 
+     * @return The thread context class loader, if available.
+     *         Otherwise return null.
+     */
+    public abstract ClassLoader getThreadContextClassLoader();
+
+    /**
+     * The system class loader is available for JDK 1.2
+     * or later, if certain security conditions are met.
+     * 
+     * @return The system class loader, if available.
+     *         Otherwise return null.
+     */
+    public abstract ClassLoader getSystemClassLoader();
+    
+    public abstract Enumeration getResources(ClassLoader loader,
+                                             String resourceName)
+        throws IOException;
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/JDKHooks.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/PsuedoSystemClassLoader.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/PsuedoSystemClassLoader.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/PsuedoSystemClassLoader.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/PsuedoSystemClassLoader.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,87 @@
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.mina.common.support.discovery.jdk;
+
+import java.io.InputStream;
+import java.net.URL;
+
+
+/**
+ * JDK 1.1.x compatible?
+ * There is no direct way to get the system class loader
+ * in 1.1.x, but this should be a good work around...
+ */
+class PsuedoSystemClassLoader extends ClassLoader {
+    protected Class loadClass(String className, boolean resolve)
+        throws ClassNotFoundException
+    {
+        return findSystemClass(className);
+    }
+    
+    public URL getResource(String resName) {
+        return getSystemResource(resName);
+    }
+    
+    public InputStream getResourceAsStream(String resName) {
+        return getSystemResourceAsStream(resName);
+    }
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/jdk/PsuedoSystemClassLoader.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/package.html
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/package.html?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/package.html (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/package.html Fri Jan 20 05:47:50 2006
@@ -0,0 +1,9 @@
+<p>
+Highlights:
+<ul>
+<li>JDK 1.3 Service discovery</li>
+<li>Discovery supports JDK 1.1.8 and up
+(@see org.apache.commons.discover.jdk.JDKHooks).
+</li>
+</ul>
+</p>
\ No newline at end of file

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/package.html
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/ClassLoaders.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/ClassLoaders.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/ClassLoaders.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/ClassLoaders.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,211 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.mina.common.support.discovery.resource;
+
+import java.util.Vector;
+
+import org.apache.mina.common.support.discovery.jdk.JDKHooks;
+
+
+/**
+ * There are many different contexts in which
+ * loaders can be used.  This provides a holder
+ * for a set of class loaders, so that they
+ * don't have to be build back up everytime...
+ *
+ * @author Richard A. Sitze
+ * @author Craig R. McClanahan
+ * @author Costin Manolache
+ */
+public class ClassLoaders
+{
+    protected Vector classLoaders = new Vector();
+    
+    /** Construct a new class loader set
+     */
+    public ClassLoaders() {
+    }
+    
+    public int size() {
+        return classLoaders.size();
+    }
+    
+    public ClassLoader get(int idx) {
+        return (ClassLoader)classLoaders.elementAt(idx);
+    }
+
+    /**
+     * Specify a new class loader to be used in searching.
+     * The order of loaders determines the order of the result.
+     * It is recommended to add the most specific loaders first.
+     */
+    public void put(ClassLoader classLoader) {
+        if (classLoader != null) {
+            classLoaders.addElement(classLoader);
+        }
+    }
+    
+
+    /**
+     * Specify a new class loader to be used in searching.
+     * The order of loaders determines the order of the result.
+     * It is recommended to add the most specific loaders first.
+     * 
+     * @param prune if true, verify that the class loader is
+     *              not an Ancestor (@see isAncestor) before
+     *              adding it to our list.
+     */
+    public void put(ClassLoader classLoader, boolean prune) {
+        if (classLoader != null  &&  !(prune && isAncestor(classLoader))) {
+            classLoaders.addElement(classLoader);
+        }
+    }
+    
+    
+    /**
+     * Check to see if <code>classLoader</code> is an
+     * ancestor of any contained class loader.
+     * 
+     * This can be used to eliminate redundant class loaders
+     * IF all class loaders defer to parent class loaders
+     * before resolving a class.
+     * 
+     * It may be that this is not always true.  Therefore,
+     * this check is not done internally to eliminate
+     * redundant class loaders, but left to the discretion
+     * of the user.
+     */
+    public boolean isAncestor(final ClassLoader classLoader) {
+        /* bootstrap classloader, at root of all trees! */
+        if (classLoader == null)
+            return true;
+
+        for (int idx = 0; idx < size(); idx++) {
+            for(ClassLoader walker = get(idx);
+                walker != null;
+                walker = walker.getParent())
+            {
+                if (walker == classLoader) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+
+    /**
+     * Utility method.  Returns a preloaded ClassLoaders instance
+     * containing the following class loaders, in order:
+     * 
+     * <ul>
+     *   <li>spi.getClassLoader</li>
+     *   <li>seeker.getClassLoader</li>
+     *   <li>System Class Loader</li>
+     * </ul>
+     * 
+     * Note that the thread context class loader is NOT present.
+     * This is a reasonable set of loaders to try if the resource to be found
+     * should be restricted to a libraries containing the SPI and Factory.
+     * 
+     * @param spi WHAT is being looked for (an implementation of this class,
+     *            a default property file related to this class).
+     * @param factory WHO is performing the lookup.
+     * @param prune Determines if ancestors are allowed to be loaded or not.
+     */    
+    public static ClassLoaders getLibLoaders(Class spi, Class factory, boolean prune) {
+        ClassLoaders loaders = new ClassLoaders();
+        
+        if (spi != null) loaders.put(spi.getClassLoader());
+        if (factory != null) loaders.put(factory.getClassLoader(), prune);
+        loaders.put(JDKHooks.getJDKHooks().getSystemClassLoader(), prune);
+        
+        return loaders;
+    }
+    
+    /**
+     * Utility method.  Returns a preloaded ClassLoaders instance
+     * containing the following class loaders, in order:
+     * 
+     * <ul>
+     *   <li>Thread Context Class Loader</li>
+     *   <li>spi.getClassLoader</li>
+     *   <li>seeker.getClassLoader</li>
+     *   <li>System Class Loader</li>
+     * </ul>
+     * 
+     * Note that the thread context class loader IS  present.
+     * This is a reasonable set of loaders to try if the resource to be found
+     * may be provided by an application.
+     * 
+     * @param spi WHAT is being looked for (an implementation of this class,
+     *            a default property file related to this class).
+     * @param factory WHO is performing the lookup (factory).
+     * @param prune Determines if ancestors are allowed to be loaded or not.
+     */    
+    public static ClassLoaders getAppLoaders(Class spi, Class factory, boolean prune) {
+        ClassLoaders loaders = new ClassLoaders();
+
+        loaders.put(JDKHooks.getJDKHooks().getThreadContextClassLoader());
+        if (spi != null) loaders.put(spi.getClassLoader(), prune);
+        if (factory != null) loaders.put(factory.getClassLoader(), prune);
+        loaders.put(JDKHooks.getJDKHooks().getSystemClassLoader(), prune);
+        
+        return loaders;
+    }
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/ClassLoaders.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/DiscoverResources.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/DiscoverResources.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/DiscoverResources.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/DiscoverResources.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,149 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.mina.common.support.discovery.resource;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+
+import org.apache.mina.common.support.discovery.Resource;
+import org.apache.mina.common.support.discovery.ResourceDiscover;
+import org.apache.mina.common.support.discovery.ResourceIterator;
+import org.apache.mina.common.support.discovery.jdk.JDKHooks;
+
+
+/**
+ * @author Richard A. Sitze
+ * @author Craig R. McClanahan
+ * @author Costin Manolache
+ * @author James Strachan
+ */
+public class DiscoverResources
+    extends ResourceDiscoverImpl
+    implements ResourceDiscover
+{
+    /**
+     * Construct a new resource discoverer
+     */
+    public DiscoverResources() {
+        super();
+    }
+    
+    /**
+     *  Construct a new resource discoverer
+     */
+    public DiscoverResources(ClassLoaders classLoaders) {
+        super(classLoaders);
+    }
+
+    /**
+     * @return ResourceIterator
+     */
+    public ResourceIterator findResources(final String resourceName) {
+        return new ResourceIterator() {
+            private int idx = 0;
+            private ClassLoader loader = null;
+            private Enumeration resources = null;
+            private Resource resource = null;
+            
+            public boolean hasNext() {
+                if (resource == null) {
+                    resource = getNextResource();
+                }
+                return resource != null;
+            }
+            
+            public Resource nextResource() {
+                Resource element = resource;
+                resource = null;
+                return element;
+            }
+            
+            private Resource getNextResource() {
+                if (resources == null || !resources.hasMoreElements()) {
+                    resources = getNextResources();
+                }
+
+                Resource resourceInfo;
+                if (resources != null) {
+                    URL url = (URL)resources.nextElement();
+
+                    resourceInfo = new Resource(resourceName, url, loader);
+                } else {
+                    resourceInfo = null;
+                }
+                
+                return resourceInfo;
+            }
+            
+            private Enumeration getNextResources() {
+                while (idx < getClassLoaders().size()) {
+                    loader = getClassLoaders().get(idx++);
+                    try {
+                        Enumeration e = JDKHooks.getJDKHooks().getResources(loader, resourceName);
+                        if (e != null && e.hasMoreElements()) {
+                            return e;
+                        }
+                    } catch( IOException ex ) {
+                    }
+                }
+                return null;
+            }
+        };
+    }
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/DiscoverResources.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/ResourceDiscoverImpl.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/ResourceDiscoverImpl.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/ResourceDiscoverImpl.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/ResourceDiscoverImpl.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,173 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.mina.common.support.discovery.resource;
+
+import org.apache.mina.common.support.discovery.Resource;
+import org.apache.mina.common.support.discovery.ResourceDiscover;
+import org.apache.mina.common.support.discovery.ResourceIterator;
+import org.apache.mina.common.support.discovery.ResourceNameIterator;
+import org.apache.mina.common.support.discovery.resource.names.ResourceNameDiscoverImpl;
+
+
+/**
+ * Helper class for methods implementing the ResourceDiscover interface.
+ * 
+ * @author Richard A. Sitze
+ */
+public abstract class ResourceDiscoverImpl
+    extends ResourceNameDiscoverImpl
+    implements ResourceDiscover
+{
+    private ClassLoaders classLoaders;
+
+    
+    /**
+     * Construct a new resource discoverer
+     */
+    public ResourceDiscoverImpl() {
+        setClassLoaders(new ClassLoaders());
+    }
+    
+    /**
+     *  Construct a new resource discoverer
+     */
+    public ResourceDiscoverImpl(ClassLoaders classLoaders) {
+        setClassLoaders(classLoaders);
+    }
+
+    /**
+     * Specify set of class loaders to be used in searching.
+     */
+    public void setClassLoaders(ClassLoaders loaders) {
+        classLoaders = loaders;
+    }
+
+    /**
+     * Specify a new class loader to be used in searching.
+     * The order of loaders determines the order of the result.
+     * It is recommended to add the most specific loaders first.
+     */
+    public void addClassLoader(ClassLoader loader) {
+        classLoaders.put(loader);
+    }
+
+    protected ClassLoaders getClassLoaders() {
+        return classLoaders;
+    }
+
+    /**
+     * Locate names of resources that are bound to <code>resourceName</code>.
+     * 
+     * @return ResourceNameIterator
+     */
+    public ResourceNameIterator findResourceNames(String resourceName) {
+        return findResources(resourceName);
+    }
+
+    /**
+     * Locate names of resources that are bound to <code>resourceNames</code>.
+     * 
+     * @return ResourceNameIterator
+     */
+    public ResourceNameIterator findResourceNames(ResourceNameIterator resourceNames) {
+        return findResources(resourceNames);
+    }
+
+    /**
+     * Locate resources that are bound to <code>resourceName</code>.
+     * 
+     * @return ResourceIterator
+     */
+    public abstract ResourceIterator findResources(String resourceName);
+
+    /**
+     * Locate resources that are bound to <code>resourceNames</code>.
+     * 
+     * @return ResourceIterator
+     */
+    public ResourceIterator findResources(final ResourceNameIterator inputNames) {
+        return new ResourceIterator() {
+            private ResourceIterator resources = null;
+            private Resource resource = null;
+            
+            public boolean hasNext() {
+                if (resource == null) {
+                    resource = getNextResource();
+                }
+                return resource != null;
+            }
+            
+            public Resource nextResource() {
+                Resource rsrc = resource;
+                resource = null;
+                return rsrc;
+            }
+            
+            private Resource getNextResource() {
+                while (inputNames.hasNext() &&
+                       (resources == null  ||  !resources.hasNext())) {
+                    resources = findResources(inputNames.nextResourceName());
+                }
+    
+                return (resources != null  &&  resources.hasNext())
+                       ? resources.nextResource()
+                       : null;
+            }
+        };
+    }
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/ResourceDiscoverImpl.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/classes/DiscoverClasses.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/classes/DiscoverClasses.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/classes/DiscoverClasses.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/classes/DiscoverClasses.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,130 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.mina.common.support.discovery.resource.classes;
+
+import java.net.URL;
+import java.util.Vector;
+
+import org.apache.mina.common.support.discovery.ResourceClass;
+import org.apache.mina.common.support.discovery.ResourceClassDiscover;
+import org.apache.mina.common.support.discovery.ResourceClassIterator;
+import org.apache.mina.common.support.discovery.resource.ClassLoaders;
+
+
+/**
+ * The findResources() method will check every loader.
+ *
+ * @author Richard A. Sitze
+ * @author Craig R. McClanahan
+ * @author Costin Manolache
+ * @author James Strachan
+ */
+public class DiscoverClasses
+    extends ResourceClassDiscoverImpl
+    implements ResourceClassDiscover
+{
+    /** Construct a new resource discoverer
+     */
+    public DiscoverClasses() {
+        super();
+    }
+    
+    /** Construct a new resource discoverer
+     */
+    public DiscoverClasses(ClassLoaders classLoaders) {
+        super(classLoaders);
+    }
+    
+    public ResourceClassIterator findResourceClasses(final String className) {
+        final String resourceName = className.replace('.','/') + ".class";
+        
+        return new ResourceClassIterator() {
+            private Vector history = new Vector();
+            private int idx = 0;
+            private ResourceClass resource = null;
+            
+            public boolean hasNext() {
+                if (resource == null) {
+                    resource = getNextClass();
+                }
+                return resource != null;
+            }
+            
+            public ResourceClass nextResourceClass() {
+                ResourceClass element = resource;
+                resource = null;
+                return element;
+            }
+            
+            private ResourceClass getNextClass() {
+                while (idx < getClassLoaders().size()) {
+                    ClassLoader loader = getClassLoaders().get(idx++);
+                    URL url = loader.getResource(resourceName);
+                    if (url != null) {
+                        if (!history.contains(url)) {
+                            history.addElement(url);
+    
+                            return new ResourceClass(className, url, loader);
+                        }
+                    }
+                }
+                return null;
+            }
+        };
+    }
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/classes/DiscoverClasses.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/classes/ResourceClassDiscoverImpl.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/classes/ResourceClassDiscoverImpl.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/classes/ResourceClassDiscoverImpl.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/classes/ResourceClassDiscoverImpl.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,171 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.mina.common.support.discovery.resource.classes;
+
+import org.apache.mina.common.support.discovery.ResourceClass;
+import org.apache.mina.common.support.discovery.ResourceClassDiscover;
+import org.apache.mina.common.support.discovery.ResourceClassIterator;
+import org.apache.mina.common.support.discovery.ResourceIterator;
+import org.apache.mina.common.support.discovery.ResourceNameIterator;
+import org.apache.mina.common.support.discovery.resource.ClassLoaders;
+import org.apache.mina.common.support.discovery.resource.ResourceDiscoverImpl;
+
+
+/**
+ * @author Richard A. Sitze
+ */
+public abstract class ResourceClassDiscoverImpl
+    extends ResourceDiscoverImpl
+    implements ResourceClassDiscover
+{
+    /**
+     * Construct a new resource discoverer
+     */
+    public ResourceClassDiscoverImpl() {
+        super();
+    }
+    
+    /**
+     *  Construct a new resource discoverer
+     */
+    public ResourceClassDiscoverImpl(ClassLoaders classLoaders) {
+        super(classLoaders);
+    }
+
+
+    /**
+     * Locate names of resources that are bound to <code>resourceName</code>.
+     * 
+     * @return ResourceNameIterator
+     */
+    public ResourceNameIterator findResourceNames(String resourceName) {
+        return findResourceClasses(resourceName);
+    }
+
+    /**
+     * Locate names of resources that are bound to <code>resourceNames</code>.
+     * 
+     * @return ResourceNameIterator
+     */
+    public ResourceNameIterator findResourceNames(ResourceNameIterator resourceNames) {
+        return findResourceClasses(resourceNames);
+    }
+
+    /**
+     * Locate resources that are bound to <code>resourceName</code>.
+     * 
+     * @return ResourceIterator
+     */
+    public ResourceIterator findResources(String resourceName) {
+        return findResourceClasses(resourceName);
+    }
+
+    /**
+     * Locate resources that are bound to <code>resourceNames</code>.
+     * 
+     * @return ResourceIterator
+     */
+    public ResourceIterator findResources(ResourceNameIterator resourceNames) {
+        return findResourceClasses(resourceNames);
+    }
+
+
+    /**
+     * Locate class resources that are bound to <code>className</code>.
+     * 
+     * @return ResourceClassIterator
+     */
+    public abstract ResourceClassIterator findResourceClasses(String className);
+
+    /**
+     * Locate class resources that are bound to <code>resourceNames</code>.
+     * 
+     * @return ResourceIterator
+     */
+    public ResourceClassIterator findResourceClasses(final ResourceNameIterator inputNames) {
+        return new ResourceClassIterator() {
+            private ResourceClassIterator classes = null;
+            private ResourceClass resource = null;
+            
+            public boolean hasNext() {
+                if (resource == null) {
+                    resource = getNextResource();
+                }
+                return resource != null;
+            }
+            
+            public ResourceClass nextResourceClass() {
+                ResourceClass rsrc = resource;
+                resource = null;
+                return rsrc;
+            }
+            
+            private ResourceClass getNextResource() {
+                while (inputNames.hasNext() &&
+                       (classes == null  ||  !classes.hasNext())) {
+                    classes =
+                        findResourceClasses(inputNames.nextResourceName());
+                }
+    
+                return (classes != null  &&  classes.hasNext())
+                       ? classes.nextResourceClass()
+                       : null;
+            }
+        };
+    }
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/classes/ResourceClassDiscoverImpl.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverMappedNames.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverMappedNames.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverMappedNames.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverMappedNames.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,131 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.mina.common.support.discovery.resource.names;
+
+import java.util.Hashtable;
+
+import org.apache.mina.common.support.discovery.ResourceNameDiscover;
+import org.apache.mina.common.support.discovery.ResourceNameIterator;
+
+
+/**
+ * Recover resource name from Managed Properties,
+ * using OLD property names.
+ * 
+ * This class maintains a mapping between old names and
+ * (new) the class names they represent.  The discovery
+ * mechanism uses the class names as property names.
+ * 
+ * @see org.apache.mina.common.support.discovery.tools.ManagedProperties
+ * 
+ * @author Richard A. Sitze
+ */
+public class DiscoverMappedNames
+    extends ResourceNameDiscoverImpl
+    implements ResourceNameDiscover
+{
+    private Hashtable mapping = new Hashtable();  // String name ==> String[] newNames
+    
+    /** Construct a new resource discoverer
+     */
+    public DiscoverMappedNames() {
+    }
+    
+    public void map(String fromName, String toName) {
+        mapping.put(fromName, toName);
+    }
+    
+    public void map(String fromName, String [] toNames) {
+        mapping.put(fromName, toNames);
+    }
+
+    /**
+     * @return Enumeration of ResourceInfo
+     */
+    public ResourceNameIterator findResourceNames(final String resourceName) {
+        final Object obj = mapping.get(resourceName);
+
+        final String[] names;
+        if (obj instanceof String) {
+            names = new String[] { (String)obj };
+        } else if (obj instanceof String[]) {
+            names = (String[])obj;
+        } else {
+            names = null;
+        }
+        
+        return new ResourceNameIterator() {
+
+            private int idx = 0;
+            
+            public boolean hasNext() {
+                if (names != null) {
+                    while (idx < names.length  &&  names[idx] == null) {
+                        idx++;
+                    }
+                    return idx < names.length;
+                }
+                return false;
+            }
+            
+            public String nextResourceName() {
+                return hasNext() ? names[idx++] : null;
+            }
+        };
+    }
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverMappedNames.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInAlternateManagedProperties.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInAlternateManagedProperties.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInAlternateManagedProperties.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInAlternateManagedProperties.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,117 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.mina.common.support.discovery.resource.names;
+
+import java.util.HashMap;
+
+import org.apache.mina.common.support.discovery.ResourceNameDiscover;
+import org.apache.mina.common.support.discovery.ResourceNameIterator;
+import org.apache.mina.common.support.discovery.tools.ManagedProperties;
+
+
+/**
+ * Recover resource name from Managed Properties,
+ * using OLD property names.
+ * 
+ * This class maintains a mapping between old names and
+ * (new) the class names they represent.  The discovery
+ * mechanism uses the class names as property names.
+ * 
+ * @see org.apache.mina.common.support.discovery.tools.ManagedProperties
+ * 
+ * @author Richard A. Sitze
+ */
+public class DiscoverNamesInAlternateManagedProperties
+    extends ResourceNameDiscoverImpl
+    implements ResourceNameDiscover
+{
+    HashMap mapping = new HashMap();
+    
+    /** Construct a new resource discoverer
+     */
+    public DiscoverNamesInAlternateManagedProperties() {
+    }
+    
+    /**
+     */
+    public void addClassToPropertyNameMapping(String className, String propertyName) {
+        mapping.put(className, propertyName);
+    }
+
+    /**
+     * @return Enumeration of ResourceInfo
+     */
+    public ResourceNameIterator findResourceNames(final String resourceName) {
+        final String mappedName = (String)mapping.get(resourceName);
+
+        return new ResourceNameIterator() {
+            private String resource =
+                (mappedName == null) ? null : ManagedProperties.getProperty(mappedName);
+            
+            public boolean hasNext() {
+                return resource != null;
+            }
+            
+            public String nextResourceName() {
+                String element = resource;
+                resource = null;
+                return element;
+            }
+        };
+    }
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInAlternateManagedProperties.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInDictionary.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInDictionary.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInDictionary.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInDictionary.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,146 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.mina.common.support.discovery.resource.names;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.mina.common.support.discovery.ResourceNameDiscover;
+import org.apache.mina.common.support.discovery.ResourceNameIterator;
+
+
+/**
+ * Recover resources from a Dictionary.  This covers Properties as well,
+ * since <code>Properties extends Hashtable extends Dictionary</code>.
+ * 
+ * The recovered value is expected to be either a <code>String</code>
+ * or a <code>String[]</code>.
+ * 
+ * @author Richard A. Sitze
+ */
+public class DiscoverNamesInDictionary
+    extends ResourceNameDiscoverImpl
+    implements ResourceNameDiscover
+{
+    private Dictionary dictionary;
+    
+    /** Construct a new resource discoverer
+     */
+    public DiscoverNamesInDictionary() {
+        setDictionary(new Hashtable());
+    }
+    
+    /** Construct a new resource discoverer
+     */
+    public DiscoverNamesInDictionary(Dictionary dictionary) {
+        setDictionary(dictionary);
+    }
+
+    protected Dictionary getDictionary() {
+        return dictionary;
+    }
+
+    /**
+     * Specify set of class loaders to be used in searching.
+     */
+    public void setDictionary(Dictionary table) {
+        this.dictionary = table;
+    }
+    
+    public void addResource(String resourceName, String resource) {
+        dictionary.put(resourceName, resource);
+    }
+    
+    public void addResource(String resourceName, String[] resources) {
+        dictionary.put(resourceName, resources);
+    }
+
+    /**
+     * @return Enumeration of ResourceInfo
+     */
+    public ResourceNameIterator findResourceNames(final String resourceName) {
+        Object baseResource = dictionary.get(resourceName);
+
+        final String[] resources;
+        if (baseResource instanceof String) {
+            resources = new String[] { (String)baseResource };
+        } else if (baseResource instanceof String[]) {
+            resources = (String[])baseResource;
+        } else {
+            resources = null;
+        }
+
+        return new ResourceNameIterator() {
+            private int idx = 0;
+            
+            public boolean hasNext() {
+                if (resources != null) {
+                    while (idx < resources.length  &&  resources[idx] == null) {
+                        idx++;
+                    }
+                    return idx < resources.length;
+                }
+                return false;
+            }
+            
+            public String nextResourceName() {
+                return hasNext() ? resources[idx++] : null;
+            }
+        };
+    }
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInDictionary.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInFile.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInFile.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInFile.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInFile.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,232 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.mina.common.support.discovery.resource.names;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Vector;
+
+import org.apache.mina.common.support.discovery.Resource;
+import org.apache.mina.common.support.discovery.ResourceDiscover;
+import org.apache.mina.common.support.discovery.ResourceIterator;
+import org.apache.mina.common.support.discovery.ResourceNameDiscover;
+import org.apache.mina.common.support.discovery.ResourceNameIterator;
+import org.apache.mina.common.support.discovery.resource.ClassLoaders;
+import org.apache.mina.common.support.discovery.resource.DiscoverResources;
+
+
+
+/**
+ * Discover ALL files of a given name, and return resource names
+ * contained within the set of files:
+ * <ul>
+ *   <li>one resource name per line,</li>
+ *   <li>whitespace ignored,</li>
+ *   <li>comments begin with '#'</li>
+ * </ul>
+ * 
+ * Default discoverer is DiscoverClassLoaderResources,
+ * but it can be set to any other.
+ *
+ * @author Richard A. Sitze
+ * @author Costin Manolache
+ * @author James Strachan
+ */
+public class DiscoverNamesInFile
+    extends ResourceNameDiscoverImpl
+    implements ResourceNameDiscover
+{
+    private ResourceDiscover discoverResources;
+    
+    /**
+     *  Construct a new resource discoverer
+     */
+    public DiscoverNamesInFile() {
+        discoverResources = new DiscoverResources();
+    }
+    
+    /**
+     *  Construct a new resource discoverer
+     */
+    public DiscoverNamesInFile(ClassLoaders loaders) {
+        discoverResources = new DiscoverResources(loaders);
+    }
+    
+    /**
+     *  Construct a new resource discoverer
+     */
+    public DiscoverNamesInFile(ResourceDiscover discoverer) {
+        this.discoverResources = discoverer;
+    }
+
+    /**
+     * Specify set of class loaders to be used in searching.
+     */
+    public void setDiscoverer(ResourceDiscover discover) {
+        this.discoverResources = discover;
+    }
+
+    /**
+     * To be used by downstream elements..
+     */
+    public ResourceDiscover getDiscover() {
+        return discoverResources;
+    }
+
+    /**
+     * @return Enumeration of ServiceInfo
+     */
+    public ResourceNameIterator findResourceNames(final String fileName) {
+        return new ResourceNameIterator() {
+            private ResourceIterator files =
+                getDiscover().findResources(fileName);
+
+            private int idx = 0;
+            private Vector classNames = null;
+            private String resource = null;
+            
+            public boolean hasNext() {
+                if (resource == null) {
+                    resource = getNextClassName();
+                }
+                return resource != null;
+            }
+            
+            public String nextResourceName() {
+                String element = resource;
+                resource = null;
+                return element;
+            }
+            
+            private String getNextClassName() {
+                if (classNames == null || idx >= classNames.size()) {
+                    classNames = getNextClassNames();
+                    idx = 0;
+                    if (classNames == null) {
+                        return null;
+                    }
+                }
+
+                String className = (String)classNames.get(idx++);
+
+                return className;
+            }
+
+            private Vector getNextClassNames() {
+                while (files.hasNext()) {
+                    Vector results = readServices(files.nextResource());
+                    if (results != null  &&  results.size() > 0) {
+                        return results;
+                    }
+                }
+                return null;
+            }
+        };
+    }
+
+    /**
+     * Read everything, no defering here..
+     * Ensure that files are closed before we leave.
+     */
+    private Vector readServices(final Resource info) {
+        Vector results = new Vector();
+        
+        InputStream is = info.getResourceAsStream();
+        
+        if( is != null ) {
+            try {
+                try {
+                    // This code is needed by EBCDIC and other
+                    // strange systems.  It's a fix for bugs
+                    // reported in xerces
+                    BufferedReader rd;
+                    try {
+                        rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+                    } catch (java.io.UnsupportedEncodingException e) {
+                        rd = new BufferedReader(new InputStreamReader(is));
+                    }
+                    
+                    try {
+                        String serviceImplName;
+                        while( (serviceImplName = rd.readLine()) != null) {
+                            int idx = serviceImplName.indexOf('#');
+                            if (idx >= 0) {
+                                serviceImplName = serviceImplName.substring(0, idx);
+                            }
+                            serviceImplName = serviceImplName.trim();
+    
+                            if (serviceImplName.length() != 0) {
+                                results.add(serviceImplName);
+                            }
+                        }
+                    } finally {
+                        rd.close();
+                    }
+                } finally {
+                    is.close();
+                }
+            } catch (IOException e) {
+                // ignore
+            }
+        }
+        
+        return results;
+    }
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/discovery/resource/names/DiscoverNamesInFile.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision