KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > loading > LegacyDomainClassLoader


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mx.loading;
23
24 import java.io.ByteArrayOutputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.net.MalformedURLException JavaDoc;
28 import java.net.URL JavaDoc;
29 import java.net.URLClassLoader JavaDoc;
30 import java.security.CodeSource JavaDoc;
31 import java.security.PermissionCollection JavaDoc;
32 import java.security.Policy JavaDoc;
33 import java.security.ProtectionDomain JavaDoc;
34 import java.security.cert.Certificate JavaDoc;
35 import java.util.Enumeration JavaDoc;
36 import java.util.HashSet JavaDoc;
37 import java.util.Vector JavaDoc;
38 import java.util.Collections JavaDoc;
39 import java.util.Set JavaDoc;
40
41 import javax.management.MalformedObjectNameException JavaDoc;
42 import javax.management.ObjectName JavaDoc;
43
44 import org.jboss.classloading.spi.ClassLoadingDomain;
45 import org.jboss.classloading.spi.DomainClassLoader;
46 import org.jboss.classloading.spi.Translator;
47 import org.jboss.logging.Logger;
48 import org.jboss.util.collection.SoftSet;
49
50 import EDU.oswego.cs.dl.util.concurrent.ReentrantLock;
51 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
52
53 /**
54  * A DomainClassLoader based on the legacy RepositoryClassLoader. This is for
55  * portability of the legacy UCL/ULR.
56  *
57  * @see LoaderRepositoryDomain
58  *
59  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
60  * @author Scott.Stark@jboss.org
61  * @version $Revision: 57108 $
62  */

