tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r652417 - in /tapestry/tapestry5/trunk: tapestry-core/src/main/java/org/apache/tapestry/internal/services/ tapestry-core/src/test/java/org/apache/tapestry/internal/services/ tapestry-core/src/test/java/org/apache/tapestry/internal/transform...
Date Thu, 01 May 2008 01:24:18 GMT
Author: hlship
Date: Wed Apr 30 18:24:18 2008
New Revision: 652417

URL: http://svn.apache.org/viewvc?rev=652417&view=rev
Log:
TAPESTRY-2398: ClassTransformation.addInjectedField() adds fields as protected which can cause exceptions due to visibility
TAPESTRY-2400: Advising a method where the parameter type or return type is the class containing the advised method may throw a java.lang.VerifyError

Added:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSource.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSourceImpl.java   (contents, props changed)
      - copied, changed from r647587, tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSource.java
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformerImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentInstantiatorSource.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentInstantiatorSourceImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InvocationBuilder.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/InternalClassTransformationImplTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/ApplicationStateWorkerTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/ParameterWorkerTest.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/AbstractFab.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFabImpl.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFactoryImpl.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/services/ClassFabImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformerImpl.java?rev=652417&r1=652416&r2=652417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformerImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformerImpl.java Wed Apr 30 18:24:18 2008
@@ -22,6 +22,7 @@
 import org.apache.tapestry.internal.model.MutableComponentModelImpl;
 import org.apache.tapestry.ioc.LoggerSource;
 import org.apache.tapestry.ioc.Resource;
+import org.apache.tapestry.ioc.internal.services.CtClassSource;
 import org.apache.tapestry.ioc.internal.util.ClasspathResource;
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newConcurrentMap;
 import org.apache.tapestry.ioc.services.ClassFactory;
@@ -52,6 +53,8 @@
 
     private final ClassFactory _classFactory;
 
