Author: jkuhnert
Date: Fri May 18 15:27:40 2007
New Revision: 539617
URL: http://svn.apache.org/viewvc?view=rev&rev=539617
Log:
TAPESTRY-1474. An imperfect solution that at least correctly validates a
generics based class but still can't quite do total auto-wiring of classes...At
least not without some help from hivemind.
Added:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericService.java
(with props)
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericServiceImpl.java
(with props)
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/SimpleGenericsInterface.java
(with props)
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/AutowireWorker.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhancementOperation.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhancementOperationImpl.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/GenericsClassInspectorImpl.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/GenericsMethodSignatureImpl.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/MethodSignatureImpl.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/BaseAutowire.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/EnhancedClassValidatorTest.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/FooGenericComponent.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/MethodSignatureTest.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestAutowireWorker.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestEnhancementOperation.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/autowire-single.xml
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/AutowireWorker.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/AutowireWorker.java?view=diff&rev=539617&r1=539616&r2=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/AutowireWorker.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/AutowireWorker.java
Fri May 18 15:27:40 2007
@@ -13,37 +13,38 @@
// limitations under the License.
package org.apache.tapestry.enhance;
-import java.util.Iterator;
-import java.util.List;
-
import org.apache.commons.logging.Log;
import org.apache.hivemind.Location;
import org.apache.hivemind.internal.Module;
import org.apache.tapestry.spec.IComponentSpecification;
+import java.util.Iterator;
+import java.util.List;
+
/**
* An enhancement worker which automatically injects HiveMind services
* into pages/components if exactly one service point exists which is
* compatible with the read-only property's type.
*
- * @author James Carman
- * @version 1.0
*/
public class AutowireWorker implements EnhancementWorker
{
private final Log _log;
+
private final Module _module;
- public AutowireWorker( Module module, Log log )
+ public AutowireWorker( Module module, Log log)
{
- this._module = module;
- this._log = log;
+ _module = module;
+ _log = log;
}
public void performEnhancement( EnhancementOperation op,
IComponentSpecification spec )
{
final List propertyNames = op.findUnclaimedAbstractProperties();
+
for( Iterator i = propertyNames.iterator(); i.hasNext(); ) {
+
String propertyName = ( String ) i.next();
Class propertyType = op.getPropertyType( propertyName );
@@ -52,8 +53,9 @@
if (!op.canClaimAsReadOnlyProperty(propertyName))
continue;
-
+
if( _module.containsService( propertyType )) {
+
final Object serviceProxy = _module.getService( propertyType );
final Location location = spec.getLocation();
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhancementOperation.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhancementOperation.java?view=diff&rev=539617&r1=539616&r2=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhancementOperation.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhancementOperation.java
Fri May 18 15:27:40 2007
@@ -14,11 +14,11 @@
package org.apache.tapestry.enhance;
-import java.util.List;
-
import org.apache.hivemind.Location;
import org.apache.hivemind.service.MethodSignature;
+import java.util.List;
+
/**
* A process object representing enhancements to a component class. The
* operation is passed to [EMAIL PROTECTED]
org.apache.tapestry.enhance.EnhancementWorker}objects
@@ -58,6 +58,7 @@
*
* @param propertyName
* The property to check.
+ *
* @return True, if no setter method has been created for the specified
property and
* the property hasn't been claimed by someone else.
*/
@@ -117,6 +118,11 @@
* Returns the name of the accessor method for the given property (if it
* exists in the component base class), or fabricates a new name if it does
* not.
+ *
+ * @param propertyName
+ * The property to get an accessor method name of.
+ *
+ * @return The existing/future name of an appropriate accessor method for
the property.
*/
String getAccessorMethodName(String propertyName);
@@ -136,19 +142,24 @@
* location may later be used to describe conflicts. May not be
* null.
*/
- void addMethod(int modifier, MethodSignature sig, String methodBody,
- Location location);
+ void addMethod(int modifier, MethodSignature sig, String methodBody,
Location location);
/**
* Returns the base component class, as defined in the specification (or
* defaulted). An enhaced subclass of the component class will usually be
* created.
+ *
+ * @return The class this enhancement operation is operating on.
*/
Class getBaseClass();
/**
* Returns a reference to a particular class. This will, effectively, by
the
* name of a private field.
+ *
+ * @param clazz The class to get a string equivalent reference of.
+ *
+ * @return The enhancement (javassist) compatiable string version of the
specified class.
*/
String getClassReference(Class clazz);
@@ -156,6 +167,11 @@
/**
* Returns the type of an existing property of the base component class. If
* the property does not exist, then returns null.
+ *
+ * @param name
+ * The property name.
+ *
+ * @return The property type, or null if it doesn't exist.
*/
Class getPropertyType(String name);
@@ -180,14 +196,19 @@
* @param code
* the Javassist markup to be added to the body of the method.
*/
- void extendMethodImplementation(Class interfaceClass,
- MethodSignature methodSignature, String code);
+ void extendMethodImplementation(Class interfaceClass, MethodSignature
methodSignature, String code);
/**
* Returns true if the class implements the specified interface. Checks the
* base class (as identified in the specification), but <em>also</em>
* accounts for any additional interfaces that may be added by
* [EMAIL PROTECTED] #extendMethodImplementation(Class, MethodSignature,
String)}.
+ *
+ * @param interfaceClass
+ * The class to check if the base class implements.
+ *
+ * @return Whether or not the specified interface is implemented by the
base class
+ * being enhanced.
*/
boolean implementsInterface(Class interfaceClass);
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhancementOperationImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhancementOperationImpl.java?view=diff&rev=539617&r1=539616&r2=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhancementOperationImpl.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/EnhancementOperationImpl.java
Fri May 18 15:27:40 2007
@@ -14,21 +14,6 @@
package org.apache.tapestry.enhance;
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.apache.commons.logging.Log;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ClassResolver;
@@ -45,6 +30,15 @@
import org.apache.tapestry.util.IdAllocator;
import org.apache.tapestry.util.ObjectIdentityMap;
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.*;
+
/**
* Implementation of [EMAIL PROTECTED]
org.apache.tapestry.enhance.EnhancementOperation}that
* knows how to collect class changes from enhancements. The method
@@ -102,7 +96,7 @@
/**
* Makes sure that names created by
- * [EMAIL PROTECTED] #addInjectedField(String, Object)} have unique names.
+ * [EMAIL PROTECTED] #addInjectedField(String, Class, Object)} have unique
names.
*/
private final IdAllocator _idAllocator = new IdAllocator();
@@ -182,8 +176,7 @@
}
catch (IntrospectionException ex)
{
- throw new ApplicationRuntimeException(EnhanceMessages
- .unabelToIntrospectClass(_baseClass, ex), ex);
+ throw new
ApplicationRuntimeException(EnhanceMessages.unabelToIntrospectClass(_baseClass,
ex), ex);
}
}
@@ -225,6 +218,7 @@
private void addPropertiesDeclaredInClass(Class introspectClass)
throws IntrospectionException
{
+
BeanInfo bi = Introspector.getBeanInfo(introspectClass);
PropertyDescriptor[] pds = bi.getPropertyDescriptors();
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/GenericsClassInspectorImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/GenericsClassInspectorImpl.java?view=diff&rev=539617&r1=539616&r2=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/GenericsClassInspectorImpl.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/GenericsClassInspectorImpl.java
Fri May 18 15:27:40 2007
@@ -13,13 +13,11 @@
// limitations under the License.
package org.apache.tapestry.enhance;
-import java.beans.BeanInfo;
+import org.apache.hivemind.ApplicationRuntimeException;
+
import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
-import org.apache.hivemind.ApplicationRuntimeException;
-
/**
* Implementation of [EMAIL PROTECTED] ClassInspector} that can properly handle
@@ -42,18 +40,32 @@
public MethodSignature getPropertyAccessor(Class type, String propertyName)
{
try {
- BeanInfo info = Introspector.getBeanInfo(type);
- PropertyDescriptor[] props = info.getPropertyDescriptors();
+ Method[] props = type.getMethods();
+ Method match = null;
for (int i=0; i < props.length; i++) {
-
- if (!propertyName.equals(props[i].getName())) {
+
+ String propName = getPropertyName(props[i]);
+
+ if (!propertyName.equals(propName)) {
continue;
}
+
+ // store for later retrieval if necessary
+ if (match == null)
+ match = props[i];
- return new GenericsMethodSignatureImpl(type,
props[i].getReadMethod() != null ? props[i].getReadMethod() :
props[i].getWriteMethod());
+ // try to find read methods before resorting to write
+ if (props[i].getReturnType() == void.class) {
+ continue;
+ }
+
+ return new GenericsMethodSignatureImpl(type, props[i]);
}
-
+
+ if (match != null)
+ return new GenericsMethodSignatureImpl(type, match);
+
} catch (Throwable t) {
throw new ApplicationRuntimeException("Error reading property " +
propertyName + " from base class : " + type, t);
@@ -62,4 +74,17 @@
return null;
}
+ static String getPropertyName(Method m)
+ {
+ String name = m.getName();
+
+ if (name.startsWith("get"))
+ name = name.substring(3);
+ else if (name.startsWith("set"))
+ name = name.substring(3);
+ else if (name.startsWith("is"))
+ name = name.substring(2);
+
+ return Introspector.decapitalize(name);
+ }
}
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/GenericsMethodSignatureImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/GenericsMethodSignatureImpl.java?view=diff&rev=539617&r1=539616&r2=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/GenericsMethodSignatureImpl.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/GenericsMethodSignatureImpl.java
Fri May 18 15:27:40 2007
@@ -53,23 +53,7 @@
Class resolvedType = resolveType(param, tvar);
if (resolvedType != null)
return resolvedType;
- /*
- if (param.getActualTypeArguments().length > 0) {
-
- for (int i = 0; i < tvar.getBounds().length; i++) {
- System.out.println("bounds value class is: " +
tvar.getBounds()[i].getClass());
- Type t = tvar.getBounds()[i];
- if (ParameterizedType.class.isInstance(t)) {
- ParameterizedType pt = (ParameterizedType)t;
-
- //System.out.println("bounds param type arguments are:
" + pt.getActualTypeArguments()[0].getClass() + " and param type arguments are:
" + param.getA);
- }
-
- Class resolvedType =
findType(param.getActualTypeArguments(), (Class)tvar.getBounds()[i]);
- if (resolvedType != null)
- return resolvedType;
- }
- }*/
+
}
return m.getReturnType();
@@ -132,21 +116,7 @@
if (TypeVariable.class.isInstance(genTypes[i])) {
Class resolved = resolveType(param,
(TypeVariable)genTypes[i]);
- System.out.println("Resolved parameter type is : " +
resolved);
-
- /* TypeVariable tvar = (TypeVariable)genTypes[i];
- for (int p = 0; p < tvar.getBounds().length; p++) {
-
- //System.out.println("Bounds parameter type is: " +
tvar.getBounds()[p].getClass());
-
- Class resolvedType =
findType(param.getActualTypeArguments(), (Class)tvar.getBounds()[p]);
- if (resolvedType != null) {
- types[i] = resolvedType;
- continue typeSearch;
- }
-
- types[i] = m.getParameterTypes()[i];
- }*/
+
if (resolved != null) {
types[i] = resolved;
continue;
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/MethodSignatureImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/MethodSignatureImpl.java?view=diff&rev=539617&r1=539616&r2=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/MethodSignatureImpl.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/enhance/MethodSignatureImpl.java
Fri May 18 15:27:40 2007
@@ -107,7 +107,7 @@
if (_returnType != ms._returnType)
return false;
-
+
if (!_name.equals(ms._name))
return false;
@@ -198,8 +198,8 @@
return false;
MethodSignatureImpl sig = (MethodSignatureImpl)ms;
-
- if (_returnType != sig._returnType)
+
+ if (!sig._returnType.isAssignableFrom(_returnType))
return false;
if (!_name.equals(sig._name))
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/BaseAutowire.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/BaseAutowire.java?view=diff&rev=539617&r1=539616&r2=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/BaseAutowire.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/BaseAutowire.java
Fri May 18 15:27:40 2007
@@ -18,8 +18,6 @@
/**
* Used to test [EMAIL PROTECTED] AutowireWorker}.
- *
- * @author jkuhnert
*/
public class BaseAutowire {
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/EnhancedClassValidatorTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/EnhancedClassValidatorTest.java?view=diff&rev=539617&r1=539616&r2=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/EnhancedClassValidatorTest.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/EnhancedClassValidatorTest.java
Fri May 18 15:27:40 2007
@@ -42,14 +42,22 @@
v.validate(AbstractBase.class, Complete.class, new
ComponentSpecification());
}
-
+
+ public void test_Generics_Complete()
+ {
+ EnhancedClassValidatorImpl v = new EnhancedClassValidatorImpl();
+ v.setClassInspector(new GenericsClassInspectorImpl());
+
+ v.validate(AbstractGenericBase.class, FooGenericComponent.class, new
ComponentSpecification());
+ }
+
/**
* Pass in an abstract class (with enhancement, its possible that a
supposedly concrete class
* may omit implementing an inherited abstract method, which is the whole
point of the
* validator.
*/
- public void testIncomplete()
+ public void test_Incomplete()
{
ErrorLog log = newErrorLog();
Location l = newLocation();
@@ -58,13 +66,11 @@
trainGetLocation(spec, l);
- log
- .error(
- "Method 'public abstract void
org.apache.tapestry.enhance.AbstractBase.foo()' "
- + "(declared in class
org.apache.tapestry.enhance.AbstractBase) has no implementation in class "
- + "org.apache.tapestry.enhance.AbstractBase
(or enhanced subclass org.apache.tapestry.enhance.Incomplete).",
- l,
- null);
+ log.error("Method 'public abstract void
org.apache.tapestry.enhance.AbstractBase.foo()' "
+ + "(declared in class
org.apache.tapestry.enhance.AbstractBase) has no implementation in class "
+ + "org.apache.tapestry.enhance.AbstractBase (or enhanced
subclass org.apache.tapestry.enhance.Incomplete).",
+ l,
+ null);
replay();
@@ -86,13 +92,11 @@
trainGetLocation(spec, l);
- log
- .error(
- "Method 'public abstract void
java.lang.Runnable.run()' "
- + "has no implementation in class
org.apache.tapestry.enhance.AbstractRunnable "
- + "(or enhanced subclass
org.apache.tapestry.enhance.AbstractRunnableSubclass).",
- l,
- null);
+ log.error("Method 'public abstract void java.lang.Runnable.run()' "
+ + "has no implementation in class
org.apache.tapestry.enhance.AbstractRunnable "
+ + "(or enhanced subclass
org.apache.tapestry.enhance.AbstractRunnableSubclass).",
+ l,
+ null);
replay();
@@ -115,7 +119,7 @@
* than other classes.
*/
- public void testObject()
+ public void test_Object()
{
EnhancedClassValidatorImpl v = new EnhancedClassValidatorImpl();
v.setClassInspector(new ClassInspectorImpl());
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/FooGenericComponent.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/FooGenericComponent.java?view=diff&rev=539617&r1=539616&r2=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/FooGenericComponent.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/FooGenericComponent.java
Fri May 18 15:27:40 2007
@@ -31,4 +31,14 @@
{
return null;
}
+
+ public FooGeneric getValue()
+ {
+ return null;
+ }
+
+ public void setSomethingCrazy(FooGeneric value)
+ {
+
+ }
}
Added:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericService.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericService.java?view=auto&rev=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericService.java
(added)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericService.java
Fri May 18 15:27:40 2007
@@ -0,0 +1,11 @@
+package org.apache.tapestry.enhance;
+
+/**
+ *
+ */
+public interface GenericService<E> {
+
+ void doFoo(E bar);
+
+ E getCurrentFoo();
+}
Propchange:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericService.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericService.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericServiceImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericServiceImpl.java?view=auto&rev=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericServiceImpl.java
(added)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericServiceImpl.java
Fri May 18 15:27:40 2007
@@ -0,0 +1,23 @@
+package org.apache.tapestry.enhance;
+
+/**
+ *
+ */
+public class GenericServiceImpl implements SimpleGenericsInterface {
+
+ private BasicObject _basic = new BasicObject();
+
+ public String getObjectName()
+ {
+ return _basic.getName();
+ }
+
+ public void doFoo(BasicObject bar)
+ {
+ }
+
+ public BasicObject getCurrentFoo()
+ {
+ return _basic;
+ }
+}
Propchange:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericServiceImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/GenericServiceImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/MethodSignatureTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/MethodSignatureTest.java?view=diff&rev=539617&r1=539616&r2=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/MethodSignatureTest.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/MethodSignatureTest.java
Fri May 18 15:27:40 2007
@@ -26,6 +26,7 @@
*/
@Test
public class MethodSignatureTest extends TestBase {
+
// used for non generic tests
class Simple {
@@ -107,12 +108,12 @@
assert child.isOverridingSignatureOf(base);
- assert child.equals(base);
- assert base.equals(child);
+ assert !child.equals(base);
+ assert !base.equals(child);
}
- public void test_Generic_Method_Hash() {
-
+ public void test_Generic_Method_Hash()
+ {
Class testClass = MyTest.class;
Method[] methods = testClass.getMethods();
@@ -128,6 +129,15 @@
assert sig.getReturnType() != null;
assertEquals(sig.getReturnType(), BaseTest.class);
+ }
+
+ public void test_Generic_Service_Property()
+ throws Exception
+ {
+ ClassInspector ins = new GenericsClassInspectorImpl();
+ MethodSignature m = ins.getPropertyAccessor(GenericServiceImpl.class,
"currentFoo");
+
+ assertEquals(m.getReturnType(), BasicObject.class);
}
public static abstract class BaseTest<T>{ }
Added:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/SimpleGenericsInterface.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/SimpleGenericsInterface.java?view=auto&rev=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/SimpleGenericsInterface.java
(added)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/SimpleGenericsInterface.java
Fri May 18 15:27:40 2007
@@ -0,0 +1,9 @@
+package org.apache.tapestry.enhance;
+
+/**
+ *
+ */
+public interface SimpleGenericsInterface extends GenericService<BasicObject> {
+
+ String getObjectName();
+}
Propchange:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/SimpleGenericsInterface.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/SimpleGenericsInterface.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/SimpleGenericsInterface.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestAutowireWorker.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestAutowireWorker.java?view=diff&rev=539617&r1=539616&r2=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestAutowireWorker.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestAutowireWorker.java
Fri May 18 15:27:40 2007
@@ -13,18 +13,17 @@
// limitations under the License.
package org.apache.tapestry.enhance;
-import static org.easymock.EasyMock.expect;
-
-import java.lang.reflect.Modifier;
-import java.util.Collections;
-
import org.apache.hivemind.Location;
import org.apache.hivemind.Registry;
import org.apache.hivemind.impl.RegistryBuilder;
import org.apache.hivemind.service.MethodSignature;
import org.apache.tapestry.spec.IComponentSpecification;
+import static org.easymock.EasyMock.expect;
import org.testng.annotations.Test;
+import java.lang.reflect.Modifier;
+import java.util.Collections;
+
/**
*
@@ -34,7 +33,7 @@
@Test(sequential = true)
public class TestAutowireWorker extends BaseEnhancementTestCase
{
-
+
private static final String HELLO_SERVICE_PROPERTY = "helloService";
public void test_No_Service() throws Exception
@@ -53,24 +52,19 @@
Location l = newLocation();
EnhancementOperation op = newMock(EnhancementOperation.class);
- expect(op.findUnclaimedAbstractProperties())
- .andReturn(Collections.singletonList( HELLO_SERVICE_PROPERTY ));
-
+
expect(op.findUnclaimedAbstractProperties()).andReturn(Collections.singletonList(
HELLO_SERVICE_PROPERTY ));
expect(op.getPropertyType( HELLO_SERVICE_PROPERTY
)).andReturn(HelloService.class);
-
expect(op.canClaimAsReadOnlyProperty(HELLO_SERVICE_PROPERTY)).andReturn(true);
IComponentSpecification spec = newMock(IComponentSpecification.class);
expect(spec.getLocation()).andReturn(l);
-
expect(spec.getDescription()).andReturn("Component1");
final String fieldName = "_$" + HELLO_SERVICE_PROPERTY;
final HelloService proxy = ( HelloService )registry.getService(
HelloService.class );
expect(op.addInjectedField( fieldName, HelloService.class, proxy
)).andReturn( fieldName );
-
expect(op.getAccessorMethodName( HELLO_SERVICE_PROPERTY
)).andReturn("getHelloService");
op.addMethod(Modifier.PUBLIC, new MethodSignature(HelloService.class,
"getHelloService", null,
@@ -84,7 +78,43 @@
verify();
}
-
+
+ private static final String GENERIC_PROPERTY = "genericService";
+
+ public void test_Generic_Service()
+ throws Exception
+ {
+ final Registry registry = buildFrameworkRegistry("autowire-single.xml"
);
+ Location l = newLocation();
+ EnhancementOperation op = newMock(EnhancementOperation.class);
+
+
expect(op.findUnclaimedAbstractProperties()).andReturn(Collections.singletonList(
GENERIC_PROPERTY ));
+ expect(op.getPropertyType( GENERIC_PROPERTY
)).andReturn(SimpleGenericsInterface.class);
+
expect(op.canClaimAsReadOnlyProperty(GENERIC_PROPERTY)).andReturn(true);
+
+ IComponentSpecification spec = newMock(IComponentSpecification.class);
+
+ expect(spec.getLocation()).andReturn(l);
+ expect(spec.getDescription()).andReturn("Component1");
+
+ final String fieldName = "_$" + GENERIC_PROPERTY;
+ final SimpleGenericsInterface proxy = ( SimpleGenericsInterface
)registry.getService( SimpleGenericsInterface.class );
+
+ expect(op.addInjectedField( fieldName, SimpleGenericsInterface.class,
proxy )).andReturn( fieldName );
+ expect(op.getAccessorMethodName( GENERIC_PROPERTY
)).andReturn("getGenericService");
+
+ op.addMethod(Modifier.PUBLIC, new
MethodSignature(SimpleGenericsInterface.class, "getGenericService", null,
+ null), "return " + fieldName + ";", l);
+ op.claimReadonlyProperty( GENERIC_PROPERTY );
+
+ replay();
+
+ final EnhancementWorker worker = ( EnhancementWorker
)registry.getService( "tapestry.enhance.AutowireWorker",
EnhancementWorker.class );
+ worker.performEnhancement( op, spec );
+
+ verify();
+ }
+
private void assertNotAutowired( Registry registry )
{
EnhancementOperation op = newMock(EnhancementOperation.class);
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestEnhancementOperation.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestEnhancementOperation.java?view=diff&rev=539617&r1=539616&r2=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestEnhancementOperation.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestEnhancementOperation.java
Fri May 18 15:27:40 2007
@@ -14,18 +14,6 @@
package org.apache.tapestry.enhance;
-import static org.easymock.EasyMock.aryEq;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.isNull;
-import static org.easymock.EasyMock.startsWith;
-
-import java.lang.reflect.Modifier;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.Location;
@@ -35,20 +23,23 @@
import org.apache.hivemind.service.ClassFactory;
import org.apache.hivemind.service.MethodSignature;
import org.apache.hivemind.service.impl.ClassFactoryImpl;
-import org.apache.tapestry.AbstractComponent;
-import org.apache.tapestry.BaseComponent;
-import org.apache.tapestry.BaseComponentTestCase;
-import org.apache.tapestry.IComponent;
-import org.apache.tapestry.IPage;
+import org.apache.tapestry.*;
import org.apache.tapestry.components.Insert;
import org.apache.tapestry.event.PageDetachListener;
import org.apache.tapestry.event.PageValidateListener;
import org.apache.tapestry.link.ServiceLink;
import org.apache.tapestry.services.ComponentConstructor;
import org.apache.tapestry.spec.IComponentSpecification;
+import static org.easymock.EasyMock.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* Tests for [EMAIL PROTECTED]
org.apache.tapestry.enhance.EnhancementOperationImpl}.
*
@@ -108,7 +99,7 @@
}
}
- public void testClaimedProperty()
+ public void test_Claimed_Property()
{
EnhancementOperationImpl eo = new EnhancementOperationImpl();
@@ -126,7 +117,7 @@
}
}
- public void testClaimReadonlyPropertyDoesNotExist()
+ public void test_Claim_Readonly_Property_Does_Not_Exist()
{
IComponentSpecification spec = newSpec();
ClassFactory cf = newClassFactory();
@@ -145,7 +136,7 @@
verify();
}
- public void testClaimReadonlyPropertyClaimed()
+ public void test_Claim_Readonly_Property_Claimed()
{
IComponentSpecification spec = newSpec();
ClassFactory cf = newClassFactory();
@@ -171,7 +162,7 @@
verify();
}
- public void testClaimReadonlyPropertyHasSetter()
+ public void test_Claim_Readonly_Property_Has_Setter()
{
IComponentSpecification spec = newSpec();
ClassFactory cf = newClassFactory();
@@ -225,7 +216,7 @@
return newMock(ClassFab.class);
}
- public void testConstructorAndAccessors()
+ public void test_Constructor_And_Accessors()
{
IComponentSpecification spec = newSpec();
ClassFactory cf = newClassFactory();
@@ -240,7 +231,7 @@
verify();
}
- public void testCheckImplementsNoInterface()
+ public void test_Check_Implements_No_Interface()
{
IComponentSpecification spec = newSpec();
ClassFactory cf = newClassFactory();
@@ -255,7 +246,7 @@
verify();
}
- public void testCheckImplementsClassImplements()
+ public void test_Check_Implements_Class_Implements()
{
IComponentSpecification spec = newSpec();
ClassFactory cf = newClassFactory(ValidatingComponent.class);
@@ -579,7 +570,7 @@
* construct a new class; the class gets a class reference passed to it in
its constructor.
*/
- public void testGetClassReference() throws Exception
+ public void test_Get_Class_Reference() throws Exception
{
Location l = newLocation();
IComponentSpecification spec = newSpec();
@@ -629,7 +620,7 @@
/**
* Really a test for [EMAIL PROTECTED]
org.apache.tapestry.enhance.ComponentConstructorImpl};
- * [EMAIL PROTECTED] #testGetClassReference()}tests the success case, just
want to fill in the failure.
+ * [EMAIL PROTECTED] #test_Get_Class_Reference()} tests the success case,
just want to fill in the failure.
*/
public void testComponentConstructorFailure()
@@ -654,7 +645,7 @@
}
}
- public void testGetPropertyType()
+ public void test_Get_Property_Type()
{
IComponentSpecification spec = newSpec();
ClassFactory cf = newClassFactory();
@@ -674,7 +665,7 @@
verify();
}
- public void testFindUnclaimedAbstractProperties()
+ public void test_Find_Unclaimed_Abstract_Properties()
{
ClassResolver cr = newMock(ClassResolver.class);
IComponentSpecification spec = newSpec();
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/autowire-single.xml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/autowire-single.xml?view=diff&rev=539617&r1=539616&r2=539617
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/autowire-single.xml
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/autowire-single.xml
Fri May 18 15:27:40 2007
@@ -16,10 +16,17 @@
-->
<module id="autowire.single" version="1.0.0">
- <service-point id="Hello"
interface="org.apache.tapestry.enhance.HelloService">
- <invoke-factory>
- <construct class="org.apache.tapestry.enhance.HelloServiceImpl" />
- </invoke-factory>
- </service-point>
+
+ <service-point id="Hello"
interface="org.apache.tapestry.enhance.HelloService">
+ <invoke-factory>
+ <construct class="org.apache.tapestry.enhance.HelloServiceImpl" />
+ </invoke-factory>
+ </service-point>
+
+ <service-point id="SimpleGeneric"
interface="org.apache.tapestry.enhance.SimpleGenericsInterface">
+ <invoke-factory>
+ <construct class="org.apache.tapestry.enhance.GenericServiceImpl"
/>
+ </invoke-factory>
+ </service-point>
</module>