[JBoss-dev] CVS update: jmx/src/main/org/jboss/mx/loading BasicLoaderRepository.java LoaderRepository.java
User: juhalindfors Date: 02/01/28 15:53:37 Modified:src/main/org/jboss/mx/loading BasicLoaderRepository.java LoaderRepository.java Log: cleared some conflicts LoaderRepository now an abstract class static getDefaultLoaderRepository() added for retrieving the repository singleton repository implementation changed using the "jbossmx.loader.repository.class" property Moved nativeClassSignatureMap to LoaderRepository so it can be shared by all repo implementations Revision ChangesPath 1.4 +48 -73jmx/src/main/org/jboss/mx/loading/BasicLoaderRepository.java Index: BasicLoaderRepository.java === RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/loading/BasicLoaderRepository.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- BasicLoaderRepository.java2002/01/26 15:13:24 1.3 +++ BasicLoaderRepository.java2002/01/28 23:53:36 1.4 @@ -1,5 +1,8 @@ /* - * LGPL + * JBoss, the OpenSource J2EE webOS + * + * Distributable under LGPL license. + * See terms of license at gnu.org. */ package org.jboss.mx.loading; @@ -8,68 +11,32 @@ import java.util.HashMap; import java.util.HashSet; -public class BasicLoaderRepository implements LoaderRepository { +/** + * + * @see org.jboss.mx.loading.LoaderRepository + * + * @author mailto:[EMAIL PROTECTED]";>Juha Lindfors. + * @version $Revision: 1.4 $ + */ +public class BasicLoaderRepository + extends LoaderRepository +{ - private static LoaderRepository instance = null; - - public synchronized static LoaderRepository getInstance() { - if (instance != null) - return instance; - else { - instance = new BasicLoaderRepository(); - return instance; - } - } - - protected Set loaders = new HashSet(); - - - /** -* Native signature to class map -*/ - private static HashMap nativeClassBySignature; - - /** -* Construct the native class map -*/ - static + // Public + public Class loadClass(String className) throws ClassNotFoundException { - nativeClassBySignature = new HashMap(); - nativeClassBySignature.put(boolean.class.getName(), -Boolean.TYPE); - nativeClassBySignature.put(byte.class.getName(), -Byte.TYPE); - nativeClassBySignature.put(char.class.getName(), -Character.TYPE); - nativeClassBySignature.put(double.class.getName(), -Double.TYPE); - nativeClassBySignature.put(float.class.getName(), -Float.TYPE); - nativeClassBySignature.put(int.class.getName(), -Integer.TYPE); - nativeClassBySignature.put(long.class.getName(), -Long.TYPE); - nativeClassBySignature.put(short.class.getName(), -Short.TYPE); - nativeClassBySignature.put(void.class.getName(), -Void.TYPE); - } - - private BasicLoaderRepository() { - - - } - - public Class loadClass(String className) throws ClassNotFoundException { return loadClassWithout(null, className); } + public Class loadClassWithout(ClassLoader skipLoader, String className) throws ClassNotFoundException { // REVIEW: Is this the correct place for this or should it only - // go where signatures are checked? + // go where signatures are checked? + // JPL:looks ok to me + // Check for native classes Class clazz = (Class) nativeClassBySignature.get(className); if (clazz != null) @@ -77,29 +44,36 @@ // try ctx cl first ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader(); - - if (ctxLoader != skipLoader) { - try { + + if (ctxLoader != skipLoader) + { + try + { clazz = ctxLoader.loadClass(className); } - catch (ClassNotFoundException e) { -// ignore and move on to the loader list + catch (ClassNotFoundException e) + { +// ignore and move on to the loader list } } - + if (clazz != null) return clazz; - - Iterator it = loaders.iterator(); - while (it.hasNext()) { + + Iterator it = loaders.iterator(); + while (it.hasNext()) + { ClassLoader cl = (ClassLoader)it.next();
Re: [JBoss-dev] CVS update: jmx/src/main/org/jboss/mx/loading BasicLoaderRepository.java LoaderRepository.java
Are you sure you don't mean Iterator it = loaders.iterator(); while (it.hasNext()) { ClassLoader cl = (ClassLoader)it.next(); if (cl != skipLoader) { try { clazz = cl.loadClass(className); return clazz; } catch (ClassNotFoundException ignored) { // go on and try the next loader } } } throw new ClassNotFoundException(className); } at the end of loadClassWithout? The original version looks through all classloaders and you get the last version that loads, rather than stopping when you find one working version. ??? thanks david jencks On 2001.12.02 21:13:31 -0500 Juha Lindfors wrote: > User: juhalindfors > Date: 01/12/02 18:13:31 > > Added: src/main/org/jboss/mx/loading BasicLoaderRepository.java > LoaderRepository.java > Log: > build fancy loaders here > > Revision ChangesPath > 1.1 jmx/src/main/org/jboss/mx/loading/BasicLoaderRepository.java > > Index: BasicLoaderRepository.java > === > /* >* LGPL >*/ > package org.jboss.mx.loading; > > import java.util.Set; > import java.util.Iterator; > import java.util.HashSet; > > public class BasicLoaderRepository implements LoaderRepository { > > private static LoaderRepository instance = null; > > public synchronized static LoaderRepository getInstance() { > if (instance != null) >return instance; > else { >instance = new BasicLoaderRepository(); >return instance; > } > } > > > protected Set loaders = new HashSet(); > > private BasicLoaderRepository() { > > > } > > public Class loadClass(String className) throws > ClassNotFoundException { > return loadClassWithout(null, className); > } > > public Class loadClassWithout(ClassLoader skipLoader, String > className) throws ClassNotFoundException { > > Class clazz = null; > > // try ctx cl first > ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader(); > > if (ctxLoader != skipLoader) { >try { > clazz = ctxLoader.loadClass(className); >} >catch (ClassNotFoundException e) { > // ignore and move on to the loader list >} > } > > if (clazz != null) >return clazz; > > Iterator it = loaders.iterator(); > while (it.hasNext()) { >ClassLoader cl = (ClassLoader)it.next(); > >if (cl != skipLoader) { > try { > clazz = cl.loadClass(className); > } > catch (ClassNotFoundException ignored) { > // go on and try the next loader > } >} > } > > if (clazz == null) >throw new ClassNotFoundException(className); > > return clazz; > } > > public void addClassLoader(ClassLoader cl) { > loaders.add(cl); > } > > public void removeClassLoader(ClassLoader cl) { > loaders.remove(cl); > } > > > } > > > > 1.1 jmx/src/main/org/jboss/mx/loading/LoaderRepository.java > > Index: LoaderRepository.java > === > /* >* LGPL >*/ > package org.jboss.mx.loading; > > public interface LoaderRepository { > > public Class loadClass(String className) throws > ClassNotFoundException; > public Class loadClassWithout(ClassLoader loader, String className) > throws ClassNotFoundException; > public void addClassLoader(ClassLoader cl); > public void removeClassLoader(ClassLoader cl); > > } > > > > > ___ > Jboss-development mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-development > > ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
[JBoss-dev] CVS update: jmx/src/main/org/jboss/mx/loading BasicLoaderRepository.java LoaderRepository.java
User: juhalindfors Date: 01/12/02 18:13:31 Added: src/main/org/jboss/mx/loading BasicLoaderRepository.java LoaderRepository.java Log: build fancy loaders here Revision ChangesPath 1.1 jmx/src/main/org/jboss/mx/loading/BasicLoaderRepository.java Index: BasicLoaderRepository.java === /* * LGPL */ package org.jboss.mx.loading; import java.util.Set; import java.util.Iterator; import java.util.HashSet; public class BasicLoaderRepository implements LoaderRepository { private static LoaderRepository instance = null; public synchronized static LoaderRepository getInstance() { if (instance != null) return instance; else { instance = new BasicLoaderRepository(); return instance; } } protected Set loaders = new HashSet(); private BasicLoaderRepository() { } public Class loadClass(String className) throws ClassNotFoundException { return loadClassWithout(null, className); } public Class loadClassWithout(ClassLoader skipLoader, String className) throws ClassNotFoundException { Class clazz = null; // try ctx cl first ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader(); if (ctxLoader != skipLoader) { try { clazz = ctxLoader.loadClass(className); } catch (ClassNotFoundException e) { // ignore and move on to the loader list } } if (clazz != null) return clazz; Iterator it = loaders.iterator(); while (it.hasNext()) { ClassLoader cl = (ClassLoader)it.next(); if (cl != skipLoader) { try { clazz = cl.loadClass(className); } catch (ClassNotFoundException ignored) { // go on and try the next loader } } } if (clazz == null) throw new ClassNotFoundException(className); return clazz; } public void addClassLoader(ClassLoader cl) { loaders.add(cl); } public void removeClassLoader(ClassLoader cl) { loaders.remove(cl); } } 1.1 jmx/src/main/org/jboss/mx/loading/LoaderRepository.java Index: LoaderRepository.java === /* * LGPL */ package org.jboss.mx.loading; public interface LoaderRepository { public Class loadClass(String className) throws ClassNotFoundException; public Class loadClassWithout(ClassLoader loader, String className) throws ClassNotFoundException; public void addClassLoader(ClassLoader cl); public void removeClassLoader(ClassLoader cl); } ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development