+    private final CtClassSource _classSource;
+
     private final ComponentClassCache _componentClassCache;
 
     private final String[] SUBPACKAGES = { "." + InternalConstants.PAGES_SUBPACKAGE + ".",
@@ -61,16 +64,20 @@
 
     /**
      * @param workerChain         the ordered list of class transform works as a chain of command instance
+     * @param classSource
      * @param componentClassCache
      */
-    public ComponentClassTransformerImpl(ComponentClassTransformWorker workerChain, LoggerSource loggerSource,
+    public ComponentClassTransformerImpl(ComponentClassTransformWorker workerChain,
+                                         LoggerSource loggerSource,
                                          @ComponentLayer ClassFactory classFactory,
+                                         @ComponentLayer CtClassSource classSource,
                                          ComponentClassCache componentClassCache)
     {
         _workerChain = workerChain;
         _loggerSource = loggerSource;
         _classFactory = classFactory;
         _componentClassCache = componentClassCache;
+        _classSource = classSource;
     }
 
     /**
@@ -143,7 +150,7 @@
 
         InternalClassTransformation transformation =
                 parentTransformation == null
-                ? new InternalClassTransformationImpl(_classFactory, _componentClassCache, ctClass, model)
+                ? new InternalClassTransformationImpl(_classFactory, ctClass, _componentClassCache, model, _classSource)
                 : parentTransformation.createChildTransformation(ctClass, model);
 
         try

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentInstantiatorSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentInstantiatorSource.java?rev=652417&r1=652416&r2=652417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentInstantiatorSource.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentInstantiatorSource.java Wed Apr 30 18:24:18 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
 package org.apache.tapestry.internal.services;
 
 import org.apache.tapestry.internal.event.InvalidationEventHub;
+import org.apache.tapestry.ioc.internal.services.CtClassSource;
 import org.apache.tapestry.ioc.services.ClassFactory;
 
 /**
@@ -63,4 +64,9 @@
      */
     ClassFactory getClassFactory();
 
+    /**
+     * Returns a class source used when creating new classes dynamically.
+     */
+    CtClassSource getClassSource();
+
 }
\ No newline at end of file

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentInstantiatorSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentInstantiatorSourceImpl.java?rev=652417&r1=652416&r2=652417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentInstantiatorSourceImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentInstantiatorSourceImpl.java Wed Apr 30 18:24:18 2008
@@ -20,6 +20,8 @@
 import org.apache.tapestry.internal.util.URLChangeTracker;
 import org.apache.tapestry.ioc.internal.services.ClassFactoryClassPool;
 import org.apache.tapestry.ioc.internal.services.ClassFactoryImpl;
+import org.apache.tapestry.ioc.internal.services.CtClassSource;
+import org.apache.tapestry.ioc.internal.services.CtClassSourceImpl;
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newSet;
 import org.apache.tapestry.ioc.internal.util.Defense;
@@ -61,6 +63,7 @@
      * Map from class name to Instantiator.
      */
     private final Map<String, Instantiator> _instantiatorMap = newMap();
+    private CtClassSource _classSource;
 
     private class PackageAwareLoader extends Loader
     {
@@ -124,6 +127,8 @@
 
         classPool.appendClassPath(path);
 
+        _classSource = new CtClassSourceImpl(classPool, _loader);
+
         try
         {
             _loader.addTranslator(classPool, this);
@@ -133,7 +138,7 @@
             throw new RuntimeException(ex);
         }
 
-        _classFactory = new ClassFactoryImpl(_loader, classPool, _logger);
+        _classFactory = new ClassFactoryImpl(_loader, classPool, _classSource, _logger);
     }
 
     // This is called from well within a synchronized block.
@@ -301,4 +306,9 @@
     {
         return _classFactory;
     }
+
+    public CtClassSource getClassSource()
+    {
+        return _classSource;
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java?rev=652417&r1=652416&r2=652417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformationImpl.java Wed Apr 30 18:24:18 2008
@@ -20,6 +20,7 @@
 import org.apache.tapestry.ComponentResources;
 import org.apache.tapestry.internal.InternalComponentResources;
 import org.apache.tapestry.internal.util.MultiKey;
+import org.apache.tapestry.ioc.internal.services.CtClassSource;
 import org.apache.tapestry.ioc.internal.util.CollectionFactory;
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.*;
 import org.apache.tapestry.ioc.internal.util.Defense;
@@ -119,6 +120,8 @@
 
     private final ComponentClassCache _componentClassCache;
 
+    private final CtClassSource _classSource;
+
     /**
      * Signature for newInstance() method of Instantiator.
      */
@@ -130,11 +133,13 @@
     /**
      * This is a constructor for a base class.
      */
-    public InternalClassTransformationImpl(ClassFactory classFactory, ComponentClassCache componentClassCache,
-                                           CtClass ctClass, ComponentModel componentModel)
+    public InternalClassTransformationImpl(ClassFactory classFactory, CtClass ctClass,
+                                           ComponentClassCache componentClassCache,
+                                           ComponentModel componentModel, CtClassSource classSource)
     {
         _ctClass = ctClass;
         _componentClassCache = componentClassCache;
+        _classSource = classSource;
         _classPool = _ctClass.getClassPool();
         _classFactory = classFactory;
         _parentTransformation = null;
@@ -166,11 +171,13 @@
      * Constructor for a component sub-class.
      */
     private InternalClassTransformationImpl(CtClass ctClass, InternalClassTransformation parentTransformation,
-                                            ClassFactory classFactory, ComponentClassCache componentClassCache,
+                                            ClassFactory classFactory, CtClassSource classSource,
+                                            ComponentClassCache componentClassCache,
                                             ComponentModel componentModel)
     {
         _ctClass = ctClass;
         _componentClassCache = componentClassCache;
+        _classSource = classSource;
         _classPool = _ctClass.getClassPool();
         _classFactory = classFactory;
         _logger = componentModel.getLogger();
@@ -183,8 +190,6 @@
 
         preloadMemberNames();
 
-        verifyFields();
-
         _constructorArgs = parentTransformation.getConstructorArgs();
 
         int count = _constructorArgs.size();
@@ -211,7 +216,9 @@
 
     public InternalClassTransformation createChildTransformation(CtClass childClass, MutableComponentModel childModel)
     {
-        return new InternalClassTransformationImpl(childClass, this, _classFactory, _componentClassCache, childModel);
+        return new InternalClassTransformationImpl(childClass, this, _classFactory, _classSource, _componentClassCache,
+                                                   childModel
+        );
     }
 
     private void freeze()
@@ -1186,6 +1193,8 @@
 
         addInjectToConstructor(fieldName, ctType, value);
 
+        _addedFieldNames.add(fieldName);
+
         return fieldName;
     }
 
@@ -1209,7 +1218,7 @@
 
         if (builder == null)
         {
-            builder = new InvocationBuilder(this, _classFactory, _componentClassCache, methodSignature);
+            builder = new InvocationBuilder(this, _componentClassCache, methodSignature, _classSource);
             _methodToInvocationBuilder.put(methodSignature, builder);
         }
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java?rev=652417&r1=652416&r2=652417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java Wed Apr 30 18:24:18 2008
@@ -24,9 +24,11 @@
 import org.apache.tapestry.ioc.annotations.Marker;
 import org.apache.tapestry.ioc.annotations.Scope;
 import org.apache.tapestry.ioc.annotations.Symbol;
+import org.apache.tapestry.ioc.internal.services.CtClassSource;
 import org.apache.tapestry.ioc.services.Builtin;
 import org.apache.tapestry.ioc.services.ClassFactory;
 import org.apache.tapestry.ioc.services.PerthreadManager;
+import org.apache.tapestry.ioc.services.PropertyShadowBuilder;
 import org.apache.tapestry.services.*;
 import org.slf4j.Logger;
 
@@ -229,5 +231,10 @@
         return service;
     }
 
+    @Marker(ComponentLayer.class)
+    public CtClassSource buildCtClassSource(PropertyShadowBuilder builder)
+    {
+        return builder.build(_componentInstantiatorSource, "classSource", CtClassSource.class);
+    }
 
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InvocationBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InvocationBuilder.java?rev=652417&r1=652416&r2=652417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InvocationBuilder.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InvocationBuilder.java Wed Apr 30 18:24:18 2008
@@ -14,11 +14,10 @@
 
 package org.apache.tapestry.internal.services;
 
+import javassist.*;
 import org.apache.tapestry.ComponentResources;
-import org.apache.tapestry.ioc.services.ClassFab;
+import org.apache.tapestry.ioc.internal.services.CtClassSource;
 import org.apache.tapestry.ioc.services.ClassFabUtils;
-import org.apache.tapestry.ioc.services.ClassFactory;
-import org.apache.tapestry.ioc.services.MethodSignature;
 import org.apache.tapestry.ioc.util.BodyBuilder;
 import org.apache.tapestry.services.ComponentMethodAdvice;
 import org.apache.tapestry.services.TransformMethodSignature;
@@ -28,48 +27,49 @@
 
 /**
  * Used by {@link org.apache.tapestry.internal.services.InternalClassTransformationImpl} to manage adding method
- * invocation advice to arbitrary methods.
+ * invocation advice to arbitrary component methods.
  */
 public class InvocationBuilder
 {
     private static final String FIELD_NAME = "_p";
 
-    private static final MethodSignature OVERRIDE_SIGNATURE =
-            new MethodSignature(void.class, "override", new Class[] { int.class, Object.class }, null);
-
-    private static final MethodSignature GET_PARAMETER_SIGNATURE =
-            new MethodSignature(Object.class, "getParameter", new Class[] { int.class }, null);
+    private static final int PROTECTED_FINAL = Modifier.PROTECTED | Modifier.FINAL;
 
-    private static final MethodSignature INVOKE_ADVISED_METHOD_SIGNATURE =
-            new MethodSignature(void.class, "invokeAdvisedMethod", null, null);
+    private static final int PUBLIC_FINAL = Modifier.PUBLIC | Modifier.FINAL;
 
     private final InternalClassTransformation _transformation;
 
-    private final ClassFactory _classFactory;
+    private final CtClassSource _classSource;
 
-    private final TransformMethodSignature _methodSignature;
+    private final TransformMethodSignature _advisedMethod;
 
     private final MethodInvocationInfo _info;
 
-    private static final AtomicLong UID_GENERATOR = new AtomicLong(System.currentTimeMillis());
+    private final CtClass _invocationCtClass;
 
-    private static final int PROTECTED_FINAL = Modifier.PROTECTED | Modifier.FINAL;
+    private final String _invocationClassName;
 
-    private static final int PUBLIC_FINAL = Modifier.PUBLIC | Modifier.FINAL;
+    private static final AtomicLong UID_GENERATOR = new AtomicLong(System.currentTimeMillis());
 
     private static String nextUID()
     {
         return Long.toHexString(UID_GENERATOR.getAndIncrement());
     }
 
-    public InvocationBuilder(InternalClassTransformation transformation, ClassFactory classFactory,
-                             ComponentClassCache componentClassCache, TransformMethodSignature methodSignature)
+    public InvocationBuilder(InternalClassTransformation transformation,
+                             ComponentClassCache componentClassCache, TransformMethodSignature advisedMethod,
+                             CtClassSource classSource)
     {
         _transformation = transformation;
-        _classFactory = classFactory;
-        _methodSignature = methodSignature;
+        _advisedMethod = advisedMethod;
+        _classSource = classSource;
+
+        _info = new MethodInvocationInfo(advisedMethod, componentClassCache);
+
+        _invocationClassName = _transformation.getClassName() + "$" + _advisedMethod.getMethodName() + "$invocation_" + nextUID();
+
+        _invocationCtClass = _classSource.newClass(_invocationClassName, AbstractComponentMethodInvocation.class);
 
-        _info = new MethodInvocationInfo(methodSignature, componentClassCache);
     }
 
     public void addAdvice(ComponentMethodAdvice advice)
@@ -77,52 +77,55 @@
         _info.addAdvice(advice);
     }
 
+    /**
+     * Commit the changes, creating the new class for the invocation, and renaming and rewriting the advised method.
+     */
     public void commit()
     {
         // The class name is the component class name plus the method name plus a unique uid. This places
         // the invocation in the same package as the component class; the original method will ultimately
         // be renamed and modified to be package private.
 
-        String className =
-                _transformation.getClassName() + "$" + _methodSignature.getMethodName() + "$invocation_" + nextUID();
-
-        ClassFab invocationFab = _classFactory.newClass(className, AbstractComponentMethodInvocation.class);
-
-        createConstructor(invocationFab);
-
-        implementOverride(invocationFab);
+        try
+        {
+            createConstructor();
 
-        implementGetParameter(invocationFab);
+            implementOverride();
 
-        String renamed = copyAdvisedMethod();
+            implementGetParameter();
 
-        implementInvokeAdviseMethod(invocationFab, renamed);
+            String renamed = copyAdvisedMethod();
 
-        rebuildOriginalMethod(className);
+            implementInvokeAdvisedMethod(renamed);
 
-        // Force the creation of the class now
+            _classSource.createClass(_invocationCtClass);
+        }
+        catch (Exception ex)
+        {
+            throw new RuntimeException(ex);
+        }
 
-        invocationFab.createClass();
+        rebuildOriginalMethod();
     }
 
-    private void rebuildOriginalMethod(String invocationClassName)
+    private void rebuildOriginalMethod()
     {
         String methodInfoField = _transformation.addInjectedField(MethodInvocationInfo.class,
-                                                                  _methodSignature.getMethodName() + "Info",
+                                                                  _advisedMethod.getMethodName() + "Info",
                                                                   _info);
 
         String componentResourcesField = _transformation.getResourcesFieldName();
 
         BodyBuilder builder = new BodyBuilder().begin();
 
-        builder.addln("%s invocation = new %<s(%s, %s, $$);", invocationClassName, methodInfoField,
+        builder.addln("%s invocation = new %<s(%s, %s, $$);", _invocationClassName, methodInfoField,
                       componentResourcesField);
 
         // Off into the first MethodAdvice
 
         builder.addln("invocation.proceed();");
 
-        String[] exceptionTypes = _methodSignature.getExceptionTypes();
+        String[] exceptionTypes = _advisedMethod.getExceptionTypes();
         int exceptionCount = exceptionTypes.length;
 
         if (exceptionCount > 0)
@@ -138,7 +141,7 @@
             }
         }
 
-        String returnType = _methodSignature.getReturnType();
+        String returnType = _advisedMethod.getReturnType();
 
         if (!returnType.equals("void"))
         {
@@ -150,18 +153,18 @@
         builder.end();
 
         /** Replace the original method with the new implementation. */
-        _transformation.addMethod(_methodSignature, builder.toString());
+        _transformation.addMethod(_advisedMethod, builder.toString());
     }
 
-    private void implementInvokeAdviseMethod(ClassFab classFab, String advisedMethodName)
+    private void implementInvokeAdvisedMethod(String advisedMethodName) throws CannotCompileException
     {
         BodyBuilder builder = new BodyBuilder().begin();
 
-        boolean isVoid = _methodSignature.getReturnType().equals("void");
+        boolean isVoid = _advisedMethod.getReturnType().equals("void");
 
         builder.addln("%s component = (%<s) getComponentResources().getComponent();", _transformation.getClassName());
 
-        String[] exceptionTypes = _methodSignature.getExceptionTypes();
+        String[] exceptionTypes = _advisedMethod.getExceptionTypes();
         int exceptionCount = exceptionTypes.length;
 
         if (exceptionCount > 0)
@@ -171,7 +174,7 @@
 
         builder.add("component.%s(", advisedMethodName);
 
-        for (int i = 0; i < _methodSignature.getParameterTypes().length; i++)
+        for (int i = 0; i < _advisedMethod.getParameterTypes().length; i++)
         {
             if (i > 0) builder.add(", ");
 
@@ -196,26 +199,32 @@
 
         builder.end();
 
-        classFab.addMethod(PROTECTED_FINAL, INVOKE_ADVISED_METHOD_SIGNATURE, builder.toString());
+        CtMethod method = new CtMethod(CtClass.voidType, "invokeAdvisedMethod",
+                                       new CtClass[0], _invocationCtClass);
+
+        method.setModifiers(PROTECTED_FINAL);
+        method.setBody(builder.toString());
+
+        _invocationCtClass.addMethod(method);
     }
 
     private String copyAdvisedMethod()
     {
-        String newName = _transformation.newMemberName("advised$" + _methodSignature.getMethodName());
+        String newName = _transformation.newMemberName("advised$" + _advisedMethod.getMethodName());
 
-        _transformation.copyMethod(_methodSignature, Modifier.FINAL, newName);
+        _transformation.copyMethod(_advisedMethod, Modifier.FINAL, newName);
 
         return newName;
     }
 
-    private void createConstructor(ClassFab classFab)
+    private void createConstructor() throws CannotCompileException
     {
         int parameterCount = _info.getParameterCount();
 
-        Class[] parameterTypes = new Class[parameterCount + 2];
+        CtClass[] parameterTypes = new CtClass[parameterCount + 2];
 
-        parameterTypes[0] = MethodInvocationInfo.class;
-        parameterTypes[1] = ComponentResources.class;
+        parameterTypes[0] = toCtClass(MethodInvocationInfo.class);
+        parameterTypes[1] = toCtClass(ComponentResources.class);
 
         BodyBuilder builder = new BodyBuilder().begin().addln("super($1,$2);");
 
@@ -223,31 +232,44 @@
         {
             String name = FIELD_NAME + i;
 
-            Class parameterType = _info.getParameterType(i);
+            String parameterTypeName = _advisedMethod.getParameterTypes()[i];
 
-            parameterTypes[2 + i] = parameterType;
+            CtClass parameterType = _classSource.toCtClass(parameterTypeName);
 
-            classFab.addField(name, _info.getParameterType(i));
+            CtField field = new CtField(parameterType, name, _invocationCtClass);
+            field.setModifiers(Modifier.PRIVATE);
+            _invocationCtClass.addField(field);
+
+            parameterTypes[2 + i] = parameterType;
 
             builder.addln("%s = $%d;", name, 3 + i);
         }
 
         builder.end();
 
-        classFab.addConstructor(parameterTypes, null, builder.toString());
+        CtConstructor constructor = new CtConstructor(parameterTypes, _invocationCtClass);
+        constructor.setBody(builder.toString());
+
+        _invocationCtClass.addConstructor(constructor);
+
     }
 
-    private void implementOverride(ClassFab classFab)
+    private CtClass toCtClass(Class input)
+    {
+        return _classSource.toCtClass(input);
+    }
+
+    private void implementOverride() throws CannotCompileException
     {
         BodyBuilder builder = new BodyBuilder().begin();
 
         builder.addln("switch ($1)").begin();
 
-        int count = _methodSignature.getParameterTypes().length;
+        int count = _advisedMethod.getParameterTypes().length;
 
         for (int i = 0; i < count; i++)
         {
-            String type = _methodSignature.getParameterTypes()[i];
+            String type = _advisedMethod.getParameterTypes()[i];
 
             builder.addln("case %d: %s = %s; break;", i, FIELD_NAME + i, ClassFabUtils.castReference("$2", type));
         }
@@ -256,16 +278,22 @@
 
         builder.end().end();
 
-        classFab.addMethod(PUBLIC_FINAL, OVERRIDE_SIGNATURE, builder.toString());
+        CtMethod method = new CtMethod(CtClass.voidType, "override",
+                                       new CtClass[] { CtClass.intType, toCtClass(Object.class) }, _invocationCtClass);
+
+        method.setModifiers(PUBLIC_FINAL);
+        method.setBody(builder.toString());
+
+        _invocationCtClass.addMethod(method);
     }
 
-    private void implementGetParameter(ClassFab classFab)
+    private void implementGetParameter() throws CannotCompileException
     {
         BodyBuilder builder = new BodyBuilder().begin();
 
         builder.addln("switch ($1)").begin();
 
-        int count = _methodSignature.getParameterTypes().length;
+        int count = _advisedMethod.getParameterTypes().length;
 
         for (int i = 0; i < count; i++)
         {
@@ -276,7 +304,13 @@
 
         builder.end().end();
 
-        classFab.addMethod(PUBLIC_FINAL, GET_PARAMETER_SIGNATURE, builder.toString());
+        CtMethod method = new CtMethod(toCtClass(Object.class), "getParameter",
+                                       new CtClass[] { CtClass.intType }, _invocationCtClass);
+
+        method.setModifiers(PUBLIC_FINAL);
+        method.setBody(builder.toString());
+
+        _invocationCtClass.addMethod(method);
     }
 
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/InternalClassTransformationImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/InternalClassTransformationImplTest.java?rev=652417&r1=652416&r2=652417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/InternalClassTransformationImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/InternalClassTransformationImplTest.java Wed Apr 30 18:24:18 2008
@@ -173,7 +173,7 @@
 
         MutableComponentModel model = new MutableComponentModelImpl("unknown-class", logger, null, null);
 
-        return new InternalClassTransformationImpl(_classFactory, null, ctClass, model);
+        return new InternalClassTransformationImpl(_classFactory, ctClass, null, model, null);
     }
 
     @Test
@@ -483,8 +483,8 @@
 
         replay();
 
-        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, null, targetObjectCtClass,
-                                                                             model);
+        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, targetObjectCtClass, null,
+                                                                             model, null);
 
         // Default behavior is to add an injected field for the InternalComponentResources object,
         // so we'll just check that.
@@ -516,8 +516,8 @@
 
         replay();
 
-        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, null, targetObjectCtClass,
-                                                                             model);
+        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, targetObjectCtClass, null,
+                                                                             model, null);
 
         String parentFieldName = ct.addInjectedField(String.class, "_value", value);
 
