public void addConstituent( URL constituent ) { // If the constituent is a jar, build an index for it. if ( "jar".equals( constituent.getProtocol() ) || constituent.toExternalForm().endsWith( ".jar" ) ) { buildIndexForJar( constituent ); } // Add the constituent to the urls collection this.urls.add( constituent ); super.addConstituent( constituent ); }
public URL findResource( String name ) { URL resourceUrl = null; Iterator urlIter = this.urls.iterator(); URL eachUrl = null; while ( urlIter.hasNext() ) { eachUrl = (URL) urlIter.next(); if ( "jar".equals( eachUrl.getProtocol() ) || eachUrl.toExternalForm().endsWith( ".jar" ) ) { resourceUrl = findResourceInJarStream( eachUrl, name ); } else { resourceUrl = findResourceInDirectoryUrl( eachUrl, name ); } if ( resourceUrl != null ) { return resourceUrl; } } return null; }
protected byte[] findClassInJarStream( URL inUrl, String path ) { URL classUrl = (URL) ( (Map) jarIndexes.get( inUrl ) ).get( path ); if ( classUrl != null ) { try { return readStream( classUrl.openStream() ); } catch ( IOException e ) { // Swallow } } return null; }
classBytes = findClassInJarStream( eachUrl, classPath ); classBytes = findClassInDirectoryUrl( eachUrl, classPath ); Class cls = defineClass( className, classBytes, 0, classBytes.length );
eachUrl.toExternalForm().endsWith( ".jar" ) ) classBytes = findClassInJarStream( eachUrl, classPath ); classBytes = findClassInDirectoryUrl( eachUrl, classPath );
public DefaultClassRealm( ClassWorld world, String id, ClassLoader foreignClassLoader ) { this.world = world; this.id = id; imports = new TreeSet(); if ( foreignClassLoader != null ) { this.foreignClassLoader = foreignClassLoader; } if ( "true".equals( System.getProperty( "classworlds.bootstrapped" ) ) ) { classLoader = new UberJarRealmClassLoader( this ); } else { classLoader = new RealmClassLoader( this ); } }
/** @see ClassLoader */ public URL getResource( String name ) { return getRealm().getResource( name ); }
/** Construct. * * @param world The world of which this realm is a member. * @param id This realm's id. */ DefaultClassRealm( ClassWorld world, String id ) { this.world = world; this.id = id; this.imports = new TreeSet(); // We need to detect whether we are running in an UberJar // or not. if ( "true".equals( System.getProperty( "classworlds.bootstrapped" ) ) ) { this.classLoader = new UberJarRealmClassLoader( this ); } else { this.classLoader = new RealmClassLoader( this ); } }
/** Load a class. * * @param name The name of the class to load. * @param resolve If <code>true</code> then resolve the class. * * @return The loaded class. * * @throws ClassNotFoundException If the class cannot be found. */ protected Class loadClass( String name, boolean resolve ) throws ClassNotFoundException { return getRealm().loadClass( name ); }
public Enumeration findResourcesDirect( String name ) { Vector list = new Vector(); URL resourceUrl = null; Iterator urlIter = this.urls.iterator(); URL eachUrl = null; while ( urlIter.hasNext() ) { eachUrl = (URL) urlIter.next(); if ( "jar".equals( eachUrl.getProtocol() ) || eachUrl.toExternalForm().endsWith( ".jar" ) ) { resourceUrl = findResourceInJarStream( eachUrl, name ); } else { resourceUrl = findResourceInDirectoryUrl( eachUrl, name ); } if ( resourceUrl != null ) { list.add( resourceUrl ); } } return list.elements(); }
/** Add a constituent to this realm for locating classes. * * @param constituent URL to contituent jar or directory. */ void addConstituent( URL constituent ) { // If the constituent is a jar, build an index for it. if ( "jar".equals( constituent.getProtocol() ) || constituent.toExternalForm().endsWith( ".jar" ) ) { buildIndexForJar( constituent ); } // Add the constituent to the urls collection this.urls.add( constituent ); super.addConstituent( constituent ); }
/** Attempt to load the bytes of a class from a JAR <code>URL</code>. * * @param inUrl The base url. * @param path The path to the desired class. * * @return The class bytes or <code>null</code> if not available * via the base url. */ protected byte[] findClassInJarStream( URL inUrl, String path ) { URL classUrl = (URL) ( (Map) jarIndexes.get( inUrl ) ).get( path ); if ( classUrl != null ) { try { return readStream( classUrl.openStream() ); } catch ( IOException e ) { // Swallow } } return null; }
/** @see ClassLoader */ public URL findResource( String name ) { URL resourceUrl = null; Iterator urlIter = this.urls.iterator(); URL eachUrl = null; while ( urlIter.hasNext() ) { eachUrl = (URL) urlIter.next(); if ( "jar".equals( eachUrl.getProtocol() ) || eachUrl.toExternalForm().endsWith( ".jar" ) ) { resourceUrl = findResourceInJarStream( eachUrl, name ); } else { resourceUrl = findResourceInDirectoryUrl( eachUrl, name ); } if ( resourceUrl != null ) { return resourceUrl; } } return null; }