hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-hivemind/framework/src/java/org/apache/hivemind/service ClassFactory.java
Date Tue, 07 Sep 2004 19:38:28 GMT
hlship      2004/09/07 12:38:28

  Modified:    library/src/test/org/apache/hivemind/lib/pipeline Tag:
                        branch-1-0 TestPipelineAssembler.java
                        TestBridgeBuilder.java
               framework/src/java/org/apache/hivemind/service/impl Tag:
                        branch-1-0 ClassFactoryImpl.java
                        LoggingInterceptorFactory.java
               library/src/java/org/apache/hivemind/lib/impl Tag:
                        branch-1-0 EJBProxyFactory.java
                        ServicePropertyFactory.java
                        DefaultImplementationBuilderImpl.java
               framework/src/java/org/apache/hivemind/impl Tag: branch-1-0
                        ProxyBuilder.java
               library/src/test/hivemind/test/lib Tag: branch-1-0
                        TestDefaultImplementationBuilder.java
               .        Tag: branch-1-0 status.xml
               library/src/test/org/apache/hivemind/lib/impl Tag:
                        branch-1-0 TestServicePropertyFactory.java
               library/src/java/org/apache/hivemind/lib/pipeline Tag:
                        branch-1-0 BridgeBuilder.java
               framework/src/java/org/apache/hivemind/service Tag:
                        branch-1-0 ClassFactory.java
  Log:
  Change the API for ClassFactory to take a ClassLoader, not a Module.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.6.2.1   +15 -32    jakarta-hivemind/library/src/test/org/apache/hivemind/lib/pipeline/TestPipelineAssembler.java
  
  Index: TestPipelineAssembler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/library/src/test/org/apache/hivemind/lib/pipeline/TestPipelineAssembler.java,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- TestPipelineAssembler.java	18 Aug 2004 19:34:12 -0000	1.6
  +++ TestPipelineAssembler.java	7 Sep 2004 19:38:27 -0000	1.6.2.1
  @@ -179,14 +179,7 @@
   
           dib.setClassFactory(cf);
   
  -        MockControl moduleControl = newControl(Module.class);
  -        Module module = (Module) moduleControl.getMock();
  -
  -        module.getModuleId();
  -        moduleControl.setReturnValue("foo.bar");
  -
  -        module.getClassResolver();
  -        moduleControl.setReturnValue(new DefaultClassResolver());
  +        Module module = newModule();
   
           ErrorHandler eh = getErrorHandler();
           Log log = getLog();
  @@ -218,14 +211,7 @@
   
           dib.setClassFactory(cf);
   
  -        MockControl moduleControl = newControl(Module.class);
  -        Module module = (Module) moduleControl.getMock();
  -
  -        module.getModuleId();
  -        moduleControl.setReturnValue("foo.bar");
  -
  -        module.getClassResolver();
  -        moduleControl.setReturnValue(new DefaultClassResolver());
  +        Module module = newModule();
   
           PipelineAssembler pa =
               new PipelineAssembler(
  @@ -286,14 +272,7 @@
   
           dib.setClassFactory(cf);
   
  -        MockControl moduleControl = newControl(Module.class);
  -        Module module = (Module) moduleControl.getMock();
  -
  -        module.getModuleId();
  -        moduleControl.setReturnValue("foo.bar");
  -
  -        module.getClassResolver();
  -        moduleControl.setReturnValue(new DefaultClassResolver());
  +        Module module = newModule();
   
           PipelineFactory factory = new PipelineFactory();
           factory.setClassFactory(cf);
  @@ -337,14 +316,7 @@
   
           dib.setClassFactory(cf);
   
  -        MockControl moduleControl = newControl(Module.class);
  -        Module module = (Module) moduleControl.getMock();
  -
  -        module.getModuleId();
  -        moduleControl.setReturnValue("foo.bar");
  -
  -        module.getClassResolver();
  -        moduleControl.setReturnValue(new DefaultClassResolver());
  +        Module module = newModule();
   
           PipelineFactory factory = new PipelineFactory();
           factory.setClassFactory(cf);
  @@ -383,6 +355,17 @@
           assertEquals(18, s.run(9));
   
           verifyControls();
  +    }
  +
  +    private Module newModule()
  +    {
  +        MockControl control = newControl(Module.class);
  +        Module result = (Module) control.getMock();
  +
  +        result.getClassResolver();
  +        control.setReturnValue(new DefaultClassResolver());
  +
  +        return result;
       }
   
       /**
  
  
  
  1.3.2.1   +0 -3      jakarta-hivemind/library/src/test/org/apache/hivemind/lib/pipeline/TestBridgeBuilder.java
  
  Index: TestBridgeBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/library/src/test/org/apache/hivemind/lib/pipeline/TestBridgeBuilder.java,v
  retrieving revision 1.3
  retrieving revision 1.3.2.1
  diff -u -r1.3 -r1.3.2.1
  --- TestBridgeBuilder.java	29 Jul 2004 13:18:52 -0000	1.3
  +++ TestBridgeBuilder.java	7 Sep 2004 19:38:27 -0000	1.3.2.1
  @@ -39,9 +39,6 @@
           MockControl control = newControl(Module.class);
           Module result = (Module) control.getMock();
   
  -        result.getModuleId();
  -        control.setReturnValue("foo.bar");
  -
           result.getClassResolver();
           control.setReturnValue(new DefaultClassResolver());
   
  
  
  
  No                   revision
  No                   revision
  1.6.2.2   +19 -29    jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/ClassFactoryImpl.java
  
  Index: ClassFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/ClassFactoryImpl.java,v
  retrieving revision 1.6.2.1
  retrieving revision 1.6.2.2
  diff -u -r1.6.2.1 -r1.6.2.2
  --- ClassFactoryImpl.java	4 Sep 2004 14:38:49 -0000	1.6.2.1
  +++ ClassFactoryImpl.java	7 Sep 2004 19:38:27 -0000	1.6.2.2
  @@ -14,13 +14,12 @@
   
   package org.apache.hivemind.service.impl;
   
  -import java.util.HashMap;
  -import java.util.Map;
  +import java.util.HashSet;
  +import java.util.Set;
   
   import javassist.CtClass;
   
   import org.apache.hivemind.ApplicationRuntimeException;
  -import org.apache.hivemind.internal.Module;
   import org.apache.hivemind.service.ClassFab;
   import org.apache.hivemind.service.ClassFactory;
   
  @@ -32,24 +31,22 @@
   public class ClassFactoryImpl implements ClassFactory
   {
       /**
  -     * Map of CtClassSource, keyed on module id.
  -     */
  -    private Map _ctClassSourceMap = new HashMap();
  -
  -    /**
        * ClassPool shared by all modules (all CtClassSource instances).
        */
       private HiveMindClassPool _pool = new HiveMindClassPool();
  +    private CtClassSource _classSource = new CtClassSource(_pool);
  +
  +    private Set _addedClassLoaders = new HashSet();
   
  -    public ClassFab newClass(String name, Class superClass, Module module)
  +    public ClassFab newClass(String name, Class superClass, ClassLoader loader)
       {
  -        CtClassSource source = findCtClassSource(module);
  +        updateSourceForClassLoader(loader);
   
           try
           {
  -            CtClass ctNewClass = source.newClass(name, superClass);
  +            CtClass ctNewClass = _classSource.newClass(name, superClass);
   
  -            return new ClassFabImpl(source, ctNewClass);
  +            return new ClassFabImpl(_classSource, ctNewClass);
           }
           catch (Exception ex)
           {
  @@ -57,27 +54,20 @@
                   ServiceMessages.unableToCreateClass(name, superClass, ex),
                   ex);
           }
  -
       }
   
  -    private synchronized CtClassSource findCtClassSource(Module module)
  +    /**
  +     * Whenever a new class loader is encountered (which is, actually, 
  +     * fairly rare), update the pool (and, indirectly, the class source)
  +     * to search it as well.
  +     */
  +    private synchronized void updateSourceForClassLoader(ClassLoader loader)
       {
  -        String id = module.getModuleId();
  +        if (_addedClassLoaders.contains(loader))
  +            return;
   
  -        CtClassSource result = (CtClassSource) _ctClassSourceMap.get(id);
  +        _pool.appendClassLoader(loader);
   
  -        if (result == null)
  -        {
  -            ClassLoader moduleLoader = module.getClassResolver().getClassLoader();
  -
  -            _pool.appendClassLoader(moduleLoader);
  -
  -            result = new CtClassSource(_pool);
  -
  -            _ctClassSourceMap.put(id, result);
  -        }
  -
  -        return result;
  +        _addedClassLoaders.add(loader);
       }
  -
   }
  
  
  
  1.8.2.1   +2 -3      jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java
  
  Index: LoggingInterceptorFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.8.2.1
  diff -u -r1.8 -r1.8.2.1
  --- LoggingInterceptorFactory.java	18 Aug 2004 19:34:11 -0000	1.8
  +++ LoggingInterceptorFactory.java	7 Sep 2004 19:38:27 -0000	1.8.2.1
  @@ -210,7 +210,8 @@
   
           String name = ClassFabUtils.generateClassName("Interceptor");
   
  -        ClassFab classFab = _factory.newClass(name, Object.class, module);
  +        ClassFab classFab =
  +            _factory.newClass(name, Object.class, module.getClassResolver().getClassLoader());
   
           classFab.addInterface(serviceInterfaceClass);
   
  @@ -272,8 +273,6 @@
                   ex);
           }
       }
  -
  -
   
       private boolean includeMethod(MethodMatcher matcher, MethodSignature sig)
       {
  
  
  
  No                   revision
  No                   revision
  1.8.2.1   +4 -1      jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/EJBProxyFactory.java
  
  Index: EJBProxyFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/EJBProxyFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.8.2.1
  diff -u -r1.8 -r1.8.2.1
  --- EJBProxyFactory.java	18 Aug 2004 23:20:11 -0000	1.8
  +++ EJBProxyFactory.java	7 Sep 2004 19:38:27 -0000	1.8.2.1
  @@ -70,7 +70,10 @@
           String proxyClassName = ClassFabUtils.generateClassName("EJBProxy");
   
           ClassFab classFab =
  -            _classFactory.newClass(proxyClassName, AbstractEJBProxy.class, invokingModule);
  +            _classFactory.newClass(
  +                proxyClassName,
  +                AbstractEJBProxy.class,
  +                invokingModule.getClassResolver().getClassLoader());
   
           classFab.addInterface(serviceInterface);
   
  
  
  
  1.4.2.1   +5 -1      jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java
  
  Index: ServicePropertyFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- ServicePropertyFactory.java	31 Aug 2004 20:02:14 -0000	1.4
  +++ ServicePropertyFactory.java	7 Sep 2004 19:38:27 -0000	1.4.2.1
  @@ -80,7 +80,11 @@
   
           String name = ClassFabUtils.generateClassName("ServicePropertyProxy");
   
  -        ClassFab cf = _classFactory.newClass(name, Object.class, invokingModule);
  +        ClassFab cf =
  +            _classFactory.newClass(
  +                name,
  +                Object.class,
  +                invokingModule.getClassResolver().getClassLoader());
   
           addInfrastructure(cf, targetService, serviceInterface, propertyName, readMethodName);
   
  
  
  
  1.3.2.1   +1 -1      jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/DefaultImplementationBuilderImpl.java
  
  Index: DefaultImplementationBuilderImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/DefaultImplementationBuilderImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.3.2.1
  diff -u -r1.3 -r1.3.2.1
  --- DefaultImplementationBuilderImpl.java	12 Jun 2004 18:43:41 -0000	1.3
  +++ DefaultImplementationBuilderImpl.java	7 Sep 2004 19:38:27 -0000	1.3.2.1
  @@ -78,7 +78,7 @@
   
           String name = ClassFabUtils.generateClassName("DefaultImpl");
   
  -        ClassFab cf = _classFactory.newClass(name, Object.class, module);
  +        ClassFab cf = _classFactory.newClass(name, Object.class, module.getClassResolver().getClassLoader());
   
           cf.addInterface(interfaceType);
   
  
  
  
  No                   revision
  No                   revision
  1.5.2.1   +7 -3      jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ProxyBuilder.java
  
  Index: ProxyBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ProxyBuilder.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- ProxyBuilder.java	25 Jun 2004 20:19:59 -0000	1.5
  +++ ProxyBuilder.java	7 Sep 2004 19:38:27 -0000	1.5.2.1
  @@ -53,7 +53,11 @@
           ClassFactory factory =
               (ClassFactory) module.getService("hivemind.ClassFactory", ClassFactory.class);
   
  -        _classFab = factory.newClass(ClassFabUtils.generateClassName(type), Object.class,
module);
  +        _classFab =
  +            factory.newClass(
  +                ClassFabUtils.generateClassName(type),
  +                Object.class,
  +                module.getClassResolver().getClassLoader());
   
           _classFab.addInterface(_serviceInterface);
       }
  @@ -76,8 +80,8 @@
           Method[] methods = _serviceInterface.getMethods();
           for (int i = 0; i < methods.length; i++)
           {
  -        	Method m = methods[i];
  -        	
  +            Method m = methods[i];
  +
               builder.clear();
               builder.begin();
               builder.add("return ($r) ");
  
  
  
  No                   revision
  No                   revision
  1.7.2.1   +0 -3      jakarta-hivemind/library/src/test/hivemind/test/lib/TestDefaultImplementationBuilder.java
  
  Index: TestDefaultImplementationBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/library/src/test/hivemind/test/lib/TestDefaultImplementationBuilder.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- TestDefaultImplementationBuilder.java	19 Aug 2004 22:24:01 -0000	1.7
  +++ TestDefaultImplementationBuilder.java	7 Sep 2004 19:38:27 -0000	1.7.2.1
  @@ -53,9 +53,6 @@
           MockControl c = newControl(Module.class);
           _module = (Module) c.getMock();
   
  -        _module.getModuleId();
  -        c.setReturnValue("some.id");
  -
           _module.getClassResolver();
           c.setReturnValue(new DefaultClassResolver());
   
  
  
  
  No                   revision
  No                   revision
  1.57.2.5  +3 -0      jakarta-hivemind/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/status.xml,v
  retrieving revision 1.57.2.4
  retrieving revision 1.57.2.5
  diff -u -r1.57.2.4 -r1.57.2.5
  --- status.xml	7 Sep 2004 13:17:20 -0000	1.57.2.4
  +++ status.xml	7 Sep 2004 19:38:28 -0000	1.57.2.5
  @@ -52,6 +52,9 @@
         <action type="add" dev="HLS">
           Add <code>clearCache()</code> method to <code>PropertyUtils</code>.
         </action>
  +      <action type="update" dev="HLS">
  +        Change the API for <code>ClassFactory</code> to take a <code>ClassLoader</code>,
not a <code>Module</code>.
  +      </action>
       </release>
     
       <release version="1.0-rc-1" date="Aug 25 2004">
  
  
  
  No                   revision
  No                   revision
  1.3.2.1   +0 -3      jakarta-hivemind/library/src/test/org/apache/hivemind/lib/impl/TestServicePropertyFactory.java
  
  Index: TestServicePropertyFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/library/src/test/org/apache/hivemind/lib/impl/TestServicePropertyFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.3.2.1
  diff -u -r1.3 -r1.3.2.1
  --- TestServicePropertyFactory.java	31 Aug 2004 20:02:14 -0000	1.3
  +++ TestServicePropertyFactory.java	7 Sep 2004 19:38:28 -0000	1.3.2.1
  @@ -47,9 +47,6 @@
           MockControl c = newControl(Module.class);
           Module result = (Module) c.getMock();
   
  -        result.getModuleId();
  -        c.setReturnValue("test.module");
  -
           result.getClassResolver();
           c.setReturnValue(new DefaultClassResolver());
   
  
  
  
  No                   revision
  No                   revision
  1.2.2.1   +1 -1      jakarta-hivemind/library/src/java/org/apache/hivemind/lib/pipeline/BridgeBuilder.java
  
  Index: BridgeBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/pipeline/BridgeBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- BridgeBuilder.java	12 Jun 2004 18:43:41 -0000	1.2
  +++ BridgeBuilder.java	7 Sep 2004 19:38:28 -0000	1.2.2.1
  @@ -63,7 +63,7 @@
   
           String name = ClassFabUtils.generateClassName("PipelineBridge");
   
  -        _classFab = classFactory.newClass(name, Object.class, module);
  +        _classFab = classFactory.newClass(name, Object.class, module.getClassResolver().getClassLoader());
   
           _filterMethodAnalyzer = new FilterMethodAnalyzer(serviceInterface);
       }
  
  
  
  No                   revision
  No                   revision
  1.3.2.1   +6 -3      jakarta-hivemind/framework/src/java/org/apache/hivemind/service/ClassFactory.java
  
  Index: ClassFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/ClassFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.3.2.1
  diff -u -r1.3 -r1.3.2.1
  --- ClassFactory.java	17 Jun 2004 15:16:14 -0000	1.3
  +++ ClassFactory.java	7 Sep 2004 19:38:28 -0000	1.3.2.1
  @@ -14,8 +14,6 @@
   
   package org.apache.hivemind.service;
   
  -import org.apache.hivemind.internal.Module;
  -
   /**
    * Service used when dynamically creating new classes.
    *
  @@ -27,7 +25,12 @@
   	 * Creates a {@link ClassFab} object for the given name; the new class
   	 * is a subclass of the indicated class.  The new class
   	 * is public and concrete.
  +	 * 
  +	 * @param name the full qualified name of the class to create
  +	 * @param superClass the parent class, which is often java.lang.Object
  +	 * @param classLoader the class loader to use when resolving classes (this is usually
  +	 * provided by the containing {@link org.apache.hivemind.internal.Module}.
   	 */
   	
  -	public ClassFab newClass(String name, Class superClass, Module module);
  +	public ClassFab newClass(String name, Class superClass, ClassLoader classLoader);
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message