@@ -568,8 +568,8 @@
 
         replay();
 
-        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, null, targetObjectCtClass,
-                                                                             model);
+        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, targetObjectCtClass, null,
+                                                                             model, null);
 
         ct.addImplementedInterface(FooInterface.class);
         ct.addImplementedInterface(GetterMethodsInterface.class);
@@ -616,8 +616,8 @@
 
         CtClass targetObjectCtClass = findCtClass(ReadOnlyBean.class);
 
-        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, null, targetObjectCtClass,
-                                                                             model);
+        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, targetObjectCtClass, null,
+                                                                             model, null);
 
         ct.makeReadOnly("_value");
 
@@ -651,7 +651,8 @@
 
         CtClass targetObjectCtClass = findCtClass(RemoveFieldBean.class);
 
-        InternalClassTransformation ct = new InternalClassTransformationImpl(null, null, targetObjectCtClass, model);
+        InternalClassTransformation ct = new InternalClassTransformationImpl(null, targetObjectCtClass, null, model,
+                                                                             null);
 
         ct.removeField("_barney");
 
@@ -672,8 +673,8 @@
 
         CtClass targetObjectCtClass = findCtClass(ReadOnlyBean.class);
 
-        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, null, targetObjectCtClass,
-                                                                             model);
+        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, targetObjectCtClass, null,
+                                                                             model, null);
 
         ct.extendConstructor("_value = \"from constructor\";");
 