63 public abstract class LegacyDomainClassLoader extends URLClassLoader JavaDoc
64    implements DomainClassLoader
65 {
66    // Constants -----------------------------------------------------
67

68    /** The log */
69    private static final Logger log = Logger.getLogger(LegacyDomainClassLoader.class);
70
71    /** The value returned by {@link #getURLs}. */
72    private static final URL JavaDoc[] EMPTY_URL_ARRAY = {};
73
74    // Attributes -----------------------------------------------------
75

76    /** Reference to the jboss5 ClassLoadingDomain */
77    protected LoaderRepositoryDomain domain = null;
78    /** The location where unregister is called from */
79    protected Exception JavaDoc unregisterTrace;
80
81    /** The relative order in which this class loader was added to the respository */
82    private int addedOrder;
83    
84    /** The parent classloader */
85    protected ClassLoader JavaDoc parent = null;
86    
87    /** Names of classes which have resulted in CNFEs in loadClassLocally */
88    private Set JavaDoc classBlackList = Collections.synchronizedSet(new SoftSet());
89    /** Names of resources that were not found in loadResourceLocally */
90    private Set JavaDoc resourceBlackList = Collections.synchronizedSet(new HashSet JavaDoc());
91    /** A HashMap<String, URL> for resource found in loadResourceLocally */
92    private ConcurrentReaderHashMap resourceCache = new ConcurrentReaderHashMap();
93    
94    /** Lock */
95    protected ReentrantLock loadLock = new ReentrantLock();
96
97    /** A debugging variable used to track the recursive depth of loadClass() */
98    protected int loadClassDepth;
99
100    // Static --------------------------------------------------------
101

102    // Constructors --------------------------------------------------
103

104    /**
105     * Create a new LoaderDomainClassLoaderImpl
106     *
107     * @param urls the urls
108     * @param parent the parent classloader
109     */

110    protected LegacyDomainClassLoader(URL JavaDoc[] urls, ClassLoader JavaDoc parent)
111    {
112       super(urls, parent);
113       this.parent = parent;
114       // Check the blacklist mode
115
String JavaDoc mode = ClassToStringAction.getProperty("org.jboss.mx.loading.blacklistMode", null);
116       if( mode == null || mode.equalsIgnoreCase("HashSet") )
117       {
118          classBlackList = Collections.synchronizedSet(new HashSet JavaDoc());
119          resourceBlackList = Collections.synchronizedSet(new HashSet JavaDoc());
120       }
121       else if( mode.equalsIgnoreCase("SoftSet") )
122       {
123          classBlackList = Collections.synchronizedSet(new SoftSet());
124          resourceBlackList = Collections.synchronizedSet(new SoftSet());
125       }
126    }
127    
128    // Public --------------------------------------------------------
129

130    /**
131     * Get the ObjectName
132     *
133     * @return the object name
134     */

135    public abstract ObjectName JavaDoc getObjectName() throws MalformedObjectNameException JavaDoc;
136    
137    public ClassLoadingDomain getDomain()
138    {
139       return domain;
140    }
141    public void setDomain(ClassLoadingDomain domain)
142    {
143       log.debug("setDomain, domain="+domain+", cl=" + this);
144       this.domain = (LoaderRepositoryDomain) domain;
145    }
146
147    /**
148     * Get the order this classloader was added to the domain
149     *
150     * @return the order
151     */

152    public int getAddedOrder()
153    {
154       return addedOrder;
155    }
156
157    /**
158     * Set the order this classloader was added to the domain
159     *
160     * @param addedOrder the added order
161     */

162    public void setAddedOrder(int addedOrder)
163    {
164       this.addedOrder = addedOrder;
165    }
166
167    /**
168     * Called to attempt to load a class from the set of URLs associated with this classloader.
169     */

170    public Class JavaDoc loadClassLocally(String JavaDoc name, boolean resolve)
171       throws ClassNotFoundException JavaDoc
172    {
173       boolean trace = log.isTraceEnabled();
174       if( trace )
175          log.trace("loadClassLocally, " + this + " name=" + name);
176       Class JavaDoc result = null;
177       try
178       {
179          if (isClassBlackListed(name))
180          {
181             if( trace )
182                log.trace("Class in blacklist, name="+name);
183             throw new ClassNotFoundException JavaDoc("Class Not Found(blacklist): " + name);
184          }
185
186          try
187          {
188             result = super.loadClass(name, resolve);
189             return result;
190          }
191          catch (ClassNotFoundException JavaDoc cnfe)
192          {
193             addToClassBlackList(name);
194             // If this is an array class, use Class.forName to resolve it
195
if( name.charAt(0) == '[' )
196             {
197                result = Class.forName(name, true, this);
198                removeFromClassBlackList(name);
199                return result;
200             }
201             if( trace )
202                log.trace("CFNE: Adding to blacklist: "+name);
203             throw cnfe;
204          }
205       }
206       finally
207       {
208          if (trace)
209          {
210             if (result != null)
211                log.trace("loadClassLocally, " + this + " name=" + name + " class=" + result + " cl=" + result.getClassLoader());
212             else
213                log.trace("loadClassLocally, " + this + " name=" + name + " not found");
214          }
215       }
216    }
217
218    /**
219    * Provides the same functionality as {@link java.net.URLClassLoader#getResource}.
220    */

221    public URL JavaDoc getResourceLocally(String JavaDoc name)
222    {
223       URL JavaDoc resURL = (URL JavaDoc) resourceCache.get(name);
224       if (resURL != null)
225          return resURL;
226       if (isResourceBlackListed(name))
227          return null;
228       resURL = super.getResource(name);
229       if( log.isTraceEnabled() == true )
230          log.trace("getResourceLocally("+this+"), name="+name+", resURL:"+resURL);
231       if (resURL == null)
232          addToResourceBlackList(name);
233       else
234          resourceCache.put(name, resURL);
235       return resURL;
236    }
237    public URL JavaDoc loadResourceLocally(String JavaDoc name)
238    {
239       return getResourceLocally(name);
240    }
241
242    /**
243     * Get the URL associated with the UCL.
244     *
245     * @return the url
246     */

247    public URL JavaDoc getURL()
248    {
249       URL JavaDoc[] urls = super.getURLs();
250       if (urls.length > 0)
251          return urls[0];
252       else
253          return null;
254    }
255    
256    public void unregister()
257    {
258       log.debug("Unregistering cl=" + this);
259       if (domain != null)
260          domain.removeClassLoader(this);
261       clearBlacklists();
262       resourceCache.clear();
263       domain = null;
264       this.unregisterTrace = new Exception JavaDoc();
265    }
266
267    /**
268     * This method simply invokes the super.getURLs() method to access the
269     * list of URLs that make up the DomainClassLoaderImpl classpath.
270     *
271     * @return the urls that make up the classpath
272     */

273    public URL JavaDoc[] getClasspath()
274    {
275       return super.getURLs();
276    }
277
278    /**
279     * Black list a class
280     *
281     * @param name the name of the class
282     */

283    public void addToClassBlackList(String JavaDoc name)
284    {
285       classBlackList.add(name);
286    }
287
288    /**
289     * Remove class from black list
290     *
291     * @param name the name of the class
292     */

293    public void removeFromClassBlackList(String JavaDoc name)
294    {
295       classBlackList.remove(name);
296    }
297    
298    /**
299     * Is the class black listed?
300     *
301     * @param name the name of the class
302     * @return true when the class is black listed, false otherwise
303     */

304    public boolean isClassBlackListed(String JavaDoc name)
305    {
306       return classBlackList.contains(name);
307    }
308     
309    /**
310     * Clear any class black list.
311     */

312    public void clearClassBlackList()
313    {
314       classBlackList.clear();
315    }
316
317    /**
318     * Black list a resource
319     *
320     * @param name the name of the resource
321     */

322    public void addToResourceBlackList(String JavaDoc name)
323    {
324       resourceBlackList.add(name);
325    }
326
327    /**
328     * Remove resource from black list
329     *
330     * @param name the name of the resource
331     */

332    public void removeFromResourceBlackList(String JavaDoc name)
333    {
334       resourceBlackList.remove(name);
335    }
336    
337    /**
338     * Is the resource black listed?
339     *
340     * @param name the name of the resource
341     * @return true when the resource is black listed, false otherwise
342     */

343    public boolean isResourceBlackListed(String JavaDoc name)
344    {
345       return resourceBlackList.contains(name);
346    }
347    
348    /**
349     * Clear any resource blacklist.
350     */

351    public void clearResourceBlackList()
352    {
353       resourceBlackList.clear();
354    }
355
356    /**
357     * Clear all blacklists
358     */

359    public void clearBlacklists()
360    {
361       clearClassBlackList();
362       clearResourceBlackList();
363    }
364
365
366    // URLClassLoader overrides --------------------------------------
367

368    /** The only caller of this method should be the VM initiated
369    * loadClassInternal() method. This method attempts to acquire the
370    * UnifiedLoaderRepository2 lock and then asks the domain to
371    * load the class.
372    *
373    * <p>Forwards request to {@link LoaderRepository}.
374    */

375    public Class JavaDoc loadClass(String JavaDoc name, boolean resolve)
376       throws ClassNotFoundException JavaDoc
377    {
378       boolean trace = log.isTraceEnabled();
379       if (trace)
380          log.trace("loadClass " + this + " name=" + name+", loadClassDepth="+loadClassDepth);
381       Class JavaDoc clazz = null;
382       try
383       {
384          if (domain != null)
385          {
386             clazz = domain.getCachedClass(name);
387             if (clazz != null)
388             {
389                if( log.isTraceEnabled() )
390                {
391                   StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("Loaded class from cache, ");
392                   ClassToStringAction.toString(clazz, buffer);
393                   log.trace(buffer.toString());
394                }
395                return clazz;
396             }
397          }
398          clazz = loadClassImpl(name, resolve, Integer.MAX_VALUE);
399          return clazz;
400       }
401       finally
402       {
403          if (trace)
404          {
405             if (clazz != null)
406                log.trace("loadClass " + this + " name=" + name + " class=" + clazz + " cl=" + clazz.getClassLoader());
407             else
408                log.trace("loadClass " + this + " name=" + name + " not found");
409          }
410       }
411    }
412
413    /** The only caller of this method should be the VM initiated
414    * loadClassInternal() method. This method attempts to acquire the
415    * UnifiedLoaderRepository2 lock and then asks the domain to
416    * load the class.
417    *
418    * <p>Forwards request to {@link LoaderRepository}.
419    */

420    public Class JavaDoc loadClassBefore(String JavaDoc name)
421       throws ClassNotFoundException JavaDoc
422    {
423       boolean trace = log.isTraceEnabled();
424       if (trace)
425          log.trace("loadClassBefore " + this + " name=" + name);
426       Class JavaDoc clazz = null;
427       try
428       {
429          clazz = loadClassImpl(name, false, addedOrder);
430          return clazz;
431       }
432       finally
433       {
434          if (trace)
435          {
436             if (clazz != null)
437                log.trace("loadClassBefore " + this + " name=" + name + " class=" + clazz + " cl=" + clazz.getClassLoader());
438             else
439                log.trace("loadClassBefore " + this + " name=" + name + " not found");
440          }
441       }
442    }
443
444    public abstract Class JavaDoc loadClassImpl(String JavaDoc name, boolean resolve, int stopAt)
445       throws ClassNotFoundException JavaDoc;
446
447    /**
448    * Attempts to load the resource from its URL and if not found
449    * forwards to the request to {@link LoaderRepository}.
450    */

451    public URL JavaDoc getResource(String JavaDoc name)
452    {
453       if (domain != null)
454          return domain.getResource(name, this);
455       return null;
456    }
457
458    /** Find all resource URLs for the given name. This overrides the
459     * URLClassLoader version to look for resources in the domain.
460     *
461     * @param name the name of the resource
462     * @return Enumeration<URL>
463     * @throws java.io.IOException
464     */

465    public Enumeration JavaDoc<URL JavaDoc> findResources(String JavaDoc name) throws IOException JavaDoc
466    {
467       Vector JavaDoc<URL JavaDoc> resURLs = new Vector JavaDoc<URL JavaDoc>();
468       if( domain == null )
469       {
470          String JavaDoc msg = "Invalid use of destroyed classloader, UCL destroyed at:";
471          IOException JavaDoc e = new IOException JavaDoc(msg);
472          e.initCause(this.unregisterTrace);
473          throw e;
474       }
475       domain.getResources(name, this, resURLs);
476       return resURLs.elements();
477    }
478
479    /**
480    * Provides the same functionality as {@link java.net.URLClassLoader#findResources}.
481    */

482    public Enumeration JavaDoc findResourcesLocally(String JavaDoc name) throws IOException JavaDoc
483    {
484       return super.findResources(name);
485    }
486
487     /** Called by loadClassLocally to find the requested class within this
488      * class loaders class path.
489      *
490      * @param name the name of the class
491      * @return the resulting class
492      * @exception ClassNotFoundException if the class could not be found
493      */

494    protected Class JavaDoc findClass(String JavaDoc name) throws ClassNotFoundException JavaDoc
495    {
496       boolean trace = log.isTraceEnabled();
497       if( trace )
498          log.trace("findClass, name="+name);
499       if (isClassBlackListed(name))
500       {
501          if( trace )
502             log.trace("Class in blacklist, name="+name);
503          throw new ClassNotFoundException JavaDoc("Class Not Found(blacklist): " + name);
504       }
505
506       Translator translator = domain.getTranslator();
507       if (translator != null)
508       {
509          // Obtain the transformed class bytecode
510
try
511          {
512             // Obtain the raw bytecode from the classpath
513
URL JavaDoc classUrl = getClassURL(name);
514             byte[] rawcode = loadByteCode(classUrl);
515             URL JavaDoc codeSourceUrl = getCodeSourceURL(name, classUrl);
516             ProtectionDomain JavaDoc pd = getProtectionDomain(codeSourceUrl);
517             byte[] bytecode = translator.transform(this, name, null, pd, rawcode);
518             // If there was no transform use the raw bytecode
519
if( bytecode == null )
520                bytecode = rawcode;
521             // Define the class package and instance
522
definePackage(name);
523             return defineClass(name, bytecode, 0, bytecode.length, pd);
524          }
525          catch(ClassNotFoundException JavaDoc e)
526          {
527             throw e;
528          }
529          catch (Throwable JavaDoc ex)
530          {
531             throw new ClassNotFoundException JavaDoc(name, ex);
532          }
533       }
534
535       Class JavaDoc clazz = null;
536       try
537       {
538          clazz = findClassLocally(name);
539       }
540       catch(ClassNotFoundException JavaDoc e)
541       {
542          if( trace )
543             log.trace("CFNE: Adding to blacklist: "+name);
544          addToClassBlackList(name);
545          throw e;
546       }
547       return clazz;
548    }
549
550    /**
551     * Find the class
552     *
553     * @param name the name of the class
554     * @return the class
555     */

556    protected Class JavaDoc findClassLocally(String JavaDoc name) throws ClassNotFoundException JavaDoc
557    {
558       return super.findClass(name);
559    }
560    
561    /**
562     * Define the package for the class if not already done
563     *
564     * @todo this properly
565     * @param className the class name
566     */

567    protected void definePackage(String JavaDoc className)
568    {
569       int i = className.lastIndexOf('.');
570       if (i == -1)
571          return;
572
573       try
574       {
575          definePackage(className.substring(0, i), null, null, null, null, null, null, null);
576       }
577       catch (IllegalArgumentException JavaDoc alreadyDone)
578       {
579       }
580    }
581
582    /** Append the given url to the URLs used for class and resource loading
583     * @param url the URL to load from
584     */

585    public void addURL(URL JavaDoc url)
586    {
587       if( url == null )
588          throw new IllegalArgumentException JavaDoc("url cannot be null");
589
590       if( domain.addClassLoaderURL(this, url) == true )
591       {
592          log.debug("Added url: "+url+", to ucl: "+this);
593          // Strip any query parameters
594
String JavaDoc query = url.getQuery();
595          if( query != null )
596          {
597             String JavaDoc ext = url.toExternalForm();
598             String JavaDoc ext2 = ext.substring(0, ext.length() - query.length() - 1);
599             try
600             {
601                url = new URL JavaDoc (ext2);
602             }
603             catch(MalformedURLException JavaDoc e)
604             {
605                log.warn("Failed to strip query from: "+url, e);
606             }
607          }
608          super.addURL(url);
609          clearBlacklists();
610       }
611       else if( log.isTraceEnabled() )
612       {
613          log.trace("Ignoring duplicate url: "+url+", for ucl: "+this);
614       }
615    }
616
617    public Package JavaDoc getPackage(String JavaDoc name)
618    {
619       return super.getPackage(name);
620    }
621    
622    public Package JavaDoc[] getPackages()
623    {
624       return super.getPackages();
625    }
626    
627    // Object overrides ----------------------------------------------
628

629    /**
630     * This is here to document that this must delegate to the
631     * super implementation to perform identity based equality. Using
632     * URL based equality caused conflicts with the Class.forName(String,
633     * boolean, ClassLoader).
634     */

635    public final boolean equals(Object JavaDoc other)
636    {
637       return super.equals(other);
638    }
639
640    /**
641     * This is here to document that this must delegate to the
642     * super implementation to perform identity based hashing. Using
643     * URL based hashing caused conflicts with the Class.forName(String,
644     * boolean, ClassLoader).
645     */

646    public final int hashCode()
647    {
648       return super.hashCode();
649    }
650
651    /**
652    * Returns a string representation.
653    */

654    public String JavaDoc toString()
655    {
656       return super.toString() + "{ url=" + getURL() + " }";
657    }
658    
659    // Protected -----------------------------------------------------
660

661    /** Attempt to acquire the class loading lock. This lock must be acquired
662     * before a thread enters the class loading task loop in loadClass. This
663     * method maintains any interrupted state of the calling thread.
664     *@see #loadClass(String, boolean)
665     */

666    protected boolean attempt(long waitMS)
667    {
668       boolean acquired = false;
669       boolean trace = log.isTraceEnabled();
670       // Save and clear the interrupted state of the incoming thread
671
boolean threadWasInterrupted = Thread.interrupted();
672       try
673       {
674          acquired = loadLock.attempt(waitMS);
675       }
676       catch(InterruptedException JavaDoc e)
677       {
678       }
679       finally
680       {
681          // Restore the interrupted state of the thread
682
if( threadWasInterrupted )
683             Thread.currentThread().interrupt();
684       }
685       if( trace )
686          log.trace("attempt("+loadLock.holds()+") was: "+acquired+" for :"+this);
687       return acquired;
688    }
689    
690    /** Acquire the class loading lock. This lock must be acquired
691     * before a thread enters the class loading task loop in loadClass.
692     *@see #loadClass(String, boolean)
693     */

694    protected void acquire()
695    {
696       // Save and clear the interrupted state of the incoming thread
697
boolean threadWasInterrupted = Thread.interrupted();
698       try
699       {
700          loadLock.acquire();
701       }
702       catch(InterruptedException JavaDoc e)
703       {
704       }
705       finally
706       {
707          // Restore the interrupted state of the thread
708
if( threadWasInterrupted )
709             Thread.currentThread().interrupt();
710       }
711       if( log.isTraceEnabled() )
712          log.trace("acquired("+loadLock.holds()+") for :"+this);
713    }
714    /** Release the class loading lock previous acquired through the acquire
715     * method.
716     */

717    protected void release()
718    {
719       if( log.isTraceEnabled() )
720          log.trace("release("+loadLock.holds()+") for :"+this);
721       loadLock.release();
722       if( log.isTraceEnabled() )
723          log.trace("released, holds: "+loadLock.holds());
724    }
725
726    /** Obtain the bytecode for the indicated class from this class loaders
727     * classpath.
728     *
729     * @param classname
730     * @return the bytecode array if found
731     * @exception ClassNotFoundException - if the class resource could not
732     * be found
733     */

734    protected byte[] loadByteCode(String JavaDoc classname)
735       throws ClassNotFoundException JavaDoc, IOException JavaDoc
736    {
737       byte[] bytecode = null;
738       URL JavaDoc classURL = getClassURL(classname);
739
740       // Load the class bytecode
741
InputStream JavaDoc is = null;
742       try
743       {
744          is = classURL.openStream();
745          ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
746          byte[] tmp = new byte[1024];
747          int read = 0;
748          while( (read = is.read(tmp)) > 0 )
749          {
750             baos.write(tmp, 0, read);
751          }
752          bytecode = baos.toByteArray();
753       }
754       finally
755       {
756          if( is != null )
757             is.close();
758       }
759
760       return bytecode;
761    }
762
763    /** Obtain the bytecode for the indicated class from this class loaders
764     * classpath.
765     *
766     * @param classURL
767     * @return the bytecode array if found
768     * @exception ClassNotFoundException - if the class resource could not
769     * be found
770     */

771    protected byte[] loadByteCode(URL JavaDoc classURL)
772       throws ClassNotFoundException JavaDoc, IOException JavaDoc
773    {
774       byte[] bytecode = null;
775       // Load the class bytecode
776
InputStream JavaDoc is = null;
777       try
778       {
779          is = classURL.openStream();
780          ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
781          byte[] tmp = new byte[1024];
782          int read = 0;
783          while( (read = is.read(tmp)) > 0 )
784          {
785             baos.write(tmp, 0, read);
786          }
787          bytecode = baos.toByteArray();
788       }
789       finally
790       {
791          if( is != null )
792             is.close();
793       }
794
795       return bytecode;
796    }
797    
798    /**
799     * Determine the protection domain. If we are a copy of the original
800     * deployment, use the original url as the codebase.
801     * @return the protection domain
802     * @todo certificates and principles?
803     */

804    protected ProtectionDomain JavaDoc getProtectionDomain(URL JavaDoc codesourceUrl)
805    {
806       Certificate JavaDoc certs[] = null;
807       CodeSource JavaDoc cs = new CodeSource JavaDoc(codesourceUrl, certs);
808       PermissionCollection JavaDoc permissions = Policy.getPolicy().getPermissions(cs);
809       if (log.isTraceEnabled())
810          log.trace("getProtectionDomain, url=" + codesourceUrl +
811                    " codeSource=" + cs + " permissions=" + permissions);
812       return new ProtectionDomain JavaDoc(cs, permissions);
813    }
814
815    // Package Private -----------------------------------------------
816

817    // Private -------------------------------------------------------
818

819    private URL JavaDoc getCodeSourceURL(String JavaDoc classname, URL JavaDoc classURL) throws java.net.MalformedURLException JavaDoc
820    {
821       String JavaDoc classRsrcName = classname.replace('.', '/') + ".class";
822       String JavaDoc urlAsString = classURL.toString();
823       int idx = urlAsString.indexOf(classRsrcName);
824       if (idx == -1) return classURL;
825       urlAsString = urlAsString.substring(0, idx);
826       return new URL JavaDoc(urlAsString);
827    }
828
829    private URL JavaDoc getClassURL(String JavaDoc classname) throws ClassNotFoundException JavaDoc
830    {
831       String JavaDoc classRsrcName = classname.replace('.', '/') + ".class";
832       URL JavaDoc classURL = this.getResourceLocally(classRsrcName);
833       if( classURL == null )
834       {
835          String JavaDoc msg = "Failed to find: "+classname+" as resource: "+classRsrcName;
836          throw new ClassNotFoundException JavaDoc(msg);
837       }
838       return classURL;
839    }
840
841    // Inner classes -------------------------------------------------
842
}
843
Popular Tags