[jboss-cvs] javassist/src/main/javassist/scopedpool ...

Shigeru Chiba chiba at is.titech.ac.jp
Tue Jul 18 10:46:25 EDT 2006


  User: chiba   
  Date: 06/07/18 10:46:25

  Modified:    src/main/javassist/scopedpool        ScopedClassPool.java
                        ScopedClassPoolRepository.java
                        ScopedClassPoolFactory.java
                        ScopedClassPoolRepositoryImpl.java
                        SoftValueHashMap.java
                        ScopedClassPoolFactoryImpl.java
  Added:       src/main/javassist/scopedpool        package.html
  Log:
  reformatted.
  
  Revision  Changes    Path
  1.3       +259 -251  javassist/src/main/javassist/scopedpool/ScopedClassPool.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ScopedClassPool.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/scopedpool/ScopedClassPool.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- ScopedClassPool.java	13 Jul 2006 10:04:51 -0000	1.2
  +++ ScopedClassPool.java	18 Jul 2006 14:46:25 -0000	1.3
  @@ -1,18 +1,18 @@
   /*
  -* Javassist, a Java-bytecode translator toolkit.
  -* Copyright (C) 2006 JBoss Inc., All Rights Reserved.
  -*
  -* The contents of this file are subject to the Mozilla Public License Version
  -* 1.1 (the "License"); you may not use this file except in compliance with
  -* the License.  Alternatively, the contents of this file may be used under
  -* the terms of the GNU Lesser General Public License Version 2.1 or later.
  -*
  -* Software distributed under the License is distributed on an "AS IS"  
  -basis,
  -* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  -* for the specific language governing rights and limitations under the
  -* License.
  -*/
  + * Javassist, a Java-bytecode translator toolkit.
  + * Copyright (C) 2006 JBoss Inc. All Rights Reserved.
  + *
  + * The contents of this file are subject to the Mozilla Public License Version
  + * 1.1 (the "License"); you may not use this file except in compliance with
  + * the License.  Alternatively, the contents of this file may be used under
  + * the terms of the GNU Lesser General Public License Version 2.1 or later.
  + *
  + * Software distributed under the License is distributed on an "AS IS" basis,
  + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  + * for the specific language governing rights and limitations under the
  + * License.
  + */
  +
   package javassist.scopedpool;
   
   import java.lang.ref.WeakReference;
  @@ -25,22 +25,23 @@
   import javassist.NotFoundException;
   
   /**
  - * A scoped class pool
  + * A scoped class pool.
    * 
    * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
    * @author <a href="adrian at jboss.com">Adrian Brock</a>
    * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
  -public class ScopedClassPool extends ClassPool
  -{
  +public class ScopedClassPool extends ClassPool {
      protected ScopedClassPoolRepository repository;
  +
      protected WeakReference classLoader;
  +
      protected LoaderClassPath classPath;
  +
      protected SoftValueHashMap softcache = new SoftValueHashMap();
   
  -   static 
  -   {
  +    static {
         ClassPool.doPruning = false;
         ClassPool.releaseUnmodifiedClassFile = false;
      }   
  @@ -48,17 +49,19 @@
      /**
       * Create a new ScopedClassPool.
       * 
  -    * @param cl the classloader
  -    * @param src the original class pool
  -    * @param repository the repository
  +     * @param cl
  +     *            the classloader
  +     * @param src
  +     *            the original class pool
  +     * @param repository
  +     *            the repository
       */
  -   protected ScopedClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
  -   {
  +    protected ScopedClassPool(ClassLoader cl, ClassPool src,
  +            ScopedClassPoolRepository repository) {
         super(src);
         this.repository = repository;
         this.classLoader = new WeakReference(cl);
  -      if (cl != null)
  -      {
  +        if (cl != null) {
            classPath = new LoaderClassPath(cl);
            this.insertClassPath(classPath);
         }
  @@ -70,24 +73,22 @@
       * 
       * @return the class loader
       */
  -   public ClassLoader getClassLoader()
  -   {
  +    public ClassLoader getClassLoader() {
         return getClassLoader0();
      }
   
  -   private ClassLoader getClassLoader0()
  -   {
  -      ClassLoader cl = (ClassLoader) classLoader.get();
  +    private ClassLoader getClassLoader0() {
  +        ClassLoader cl = (ClassLoader)classLoader.get();
         if (cl == null)
  -         throw new IllegalStateException("ClassLoader has been garbage collected");
  +            throw new IllegalStateException(
  +                    "ClassLoader has been garbage collected");
         return cl;
      }
      
      /**
       * Close the class pool
       */
  -   public void close()
  -   {
  +    public void close() {
         this.removeClassPath(classPath);
         classPath.close();
         classes.clear();
  @@ -97,10 +98,10 @@
      /**
       * Flush a class
       * 
  -    * @param classname the class to flush
  +     * @param classname
  +     *            the class to flush
       */
  -   public synchronized void flushClass(String classname)
  -   {
  +    public synchronized void flushClass(String classname) {
         classes.remove(classname);
         softcache.remove(classname);
      }
  @@ -108,11 +109,12 @@
      /**
       * Soften a class
       * 
  -    * @param clazz the class
  +     * @param clazz
  +     *            the class
       */
  -   public synchronized void soften(CtClass clazz)
  -   {
  -      if (repository.isPrune()) clazz.prune();
  +    public synchronized void soften(CtClass clazz) {
  +        if (repository.isPrune())
  +            clazz.prune();
         classes.remove(clazz.getName());
         softcache.put(clazz.getName(), clazz);
      }
  @@ -122,59 +124,53 @@
       * 
       * @return false always
       */
  -   public boolean isUnloadedClassLoader()
  -   {
  +    public boolean isUnloadedClassLoader() {
         return false;
      }
   
      /**
       * Get the cached class
       * 
  -    * @param classname the class name
  +     * @param classname
  +     *            the class name
       * @return the class
       */
  -   protected CtClass getCached(String classname)
  -   {
  +    protected CtClass getCached(String classname) {
         CtClass clazz = getCachedLocally(classname);
  -      if (clazz == null)
  -      {
  +        if (clazz == null) {
            boolean isLocal = false; 
            
            ClassLoader dcl = getClassLoader0();
  -         if (dcl != null)
  -         {
  +            if (dcl != null) {
               final int lastIndex = classname.lastIndexOf('$');
               String classResourceName = null;
  -            if (lastIndex < 0)
  -            {
  -               classResourceName = classname.replaceAll("[\\.]", "/") + ".class";
  -            }
  -            else
  -            {
  -               classResourceName = classname.substring(0, lastIndex).replaceAll("[\\.]", "/") + classname.substring(lastIndex) + ".class";
  +                if (lastIndex < 0) {
  +                    classResourceName = classname.replaceAll("[\\.]", "/")
  +                            + ".class";
  +                }
  +                else {
  +                    classResourceName = classname.substring(0, lastIndex)
  +                            .replaceAll("[\\.]", "/")
  +                            + classname.substring(lastIndex) + ".class";
               }
   
               isLocal = dcl.getResource(classResourceName) != null; 
            }
            
  -         if (!isLocal)
  -         {
  +            if (!isLocal) {
               Map registeredCLs = repository.getRegisteredCLs();
  -            synchronized (registeredCLs)
  -            {
  +                synchronized (registeredCLs) {
                  Iterator it = registeredCLs.values().iterator();
  -               while (it.hasNext())
  -               {
  -                  ScopedClassPool pool = (ScopedClassPool) it.next();
  -                  if (pool.isUnloadedClassLoader())
  -                  {
  -                     repository.unregisterClassLoader(pool.getClassLoader());
  +                    while (it.hasNext()) {
  +                        ScopedClassPool pool = (ScopedClassPool)it.next();
  +                        if (pool.isUnloadedClassLoader()) {
  +                            repository.unregisterClassLoader(pool
  +                                    .getClassLoader());
                        continue;
                     }
      
                     clazz = pool.getCachedLocally(classname);
  -                  if (clazz != null)
  -                  {
  +                        if (clazz != null) {
                        return clazz;
                     }
                  }
  @@ -188,19 +184,20 @@
      /**
       * Cache a class
       * 
  -    * @param classname the class name
  -    * @param c the ctClass
  -    * @param dynamic whether the class is dynamically generated
  -    */
  -   protected void cacheCtClass(String classname, CtClass c, boolean dynamic)
  -   {
  -      if (dynamic)
  -      {
  +     * @param classname
  +     *            the class name
  +     * @param c
  +     *            the ctClass
  +     * @param dynamic
  +     *            whether the class is dynamically generated
  +     */
  +    protected void cacheCtClass(String classname, CtClass c, boolean dynamic) {
  +        if (dynamic) {
            super.cacheCtClass(classname, c, dynamic);
         }
  -      else
  -      {
  -         if (repository.isPrune()) c.prune();
  +        else {
  +            if (repository.isPrune())
  +                c.prune();
            softcache.put(classname, c);
         }
      }
  @@ -208,44 +205,46 @@
      /**
       * Lock a class into the cache
       * 
  -    * @param c the class
  +     * @param c
  +     *            the class
       */
  -   public void lockInCache(CtClass c)
  -   {
  +    public void lockInCache(CtClass c) {
         super.cacheCtClass(c.getName(), c, false);
      }
   
      /**
       * Whether the class is cached in this pooled
       * 
  -    * @param classname the class name
  +     * @param classname
  +     *            the class name
       * @return the cached class
       */
  -   protected CtClass getCachedLocally(String classname)
  -   {
  -      CtClass cached = (CtClass) classes.get(classname);
  -      if (cached != null) return cached;
  -      synchronized (softcache)
  -      {
  -         return (CtClass) softcache.get(classname);
  +    protected CtClass getCachedLocally(String classname) {
  +        CtClass cached = (CtClass)classes.get(classname);
  +        if (cached != null)
  +            return cached;
  +        synchronized (softcache) {
  +            return (CtClass)softcache.get(classname);
         }
      }
   
      /**
       * Get any local copy of the class
       * 
  -    * @param classname the class name
  +     * @param classname
  +     *            the class name
       * @return the class
  -    * @throws NotFoundException when the class is not found
  +     * @throws NotFoundException
  +     *             when the class is not found
       */
  -   public synchronized CtClass getLocally(String classname) throws NotFoundException
  -   {
  +    public synchronized CtClass getLocally(String classname)
  +            throws NotFoundException {
         softcache.remove(classname);
  -      CtClass clazz = (CtClass) classes.get(classname);
  -      if (clazz == null)
  -      {
  +        CtClass clazz = (CtClass)classes.get(classname);
  +        if (clazz == null) {
            clazz = createCtClass(classname, true);
  -         if (clazz == null) throw new NotFoundException(classname);
  +            if (clazz == null)
  +                throw new NotFoundException(classname);
            super.cacheCtClass(classname, clazz, false);
         }
   
  @@ -255,18 +254,27 @@
      /**
       * Convert a javassist class to a java class
       * 
  -    * @param ct the javassist class
  -    * @param loader the loader
  -    * @throws CannotCompileException for any error
  -    */
  -   public Class toClass(CtClass ct, ClassLoader loader) throws CannotCompileException
  -   {
  -      //We need to pass up the classloader stored in this pool, as the default implementation uses the Thread context cl.
  -      //In the case of JSP's in Tomcat, org.apache.jasper.servlet.JasperLoader will be stored here, while it's parent
  -      //org.jboss.web.tomcat.tc5.WebCtxLoader$ENCLoader is used as the Thread context cl. The invocation class needs to
  -      // be generated in the JasperLoader classloader since in the case of method invocations, the package name will be
  -      //the same as for the class generated from the jsp, i.e. org.apache.jsp. For classes belonging to org.apache.jsp,
  -      //JasperLoader does NOT delegate to its parent if it cannot find them.
  +     * @param ct
  +     *            the javassist class
  +     * @param loader
  +     *            the loader
  +     * @throws CannotCompileException
  +     *             for any error
  +     */
  +    public Class toClass(CtClass ct, ClassLoader loader)
  +            throws CannotCompileException {
  +        // We need to pass up the classloader stored in this pool, as the
  +        // default implementation uses the Thread context cl.
  +        // In the case of JSP's in Tomcat,
  +        // org.apache.jasper.servlet.JasperLoader will be stored here, while
  +        // it's parent
  +        // org.jboss.web.tomcat.tc5.WebCtxLoader$ENCLoader is used as the Thread
  +        // context cl. The invocation class needs to
  +        // be generated in the JasperLoader classloader since in the case of
  +        // method invocations, the package name will be
  +        // the same as for the class generated from the jsp, i.e.
  +        // org.apache.jsp. For classes belonging to org.apache.jsp,
  +        // JasperLoader does NOT delegate to its parent if it cannot find them.
         lockInCache(ct);
         return super.toClass(ct, getClassLoader0());
      }
  
  
  
  1.3       +87 -78    javassist/src/main/javassist/scopedpool/ScopedClassPoolRepository.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ScopedClassPoolRepository.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/scopedpool/ScopedClassPoolRepository.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- ScopedClassPoolRepository.java	13 Jul 2006 10:04:51 -0000	1.2
  +++ ScopedClassPoolRepository.java	18 Jul 2006 14:46:25 -0000	1.3
  @@ -1,18 +1,18 @@
   /*
  -* Javassist, a Java-bytecode translator toolkit.
  -* Copyright (C) 2006 JBoss Inc., All Rights Reserved.
  -*
  -* The contents of this file are subject to the Mozilla Public License Version
  -* 1.1 (the "License"); you may not use this file except in compliance with
  -* the License.  Alternatively, the contents of this file may be used under
  -* the terms of the GNU Lesser General Public License Version 2.1 or later.
  -*
  -* Software distributed under the License is distributed on an "AS IS"  
  -basis,
  -* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  -* for the specific language governing rights and limitations under the
  -* License.
  -*/
  + * Javassist, a Java-bytecode translator toolkit.
  + * Copyright (C) 2006 JBoss Inc. All Rights Reserved.
  + *
  + * The contents of this file are subject to the Mozilla Public License Version
  + * 1.1 (the "License"); you may not use this file except in compliance with
  + * the License.  Alternatively, the contents of this file may be used under
  + * the terms of the GNU Lesser General Public License Version 2.1 or later.
  + *
  + * Software distributed under the License is distributed on an "AS IS" basis,
  + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  + * for the specific language governing rights and limitations under the
  + * License.
  + */
  +
   package javassist.scopedpool;
   
   import java.util.Map;
  @@ -20,69 +20,78 @@
   import javassist.ClassPool;
   
   /**
  + * An interface to <code>ScopedClassPoolRepositoryImpl</code>.
    * 
    * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
  + */
  +public interface ScopedClassPoolRepository {
  +    /**
  +     * Records a factory.
    */
  -public interface ScopedClassPoolRepository
  -{
      void setClassPoolFactory(ScopedClassPoolFactory factory);
      
  +    /**
  +     * Obtains the recorded factory.
  +     */
      ScopedClassPoolFactory getClassPoolFactory();
   
      /**
  -    * Get the prune.
  +     * Returns whether or not the class pool is pruned.
       * 
       * @return the prune.
       */
      boolean isPrune();
   
      /**
  -    * Set the prune.
  +     * Sets the prune flag.
       * 
  -    * @param prune the prune.
  +     * @param prune     a new value.
       */
      void setPrune(boolean prune);
      
      /**
  -    * Create a scoped classpool
  +     * Create a scoped classpool.
       * 
  -    * @param cl the classloader
  -    * @param src the original classpool
  -    * @return the classpool
  +     * @param cl    the classloader.
  +     * @param src   the original classpool.
  +     * @return the classpool.
       */
      ScopedClassPool createScopedClassPool(ClassLoader cl, ClassPool src);
   
      /**
  -    * Finds a scoped classpool registered under the passed in classloader
  -    * @param the classloader
  -    * @return the classpool
  +     * Finds a scoped classpool registered under the passed in classloader.
  +     * 
  +     * @param cl    the classloader.
  +     * @return the classpool.
       */
      ClassPool findClassPool(ClassLoader cl);
   
      /**
  -    * Register a classloader
  +     * Register a classloader.
       * 
  -    * @param ucl the classloader
  -    * @return the classpool
  +     * @param ucl   the classloader.
  +     * @return the classpool.
       */
      ClassPool registerClassLoader(ClassLoader ucl);
   
      /**
  -    * Get the registered classloaders
  +     * Get the registered classloaders.
       * 
  -    * @return the registered classloaders
  +     * @return the registered classloaders.
       */
      Map getRegisteredCLs();
   
      /**
  -    * This method will check to see if a register classloader has been undeployed (as in JBoss)
  +     * This method will check to see if a register classloader has been
  +     * undeployed (as in JBoss).
       */
      void clearUnregisteredClassLoaders();
   
      /**
       * Unregisters a classpool and unregisters its classloader.
  -    * @ClassLoader the classloader the pool is stored under
  +     * 
  +     * @param cl    the classloader the pool is stored under.
       */
      void unregisterClassLoader(ClassLoader cl);
   }
  \ No newline at end of file
  
  
  
  1.3       +29 -21    javassist/src/main/javassist/scopedpool/ScopedClassPoolFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ScopedClassPoolFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/scopedpool/ScopedClassPoolFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- ScopedClassPoolFactory.java	13 Jul 2006 10:04:51 -0000	1.2
  +++ ScopedClassPoolFactory.java	18 Jul 2006 14:46:25 -0000	1.3
  @@ -1,30 +1,38 @@
   /*
  -* Javassist, a Java-bytecode translator toolkit.
  -* Copyright (C) 2006 JBoss Inc., All Rights Reserved.
  -*
  -* The contents of this file are subject to the Mozilla Public License Version
  -* 1.1 (the "License"); you may not use this file except in compliance with
  -* the License.  Alternatively, the contents of this file may be used under
  -* the terms of the GNU Lesser General Public License Version 2.1 or later.
  -*
  -* Software distributed under the License is distributed on an "AS IS"  
  -basis,
  -* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  -* for the specific language governing rights and limitations under the
  -* License.
  -*/
  + * Javassist, a Java-bytecode translator toolkit.
  + * Copyright (C) 2006 JBoss Inc. All Rights Reserved.
  + *
  + * The contents of this file are subject to the Mozilla Public License Version
  + * 1.1 (the "License"); you may not use this file except in compliance with
  + * the License.  Alternatively, the contents of this file may be used under
  + * the terms of the GNU Lesser General Public License Version 2.1 or later.
  + *
  + * Software distributed under the License is distributed on an "AS IS" basis,
  + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  + * for the specific language governing rights and limitations under the
  + * License.
  + */
  +
   package javassist.scopedpool;
   
   import javassist.ClassPool;
   
   /**
  + * A factory interface.
    * 
    * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
  + */
  +public interface ScopedClassPoolFactory {
  +    /**
  +     * Makes an instance.
    */
  -public interface ScopedClassPoolFactory
  -{
  -   ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository);
  +    ScopedClassPool create(ClassLoader cl, ClassPool src,
  +                           ScopedClassPoolRepository repository);
      
  -   ScopedClassPool create(ClassPool src, ScopedClassPoolRepository repository);
  +    /**
  +     * Makes an instance.
  +     */
  +    ScopedClassPool create(ClassPool src,
  +                           ScopedClassPoolRepository repository);
   }
  
  
  
  1.3       +169 -188  javassist/src/main/javassist/scopedpool/ScopedClassPoolRepositoryImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ScopedClassPoolRepositoryImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/scopedpool/ScopedClassPoolRepositoryImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- ScopedClassPoolRepositoryImpl.java	13 Jul 2006 10:04:51 -0000	1.2
  +++ ScopedClassPoolRepositoryImpl.java	18 Jul 2006 14:46:25 -0000	1.3
  @@ -1,18 +1,18 @@
   /*
  -* Javassist, a Java-bytecode translator toolkit.
  -* Copyright (C) 2006 JBoss Inc., All Rights Reserved.
  -*
  -* The contents of this file are subject to the Mozilla Public License Version
  -* 1.1 (the "License"); you may not use this file except in compliance with
  -* the License.  Alternatively, the contents of this file may be used under
  -* the terms of the GNU Lesser General Public License Version 2.1 or later.
  -*
  -* Software distributed under the License is distributed on an "AS IS"  
  -basis,
  -* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  -* for the specific language governing rights and limitations under the
  -* License.
  -*/
  + * Javassist, a Java-bytecode translator toolkit.
  + * Copyright (C) 2006 JBoss Inc. All Rights Reserved.
  + *
  + * The contents of this file are subject to the Mozilla Public License Version
  + * 1.1 (the "License"); you may not use this file except in compliance with
  + * the License.  Alternatively, the contents of this file may be used under
  + * the terms of the GNU Lesser General Public License Version 2.1 or later.
  + *
  + * Software distributed under the License is distributed on an "AS IS" basis,
  + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  + * for the specific language governing rights and limitations under the
  + * License.
  + */
  +
   package javassist.scopedpool;
   
   import java.util.ArrayList;
  @@ -25,12 +25,13 @@
   import javassist.LoaderClassPath;
   
   /**
  + * An implementation of <code>ScopedClassPoolRepository</code>.
  + * It is an singleton.
    * 
    * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
  -public class ScopedClassPoolRepositoryImpl implements ScopedClassPoolRepository
  -{
  +public class ScopedClassPoolRepositoryImpl implements ScopedClassPoolRepository {
      /** The instance */
      private static final ScopedClassPoolRepositoryImpl instance = new ScopedClassPoolRepositoryImpl();
   
  @@ -41,7 +42,8 @@
      boolean pruneWhenCached;
   
      /** The registered classloaders */
  -   protected Map registeredCLs = Collections.synchronizedMap(new WeakHashMap());
  +    protected Map registeredCLs = Collections
  +            .synchronizedMap(new WeakHashMap());
      
      /** The default class pool */
      protected ClassPool classpool;
  @@ -50,20 +52,18 @@
      protected ScopedClassPoolFactory factory = new ScopedClassPoolFactoryImpl();
   
      /**
  -    * Get the instance
  +     * Get the instance.
       * 
  -    * @return the instance
  +     * @return the instance.
       */
  -   public static ScopedClassPoolRepository getInstance()
  -   {
  +    public static ScopedClassPoolRepository getInstance() {
         return instance;
      }
   
      /**
  -    * Singleton
  +     * Singleton.
       */
  -   private ScopedClassPoolRepositoryImpl()
  -   {
  +    private ScopedClassPoolRepositoryImpl() {
         classpool = ClassPool.getDefault();
         // FIXME This doesn't look correct 
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
  @@ -71,61 +71,56 @@
      }
      
      /**
  -    * Get the prune.
  +     * Returns the value of the prune attribute.
       * 
       * @return the prune.
       */
  -   public boolean isPrune()
  -   {
  +    public boolean isPrune() {
         return prune;
      }
   
      /**
  -    * Set the prune.
  +     * Set the prune attribute.
       * 
  -    * @param prune the prune.
  +     * @param prune     a new value.
       */
  -   public void setPrune(boolean prune)
  -   {
  +    public void setPrune(boolean prune) {
         this.prune = prune;
      }
   
      /**
  -    * Create a scoped classpool
  +     * Create a scoped classpool.
       * 
  -    * @param cl the classloader
  -    * @param src the original classpool
  +     * @param cl    the classloader.
  +     * @param src   the original classpool.
       * @return the classpool
       */
  -   public ScopedClassPool createScopedClassPool(ClassLoader cl, ClassPool src)
  -   {
  +    public ScopedClassPool createScopedClassPool(ClassLoader cl, ClassPool src) {
         return factory.create(cl, src, this);
      }
   
  -   public ClassPool findClassPool(ClassLoader cl)
  -   {
  +    public ClassPool findClassPool(ClassLoader cl) {
         if (cl == null)
            return registerClassLoader(ClassLoader.getSystemClassLoader());
  +
         return registerClassLoader(cl);
      }
   
      /**
  -    * Register a classloader
  +     * Register a classloader.
       * 
  -    * @param ucl the classloader
  +     * @param ucl       the classloader.
       * @return the classpool
       */
  -   public ClassPool registerClassLoader(ClassLoader ucl)
  -   {
  -      synchronized (registeredCLs)
  -      {
  +    public ClassPool registerClassLoader(ClassLoader ucl) {
  +        synchronized (registeredCLs) {
            // FIXME: Probably want to take this method out later
            // so that AOP framework can be independent of JMX
  -         // This is in here so that we can remove a UCL from the ClassPool as a
  +            // This is in here so that we can remove a UCL from the ClassPool as
  +            // a
            // ClassPool.classpath
  -         if (registeredCLs.containsKey(ucl))
  -         {
  -            return (ClassPool) registeredCLs.get(ucl);
  +            if (registeredCLs.containsKey(ucl)) {
  +                return (ClassPool)registeredCLs.get(ucl);
            }
            ScopedClassPool pool = createScopedClassPool(ucl, classpool);
            registeredCLs.put(ucl, pool);
  @@ -134,73 +129,59 @@
      }
   
      /**
  -    * Get the registered classloaders
  -    * 
  -    * @return the registered classloaders
  +     * Get the registered classloaders.
       */
  -   public Map getRegisteredCLs()
  -   {
  +    public Map getRegisteredCLs() {
         clearUnregisteredClassLoaders();
         return registeredCLs;
      }
   
      /**
  -    * This method will check to see if a register classloader has been undeployed (as in JBoss)
  +     * This method will check to see if a register classloader has been
  +     * undeployed (as in JBoss)
       */
  -   public void clearUnregisteredClassLoaders()
  -   {
  +    public void clearUnregisteredClassLoaders() {
         ArrayList toUnregister = null;
  -      synchronized (registeredCLs)
  -      {
  +        synchronized (registeredCLs) {
            Iterator it = registeredCLs.values().iterator();
  -         while (it.hasNext())
  -         {
  -            ScopedClassPool pool = (ScopedClassPool) it.next();
  -            if (pool.isUnloadedClassLoader())
  -            {
  +            while (it.hasNext()) {
  +                ScopedClassPool pool = (ScopedClassPool)it.next();
  +                if (pool.isUnloadedClassLoader()) {
                  it.remove();
                  ClassLoader cl = pool.getClassLoader();
  -               if (cl != null)
  -               {
  -                  if (toUnregister == null)
  -                  {
  +                    if (cl != null) {
  +                        if (toUnregister == null) {
                        toUnregister = new ArrayList();
                     }
                     toUnregister.add(cl);
                  }
               }
            }
  -         if (toUnregister != null)
  -         {
  -            for (int i = 0; i < toUnregister.size(); i++)
  -            {
  -               unregisterClassLoader((ClassLoader) toUnregister.get(i));
  +            if (toUnregister != null) {
  +                for (int i = 0; i < toUnregister.size(); i++) {
  +                    unregisterClassLoader((ClassLoader)toUnregister.get(i));
               }
            }
         }
      }
   
  -   public void unregisterClassLoader(ClassLoader cl)
  -   {
  -      synchronized (registeredCLs)
  -      {
  -         ScopedClassPool pool = (ScopedClassPool) registeredCLs.remove(cl);
  -         if (pool != null) pool.close();
  +    public void unregisterClassLoader(ClassLoader cl) {
  +        synchronized (registeredCLs) {
  +            ScopedClassPool pool = (ScopedClassPool)registeredCLs.remove(cl);
  +            if (pool != null)
  +                pool.close();
         }
      }
   
  -   public void insertDelegate(ScopedClassPoolRepository delegate)
  -   {
  -      //Noop - this is the end
  +    public void insertDelegate(ScopedClassPoolRepository delegate) {
  +        // Noop - this is the end
      }
   
  -   public void setClassPoolFactory(ScopedClassPoolFactory factory)
  -   {
  +    public void setClassPoolFactory(ScopedClassPoolFactory factory) {
         this.factory = factory;
      }
      
  -   public ScopedClassPoolFactory getClassPoolFactory()
  -   {
  +    public ScopedClassPoolFactory getClassPoolFactory() {
         return factory;
      }
   }
  
  
  
  1.3       +219 -228  javassist/src/main/javassist/scopedpool/SoftValueHashMap.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SoftValueHashMap.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/scopedpool/SoftValueHashMap.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- SoftValueHashMap.java	13 Jul 2006 10:04:51 -0000	1.2
  +++ SoftValueHashMap.java	18 Jul 2006 14:46:25 -0000	1.3
  @@ -1,18 +1,18 @@
   /*
  -* Javassist, a Java-bytecode translator toolkit.
  -* Copyright (C) 2006 JBoss Inc., All Rights Reserved.
  -*
  -* The contents of this file are subject to the Mozilla Public License Version
  -* 1.1 (the "License"); you may not use this file except in compliance with
  -* the License.  Alternatively, the contents of this file may be used under
  -* the terms of the GNU Lesser General Public License Version 2.1 or later.
  -*
  -* Software distributed under the License is distributed on an "AS IS"  
  -basis,
  -* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  -* for the specific language governing rights and limitations under the
  -* License.
  -*/
  + * Javassist, a Java-bytecode translator toolkit.
  + * Copyright (C) 2006 JBoss Inc. All Rights Reserved.
  + *
  + * The contents of this file are subject to the Mozilla Public License Version
  + * 1.1 (the "License"); you may not use this file except in compliance with
  + * the License.  Alternatively, the contents of this file may be used under
  + * the terms of the GNU Lesser General Public License Version 2.1 or later.
  + *
  + * Software distributed under the License is distributed on an "AS IS" basis,
  + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  + * for the specific language governing rights and limitations under the
  + * License.
  + */
  +
   package javassist.scopedpool;
   
   import java.lang.ref.ReferenceQueue;
  @@ -22,37 +22,36 @@
   import java.util.Map;
   import java.util.Set;
   
  -
   /**
  - * This Map will remove entries when the value in the map has been
  - * cleaned from garbage collection
  + * This Map will remove entries when the value in the map has been cleaned from
  + * garbage collection
    *
  - * @version <tt>$Revision: 1.2 $</tt>
  + * @version <tt>$Revision: 1.3 $</tt>
    * @author  <a href="mailto:bill at jboss.org">Bill Burke</a>
    */
  -public class SoftValueHashMap
  -   extends AbstractMap
  -   implements Map 
  -{
  -   private static class SoftValueRef extends SoftReference
  -   {
  +public class SoftValueHashMap extends AbstractMap implements Map {
  +    private static class SoftValueRef extends SoftReference {
         public Object key;
   
  -      private SoftValueRef(Object key, Object val, ReferenceQueue q)
  -      {
  +        private SoftValueRef(Object key, Object val, ReferenceQueue q) {
            super(val, q);
            this.key = key;
         }
         
  -      private static SoftValueRef create(Object key, Object val, ReferenceQueue q)
  -      {
  -         if (val == null) return null;
  -         else return new SoftValueRef(key, val, q);
  +        private static SoftValueRef create(Object key, Object val,
  +                ReferenceQueue q) {
  +            if (val == null)
  +                return null;
  +            else
  +                return new SoftValueRef(key, val, q);
         }
         
      }
  -   public Set entrySet() 
  -   { 
  +
  +    /**
  +     * Returns a set of the mappings contained in this hash table.
  +     */
  +    public Set entrySet() {
         processQueue();
         return hash.entrySet();
      }
  @@ -63,14 +62,14 @@
      /* Reference queue for cleared WeakKeys */
      private ReferenceQueue queue = new ReferenceQueue();
      
  -   /* Remove all invalidated entries from the map, that is, remove all entries
  -      whose values have been discarded.  
  +    /*
  +     * Remove all invalidated entries from the map, that is, remove all entries
  +     * whose values have been discarded.
       */
  -   private void processQueue()
  -   {
  +    private void processQueue() {
         SoftValueRef ref;
         while ((ref = (SoftValueRef)queue.poll()) != null) {
  -         if (ref == (SoftValueRef) hash.get(ref.key)) {
  +            if (ref == (SoftValueRef)hash.get(ref.key)) {
               // only remove if it is the *exact* same WeakValueRef
               //
               hash.remove(ref.key);
  @@ -78,79 +77,71 @@
         }
      }
   
  -
      /* -- Constructors -- */
   
      /**
  -    * Constructs a new, empty <code>WeakHashMap</code> with the given
  -    * initial capacity and the given load factor.
  +     * Constructs a new, empty <code>WeakHashMap</code> with the given initial
  +     * capacity and the given load factor.
       *
  -    * @param  initialCapacity  The initial capacity of the
  -    *                          <code>WeakHashMap</code>
  +     * @param initialCapacity
  +     *            The initial capacity of the <code>WeakHashMap</code>
       *
  -    * @param  loadFactor       The load factor of the <code>WeakHashMap</code>
  +     * @param loadFactor
  +     *            The load factor of the <code>WeakHashMap</code>
       *
  -    * @throws IllegalArgumentException  If the initial capacity is less than
  -    *                                   zero, or if the load factor is
  -    *                                   nonpositive
  +     * @throws IllegalArgumentException
  +     *             If the initial capacity is less than zero, or if the load
  +     *             factor is nonpositive
       */
  -   public SoftValueHashMap(int initialCapacity, float loadFactor)
  -   {
  +    public SoftValueHashMap(int initialCapacity, float loadFactor) {
         hash = new HashMap(initialCapacity, loadFactor);
      }
   
      /**
  -    * Constructs a new, empty <code>WeakHashMap</code> with the given
  -    * initial capacity and the default load factor, which is
  -    * <code>0.75</code>.
  +     * Constructs a new, empty <code>WeakHashMap</code> with the given initial
  +     * capacity and the default load factor, which is <code>0.75</code>.
       *
  -    * @param  initialCapacity  The initial capacity of the
  -    *                          <code>WeakHashMap</code>
  +     * @param initialCapacity
  +     *            The initial capacity of the <code>WeakHashMap</code>
       *
  -    * @throws IllegalArgumentException  If the initial capacity is less than
  -    *                                   zero
  +     * @throws IllegalArgumentException
  +     *             If the initial capacity is less than zero
       */
  -   public SoftValueHashMap(int initialCapacity)
  -   {
  +    public SoftValueHashMap(int initialCapacity) {
         hash = new HashMap(initialCapacity);
      }
   
      /**
       * Constructs a new, empty <code>WeakHashMap</code> with the default
  -    * initial capacity and the default load factor, which is
  -    * <code>0.75</code>.
  +     * initial capacity and the default load factor, which is <code>0.75</code>.
       */
  -   public SoftValueHashMap()
  -   {
  +    public SoftValueHashMap() {
         hash = new HashMap();
      }
   
      /**
       * Constructs a new <code>WeakHashMap</code> with the same mappings as the
  -    * specified <tt>Map</tt>.  The <code>WeakHashMap</code> is created with an
  -    * initial capacity of twice the number of mappings in the specified map
  +     * specified <tt>Map</tt>. The <code>WeakHashMap</code> is created with
  +     * an initial capacity of twice the number of mappings in the specified map
       * or 11 (whichever is greater), and a default load factor, which is
       * <tt>0.75</tt>.
       *
       * @param   t the map whose mappings are to be placed in this map.
  -    * @since	1.3
       */
  -   public SoftValueHashMap(Map t)
  -   {
  -      this(Math.max(2*t.size(), 11), 0.75f);
  +    public SoftValueHashMap(Map t) {
  +        this(Math.max(2 * t.size(), 11), 0.75f);
         putAll(t);
      }
   
      /* -- Simple queries -- */
   
      /**
  -    * Returns the number of key-value mappings in this map.
  -    * <strong>Note:</strong> <em>In contrast with most implementations of the
  +     * Returns the number of key-value mappings in this map. <strong>Note:</strong>
  +     * <em>In contrast with most implementations of the
       * <code>Map</code> interface, the time required by this operation is
       * linear in the size of the map.</em>
       */
  -   public int size()
  -   {
  +    public int size() {
         processQueue();
         return hash.size();
      }
  @@ -158,8 +149,7 @@
      /**
       * Returns <code>true</code> if this map contains no key-value mappings.
       */
  -   public boolean isEmpty()
  -   {
  +    public boolean isEmpty() {
         processQueue();
         return hash.isEmpty();
      }
  @@ -168,10 +158,10 @@
       * Returns <code>true</code> if this map contains a mapping for the
       * specified key.
       *
  -    * @param   key   The key whose presence in this map is to be tested
  +     * @param key
  +     *            The key whose presence in this map is to be tested.
       */
  -   public boolean containsKey(Object key)
  -   {
  +    public boolean containsKey(Object key) {
         processQueue();
         return hash.containsKey(key);
      }
  @@ -183,35 +173,37 @@
       * If this map does not contain a value for this key, then return
       * <code>null</code>.
       *
  -    * @param  key  The key whose associated value, if any, is to be returned
  +     * @param key
  +     *            The key whose associated value, if any, is to be returned.
       */
  -   public Object get(Object key)
  -   {
  +    public Object get(Object key) {
         processQueue();
         SoftReference ref = (SoftReference)hash.get(key);
  -      if (ref != null) return ref.get();
  +        if (ref != null)
  +            return ref.get();
         return null;
      }
   
      /**
       * Updates this map so that the given <code>key</code> maps to the given
       * <code>value</code>.  If the map previously contained a mapping for
  -    * <code>key</code> then that mapping is replaced and the previous value is
  -    * returned.
  +     * <code>key</code> then that mapping is replaced and the previous value
  +     * is returned.
       *
  -    * @param  key    The key that is to be mapped to the given
  -    *                <code>value</code> 
  -    * @param  value  The value to which the given <code>key</code> is to be
  +     * @param key
  +     *            The key that is to be mapped to the given <code>value</code>
  +     * @param value
  +     *            The value to which the given <code>key</code> is to be
       *                mapped
       *
       * @return  The previous value to which this key was mapped, or
       *          <code>null</code> if if there was no mapping for the key
       */
  -   public Object put(Object key, Object value) 
  -   {
  +    public Object put(Object key, Object value) {
         processQueue();
         Object rtn = hash.put(key, SoftValueRef.create(key, value, queue));
  -      if (rtn != null) rtn = ((SoftReference)rtn).get();
  +        if (rtn != null)
  +            rtn = ((SoftReference)rtn).get();
         return rtn;
      }
   
  @@ -219,13 +211,13 @@
       * Removes the mapping for the given <code>key</code> from this map, if
       * present.
       *
  -    * @param  key  The key whose mapping is to be removed
  +     * @param key
  +     *            The key whose mapping is to be removed.
       *
       * @return  The value to which this key was mapped, or <code>null</code> if
  -    *          there was no mapping for the key
  +     *         there was no mapping for the key.
       */
  -   public Object remove(Object key) 
  -   {
  +    public Object remove(Object key) {
         processQueue();
         return hash.remove(key);
      }
  @@ -233,8 +225,7 @@
      /**
       * Removes all mappings from this map.
       */
  -   public void clear()
  -   {
  +    public void clear() {
         processQueue();
         hash.clear();
      }
  
  
  
  1.3       +32 -27    javassist/src/main/javassist/scopedpool/ScopedClassPoolFactoryImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ScopedClassPoolFactoryImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/scopedpool/ScopedClassPoolFactoryImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- ScopedClassPoolFactoryImpl.java	13 Jul 2006 10:04:51 -0000	1.2
  +++ ScopedClassPoolFactoryImpl.java	18 Jul 2006 14:46:25 -0000	1.3
  @@ -1,37 +1,42 @@
   /*
  -* Javassist, a Java-bytecode translator toolkit.
  -* Copyright (C) 2006 JBoss Inc., All Rights Reserved.
  -*
  -* The contents of this file are subject to the Mozilla Public License Version
  -* 1.1 (the "License"); you may not use this file except in compliance with
  -* the License.  Alternatively, the contents of this file may be used under
  -* the terms of the GNU Lesser General Public License Version 2.1 or later.
  -*
  -* Software distributed under the License is distributed on an "AS IS"  
  -basis,
  -* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  -* for the specific language governing rights and limitations under the
  -* License.
  -*/
  + * Javassist, a Java-bytecode translator toolkit.
  + * Copyright (C) 2006 JBoss Inc. All Rights Reserved.
  + *
  + * The contents of this file are subject to the Mozilla Public License Version
  + * 1.1 (the "License"); you may not use this file except in compliance with
  + * the License.  Alternatively, the contents of this file may be used under
  + * the terms of the GNU Lesser General Public License Version 2.1 or later.
  + *
  + * Software distributed under the License is distributed on an "AS IS" basis,
  + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  + * for the specific language governing rights and limitations under the
  + * License.
  + */
  +
   package javassist.scopedpool;
   
   import javassist.ClassPool;
   
  -
   /**
  + * An implementation of factory.
    * 
    * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
  + */
  +public class ScopedClassPoolFactoryImpl implements ScopedClassPoolFactory {
  +    /**
  +     * Makes an instance.
    */
  -public class ScopedClassPoolFactoryImpl implements ScopedClassPoolFactory
  -{
  -   public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
  -   {
  +    public ScopedClassPool create(ClassLoader cl, ClassPool src,
  +                                  ScopedClassPoolRepository repository) {
         return new ScopedClassPool(cl, src, repository);
      }
   
  -   public ScopedClassPool create(ClassPool src, ScopedClassPoolRepository repository)
  -   {
  +    /**
  +     * Makes an instance.
  +     */
  +    public ScopedClassPool create(ClassPool src,
  +                                  ScopedClassPoolRepository repository) {
         return new ScopedClassPool(null, src, repository);
      }   
   }
  
  
  
  1.1      date: 2006/07/18 14:46:25;  author: chiba;  state: Exp;javassist/src/main/javassist/scopedpool/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <body>
  <p>A custom class pool for several JBoss products.
  It is not part of Javassist.
  </p>
  </body>
  </html>
  
  
  



More information about the jboss-cvs-commits mailing list