You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2008/01/15 21:52:08 UTC
svn commit: r612212 [1/2] - in /tapestry/tapestry5/trunk:
tapestry-core/src/main/java/org/apache/tapestry/internal/services/
tapestry-core/src/main/java/org/apache/tapestry/test/
tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ t...
Author: hlship
Date: Tue Jan 15 12:51:58 2008
New Revision: 612212
URL: http://svn.apache.org/viewvc?rev=612212&view=rev
Log:
TAPESTRY-2049: Avoid reflection when instantiating component instances
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AbstractInstantiator.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/SimpleASO.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TestPackageAwareLoader.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/StateHolder.java
- copied, changed from r594255, tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/StateHolder.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/components/
Removed:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ReflectiveInstantiator.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/StateHolder.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformer.java
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/ComponentInstantiatorSourceImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformation.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/ServicesMessages.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateManagerImplTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateWorkerTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentInstantiatorSourceImplTest.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/services/ParameterWorkerTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/SessionApplicationStatePersistenceStrategyTest.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/test/TestBase.java
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AbstractInstantiator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AbstractInstantiator.java?rev=612212&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AbstractInstantiator.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AbstractInstantiator.java Tue Jan 15 12:51:58 2008
@@ -0,0 +1,44 @@
+// 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.internal.services;
+
+import org.apache.tapestry.model.ComponentModel;
+
+/**
+ * Abstract base class for instantiators; for each component, a new subclass is created at runtime.
+ */
+public abstract class AbstractInstantiator implements Instantiator
+{
+ private final ComponentModel _model;
+
+ private final String _description;
+
+ public AbstractInstantiator(ComponentModel model, String description)
+ {
+ _model = model;
+ _description = description;
+ }
+
+ @Override
+ public String toString()
+ {
+ return _description;
+ }
+
+ public ComponentModel getModel()
+ {
+ return _model;
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformer.java?rev=612212&r1=612211&r2=612212&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformer.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentClassTransformer.java Tue Jan 15 12:51:58 2008
@@ -1,25 +1,24 @@
-// Copyright 2006 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.
-
+// Copyright 2006, 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.internal.services;
import javassist.CtClass;
/**
- * Encapsulates all the work performed by the
- * {@link org.apache.tapestry.internal.services.ComponentInstantiatorSource} when it loads and
- * transforms a class.
+ * Encapsulates all the work performed by the {@link org.apache.tapestry.internal.services.ComponentInstantiatorSource}
+ * when it loads and transforms a class.
*/
public interface ComponentClassTransformer
{
@@ -27,13 +26,14 @@
* Performs a transformation on the class, accessing the class from the class pool.
*
* @param ctClass compile time class to be transformed
- * @param classLoader class loader used to resolve references to other classes (both transformed and
- * not)
+ * @param classLoader class loader used to resolve references to other classes (both transformed and not)
*/
void transformComponentClass(CtClass ctClass, ClassLoader classLoader);
/**
* Creates a new instantiator instance.
+ *
+ * @param componentClassName fully qualified name of component class to instantiate
*/
- Instantiator createInstantiator(Class componentClass);
+ Instantiator createInstantiator(String componentClassName);
}
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=612212&r1=612211&r2=612212&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 Tue Jan 15 12:51:58 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.
@@ -24,9 +24,11 @@
import org.apache.tapestry.ioc.Resource;
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;
import org.apache.tapestry.model.ComponentModel;
import org.apache.tapestry.model.MutableComponentModel;
import org.apache.tapestry.services.ComponentClassTransformWorker;
+import org.apache.tapestry.services.ComponentLayer;
import org.slf4j.Logger;
import java.lang.reflect.Modifier;
@@ -46,7 +48,9 @@
private final ComponentClassTransformWorker _workerChain;
- private final LoggerSource _logSource;
+ private final LoggerSource _loggerSource;
+
+ private final ClassFactory _classFactory;
private final String[] SUBPACKAGES = {"." + InternalConstants.PAGES_SUBPACKAGE + ".",
"." + InternalConstants.COMPONENTS_SUBPACKAGE + ".",
@@ -56,15 +60,16 @@
/**
* @param workerChain the ordered list of class transform works as a chain of command instance
*/
- public ComponentClassTransformerImpl(ComponentClassTransformWorker workerChain, LoggerSource logSource)
+ public ComponentClassTransformerImpl(ComponentClassTransformWorker workerChain, LoggerSource loggerSource,
+ @ComponentLayer ClassFactory classFactory)
{
_workerChain = workerChain;
- _logSource = logSource;
+ _loggerSource = loggerSource;
+ _classFactory = classFactory;
}
/**
- * Clears the cache of {@link InternalClassTransformation} instances whenever the class loader
- * is invalidated.
+ * Clears the cache of {@link InternalClassTransformation} instances whenever the class loader is invalidated.
*/
public void objectWasInvalidated()
{
@@ -106,7 +111,7 @@
String classname = ctClass.getName();
- Logger logger = _logSource.getLogger(classname);
+ Logger logger = _loggerSource.getLogger(classname);
// If the parent class is in a controlled package, it will already have been loaded and
// transformed (that is driven by the ComponentInstantiatorSource).
@@ -132,9 +137,10 @@
MutableComponentModel model = new MutableComponentModelImpl(classname, logger, baseResource, parentModel);
InternalClassTransformation transformation = parentTransformation == null ? new InternalClassTransformationImpl(
- ctClass, classLoader, logger, model) : new InternalClassTransformationImpl(ctClass,
- parentTransformation,
- classLoader, logger, model);
+ ctClass, _classFactory, logger, model) : new InternalClassTransformationImpl(ctClass,
+ parentTransformation,
+ _classFactory, logger,
+ model);
try
{
@@ -153,17 +159,15 @@
_nameToComponentModel.put(classname, model);
}
- public Instantiator createInstantiator(Class componentClass)
+ public Instantiator createInstantiator(String componentClassName)
{
- String className = componentClass.getName();
-
- InternalClassTransformation ct = _nameToClassTransformation.get(className);
+ InternalClassTransformation ct = _nameToClassTransformation.get(componentClassName);
- if (ct == null) throw new RuntimeException(ServicesMessages.classNotTransformed(className));
+ if (ct == null) throw new RuntimeException(ServicesMessages.classNotTransformed(componentClassName));
try
{
- return ct.createInstantiator(componentClass);
+ return ct.createInstantiator();
}
catch (Throwable ex)
{
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=612212&r1=612211&r2=612212&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 Tue Jan 15 12:51:58 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.
@@ -31,14 +31,13 @@
import java.util.Set;
/**
- * A wrapper around a Javassist class loader that allows certain classes to be modified as they are
- * loaded.
+ * A wrapper around a Javassist class loader that allows certain classes to be modified as they are loaded.
*/
public final class ComponentInstantiatorSourceImpl extends InvalidationEventHubImpl implements Translator, ComponentInstantiatorSource, UpdateListener
{
/**
- * Add -Djavassist-write-dir=target/transformed-classes to the command line to force output of
- * transformed classes to disk (for hardcore debugging).
+ * Add -Djavassist-write-dir=target/transformed-classes to the command line to force output of transformed classes
+ * to disk (for hardcore debugging).
*/
private static final String JAVASSIST_WRITE_DIR = System.getProperty("javassist-write-dir");
@@ -108,8 +107,8 @@
}
/**
- * Invoked at object creation, or when there are updates to class files (i.e., invalidation), to
- * create a new set of Javassist class pools and loaders.
+ * Invoked at object creation, or when there are updates to class files (i.e., invalidation), to create a new set of
+ * Javassist class pools and loaders.
*/
private void initializeService()
{
@@ -213,17 +212,19 @@
{
}
- public synchronized Instantiator findInstantiator(String classname)
+ public synchronized Instantiator findInstantiator(String className)
{
- Instantiator result = _instantiatorMap.get(classname);
+ Instantiator result = _instantiatorMap.get(className);
if (result == null)
{
- Class instanceClass = findClass(classname);
+ // Force the creation of the class (and the transformation of the class).
- result = _transformer.createInstantiator(instanceClass);
+ findClass(className);
- _instantiatorMap.put(classname, result);
+ result = _transformer.createInstantiator(className);
+
+ _instantiatorMap.put(className, result);
}
return result;
@@ -242,8 +243,8 @@
}
/**
- * Returns true if the package for the class name is in a package that is controlled by the
- * enhancer. Controlled packages are identified by {@link #addPackage(String)}.
+ * Returns true if the package for the class name is in a package that is controlled by the enhancer. Controlled
+ * packages are identified by {@link #addPackage(String)}.
*/
boolean inControlledPackage(String classname)
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformation.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformation.java?rev=612212&r1=612211&r2=612212&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformation.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalClassTransformation.java Tue Jan 15 12:51:58 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.
@@ -22,29 +22,28 @@
import java.util.List;
/**
- * Extends {@link org.apache.tapestry.services.ClassTransformation} with additional methods that may
- * only be used internally by Tapestry.
+ * Extends {@link org.apache.tapestry.services.ClassTransformation} with additional methods that may only be used
+ * internally by Tapestry.
*/
public interface InternalClassTransformation extends ClassTransformation
{
/**
- * Invoked after all {@link ComponentClassTransformWorker}s have had their chance to work over
- * the class. This performs any final operations for the class transformation, which includes
- * coming up with the final constructor method for the class.
+ * Invoked after all {@link ComponentClassTransformWorker}s have had their chance to work over the class. This
+ * performs any final operations for the class transformation, which includes coming up with the final constructor
+ * method for the class.
*/
void finish();
/**
* Called (after {@link #finish()}) to construct an instantiator for the component.
*
- * @param componentClass the class to be instantiated
* @return the component's instantiator
*/
- Instantiator createInstantiator(Class componentClass);
+ Instantiator createInstantiator();
/**
- * Returns a copy of the transformation's IdAllocator. Used when creating a child class
- * transformation. May only be invoked on a frozen transformation.
+ * Returns a copy of the transformation's IdAllocator. Used when creating a child class transformation. May only be
+ * invoked on a frozen transformation.
*/
IdAllocator getIdAllocator();
@@ -54,8 +53,8 @@
List<ConstructorArg> getConstructorArgs();
/**
- * Searchs for an existing injection of an object, returning the name of the protected field
- * into which the value was injected.
+ * Searchs for an existing injection of an object, returning the name of the protected field into which the value
+ * was injected.
*/
String searchForPreviousInjection(MultiKey key);
}
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=612212&r1=612211&r2=612212&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 Tue Jan 15 12:51:58 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.
@@ -26,6 +26,11 @@
import static org.apache.tapestry.ioc.internal.util.Defense.notNull;
import org.apache.tapestry.ioc.internal.util.IdAllocator;
import org.apache.tapestry.ioc.internal.util.InternalUtils;
+import org.apache.tapestry.ioc.services.ClassFab;
+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.model.ComponentModel;
import org.apache.tapestry.runtime.Component;
import org.apache.tapestry.services.FieldFilter;
@@ -40,8 +45,7 @@
import java.util.*;
/**
- * Implementation of the {@link org.apache.tapestry.internal.services.InternalClassTransformation}
- * interface.
+ * Implementation of the {@link org.apache.tapestry.internal.services.InternalClassTransformation} interface.
*/
public final class InternalClassTransformationImpl implements InternalClassTransformation
{
@@ -110,17 +114,25 @@
private Formatter _formatter = new Formatter(_description);
- private ClassLoader _loader;
+ private final ClassFactory _classFactory;
+
+ /**
+ * Signature for newInstance() method of Instantiator.
+ */
+ private static final MethodSignature NEW_INSTANCE_SIGNATURE = new MethodSignature(Component.class, "newInstance",
+ new Class[]{
+ InternalComponentResources.class},
+ null);
/**
* This is a constructor for a base class.
*/
- public InternalClassTransformationImpl(CtClass ctClass, ClassLoader loader, Logger logger,
+ public InternalClassTransformationImpl(CtClass ctClass, ClassFactory classFactory, Logger logger,
ComponentModel componentModel)
{
_ctClass = ctClass;
_classPool = _ctClass.getClassPool();
- _loader = loader;
+ _classFactory = classFactory;
_parentTransformation = null;
_componentModel = componentModel;
@@ -150,11 +162,11 @@
* Constructor for a component sub-class.
*/
public InternalClassTransformationImpl(CtClass ctClass, InternalClassTransformation parentTransformation,
- ClassLoader loader, Logger logger, ComponentModel componentModel)
+ ClassFactory classFactory, Logger logger, ComponentModel componentModel)
{
_ctClass = ctClass;
_classPool = _ctClass.getClassPool();
- _loader = loader;
+ _classFactory = classFactory;
_logger = logger;
_parentTransformation = parentTransformation;
_componentModel = componentModel;
@@ -210,7 +222,6 @@
_removedFieldNames = null;
_constructor = null;
_formatter = null;
- _loader = null;
// _ctClass = null; -- needed by toString()
_classPool = null;
}
@@ -283,8 +294,8 @@
}
/**
- * Searches an array of objects (that are really annotations instances) to find one that is of
- * the correct type, which is returned.
+ * Searches an array of objects (that are really annotations instances) to find one that is of the correct type,
+ * which is returned.
*
* @param <T>
* @param annotationClass the annotation to search for
@@ -416,10 +427,10 @@
}
/**
- * Adds default implementations for the methods defined by the interface (and all of its
- * super-interfaces). The implementations return null (or 0, or false, as appropriate to to the
- * method type). There are a number of degenerate cases that are not covered properly: these are
- * related to base interfaces that may be implemented by base classes.
+ * Adds default implementations for the methods defined by the interface (and all of its super-interfaces). The
+ * implementations return null (or 0, or false, as appropriate to to the method type). There are a number of
+ * degenerate cases that are not covered properly: these are related to base interfaces that may be implemented by
+ * base classes.
*
* @param ctInterface
* @throws NotFoundException
@@ -479,10 +490,9 @@
}
/**
- * Check to see if the target class (or any of its super classes) implements the provided
- * interface. This is geared for simple interfaces (that don't extend other interfaces), thus if
- * the class (or a base class) implement interface Y that extends interface X, we may not return
- * true for interface X.
+ * Check to see if the target class (or any of its super classes) implements the provided interface. This is geared
+ * for simple interfaces (that don't extend other interfaces), thus if the class (or a base class) implement
+ * interface Y that extends interface X, we may not return true for interface X.
*/
private boolean classImplementsInterface(CtClass ctInterface) throws NotFoundException
@@ -1043,9 +1053,9 @@
}
/**
- * This is split out from {@link #addInjectedField(Class, String, Object)} to handle a special
- * case for the InternalComponentResources, which is null when "injected" (during the class
- * transformation) and is only determined when a component is actually instantiated.
+ * This is split out from {@link #addInjectedField(Class, String, Object)} to handle a special case for the
+ * InternalComponentResources, which is null when "injected" (during the class transformation) and is only
+ * determined when a component is actually instantiated.
*/
private String addInjectedFieldUncached(Class type, String suggestedName, Object value)
{
@@ -1079,8 +1089,7 @@
}
/**
- * Adds a parameter to the constructor for the class; the parameter is used to initialize the
- * value for a field.
+ * Adds a parameter to the constructor for the class; the parameter is used to initialize the value for a field.
*
* @param fieldName name of field to inject
* @param fieldType Javassist type of the field (and corresponding parameter)
@@ -1188,25 +1197,82 @@
_formatter.format(")\n%s\n\n", constructorBody);
}
- public Instantiator createInstantiator(Class componentClass)
+ public Instantiator createInstantiator()
{
- String className = _ctClass.getName();
+ String componentClassName = _ctClass.getName();
+
+ String name = ClassFabUtils.generateClassName("Instantiator");
+
+ ClassFab cf = _classFactory.newClass(name, AbstractInstantiator.class);
+
+ BodyBuilder constructor = new BodyBuilder();
+
+ // This is realy -1 + 2: The first value in _constructorArgs is the InternalComponentResources, which doesn't
+ // count toward's the Instantiator's constructor ... then we add in the Model and String description.
+ // It's tricky because there's the constructor parameters for the Instantiator, most of which are stored
+ // in fields and then used as the constructor parameters for the Component.
+
+ Class[] constructorParameterTypes = new Class[_constructorArgs.size() + 1];
+ Object[] constructorParameterValues = new Object[_constructorArgs.size() + 1];
+
+ constructorParameterTypes[0] = ComponentModel.class;
+ constructorParameterValues[0] = _componentModel;
- if (!className.equals(componentClass.getName())) throw new IllegalArgumentException(
- ServicesMessages.incorrectClassForInstantiator(className, componentClass));
+ constructorParameterTypes[1] = String.class;
+ constructorParameterValues[1] = String.format("Instantiator[%s]", componentClassName);
- Object[] parameters = new Object[_constructorArgs.size()];
+ BodyBuilder newInstance = new BodyBuilder();
- // Skip the first constructor argument, it's always a placeholder
- // for the InternalComponentResources instance that's provided
- // later.
+ newInstance.add("return new %s($1", componentClassName);
+
+ constructor.begin();
+
+ // Pass the model and description to AbstractInstantiator
+
+ constructor.addln("super($1, $2);");
+
+ // Again, skip the (implicit) InternalComponentResources field, that's
+ // supplied to the Instantiator's newInstance() method.
for (int i = 1; i < _constructorArgs.size(); i++)
{
- parameters[i] = _constructorArgs.get(i).getValue();
+ ConstructorArg arg = _constructorArgs.get(i);
+
+ Class argType = toClass(arg.getType().getName());
+
+ String fieldName = "_param_" + i;
+
+ constructorParameterTypes[i + 1] = argType;
+ constructorParameterValues[i + 1] = arg.getValue();
+
+ cf.addField(fieldName, argType);
+
+ // $1 is model, $2 is description, to $3 is first dynamic parameter.
+
+ constructor.addln("%s = $%d;", fieldName, i + 2);
+
+ newInstance.add(", %s", fieldName);
}
- return new ReflectiveInstantiator(_componentModel, componentClass, parameters);
+ constructor.end();
+ newInstance.addln(");");
+
+ cf.addConstructor(constructorParameterTypes, null, constructor.toString());
+
+ cf.addMethod(Modifier.PUBLIC, NEW_INSTANCE_SIGNATURE, newInstance.toString());
+
+ Class instantiatorClass = cf.createClass();
+
+ try
+ {
+ Object instance = instantiatorClass.getConstructors()[0].newInstance(constructorParameterValues);
+
+ return (Instantiator) instance;
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException(ex);
+ }
}
private void failIfFrozen()
@@ -1450,15 +1516,11 @@
public Class toClass(String type)
{
- failIfFrozen();
-
- // No reason why this can't be allowed to work after freezing.
-
String finalType = TransformUtils.getWrapperTypeName(type);
try
{
- return Class.forName(finalType, true, _loader);
+ return Class.forName(finalType, true, _classFactory.getClassLoader());
}
catch (ClassNotFoundException ex)
{
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java?rev=612212&r1=612211&r2=612212&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java Tue Jan 15 12:51:58 2008
@@ -70,12 +70,6 @@
return MESSAGES.format("no-declared-method", ctClass.getName(), methodSignature);
}
- static String incorrectClassForInstantiator(String className, Class componentClass)
- {
- return MESSAGES.format("incorrect-class-for-instantiator", className, componentClass
- .getName());
- }
-
static String classNotTransformed(String className)
{
return MESSAGES.format("class-not-transformed", className);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/test/TapestryTestCase.java?rev=612212&r1=612211&r2=612212&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/test/TapestryTestCase.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/test/TapestryTestCase.java Tue Jan 15 12:51:58 2008
@@ -50,16 +50,16 @@
import java.util.*;
/**
- * Base test case that adds a number of convienience factory and training methods for the public
- * interfaces of Tapestry.
+ * Base test case that adds a number of convienience factory and training methods for the public interfaces of
+ * Tapestry.
*/
public abstract class TapestryTestCase extends IOCTestCase
{
/**
- * Creates a new markup writer instance (not a markup writer mock). Output can be directed at
- * the writer, which uses the default (HTML) markup model. The writer's toString() value
- * represents all the collected markup in the writer.
+ * Creates a new markup writer instance (not a markup writer mock). Output can be directed at the writer, which uses
+ * the default (HTML) markup model. The writer's toString() value represents all the collected markup in the
+ * writer.
*
* @return
*/
@@ -909,9 +909,8 @@
}
/**
- * Provides access to component messages, suitable for testing. Reads the associated .properties
- * file for the class (NOT any localization of it). Only the messages directly in the
- * .properties file is available.
+ * Provides access to component messages, suitable for testing. Reads the associated .properties file for the class
+ * (NOT any localization of it). Only the messages directly in the .properties file is available.
*
* @param componentClass component class whose messages are needed *
* @return the Messages instance
@@ -964,5 +963,15 @@
protected final void train_getInheritInformalParameters(EmbeddedComponentModel model, boolean inherits)
{
expect(model.getInheritInformalParameters()).andReturn(inherits).atLeastOnce();
+ }
+
+ protected final ApplicationStateManager mockApplicationStateManager()
+ {
+ return newMock(ApplicationStateManager.class);
+ }
+
+ protected final <T> void train_get(ApplicationStateManager manager, Class<T> asoClass, T aso)
+ {
+ expect(manager.get(asoClass)).andReturn(aso);
}
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties?rev=612212&r1=612211&r2=612212&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties Tue Jan 15 12:51:58 2008
@@ -21,7 +21,6 @@
error-adding-method=Error adding method %s to class %s: %s
field-already-claimed=Field %s of class %s is already claimed by %s and can not be claimed by %s.
no-declared-method=Class %s does not declare method '%s'.
-incorrect-class-for-instantiator=Unable to create a component instantiator for class %s because class %s was provided instead.
class-not-transformed=Class %s was not transformed for use as a component; this can happen if it is an interface, or was not in a package subject to component transformation.
new-parser-error=Failure obtaining a SAX parser for resource %s: %s
missing-template-resource=Template resource %s does not exist.
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateManagerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateManagerImplTest.java?rev=612212&r1=612211&r2=612212&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateManagerImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateManagerImplTest.java Tue Jan 15 12:51:58 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 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.test.InternalBaseTestCase;
+import org.apache.tapestry.internal.transform.ReadOnlyBean;
import org.apache.tapestry.internal.util.Holder;
import org.apache.tapestry.services.*;
import org.easymock.EasyMock;
@@ -39,9 +40,10 @@
ApplicationStateCreator<ReadOnlyBean> creator = mockApplicationStateCreator();
ReadOnlyBean aso = new ReadOnlyBean();
- Map<Class, ApplicationStateContribution> configuration = Collections.singletonMap(
- asoClass,
- new ApplicationStateContribution(strategyName, creator));
+ Map<Class, ApplicationStateContribution> configuration = Collections.singletonMap(asoClass,
+ new ApplicationStateContribution(
+ strategyName,
+ creator));
train_get(source, strategyName, strategy);
@@ -66,9 +68,10 @@
Class asoClass = ReadOnlyBean.class;
ApplicationStateCreator<ReadOnlyBean> creator = mockApplicationStateCreator();
- Map<Class, ApplicationStateContribution> configuration = Collections.singletonMap(
- asoClass,
- new ApplicationStateContribution(strategyName, creator));
+ Map<Class, ApplicationStateContribution> configuration = Collections.singletonMap(asoClass,
+ new ApplicationStateContribution(
+ strategyName,
+ creator));
train_get(source, strategyName, strategy);
train_exists(strategy, asoClass, false);
@@ -92,9 +95,10 @@
Class asoClass = ReadOnlyBean.class;
ApplicationStateCreator<ReadOnlyBean> creator = mockApplicationStateCreator();
- Map<Class, ApplicationStateContribution> configuration = Collections.singletonMap(
- asoClass,
- new ApplicationStateContribution(strategyName, creator));
+ Map<Class, ApplicationStateContribution> configuration = Collections.singletonMap(asoClass,
+ new ApplicationStateContribution(
+ strategyName,
+ creator));
train_get(source, strategyName, strategy);
train_exists(strategy, asoClass, true);
@@ -118,9 +122,9 @@
Class asoClass = ReadOnlyBean.class;
Object aso = new ReadOnlyBean();
- Map<Class, ApplicationStateContribution> configuration = Collections.singletonMap(
- asoClass,
- new ApplicationStateContribution(strategyName));
+ Map<Class, ApplicationStateContribution> configuration = Collections.singletonMap(asoClass,
+ new ApplicationStateContribution(
+ strategyName));
train_get(source, strategyName, strategy);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateWorkerTest.java?rev=612212&r1=612211&r2=612212&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateWorkerTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ApplicationStateWorkerTest.java Tue Jan 15 12:51:58 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 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.
@@ -14,21 +14,27 @@
package org.apache.tapestry.internal.services;
-import javassist.ClassPool;
import javassist.CtClass;
import javassist.Loader;
import javassist.LoaderClassPath;
+import javassist.NotFoundException;
import org.apache.tapestry.annotations.ApplicationState;
import org.apache.tapestry.internal.InternalComponentResources;
import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.internal.transform.StateHolder;
+import org.apache.tapestry.ioc.internal.services.ClassFactoryClassPool;
+import org.apache.tapestry.ioc.internal.services.ClassFactoryImpl;
import org.apache.tapestry.ioc.internal.services.PropertyAccessImpl;
+import org.apache.tapestry.ioc.services.ClassFactory;
import org.apache.tapestry.ioc.services.PropertyAccess;
import org.apache.tapestry.model.MutableComponentModel;
import org.apache.tapestry.services.ApplicationStateManager;
import org.apache.tapestry.services.ClassTransformation;
import org.apache.tapestry.services.ComponentClassTransformWorker;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class ApplicationStateWorkerTest extends InternalBaseTestCase
@@ -37,6 +43,44 @@
private PropertyAccess _access = new PropertyAccessImpl();
+ private ClassFactory _classFactory;
+
+ private Loader _loader;
+
+ private ClassFactoryClassPool _classFactoryClassPool;
+
+ /**
+ * We need a new ClassPool for each individual test, since many of the tests will end up modifying one or more
+ * CtClass instances.
+ */
+ @BeforeMethod
+ public void setup_classpool()
+ {
+ // _classPool = new ClassPool();
+
+ _classFactoryClassPool = new ClassFactoryClassPool(_contextClassLoader);
+
+ _loader = new TestPackageAwareLoader(_contextClassLoader, _classFactoryClassPool);
+
+ // Inside Maven Surefire, the system classpath is not sufficient to find all
+ // the necessary files.
+ _classFactoryClassPool.appendClassPath(new LoaderClassPath(_loader));
+
+ Logger logger = LoggerFactory.getLogger(InternalClassTransformationImplTest.class);
+
+ _classFactory = new ClassFactoryImpl(_loader, _classFactoryClassPool, logger);
+ }
+
+ private CtClass findCtClass(Class targetClass) throws NotFoundException
+ {
+ return _classFactoryClassPool.get(targetClass.getName());
+ }
+
+ private Class toClass(CtClass ctClass) throws Exception
+ {
+ return _classFactoryClassPool.toClass(ctClass, _loader, null);
+ }
+
@AfterClass
public void cleanup()
{
@@ -46,7 +90,7 @@
@Test
public void no_fields_with_annotation()
{
- ApplicationStateManager manager = newApplicationStateManager();
+ ApplicationStateManager manager = mockApplicationStateManager();
ClassTransformation ct = mockClassTransformation();
MutableComponentModel model = mockMutableComponentModel();
@@ -65,28 +109,19 @@
@Test
public void field_read_and_write() throws Exception
{
- ApplicationStateManager manager = newApplicationStateManager();
+ ApplicationStateManager manager = mockApplicationStateManager();
Logger logger = mockLogger();
MutableComponentModel model = mockMutableComponentModel();
InternalComponentResources resources = mockInternalComponentResources();
ComponentClassCache cache = mockComponentClassCache();
- String componentClassName = StateHolder.class.getName();
- Class asoClass = ReadOnlyBean.class;
-
- ClassPool pool = new ClassPool();
- ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
- pool.appendClassPath(new LoaderClassPath(contextLoader));
-
- Loader loader = new Loader(contextLoader, pool);
+ Class asoClass = SimpleASO.class;
- loader.delegateLoadingOf("org.apache.tapestry.");
+ CtClass ctClass = findCtClass(StateHolder.class);
- CtClass ctClass = pool.get(componentClassName);
- InternalClassTransformation transformation = new InternalClassTransformationImpl(ctClass, _contextClassLoader,
- logger, null);
-
- train_forName(cache, ReadOnlyBean.class);
+ InternalClassTransformation transformation = new InternalClassTransformationImpl(ctClass, _classFactory, logger,
+ null);
+ train_forName(cache, asoClass);
replay();
@@ -96,9 +131,7 @@
transformation.finish();
- Class transformedClass = pool.toClass(ctClass, loader);
-
- Instantiator instantiator = transformation.createInstantiator(transformedClass);
+ Instantiator instantiator = transformation.createInstantiator();
Object component = instantiator.newInstance(resources);
@@ -114,7 +147,7 @@
// Test read property (get from ASM)
- Object aso = new ReadOnlyBean();
+ Object aso = new SimpleASO();
train_get(manager, asoClass, aso);
@@ -126,7 +159,7 @@
// Test write property (set ASM)
- Object aso2 = new ReadOnlyBean();
+ Object aso2 = new SimpleASO();
manager.set(asoClass, aso2);
@@ -137,13 +170,5 @@
verify();
}
- protected final ApplicationStateManager newApplicationStateManager()
- {
- return newMock(ApplicationStateManager.class);
- }
- protected final <T> void train_get(ApplicationStateManager manager, Class<T> asoClass, T aso)
- {
- expect(manager.get(asoClass)).andReturn(aso);
- }
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java?rev=612212&r1=612211&r2=612212&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java Tue Jan 15 12:51:58 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 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.
@@ -20,6 +20,7 @@
import org.apache.tapestry.beaneditor.PropertyModel;
import org.apache.tapestry.beaneditor.RelativePosition;
import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.internal.transform.ReadOnlyBean;
import org.apache.tapestry.ioc.Messages;
import org.apache.tapestry.services.BeanModelSource;
import org.easymock.EasyMock;
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentInstantiatorSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentInstantiatorSourceImplTest.java?rev=612212&r1=612211&r2=612212&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentInstantiatorSourceImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentInstantiatorSourceImplTest.java Tue Jan 15 12:51:58 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.
@@ -40,9 +40,8 @@
import java.util.UUID;
/**
- * Tests for {@link org.apache.tapestry.internal.services.ComponentInstantiatorSourceImpl}. Several
- * of these tests are more of the form of integration tests that instantiate the Tapestry IoC
- * Registry.
+ * Tests for {@link org.apache.tapestry.internal.services.ComponentInstantiatorSourceImpl}. Several of these tests are
+ * more of the form of integration tests that instantiate the Tapestry IoC Registry.
*/
public class ComponentInstantiatorSourceImplTest extends InternalBaseTestCase
{
@@ -71,8 +70,7 @@
replay();
- ComponentInstantiatorSourceImpl e = new ComponentInstantiatorSourceImpl(_contextLoader,
- transformer, logger);
+ ComponentInstantiatorSourceImpl e = new ComponentInstantiatorSourceImpl(_contextLoader, transformer, logger);
assertEquals(e.inControlledPackage("foo.bar.Baz"), false);
@@ -203,8 +201,7 @@
return connection.getLastModified();
}
- private void createSynthComponentClass(String name) throws CannotCompileException,
- NotFoundException, IOException
+ private void createSynthComponentClass(String name) throws CannotCompileException, NotFoundException, IOException
{
ClassPool pool = new ClassPool();
// Inside Maven Surefire, the system classpath is not sufficient to find all
@@ -217,9 +214,7 @@
// Implement method getName()
- CtMethod method = CtNewMethod.make(
- "public String getName() { return \"" + name + "\"; }",
- ctClass);
+ CtMethod method = CtNewMethod.make("public String getName() { return \"" + name + "\"; }", ctClass);
ctClass.addMethod(method);
ctClass.addInterface(pool.get(Named.class.getName()));
@@ -240,9 +235,6 @@
replay();
- // Can't wait for the HiveMind code base to start using some generics for this kind of
- // thing.
-
Instantiator inst = _source.findInstantiator(classname);
Component target = inst.newInstance(resources);
@@ -267,16 +259,14 @@
URL url = _extraClasspath.toURL();
- _extraLoader = new URLClassLoader(new URL[]
- {url}, _contextLoader);
+ _extraLoader = new URLClassLoader(new URL[]{url}, _contextLoader);
RegistryBuilder builder = new RegistryBuilder(_extraLoader);
builder.add(TapestryModule.class);
- SymbolProvider provider = new SingleKeySymbolProvider(
- InternalConstants.TAPESTRY_ALIAS_MODE_SYMBOL, "servlet");
- ContributionDef contribution = new SyntheticSymbolSourceContributionDef("AliasMode",
- provider, "before:ApplicationDefaults");
+ SymbolProvider provider = new SingleKeySymbolProvider(InternalConstants.TAPESTRY_ALIAS_MODE_SYMBOL, "servlet");
+ ContributionDef contribution = new SyntheticSymbolSourceContributionDef("AliasMode", provider,
+ "before:ApplicationDefaults");
ModuleDef module = new SyntheticModuleDef(contribution);
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=612212&r1=612211&r2=612212&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 Tue Jan 15 12:51:58 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,8 +21,11 @@
import org.apache.tapestry.annotations.SetupRender;
import org.apache.tapestry.internal.InternalComponentResources;
import org.apache.tapestry.internal.test.InternalBaseTestCase;
-import org.apache.tapestry.internal.transform.InheritedAnnotation;
+import org.apache.tapestry.internal.transform.*;
import org.apache.tapestry.internal.transform.pages.*;
+import org.apache.tapestry.ioc.internal.services.ClassFactoryClassPool;
+import org.apache.tapestry.ioc.internal.services.ClassFactoryImpl;
+import org.apache.tapestry.ioc.services.ClassFactory;
import org.apache.tapestry.ioc.services.PropertyAccess;
import org.apache.tapestry.ioc.util.BodyBuilder;
import org.apache.tapestry.runtime.Component;
@@ -31,6 +34,7 @@
import org.apache.tapestry.services.MethodFilter;
import org.apache.tapestry.services.TransformMethodSignature;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
@@ -53,13 +57,15 @@
{
private static final String STRING_CLASS_NAME = "java.lang.String";
- private ClassPool _classPool;
+ private PropertyAccess _access;
private final ClassLoader _contextClassLoader = currentThread().getContextClassLoader();
+ private ClassFactory _classFactory;
+
private Loader _loader;
- private PropertyAccess _access;
+ private ClassFactoryClassPool _classFactoryClassPool;
@BeforeClass
public void setup_access()
@@ -74,30 +80,35 @@
}
/**
- * We need a new ClassPool for each individual test, since many of the tests will end up
- * modifying one or more CtClass instances.
+ * We need a new ClassPool for each individual test, since many of the tests will end up modifying one or more
+ * CtClass instances.
*/
@BeforeMethod
public void setup_classpool()
{
- _classPool = new ClassPool();
+ // _classPool = new ClassPool();
- _loader = new Loader(_contextClassLoader, _classPool);
+ _classFactoryClassPool = new ClassFactoryClassPool(_contextClassLoader);
- // This ensures that only the classes we explicitly access and modify
- // are loaded by the new loader; everthing else comes out of the common
- // context class loader, which prevents a lot of nasty class cast exceptions.
-
- _loader.delegateLoadingOf("org.apache.tapestry.");
+ _loader = new TestPackageAwareLoader(_contextClassLoader, _classFactoryClassPool);
// Inside Maven Surefire, the system classpath is not sufficient to find all
// the necessary files.
- _classPool.appendClassPath(new LoaderClassPath(_loader));
+ _classFactoryClassPool.appendClassPath(new LoaderClassPath(_loader));
+
+ Logger logger = LoggerFactory.getLogger(InternalClassTransformationImplTest.class);
+
+ _classFactory = new ClassFactoryImpl(_loader, _classFactoryClassPool, logger);
}
private CtClass findCtClass(Class targetClass) throws NotFoundException
{
- return _classPool.get(targetClass.getName());
+ return _classFactoryClassPool.get(targetClass.getName());
+ }
+
+ private Class toClass(CtClass ctClass) throws Exception
+ {
+ return _classFactoryClassPool.toClass(ctClass, _loader, null);
}
@Test
@@ -156,7 +167,7 @@
{
CtClass ctClass = findCtClass(targetClass);
- return new InternalClassTransformationImpl(ctClass, _contextClassLoader, logger, null);
+ return new InternalClassTransformationImpl(ctClass, _classFactory, logger, null);
}
@Test
@@ -370,9 +381,8 @@
}
/**
- * More a test of how Javassist works. Javassist does not honor the Inherited annotation for
- * classes (this kind of makes sense, since it won't necessarily have the super-class in
- * memory).
+ * More a test of how Javassist works. Javassist does not honor the Inherited annotation for classes (this kind of
+ * makes sense, since it won't necessarily have the super-class in memory).
*/
@Test
public void ensure_subclasses_inherit_parent_class_annotations() throws Exception
@@ -396,8 +406,8 @@
}
/**
- * These tests are really to assert my understanding of Javassist's API. I guess we should keep
- * them around to make sure that future versions of Javassist work the same as our expectations.
+ * These tests are really to assert my understanding of Javassist's API. I guess we should keep them around to make
+ * sure that future versions of Javassist work the same as our expectations.
*/
@Test
public void ensure_javassist_still_does_not_show_inherited_interfaces() throws Exception
@@ -466,17 +476,15 @@
replay();
- InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _contextClassLoader,
- logger, null);
+ InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _classFactory, logger,
+ null);
// Default behavior is to add an injected field for the InternalComponentResources object,
// so we'll just check that.
ct.finish();
- Class transformed = _classPool.toClass(targetObjectCtClass, _loader);
-
- Instantiator instantiator = ct.createInstantiator(transformed);
+ Instantiator instantiator = ct.createInstantiator();
ComponentResourcesAware instance = instantiator.newInstance(resources);
@@ -498,7 +506,7 @@
replay();
- InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _loader, logger,
+ InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _classFactory, logger,
null);
String parentFieldName = ct.addInjectedField(String.class, "_value", value);
@@ -508,16 +516,11 @@
ct.finish();
- // Instantiate the transformed base class, so that we can create a transformed
- // subclass.
-
- _classPool.toClass(targetObjectCtClass, _loader);
-
// Now lets work on the subclass
CtClass subclassCtClass = findCtClass(TargetObjectSubclass.class);
- ct = new InternalClassTransformationImpl(subclassCtClass, ct, _loader, logger, null);
+ ct = new InternalClassTransformationImpl(subclassCtClass, ct, _classFactory, logger, null);
String subclassFieldName = ct.addInjectedField(String.class, "_childValue", value);
@@ -532,9 +535,8 @@
ct.finish();
- Class transformed = _classPool.toClass(subclassCtClass, _loader);
- Instantiator instantiator = ct.createInstantiator(transformed);
+ Instantiator instantiator = ct.createInstantiator();
Object instance = instantiator.newInstance(resources);
@@ -546,34 +548,6 @@
}
@Test
- public void wrong_instance_type_passed_to_create_instantiator() throws Exception
- {
- CtClass ctClass = findCtClass(BasicComponent.class);
-
- Logger logger = mockLogger();
-
- replay();
-
- InternalClassTransformation ct = new InternalClassTransformationImpl(ctClass, _contextClassLoader, logger,
- null);
-
- _classPool.toClass(ctClass, _loader);
-
- try
- {
- ct.createInstantiator(Boolean.class);
- unreachable();
- }
- catch (IllegalArgumentException ex)
- {
- assertEquals(ex.getMessage(),
- ServicesMessages.incorrectClassForInstantiator(BasicComponent.class.getName(), Boolean.class));
- }
-
- verify();
- }
-
- @Test
public void add_interface_to_class() throws Exception
{
InternalComponentResources resources = mockInternalComponentResources();
@@ -584,21 +558,21 @@
replay();
- InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _contextClassLoader,
- logger, null);
+ InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _classFactory, logger,
+ null);
ct.addImplementedInterface(FooInterface.class);
ct.addImplementedInterface(GetterMethodsInterface.class);
ct.finish();
- Class transformed = _classPool.toClass(targetObjectCtClass, _loader);
+ Class transformed = toClass(targetObjectCtClass);
Class[] interfaces = transformed.getInterfaces();
assertEquals(interfaces, new Class[]{Component.class, FooInterface.class, GetterMethodsInterface.class});
- Object target = ct.createInstantiator(transformed).newInstance(resources);
+ Object target = ct.createInstantiator().newInstance(resources);
FooInterface asFoo = (FooInterface) target;
@@ -631,8 +605,8 @@
CtClass targetObjectCtClass = findCtClass(ReadOnlyBean.class);
- InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _contextClassLoader,
- logger, null);
+ InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _classFactory, logger,
+ null);
ct.makeReadOnly("_value");
@@ -650,7 +624,7 @@
// The PropertyAccess layer adds a wrapper exception around the real one.
assertEquals(ex.getCause().getMessage(),
- "Field org.apache.tapestry.internal.services.ReadOnlyBean._value is read-only.");
+ "Field org.apache.tapestry.internal.transform.ReadOnlyBean._value is read-only.");
}
verify();
@@ -665,8 +639,7 @@
CtClass targetObjectCtClass = findCtClass(RemoveFieldBean.class);
- InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _contextClassLoader,
- logger, null);
+ InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, null, logger, null);
ct.removeField("_barney");
@@ -686,8 +659,8 @@
CtClass targetObjectCtClass = findCtClass(ReadOnlyBean.class);
- InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _contextClassLoader,
- logger, null);
+ InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _classFactory, logger,
+ null);
ct.extendConstructor("_value = \"from constructor\";");
@@ -711,8 +684,8 @@
CtClass targetObjectCtClass = findCtClass(ReadOnlyBean.class);
- InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _contextClassLoader,
- logger, null);
+ InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _classFactory, logger,
+ null);
ct.injectField("_value", "Tapestry");
@@ -732,15 +705,15 @@
// The PropertyAccess layer adds a wrapper exception around the real one.
assertEquals(ex.getCause().getMessage(),
- "Field org.apache.tapestry.internal.services.ReadOnlyBean._value is read-only.");
+ "Field org.apache.tapestry.internal.transform.ReadOnlyBean._value is read-only.");
}
verify();
}
/**
- * Tests the basic functionality of overriding read and write; also tests the case for multiple
- * field read/field write substitions.
+ * Tests the basic functionality of overriding read and write; also tests the case for multiple field read/field
+ * write substitions.
*/
@Test
public void override_field_read_and_write() throws Exception
@@ -753,8 +726,8 @@
CtClass targetObjectCtClass = findCtClass(FieldAccessBean.class);
- InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _contextClassLoader,
- logger, null);
+ InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _classFactory, logger,
+ null);
replaceAccessToField(ct, "foo");
replaceAccessToField(ct, "bar");
@@ -1057,11 +1030,7 @@
private Component instantiate(Class<?> expectedClass, InternalClassTransformation ct,
InternalComponentResources resources) throws Exception
{
- CtClass targetObjectCtClass = findCtClass(expectedClass);
-
- Class transformedClass = _classPool.toClass(targetObjectCtClass, _loader);
-
- Instantiator ins = ct.createInstantiator(transformedClass);
+ Instantiator ins = ct.createInstantiator();
return ins.newInstance(resources);
}
@@ -1144,14 +1113,14 @@
CtClass targetObjectCtClass = findCtClass(FieldRemoval.class);
- InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _contextClassLoader,
- logger, null);
+ InternalClassTransformation ct = new InternalClassTransformationImpl(targetObjectCtClass, _classFactory, logger,
+ null);
ct.removeField("_fieldToRemove");
ct.finish();
- Class transformed = _classPool.toClass(targetObjectCtClass, _loader);
+ Class transformed = toClass(targetObjectCtClass);
for (Field f : transformed.getDeclaredFields())
{
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java?rev=612212&r1=612211&r2=612212&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ParameterWorkerTest.java Tue Jan 15 12:51:58 2008
@@ -14,7 +14,6 @@
package org.apache.tapestry.internal.services;
-import javassist.ClassPool;
import javassist.CtClass;
import javassist.Loader;
import javassist.LoaderClassPath;
@@ -22,7 +21,13 @@
import org.apache.tapestry.TapestryConstants;
import org.apache.tapestry.internal.InternalComponentResources;
import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.internal.transform.components.DefaultParameterBindingMethodComponent;
+import org.apache.tapestry.internal.transform.components.DefaultParameterComponent;
+import org.apache.tapestry.internal.transform.components.ParameterComponent;
+import org.apache.tapestry.ioc.internal.services.ClassFactoryClassPool;
+import org.apache.tapestry.ioc.internal.services.ClassFactoryImpl;
import org.apache.tapestry.ioc.internal.services.PropertyAccessImpl;
+import org.apache.tapestry.ioc.services.ClassFactory;
import org.apache.tapestry.ioc.services.PropertyAccess;
import org.apache.tapestry.model.MutableComponentModel;
import org.apache.tapestry.runtime.Component;
@@ -32,9 +37,8 @@
import org.testng.annotations.Test;
/**
- * There's no point in trying to unit test the code generated by
- * {@link org.apache.tapestry.internal.services.ParameterWorker}. Instead, we excercize
- * ParameterWorker, and test that the generated code works correctly in a number of scenarios.
+ * There's no point in trying to unit test the code generated by {@link org.apache.tapestry.internal.services.ParameterWorker}.
+ * Instead, we excercize ParameterWorker, and test that the generated code works correctly in a number of scenarios.
*/
public class ParameterWorkerTest extends InternalBaseTestCase
{
@@ -145,14 +149,10 @@
}
/**
- * This actually checks several things:
- * <ul>
- * <li>Changing a parameter property before the page loads doesn't update the binding</li>
- * <li>Changing a parameter property changes the property AND the default value for the
- * property</li>
- * <li>Unbound parameters to do not attempt to read or update their bindings (they'll be
- * optional)</li>
- * </ul>
+ * This actually checks several things: <ul> <li>Changing a parameter property before the page loads doesn't update
+ * the binding</li> <li>Changing a parameter property changes the property AND the default value for the
+ * property</li> <li>Unbound parameters to do not attempt to read or update their bindings (they'll be
+ * optional)</li> </ul>
*
* @throws Exception
*/
@@ -459,6 +459,7 @@
final InternalComponentResources resources = mockInternalComponentResources();
final Binding binding = mockBinding();
String boundValue = "howdy!";
+ final Logger logger = mockLogger();
MutableComponentModel model = mockMutableComponentModel();
@@ -477,18 +478,17 @@
train_isInvariant(resources, "value", true);
+ stub_isDebugEnabled(logger, false);
}
-
- ;
};
- Component component = setupForIntegrationTest(resources, mockLogger(),
- DefaultParameterComponent.class.getName(), model, source,
- phaseTwoTraining);
+ Component component = setupForIntegrationTest(resources, logger, DefaultParameterComponent.class.getName(),
+ model, source, phaseTwoTraining);
train_isLoaded(resources, true);
train_isBound(resources, "value", true);
train_readParameter(resources, "value", String.class, boundValue);
+ stub_isDebugEnabled(logger, false);
replay();
@@ -504,6 +504,7 @@
final InternalComponentResources resources = mockInternalComponentResources();
_binding = mockBinding();
String boundValue = "yowza!";
+ final Logger logger = mockLogger();
MutableComponentModel model = mockMutableComponentModel();
@@ -520,19 +521,19 @@
resources.bindParameter("value", _binding);
train_isInvariant(resources, "value", true);
+ stub_isDebugEnabled(logger, false);
}
-
- ;
};
- Component component = setupForIntegrationTest(resources, mockLogger(),
+
+ Component component = setupForIntegrationTest(resources, logger,
DefaultParameterBindingMethodComponent.class.getName(), model,
source, phaseTwoTraining);
train_isLoaded(resources, true);
train_isBound(resources, "value", true);
train_readParameter(resources, "value", String.class, boundValue);
-
+ stub_isDebugEnabled(logger, false);
replay();
assertEquals(_access.get(component, "value"), boundValue);
@@ -564,15 +565,21 @@
model.addParameter("primitive", true, TapestryConstants.PROP_BINDING_PREFIX);
model.addParameter("uncached", false, TapestryConstants.LITERAL_BINDING_PREFIX);
+ final Logger logger = mockLogger();
+
Runnable phaseTwoTraining = new Runnable()
{
public void run()
{
trainForPageDidLoad(resources);
+ stub_isDebugEnabled(logger, false);
}
};
- return setupForIntegrationTest(resources, mockLogger(), ParameterComponent.class.getName(), model,
+
+ stub_isDebugEnabled(logger, false);
+
+ return setupForIntegrationTest(resources, logger, ParameterComponent.class.getName(), model,
mockBindingSource(), phaseTwoTraining);
}
@@ -580,17 +587,16 @@
String componentClassName, MutableComponentModel model,
BindingSource source, Runnable phaseTwoTraining) throws Exception
{
- ClassPool pool = new ClassPool();
- ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
- pool.appendClassPath(new LoaderClassPath(contextLoader));
+ ClassFactoryClassPool pool = new ClassFactoryClassPool(_contextClassLoader);
+
+ Loader loader = new TestPackageAwareLoader(_contextClassLoader, pool);
- Loader loader = new Loader(contextLoader, pool);
+ pool.appendClassPath(new LoaderClassPath(loader));
- loader.delegateLoadingOf("org.apache.tapestry.");
+ ClassFactory cf = new ClassFactoryImpl(loader, pool, logger);
CtClass ctClass = pool.get(componentClassName);
- InternalClassTransformation transformation = new InternalClassTransformationImpl(ctClass, _contextClassLoader,
- logger, null);
+ InternalClassTransformation transformation = new InternalClassTransformationImpl(ctClass, cf, logger, null);
replay();
@@ -598,17 +604,14 @@
verify();
- transformation.finish();
-
- // System.out.println("Transformation: " + transformation);
-
- Class transformedClass = pool.toClass(ctClass, loader);
-
- Instantiator instantiator = transformation.createInstantiator(transformedClass);
phaseTwoTraining.run();
replay();
+
+ transformation.finish();
+
+ Instantiator instantiator = transformation.createInstantiator();
Component component = instantiator.newInstance(resources);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/SessionApplicationStatePersistenceStrategyTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/SessionApplicationStatePersistenceStrategyTest.java?rev=612212&r1=612211&r2=612212&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/SessionApplicationStatePersistenceStrategyTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/SessionApplicationStatePersistenceStrategyTest.java Tue Jan 15 12:51:58 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 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.test.InternalBaseTestCase;
+import org.apache.tapestry.internal.transform.ReadOnlyBean;
import org.apache.tapestry.services.ApplicationStateCreator;
import org.apache.tapestry.services.ApplicationStatePersistenceStrategy;
import org.apache.tapestry.services.Request;
@@ -39,8 +40,7 @@
replay();
- ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(
- request);
+ ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(request);
assertSame(strategy.get(asoClass, creator), aso);
@@ -58,8 +58,7 @@
replay();
- ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(
- request);
+ ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(request);
assertFalse(strategy.exists(asoClass));
@@ -95,8 +94,7 @@
replay();
- ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(
- request);
+ ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(request);
assertFalse(strategy.exists(asoClass));
@@ -122,8 +120,7 @@
replay();
- ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(
- request);
+ ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(request);
strategy.set(asoClass, aso);
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/SimpleASO.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/SimpleASO.java?rev=612212&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/SimpleASO.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/SimpleASO.java Tue Jan 15 12:51:58 2008
@@ -0,0 +1,35 @@
+// 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.internal.services;
+
+public class SimpleASO
+{
+ private String _value;
+
+ public String getValue()
+ {
+ return _value;
+ }
+
+ public void setValue(String value)
+ {
+ _value = value;
+ }
+
+ public String getReadOnly()
+ {
+ return null;
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TestPackageAwareLoader.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TestPackageAwareLoader.java?rev=612212&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TestPackageAwareLoader.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TestPackageAwareLoader.java Tue Jan 15 12:51:58 2008
@@ -0,0 +1,36 @@
+// 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.internal.services;
+
+import javassist.ClassPool;
+import javassist.Loader;
+
+class TestPackageAwareLoader extends Loader
+{
+ public TestPackageAwareLoader(ClassLoader parent, ClassPool cp)
+ {
+ super(parent, cp);
+ }
+
+ @Override
+ protected Class findClass(String className) throws ClassNotFoundException
+ {
+ if (className.startsWith("org.apache.tapestry.internal.transform.")) return super.findClass(className);
+
+ // Returning null forces delegation to the parent class loader.
+
+ return null;
+ }
+}
Copied: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/StateHolder.java (from r594255, tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/StateHolder.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/StateHolder.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/StateHolder.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/StateHolder.java&r1=594255&r2=612212&rev=612212&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/StateHolder.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/transform/StateHolder.java Tue Jan 15 12:51:58 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 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.
@@ -12,23 +12,24 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry.internal.services;
+package org.apache.tapestry.internal.transform;
import org.apache.tapestry.annotations.ApplicationState;
+import org.apache.tapestry.internal.services.SimpleASO;
public class StateHolder
{
@ApplicationState
- private ReadOnlyBean _bean;
+ private SimpleASO _bean;
private boolean _beanExists;
- public ReadOnlyBean getBean()
+ public SimpleASO getBean()
{
return _bean;
}
- public void setBean(ReadOnlyBean bean)
+ public void setBean(SimpleASO bean)
{
_bean = bean;
}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java?rev=612212&r1=612211&r2=612212&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java Tue Jan 15 12:51:58 2008
@@ -118,6 +118,11 @@
return newMock(Logger.class);
}
+ protected final void stub_isDebugEnabled(Logger logger, boolean enabled)
+ {
+ expect(logger.isDebugEnabled()).andStubReturn(enabled);
+ }
+
@SuppressWarnings("unchecked")
protected final <K, V> MappedConfiguration<K, V> mockMappedConfiguration()
{