@@ -698,8 +699,8 @@
 
         CtClass targetObjectCtClass = findCtClass(ReadOnlyBean.class);
 
-        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, null, targetObjectCtClass,
-                                                                             model);
+        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, targetObjectCtClass, null,
+                                                                             model, null);
 
         ct.injectField("_value", "Tapestry");
 
@@ -741,8 +742,8 @@
 
         CtClass targetObjectCtClass = findCtClass(FieldAccessBean.class);
 
-        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, null, targetObjectCtClass,
-                                                                             model);
+        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, targetObjectCtClass, null,
+                                                                             model, null);
 
         replaceAccessToField(ct, "foo");
         replaceAccessToField(ct, "bar");
@@ -1129,8 +1130,8 @@
 
         CtClass targetObjectCtClass = findCtClass(FieldRemoval.class);
 
-        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, null, targetObjectCtClass,
-                                                                             model);
+        InternalClassTransformation ct = new InternalClassTransformationImpl(_classFactory, targetObjectCtClass, null,
+                                                                             model, null);
 
         ct.removeField("_fieldToRemove");
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/ApplicationStateWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/ApplicationStateWorkerTest.java?rev=652417&r1=652416&r2=652417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/ApplicationStateWorkerTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/ApplicationStateWorkerTest.java Wed Apr 30 18:24:18 2008
@@ -127,8 +127,8 @@
 
         replay();
 
