You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rs...@apache.org on 2002/08/21 23:18:32 UTC
cvs commit: jakarta-commons/discovery/src/java/org/apache/commons/discovery ClassLoaders.java ResourceDiscovery.java ServiceDiscoveryTask.java
rsitze 2002/08/21 14:18:32
Modified: discovery/src/java/org/apache/commons/discovery
ResourceDiscovery.java ServiceDiscoveryTask.java
Added: discovery/src/java/org/apache/commons/discovery
ClassLoaders.java
Log:
Timidly he sticks his toes into the water... :-)
Revision Changes Path
1.3 +36 -31 jakarta-commons/discovery/src/java/org/apache/commons/discovery/ResourceDiscovery.java
Index: ResourceDiscovery.java
===================================================================
RCS file: /home/cvs/jakarta-commons/discovery/src/java/org/apache/commons/discovery/ResourceDiscovery.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ResourceDiscovery.java 21 Aug 2002 20:58:00 -0000 1.2
+++ ResourceDiscovery.java 21 Aug 2002 21:18:32 -0000 1.3
@@ -87,7 +87,7 @@
*/
protected static JDKHooks jdkHooks = JDKHooks.getJDKHooks();
- protected Vector classLoaders=new Vector();
+ protected Vector classLoaders = null;
/** Construct a new resource discoverer
*/
@@ -103,43 +103,48 @@
// XXX Check if JDK1.1 is used no longer necessary.
}
- /** 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.
+ /**
+ * Specify set of class loaders to be used in searching.
*/
- public void addClassLoader(ClassLoader loader) {
- classLoaders.addElement( loader );
+ public void setClassLoaders(ClassLoaders loaders) {
+ classLoaders = loaders.getClassLoaders();
}
public ResourceInfo[] findResources(String resourceName) {
- Vector results = new Vector();
-
- // For each loader
- for( int i=0; i<classLoaders.size() ; i++ ) {
- ClassLoader loader=(ClassLoader)classLoaders.elementAt(i);
-
- Enumeration enum=null;
-
- try {
- enum=jdkHooks.getResources(loader, resourceName);
- } catch( IOException ex ) {
- ex.printStackTrace();
- }
- if( enum==null ) continue;
-
- while( enum.hasMoreElements() ) {
- URL url=(URL)enum.nextElement();
-
- System.out.println("XXX URL " + url );
-
- ResourceInfo sinfo = new ResourceInfo(resourceName, loader, url);
- results.add(sinfo);
- System.out.println("XXX " + sinfo.toString());
+ ResourceInfo resultA[];
+
+ if (classLoaders != null) {
+ Vector results = new Vector();
+
+ // For each loader
+ for( int i=0; i<classLoaders.size() ; i++ ) {
+ ClassLoader loader=(ClassLoader)classLoaders.elementAt(i);
+
+ Enumeration enum=null;
+
+ try {
+ enum=jdkHooks.getResources(loader, resourceName);
+ } catch( IOException ex ) {
+ ex.printStackTrace();
+ }
+ if( enum==null ) continue;
+
+ while( enum.hasMoreElements() ) {
+ URL url=(URL)enum.nextElement();
+
+ System.out.println("XXX URL " + url );
+
+ ResourceInfo sinfo = new ResourceInfo(resourceName, loader, url);
+ results.add(sinfo);
+ System.out.println("XXX " + sinfo.toString());
+ }
}
+ resultA = new ResourceInfo[ results.size() ];
+ results.copyInto( resultA );
+ } else {
+ resultA = new ResourceInfo[0];
}
- ResourceInfo resultA[]=new ResourceInfo[ results.size() ];
- results.copyInto( resultA );
return resultA;
}
}
1.5 +7 -4 jakarta-commons/discovery/src/java/org/apache/commons/discovery/ServiceDiscoveryTask.java
Index: ServiceDiscoveryTask.java
===================================================================
RCS file: /home/cvs/jakarta-commons/discovery/src/java/org/apache/commons/discovery/ServiceDiscoveryTask.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ServiceDiscoveryTask.java 21 Aug 2002 20:31:40 -0000 1.4
+++ ServiceDiscoveryTask.java 21 Aug 2002 21:18:32 -0000 1.5
@@ -95,11 +95,14 @@
public void execute() throws Exception {
System.out.println("XXX ");
- ResourceDiscovery disc=ResourceDiscovery.newInstance();
-
- disc.addClassLoader( JDKHooks.getJDKHooks().getThreadContextClassLoader() );
- disc.addClassLoader( this.getClass().getClassLoader() );
+
+ ClassLoaders classLoaders = new ClassLoaders();
+ classLoaders.addClassLoader( JDKHooks.getJDKHooks().getThreadContextClassLoader() );
+ classLoaders.addClassLoader( this.getClass().getClassLoader() );
+ ResourceDiscovery disc=ResourceDiscovery.newInstance();
+ disc.setClassLoaders(classLoaders);
+
drivers=disc.findResources(name);
if( debug > 0 ) {
1.1 jakarta-commons/discovery/src/java/org/apache/commons/discovery/ClassLoaders.java
Index: ClassLoaders.java
===================================================================
/*
* ====================================================================
*
* 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.commons.discovery;
import java.util.Vector;
/**
* 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() {
}
/**
* 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.addElement(loader);
}
public Vector getClassLoaders() {
return classLoaders;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>