-        InternalClassTransformation transformation = new InternalClassTransformationImpl(_classFactory, null, ctClass,
-                                                                                         model);
+        InternalClassTransformation transformation = new InternalClassTransformationImpl(_classFactory, ctClass, null,
+                                                                                         model, null);
         new ApplicationStateWorker(manager, cache).transform(transformation, model);
 
         verify();
@@ -194,8 +194,8 @@
 
         replay();
 
-        InternalClassTransformation transformation = new InternalClassTransformationImpl(_classFactory, null, ctClass,
-                                                                                         model);
+        InternalClassTransformation transformation = new InternalClassTransformationImpl(_classFactory, ctClass, null,
+                                                                                         model, null);
         new ApplicationStateWorker(manager, cache).transform(transformation, model);
 
         verify();

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/ParameterWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/ParameterWorkerTest.java?rev=652417&r1=652416&r2=652417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/ParameterWorkerTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/ParameterWorkerTest.java Wed Apr 30 18:24:18 2008
@@ -602,7 +602,8 @@
 
         replay();
 
-        InternalClassTransformation transformation = new InternalClassTransformationImpl(cf, null, ctClass, model);
+        InternalClassTransformation transformation = new InternalClassTransformationImpl(cf, ctClass, null, model,
+                                                                                         null);
 
         new ParameterWorker(source).transform(transformation, model);
 

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/AbstractFab.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/AbstractFab.java?rev=652417&r1=652416&r2=652417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/AbstractFab.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/AbstractFab.java Wed Apr 30 18:24:18 2008
@@ -1,4 +1,4 @@
-// Copyright 2005, 2006, 2007 The Apache Software Foundation
+// Copyright 2005, 2006, 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -15,16 +15,12 @@
 package org.apache.tapestry.ioc.internal.services;
 
 import javassist.CtClass;
-import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
 import org.apache.tapestry.ioc.internal.util.OneShotLock;
 import org.slf4j.Logger;
 
-import java.util.Map;
-
 /**
- * Base class for {@link org.apache.tapestry.ioc.internal.services.ClassFabImpl}. This code is a
- * fork from HiveMind; it is kept seperate from ClassFabImpl in case we want to re-introduce the
- * idea of an InterfaceFab.
+ * Base class for {@link org.apache.tapestry.ioc.internal.services.ClassFabImpl}. This code is a fork from HiveMind; it
+ * is kept seperate from ClassFabImpl in case we want to re-introduce the idea of an InterfaceFab.
  */
 public class AbstractFab
 {
@@ -43,16 +39,11 @@
         _logger = logger;
     }
 
-    /**
-     * Map from Class to CtClass.
-     */
-    private final Map<Class, CtClass> _ctClassCache = newMap();
-
     public void addInterface(Class interfaceClass)
     {
         _lock.check();
 
-        CtClass ctInterfaceClass = _source.getCtClass(interfaceClass);
+        CtClass ctInterfaceClass = _source.toCtClass(interfaceClass);
 
         try
         {
@@ -67,7 +58,7 @@
         _ctClass.addInterface(ctInterfaceClass);
     }
 
-    protected CtClass[] convertClasses(Class[] inputClasses)
+    protected CtClass[] toCtClasses(Class[] inputClasses)
     {
         if (inputClasses == null || inputClasses.length == 0) return null;
 
@@ -76,7 +67,7 @@
 
         for (int i = 0; i < count; i++)
         {
-            CtClass ctClass = convertClass(inputClasses[i]);
+            CtClass ctClass = toCtClass(inputClasses[i]);
 
             result[i] = ctClass;
         }
@@ -84,17 +75,9 @@
         return result;
     }
 
-    protected CtClass convertClass(Class inputClass)
+    protected CtClass toCtClass(Class inputClass)
     {
-        CtClass result = _ctClassCache.get(inputClass);
-
-        if (result == null)
-        {
-            result = _source.getCtClass(inputClass);
-            _ctClassCache.put(inputClass, result);
-        }
-
-        return result;
+        return _source.toCtClass(inputClass);
     }
 
     public Class createClass()

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFabImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFabImpl.java?rev=652417&r1=652416&r2=652417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFabImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFabImpl.java Wed Apr 30 18:24:18 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -32,8 +32,8 @@
 import java.util.Set;
 
 /**
- * Implementation of {@link org.apache.tapestry.ioc.services.ClassFab}. Hides, as much as possible,
- * the underlying library (Javassist).
+ * Implementation of {@link org.apache.tapestry.ioc.services.ClassFab}. Hides, as much as possible, the underlying
+ * library (Javassist).
  */
 public class ClassFabImpl extends AbstractFab implements ClassFab
 {
@@ -48,8 +48,8 @@
     }
 
     /**
-     * Add fields, methods, and constructors are added, their psuedo-code is appended to this
-     * description, which is used by toString().
+     * Add fields, methods, and constructors are added, their psuedo-code is appended to this description, which is used
+     * by toString().
      */
     private final StringBuilder _description = new StringBuilder();
 
@@ -63,8 +63,8 @@
     }
 
     /**
-     * Returns a representation of the fabricated class, including inheritance, fields,
-     * constructors, methods and method bodies.
+     * Returns a representation of the fabricated class, including inheritance, fields, constructors, methods and method
+     * bodies.
      *
      * @since 1.1
      */
@@ -137,7 +137,7 @@
     {
         _lock.check();
 
-        CtClass ctType = convertClass(type);
+        CtClass ctType = toCtClass(type);
 
         try
         {
@@ -198,10 +198,10 @@
         if (_addedSignatures.contains(ms))
             throw new RuntimeException(ServiceMessages.duplicateMethodInClass(ms, this));
 
-        CtClass ctReturnType = convertClass(ms.getReturnType());
+        CtClass ctReturnType = toCtClass(ms.getReturnType());
 
-        CtClass[] ctParameters = convertClasses(ms.getParameterTypes());
-        CtClass[] ctExceptions = convertClasses(ms.getExceptionTypes());
+        CtClass[] ctParameters = toCtClasses(ms.getParameterTypes());
+        CtClass[] ctExceptions = toCtClasses(ms.getExceptionTypes());
 
         CtMethod method = new CtMethod(ctReturnType, ms.getName(), ctParameters, getCtClass());
 
@@ -259,8 +259,8 @@
 
         _lock.check();
 
-        CtClass[] ctParameters = convertClasses(parameterTypes);
-        CtClass[] ctExceptions = convertClasses(exceptions);
+        CtClass[] ctParameters = toCtClasses(parameterTypes);
+        CtClass[] ctExceptions = toCtClasses(exceptions);
 
         try
         {
@@ -289,8 +289,7 @@
     }
 
     /**
-     * Adds a listing of method (or constructor) parameters and thrown exceptions, and the body, to
-     * the description
+     * Adds a listing of method (or constructor) parameters and thrown exceptions, and the body, to the description
      *
      * @param parameterTypes types of method parameters, or null
      * @param exceptions     types of throw exceptions, or null

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFactoryImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFactoryImpl.java?rev=652417&r1=652416&r2=652417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFactoryImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFactoryImpl.java Wed Apr 30 18:24:18 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -68,15 +68,22 @@
      */
     public ClassFactoryImpl(ClassLoader classLoader, ClassFactoryClassPool pool, Logger logger)
     {
+        this(classLoader, pool, new CtClassSourceImpl(pool, classLoader), logger);
+    }
+
+    public ClassFactoryImpl(ClassLoader classLoader, ClassFactoryClassPool pool, CtClassSource classSource,
+                            Logger logger)
+    {
         _loader = classLoader;
 
         _pool = pool;
 
-        _classSource = new CtClassSource(_pool, classLoader);
+        _classSource = classSource;
 
         _logger = logger;
     }
 
+
     public ClassFab newClass(Class serviceInterface)
     {
         String name = ClassFabUtils.generateClassName(serviceInterface);
@@ -131,7 +138,7 @@
         Class declaringClass = method.getDeclaringClass();
         Class effectiveClass = importClass(declaringClass);
 
-        CtClass ctClass = _classSource.getCtClass(effectiveClass);
+        CtClass ctClass = _classSource.toCtClass(effectiveClass);
 
         StringBuilder builder = new StringBuilder("(");
 
@@ -172,7 +179,7 @@
         builder.append(declaringClass.getName());
         builder.append("(");
 
-        CtClass ctClass = _classSource.getCtClass(declaringClass);
+        CtClass ctClass = _classSource.toCtClass(declaringClass);
 
         StringBuilder descripton = new StringBuilder("(");
 

Added: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSource.java?rev=652417&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSource.java (added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSource.java Wed Apr 30 18:24:18 2008
@@ -0,0 +1,50 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.ioc.internal.services;
+
+import javassist.CtClass;
+
+/**
+ * Used when generating new classes on the fly.
+ *
+ * @see org.apache.tapestry.ioc.services.ClassFactory
+ */
+public interface CtClassSource
+{
+    /**
+     * Returns the number of classes created.
+     */
+    int getCreatedClassCount();
+
+    /**
+     * Converts an existing class to a CtClass instance.
+     */
+    CtClass toCtClass(Class searchClass);
+
+    /**
+     * Converts a class name to a CtClass instance.
+     */
+    CtClass toCtClass(String name);
+
+    /**
+     * Createa a new CtClass instance.
+     */
+    CtClass newClass(String name, Class superClass);
+
+    /**
+     * Used after constructing the CtClass fully, to convert it into a Class ready to be instantiated.
+     */
+    Class createClass(CtClass ctClass);
+}

Copied: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSourceImpl.java (from r647587, tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSource.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSourceImpl.java?p2=tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSourceImpl.java&p1=tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSource.java&r1=647587&r2=652417&rev=652417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSource.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSourceImpl.java Wed Apr 30 18:24:18 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -21,10 +21,10 @@
 import java.security.ProtectionDomain;
 
 /**
- * Wrapper around Javassist's {@link javassist.ClassPool} that manages the creation of new instances
- * of {@link javassist.CtClass} and converts finished CtClass's into instantiable Classes.
+ * Wrapper around Javassist's {@link javassist.ClassPool} that manages the creation of new instances of {@link
+ * javassist.CtClass} and converts finished CtClass's into instantiable Classes.
  */
-class CtClassSource
+public class CtClassSourceImpl implements CtClassSource
 {
     private final ClassFactoryClassPool _pool;
 
@@ -42,13 +42,13 @@
         return _createdClassCount;
     }
 
-    public CtClassSource(ClassFactoryClassPool pool, ClassLoader loader)
+    public CtClassSourceImpl(ClassFactoryClassPool pool, ClassLoader loader)
     {
         _pool = pool;
         _loader = loader;
     }
 
-    public CtClass getCtClass(Class searchClass)
+    public CtClass toCtClass(Class searchClass)
     {
         ClassLoader loader = searchClass.getClassLoader();
 
@@ -59,6 +59,11 @@
 
         String name = ClassFabUtils.toJavaClassName(searchClass);
 
+        return toCtClass(name);
+    }
+
+    public CtClass toCtClass(String name)
+    {
         try
         {
             return _pool.get(name);
@@ -71,7 +76,7 @@
 
     public synchronized CtClass newClass(String name, Class superClass)
     {
-        CtClass ctSuperClass = getCtClass(superClass);
+        CtClass ctSuperClass = toCtClass(superClass);
 
         return _pool.makeClass(name, ctSuperClass);
     }

Propchange: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSourceImpl.java
------------------------------------------------------------------------------
    cvs2svn:cvs-rev = 1.8

Propchange: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSourceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSourceImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/services/ClassFabImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/services/ClassFabImplTest.java?rev=652417&r1=652416&r2=652417&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/services/ClassFabImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/services/ClassFabImplTest.java Wed Apr 30 18:24:18 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@
 
         pool.addClassLoaderIfNeeded(threadLoader);
 
-        _source = new CtClassSource(pool, threadLoader);
+        _source = new CtClassSourceImpl(pool, threadLoader);
     }
 
     private ClassFab newClassFab(String className, Class superClass)
@@ -76,7 +76,7 @@
 
         cf.addField("_stringValue", String.class);
 
-        MethodSignature setStringValue = new MethodSignature(void.class, "setStringValue", new Class[]{String.class},
+        MethodSignature setStringValue = new MethodSignature(void.class, "setStringValue", new Class[] { String.class },
                                                              null);
 
         cf.addMethod(Modifier.PUBLIC, setStringValue, "_stringValue = $1;");
@@ -118,7 +118,7 @@
         ClassFab cf = newClassFab("Delegator", Object.class);
 
         cf.addField("_delegate", SampleService.class);
-        cf.addConstructor(new Class[]{SampleService.class}, null, "_delegate = $1;");
+        cf.addConstructor(new Class[] { SampleService.class }, null, "_delegate = $1;");
 
         cf.proxyMethodsToDelegate(SampleService.class, "_delegate", "<Delegator>");
 
@@ -152,7 +152,7 @@
         ClassFab cf = newClassFab("ToStringDelegator", Object.class);
 
         cf.addField("_delegate", ToStringService.class);
-        cf.addConstructor(new Class[]{ToStringService.class}, null, "_delegate = $1;");
+        cf.addConstructor(new Class[] { ToStringService.class }, null, "_delegate = $1;");
 
         cf.proxyMethodsToDelegate(ToStringService.class, "_delegate", "<ToStringDelegator>");
 
@@ -178,7 +178,7 @@
         ClassFab cf = newClassFab("ConstructableBean", Object.class);
 
         cf.addField("_stringValue", String.class);
-        cf.addConstructor(new Class[]{String.class}, null, "{ _stringValue = $1; }");
+        cf.addConstructor(new Class[] { String.class }, null, "{ _stringValue = $1; }");
 
         MethodSignature getStringValue = new MethodSignature(String.class, "getStringValue", null, null);
 
@@ -197,7 +197,7 @@
 
         Constructor c = targetClass.getConstructors()[0];
 
-        Object targetBean = c.newInstance(new Object[]{"Buffy"});
+        Object targetBean = c.newInstance(new Object[] { "Buffy" });
 
         String actual = (String) _access.get(targetBean, "stringValue");
 
@@ -210,14 +210,14 @@
         ClassFab cf = newClassFab("MyIntHolder", AbstractIntWrapper.class);
 
         cf.addField("_intValue", int.class);
-        cf.addConstructor(new Class[]{int.class}, null, "{ _intValue = $1; }");
+        cf.addConstructor(new Class[] { int.class }, null, "{ _intValue = $1; }");
 
         cf.addMethod(Modifier.PUBLIC, new MethodSignature(int.class, "getIntValue", null, null), "return _intValue;");
 
         Class targetClass = cf.createClass();
         Constructor c = targetClass.getConstructors()[0];
 
-        AbstractIntWrapper targetBean = (AbstractIntWrapper) c.newInstance(new Object[]{new Integer(137)});
+        AbstractIntWrapper targetBean = (AbstractIntWrapper) c.newInstance(new Object[] { new Integer(137) });
 
         assertEquals(targetBean.getIntValue(), 137);
     }
@@ -250,7 +250,7 @@
 
         cf.addInterface(SimpleService.class);
 
-        cf.addMethod(Modifier.PUBLIC, new MethodSignature(int.class, "add", new Class[]{int.class, int.class}, null),
+        cf.addMethod(Modifier.PUBLIC, new MethodSignature(int.class, "add", new Class[] { int.class, int.class }, null),
                      "return $1 + $2;");
 
         Class targetClass = cf.createClass();
@@ -381,12 +381,12 @@
 
         cf.addField("_map", Map.class);
 
-        cf.addConstructor(new Class[]{Map.class, Runnable.class},
-                          new Class[]{IllegalArgumentException.class, DataFormatException.class}, "{ _map = $1; }");
+        cf.addConstructor(new Class[] { Map.class, Runnable.class },
+                          new Class[] { IllegalArgumentException.class, DataFormatException.class }, "{ _map = $1; }");
 
-        MethodSignature sig = new MethodSignature(Map.class, "doTheNasty", new Class[]{int.class, String.class},
-                                                  new Class[]{InstantiationException.class,
-                                                              IllegalAccessException.class});
+        MethodSignature sig = new MethodSignature(Map.class, "doTheNasty", new Class[] { int.class, String.class },
+                                                  new Class[] { InstantiationException.class,
+                                                          IllegalAccessException.class });
 
         cf.addMethod(Modifier.PUBLIC + Modifier.FINAL + Modifier.SYNCHRONIZED, sig, "{ return _map; }");
 



Mime
View raw message