You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2005/05/12 20:18:19 UTC
cvs commit: jakarta-tapestry/framework/src/test/org/apache/tapestry/junit TestComponentMessages.java
hlship 2005/05/12 11:18:19
Modified: framework/src/java/org/apache/tapestry/enhance
InjectSpecificationWorker.java EnhanceMessages.java
EnhancementOperation.java InjectStateWorker.java
EnhancementOperationImpl.java
SpecifiedPropertyWorker.java
EnhanceStrings.properties InjectMessagesWorker.java
. status.xml
src/documentation/content/xdocs/UsersGuide spec.xml
common.ent index.xml state.xml
framework/src/java/org/apache/tapestry/spec
InjectSpecificationImpl.java
IComponentSpecification.java SpecFactory.java
InjectSpecification.java
ComponentSpecification.java
framework/src/test/org/apache/tapestry/enhance
TestSpecifiedPropertyWorker.java
TestInjectMessagesWorker.java
TestInjectSpecificationWorker.java
TestInjectStateWorker.java
framework/src/java/org/apache/tapestry/parse
SpecificationParser.java Tapestry_4_0.dtd
framework/src/descriptor/META-INF tapestry.enhance.xml
framework/src/test/org/apache/tapestry/junit/parse
Inject.jwc TestSpecificationParser.java
framework/src/test/org/apache/tapestry/junit
TestComponentMessages.java
Added: framework/src/java/org/apache/tapestry/enhance
DispatchToInjectWorker.java InjectObjectWorker.java
InjectEnhancementWorker.java
framework/src/test/org/apache/tapestry/enhance
TestDispatchToInjectWorker.java
TestInjectObjectWorker.java
Removed: framework/src/java/org/apache/tapestry/enhance
InjectWorker.java
framework/src/java/org/apache/tapestry/spec
InjectStateSpecification.java
InjectStateSpecificationImpl.java
framework/src/test/org/apache/tapestry/enhance
TestInjectWorker.java
framework/src/test/org/apache/tapestry/junit/parse
InjectState.page
Log:
Remove <inject-state>, add type attribute to <inject>.
Revision Changes Path
1.3 +1 -3 jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectSpecificationWorker.java
Index: InjectSpecificationWorker.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectSpecificationWorker.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InjectSpecificationWorker.java 18 Apr 2005 17:06:34 -0000 1.2
+++ InjectSpecificationWorker.java 12 May 2005 18:18:18 -0000 1.3
@@ -47,9 +47,7 @@
{
op.claimProperty(SPECIFICATION_PROPERTY_NAME);
- String fieldName = "_$" + SPECIFICATION_PROPERTY_NAME;
-
- op.addField(fieldName, IComponentSpecification.class, spec);
+ String fieldName = op.addFinalField("_$" + SPECIFICATION_PROPERTY_NAME, spec);
EnhanceUtils.createSimpleAccessor(
op,
1.13 +15 -12 jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhanceMessages.java
Index: EnhanceMessages.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhanceMessages.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- EnhanceMessages.java 18 Apr 2005 17:06:34 -0000 1.12
+++ EnhanceMessages.java 12 May 2005 18:18:18 -0000 1.13
@@ -31,19 +31,19 @@
private static final MessageFormatter _formatter = new MessageFormatter(EnhanceMessages.class,
"EnhanceStrings");
- public static String noImplForAbstractMethod(Method method, Class declareClass,
- String className, Class enhancedClass)
+ static String noImplForAbstractMethod(Method method, Class declareClass, String className,
+ Class enhancedClass)
{
return _formatter.format("no-impl-for-abstract-method", new Object[]
{ method, declareClass.getName(), className, enhancedClass.getName() });
}
- public static String unabelToIntrospectClass(Class targetClass, Throwable cause)
+ static String unabelToIntrospectClass(Class targetClass, Throwable cause)
{
return _formatter.format("unable-to-introspect-class", targetClass.getName(), cause);
}
- public static String propertyTypeMismatch(Class componentClass, String propertyName,
+ static String propertyTypeMismatch(Class componentClass, String propertyName,
Class actualPropertyType, Class expectedPropertyType)
{
return _formatter.format("property-type-mismatch", new Object[]
@@ -52,9 +52,7 @@
ClassFabUtils.getJavaClassName(expectedPropertyType) });
}
-
- public static String errorAddingProperty(String propertyName, Class componentClass,
- Throwable cause)
+ static String errorAddingProperty(String propertyName, Class componentClass, Throwable cause)
{
return _formatter.format(
"error-adding-property",
@@ -63,29 +61,34 @@
cause);
}
- public static String claimedProperty(String propertyName)
+ static String claimedProperty(String propertyName)
{
return _formatter.format("claimed-property", propertyName);
}
- public static String instantiationFailure(Constructor c, Throwable cause)
+ static String instantiationFailure(Constructor c, Throwable cause)
{
return _formatter.format("instantiation-failure", c.getDeclaringClass().getName(), cause);
}
- public static String locatedValueIsNull(String objectReference)
+ static String locatedValueIsNull(String objectReference)
{
return _formatter.format("located-value-is-null", objectReference);
}
- public static String incompatibleInjectType(String locator, Object value, Class propertyType)
+ static String incompatibleInjectType(String locator, Object value, Class propertyType)
{
return _formatter.format("incompatible-inject-type", locator, value, ClassFabUtils
.getJavaClassName(propertyType));
}
- public static String initialValueForProperty(String propertyName)
+ static String initialValueForProperty(String propertyName)
{
return _formatter.format("initial-value-for-property", propertyName);
}
+
+ static String unknownInjectType(String propertyName, String injectType)
+ {
+ return _formatter.format("unknown-inject-type", propertyName, injectType);
+ }
}
\ No newline at end of file
1.14 +17 -8 jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhancementOperation.java
Index: EnhancementOperation.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhancementOperation.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- EnhancementOperation.java 18 Apr 2005 17:06:34 -0000 1.13
+++ EnhancementOperation.java 12 May 2005 18:18:18 -0000 1.14
@@ -54,10 +54,20 @@
/**
* Adds a field containing an initial value. The EnhancementOperation will ensure that the value
- * is passed into the enhanced class' constructor and assigned.
+ * is passed into the enhanced class' constructor and assigned. This method may be called
+ * multiple times with the same value and will return the name variable name (an identity map is
+ * kept internally).
+ *
+ * @param fieldName
+ * The name of the field, used if a new field (and contructor argument) is being
+ * created. Only used if a field for the value doesn't exist.
+ * @param value
+ * the value to be referenced, which may not be null
+ * @return the name of the field (which may be fieldName, or maybe not, if some other
+ * enhancement worker created the field first).
*/
- public void addField(String name, Class type, Object value);
+ public String addFinalField(String fieldName, Object value);
/**
* Converts a type name (an object class name, a primtive name, or an array) into the
@@ -133,13 +143,12 @@
*/
public 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 {@link #extendMethodImplementation(Class, MethodSignature, String)}.
- *
+ * 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 {@link #extendMethodImplementation(Class, MethodSignature, String)}.
*/
-
+
public boolean implementsInterface(Class interfaceClass);
}
\ No newline at end of file
1.4 +12 -51 jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectStateWorker.java
Index: InjectStateWorker.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectStateWorker.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- InjectStateWorker.java 18 Apr 2005 17:06:34 -0000 1.3
+++ InjectStateWorker.java 12 May 2005 18:18:18 -0000 1.4
@@ -15,17 +15,13 @@
package org.apache.tapestry.enhance;
import java.lang.reflect.Modifier;
-import java.util.Iterator;
-import java.util.List;
-import org.apache.hivemind.ErrorLog;
import org.apache.hivemind.service.BodyBuilder;
import org.apache.hivemind.service.ClassFabUtils;
import org.apache.hivemind.service.MethodSignature;
import org.apache.tapestry.engine.state.ApplicationStateManager;
import org.apache.tapestry.event.PageDetachListener;
-import org.apache.tapestry.spec.IComponentSpecification;
-import org.apache.tapestry.spec.InjectStateSpecification;
+import org.apache.tapestry.spec.InjectSpecification;
/**
* Worker for injecting application state objects as properties of the component. These properties
@@ -36,66 +32,36 @@
* @author Howard M. Lewis Ship
* @since 4.0
*/
-public class InjectStateWorker implements EnhancementWorker
+public class InjectStateWorker implements InjectEnhancementWorker
{
- private ErrorLog _errorLog;
-
private ApplicationStateManager _applicationStateManager;
- public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
+ public void performEnhancement(EnhancementOperation op, InjectSpecification spec)
{
- List injects = spec.getInjectStateSpecifications();
-
- if (injects.isEmpty())
- return;
-
- // TODO: The EnhancementOperation should have a way of assigning non-conflicting
- // attribute names. What if someone injects a property named "applicationStateManager"
- // as well?
-
- op.addField(
- "_$applicationStateManager",
- ApplicationStateManager.class,
- _applicationStateManager);
-
- Iterator i = injects.iterator();
- while (i.hasNext())
- {
- InjectStateSpecification iss = (InjectStateSpecification) i.next();
-
- try
- {
- injectState(op, iss.getProperty(), iss.getObjectName());
- }
- catch (Exception ex)
- {
- _errorLog.error(EnhanceMessages.errorAddingProperty(iss.getProperty(), op
- .getBaseClass(), ex), iss.getLocation(), ex);
- }
- }
+ injectState(op, spec.getProperty(), spec.getObject());
}
private void injectState(EnhancementOperation op, String propertyName, String objectName)
{
- Class propertyType =
- EnhanceUtils.extractPropertyType(op, propertyName, null);
+ Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, null);
String fieldName = "_$" + propertyName;
op.claimProperty(propertyName);
op.addField(fieldName, propertyType);
+ String managerField = op.addFinalField(
+ "_$applicationStateManager",
+ _applicationStateManager);
+
BodyBuilder builder = new BodyBuilder();
// Accessor
builder.begin();
builder.addln("if ({0} == null)", fieldName);
- builder.addln(
- " {0} = ({1}) _$applicationStateManager.get(\"{2}\");",
- fieldName,
- ClassFabUtils.getJavaClassName(propertyType),
- objectName);
+ builder.addln(" {0} = ({1}) {2}.get(\"{3}\");", new Object[]
+ { fieldName, ClassFabUtils.getJavaClassName(propertyType), managerField, objectName });
builder.addln("return {0};", fieldName);
builder.end();
@@ -109,7 +75,7 @@
builder.clear();
builder.begin();
- builder.addln("_$applicationStateManager.store(\"{0}\", $1);", objectName);
+ builder.addln("{0}.store(\"{1}\", $1);", managerField, objectName);
builder.addln("{0} = $1;", fieldName);
builder.end();
@@ -131,9 +97,4 @@
{
_applicationStateManager = applicationStateManager;
}
-
- public void setErrorLog(ErrorLog errorLog)
- {
- _errorLog = errorLog;
- }
}
\ No newline at end of file
1.17 +38 -20 jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhancementOperationImpl.java
Index: EnhancementOperationImpl.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhancementOperationImpl.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- EnhancementOperationImpl.java 18 Apr 2005 17:06:34 -0000 1.16
+++ EnhancementOperationImpl.java 12 May 2005 18:18:18 -0000 1.17
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -58,13 +59,15 @@
private ClassFab _classFab;
- private Set _claimedProperties = new HashSet();
+ private final Set _claimedProperties = new HashSet();
- private JavaClassMapping _javaClassMapping = new JavaClassMapping();
+ private final JavaClassMapping _javaClassMapping = new JavaClassMapping();
- private List _constructorTypes = new ArrayList();
+ private final List _constructorTypes = new ArrayList();
- private List _constructorArguments = new ArrayList();
+ private final List _constructorArguments = new ArrayList();
+
+ private final Map _finalFields = new IdentityHashMap();
/**
* Set of interfaces added to the enhanced class.
@@ -79,12 +82,6 @@
private Map _incompleteMethods = new HashMap();
/**
- * Keyed on class to instance variable name.
- */
-
- private Map _classReferences = new HashMap();
-
- /**
* Map of property names to {@link PropertyDescriptor}.
*/
@@ -227,13 +224,38 @@
_classFab.addField(name, type);
}
- public void addField(String name, Class type, Object value)
+ public String addFinalField(String fieldName, Object value)
{
- _classFab.addField(name, type);
+ Defense.notNull(fieldName, "fieldName");
+ Defense.notNull(value, "value");
+
+ String existing = (String) _finalFields.get(value);
+
+ // See if this object has been previously added.
+
+ if (existing != null)
+ return existing;
+
+ // TODO: Should be ensure that the name is unique?
+
+ // Add a new field using the object's actual type.
- int x = addConstructorParameter(type, value);
+ Class type = value.getClass();
- constructorBuilder().addln("{0} = ${1};", name, Integer.toString(x));
+ // ClassFab doesn't have an option for saying the field should be final, just private.
+ // Doesn't make a huge difference.
+
+ _classFab.addField(fieldName, type);
+
+ int parameterIndex = addConstructorParameter(type, value);
+
+ constructorBuilder().addln("{0} = ${1};", fieldName, Integer.toString(parameterIndex));
+
+ // Remember the mapping from the value to the field name.
+
+ _finalFields.put(value, fieldName);
+
+ return fieldName;
}
public Class convertTypeName(String type)
@@ -314,7 +336,7 @@
{
Defense.notNull(clazz, "clazz");
- String result = (String) _classReferences.get(clazz);
+ String result = (String) _finalFields.get(clazz);
if (result == null)
result = addClassReference(clazz);
@@ -338,11 +360,7 @@
String fieldName = buffer.toString();
- addField(fieldName, Class.class, clazz);
-
- _classReferences.put(clazz, fieldName);
-
- return fieldName;
+ return addFinalField(fieldName, clazz);
}
/**
1.10 +1 -2 jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/SpecifiedPropertyWorker.java
Index: SpecifiedPropertyWorker.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/SpecifiedPropertyWorker.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SpecifiedPropertyWorker.java 18 Apr 2005 17:06:34 -0000 1.9
+++ SpecifiedPropertyWorker.java 12 May 2005 18:18:18 -0000 1.10
@@ -131,8 +131,7 @@
InitialValueBindingCreator creator = new InitialValueBindingCreator(_bindingSource,
description, initialValue, location);
- String creatorField = fieldName + "$initialValueBindingCreator";
- op.addField(creatorField, InitialValueBindingCreator.class, creator);
+ String creatorField = op.addFinalField(fieldName + "$initialValueBindingCreator", creator);
String bindingField = fieldName + "$initialValueBinding";
op.addField(bindingField, IBinding.class);
1.11 +2 -1 jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhanceStrings.properties
Index: EnhanceStrings.properties
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/EnhanceStrings.properties,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- EnhanceStrings.properties 10 Feb 2005 16:22:58 -0000 1.10
+++ EnhanceStrings.properties 12 May 2005 18:18:18 -0000 1.11
@@ -21,4 +21,5 @@
located-value-is-null=Value obtained using locator ''{0}'' is null.
incompatible-inject-type=The value obtained using locator ''{0}'' ({1}) is not compatible with the existing property (of type {2}).
-initial-value-for-property=initial value for property {0}
\ No newline at end of file
+initial-value-for-property=initial value for property {0}
+unknown-inject-type=Unable to create injected property {0}: injection type ''{1}'' is not defined.
\ No newline at end of file
1.3 +11 -9 jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectMessagesWorker.java
Index: InjectMessagesWorker.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectMessagesWorker.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InjectMessagesWorker.java 18 Apr 2005 17:06:34 -0000 1.2
+++ InjectMessagesWorker.java 12 May 2005 18:18:18 -0000 1.3
@@ -18,6 +18,7 @@
import org.apache.hivemind.ErrorLog;
import org.apache.hivemind.Messages;
+import org.apache.hivemind.service.BodyBuilder;
import org.apache.hivemind.service.MethodSignature;
import org.apache.tapestry.services.ComponentMessagesSource;
import org.apache.tapestry.spec.IComponentSpecification;
@@ -37,10 +38,6 @@
private ComponentMessagesSource _componentMessagesSource;
- final String METHOD_CODE = "{\nif (_$messages == null)\n"
- + " _$messages = _$componentMessagesSource.getMessages(this);\n"
- + "return _$messages;\n}\n";
-
final MethodSignature METHOD_SIGNATURE = new MethodSignature(Messages.class, "getMessages",
null, null);
@@ -50,13 +47,18 @@
{
op.claimProperty(MESSAGES_PROPERTY);
- op.addField(
- "_$componentMessagesSource",
- ComponentMessagesSource.class,
- _componentMessagesSource);
+ String sourceField = op.addFinalField("_$componentMessagesSource", _componentMessagesSource);
+
op.addField("_$messages", Messages.class);
- op.addMethod(Modifier.PUBLIC, METHOD_SIGNATURE, METHOD_CODE);
+ BodyBuilder builder = new BodyBuilder();
+ builder.begin();
+ builder.addln("if (_$messages == null)");
+ builder.addln(" _$messages = {0}.getMessages(this);", sourceField);
+ builder.addln("return _$messages;");
+ builder.end();
+
+ op.addMethod(Modifier.PUBLIC, METHOD_SIGNATURE, builder.toString());
}
catch (Exception ex)
{
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/DispatchToInjectWorker.java
Index: DispatchToInjectWorker.java
===================================================================
// Copyright 2005 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.enhance;
import java.util.Iterator;
import java.util.Map;
import org.apache.hivemind.ErrorLog;
import org.apache.tapestry.spec.IComponentSpecification;
import org.apache.tapestry.spec.InjectSpecification;
/**
* Iterates over the {@link org.apache.tapestry.spec.InjectSpecification}s and locates and
* delegates to a {@link org.apache.tapestry.enhance.InjectEnhancementWorker} for each one.
*
* @author Howard M. Lewis Ship
* @since 4.0
*/
public class DispatchToInjectWorker implements EnhancementWorker
{
private ErrorLog _errorLog;
private Map _injectWorkers;
public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
{
Iterator i = spec.getInjectSpecifications().iterator();
while (i.hasNext())
{
InjectSpecification is = (InjectSpecification) i.next();
invokeWorker(op, is);
}
}
private void invokeWorker(EnhancementOperation op, InjectSpecification spec)
{
try
{
InjectEnhancementWorker worker = (InjectEnhancementWorker) _injectWorkers.get(spec
.getType());
if (worker == null)
{
_errorLog.error(EnhanceMessages.unknownInjectType(spec.getProperty(), spec
.getType()), spec.getLocation(), null);
return;
}
worker.performEnhancement(op, spec);
}
catch (Exception ex)
{
_errorLog.error(EnhanceMessages.errorAddingProperty(spec.getProperty(), op
.getBaseClass(), ex), spec.getLocation(), ex);
}
}
public void setErrorLog(ErrorLog errorLog)
{
_errorLog = errorLog;
}
public void setInjectWorkers(Map injectWorkers)
{
_injectWorkers = injectWorkers;
}
}
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectObjectWorker.java
Index: InjectObjectWorker.java
===================================================================
// Copyright 2004, 2005 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.enhance;
import java.lang.reflect.Modifier;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.service.MethodSignature;
import org.apache.tapestry.services.InjectedValueProvider;
import org.apache.tapestry.spec.InjectSpecification;
/**
* Implementation for injection type "object" (the default). Adds read-only properties to the
* enhanced class that contain objects injected from HiveMind.
*
* @author Howard M. Lewis Ship
* @since 4.0
*/
public class InjectObjectWorker implements InjectEnhancementWorker
{
private InjectedValueProvider _provider;
public void performEnhancement(EnhancementOperation op, InjectSpecification is)
{
String name = is.getProperty();
String objectReference = is.getObject();
Class propertyType = op.getPropertyType(name);
if (propertyType == null)
propertyType = Object.class;
String fieldName = "_$" + name;
op.claimProperty(name);
Object injectedValue = _provider.obtainValue(objectReference, is.getLocation());
if (injectedValue == null)
throw new ApplicationRuntimeException(EnhanceMessages
.locatedValueIsNull(objectReference), is.getLocation(), null);
if (!propertyType.isAssignableFrom(injectedValue.getClass()))
throw new ApplicationRuntimeException(EnhanceMessages.incompatibleInjectType(
objectReference,
injectedValue,
propertyType), is.getLocation(), null);
op.addFinalField(fieldName, injectedValue);
String methodName = EnhanceUtils.createAccessorMethodName(name);
op.addMethod(
Modifier.PUBLIC,
new MethodSignature(propertyType, methodName, null, null),
"return " + fieldName + ";");
}
public void setProvider(InjectedValueProvider provider)
{
_provider = provider;
}
}
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectEnhancementWorker.java
Index: InjectEnhancementWorker.java
===================================================================
// Copyright 2005 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.enhance;
import org.apache.tapestry.spec.InjectSpecification;
/**
* A kind of enhancement worker dedicated to injection, based on the <inject> element of the
* specification. There are different types of injection which match up to different implementations
* of this interface (i.e., the Strategy pattern).
*
* @author Howard M. Lewis Ship
* @since 4.0
* @see org.apache.tapestry.spec.InjectSpecification
* @see org.apache.tapestry.enhance.DispatchToInjectWorker
*/
public interface InjectEnhancementWorker
{
/**
* Perform the enhancement defined by the {@link org.apache.tapestry.spec.InjectSpecification}.
* Thrown runtime exceptions are caught and reported by the invoker.
*/
public void performEnhancement(EnhancementOperation op, InjectSpecification spec);
}
1.104 +1 -0 jakarta-tapestry/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/status.xml,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -r1.103 -r1.104
--- status.xml 11 May 2005 17:07:20 -0000 1.103
+++ status.xml 12 May 2005 18:18:18 -0000 1.104
@@ -59,6 +59,7 @@
<action type="fix" dev="HLS" fixes-bug="TAPESTRY-320"> Property seperate data from different users stored using the tapestry.persist.ClientPropertyPersistenceStrategy service.</action>
<action type="add" dev="HLS"> Store the Registry as a ServletContext attribute, so that it may be accessed from other servlets. </action>
<action type="add" dev="HLS" fixes-bug="TAPESTRY-323"> Allow control over the ErrorHandler used when building the HiveMind Registry. </action>
+ <action type="update" dev="HLS"> Remove <inject-state>, and add type attribute to <inject>.</action>
</release>
<release version="4.0-alpha-2" date="May 5 2005">
<action type="update" dev="HLS"> Coordinate Locale changes with the hivemind.ThreadLocale service. </action>
1.24 +25 -52 jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/spec.xml
Index: spec.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/spec.xml,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- spec.xml 2 May 2005 14:18:37 -0000 1.23
+++ spec.xml 12 May 2005 18:18:18 -0000 1.24
@@ -137,7 +137,6 @@
have been consolidated into <set>, which now uses a (wait for it)
&binding-reference;.</li>
<li>The 4.0 DTD is more liberal about the order in which elements may be specified than the 3.0 DTD.</li>
- <li>The &spec.inject-state; element has been added.</li>
<li>Added the property attribute to the &spec.component; and &spec.bean; elements.</li>
<li>Removed the type attribute from the &spec.configure; element.</li>
<li>Added many more options for <link href="#spec.boolean-types">boolean attributes</link>.</li>
@@ -154,7 +153,7 @@
<title>Property Injection</title>
<p>
-Several of the specification elements are concerned with <em>property injection</em>. For &spec.inject; and &spec.inject-state;,
+Several of the specification elements are concerned with <em>property injection</em>. For &spec.inject;,
the entire element exists to describe a property injection; in others (&spec.component;, &spec.bean; and &spec.asset;),
the injection is just one piece of the behavior defined using the element.
</p>
@@ -929,22 +928,6 @@
</tr>
<tr>
- <td>object</td>
- <td>string</td>
- <td>yes</td>
- <td/>
- <td>
- The <em>object reference</em> for the object to be injected. An object
- reference contains a prefix, such as "service:", which defines the
- type of object to locate. The string following the prefix locates the specific object to be returned.
- &HiveMind; provides a
- <link href="http://jakarta.apache.org/hivemind/hivemind/ObjectProviders.html">basic set of prefixes</link>;
- Tapestry adds <link href="hivemind.html#hivemind.inject">several additional prefixes</link>.
-
- </td>
-</tr>
-
-<tr>
<td>property</td>
<td>string</td>
<td>yes</td>
@@ -954,56 +937,46 @@
the type of the property; otherwise java.lang.Object will be used.
</td>
</tr>
- </table>
-
-</section>
-
-<section id="spec.inject-state">
- <title><inject-state> element</title>
-
- <p>
- Appears in: &spec.component-specification; and &spec.page-specification;.
- </p>
-
- <p>
- <em>Injects</em> an &aso; into a component as a property. Reading the property will obtain the state object
- from the application state manager (this may cause the object to be created). Updating the property
- will store a new value into the application state manager (overwriting the initially created one).
- </p>
-
- <table>
<tr>
- <th>Name</th>
- <th>Type</th>
- <th>Required ?</th>
- <th>Default Value</th>
- <th>Description</th>
-</tr>
-
-<tr>
- <td>object</td>
+ <td>type</td>
<td>string</td>
- <td>yes</td>
- <td/>
+ <td>no</td>
+ <td>object</td>
<td>
- The object name of the &aso;
+ The type of injection, which determines how the object attribute is interpreted.
</td>
</tr>
<tr>
- <td>property</td>
+ <td>object</td>
<td>string</td>
<td>yes</td>
<td/>
<td>
- The name of the property to be created. If the class provides an abstract accessor method, then that method defines
- the type of the property; otherwise java.lang.Object will be used.
+ The <em>object reference</em> for the object to be injected.
+
</td>
</tr>
+
</table>
-</section>
+<p>
+For object injection, the object attribute is a reference to a HiveMind object.
+Such an object contains a prefix, such as "service:", which defines the
+ type of object to locate within the HiveMind Registry. The string following the prefix locates the specific object to be returned.
+ &HiveMind; provides a
+ <link href="http://jakarta.apache.org/hivemind/hivemind/ObjectProviders.html">basic set of prefixes</link>;
+ Tapestry adds <link href="hivemind.html#hivemind.inject">several additional prefixes</link>. This
+ style of injection results in a read-only property.
+</p>
+
+<p>
+For state injection, the object attribute is the name of the &aso; to inject. This injection
+will result in a read/write property.
+</p>
+</section> <!-- spec.inject -->
+
<section id="spec.library">
<title><library> element</title>
1.19 +0 -1 jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/common.ent
Index: common.ent
===================================================================
RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/common.ent,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- common.ent 13 Apr 2005 22:38:46 -0000 1.18
+++ common.ent 12 May 2005 18:18:18 -0000 1.19
@@ -31,7 +31,6 @@
<!ENTITY spec.description '<link href="spec.html#spec.description"><description></link>'>
<!ENTITY spec.extension '<link href="spec.html#spec.extension"><extension></link>'>
<!ENTITY spec.inject '<link href="spec.html#spec.inject"><inject></link>'>
-<!ENTITY spec.inject-state '<link href="spec.html#spec.inject-state"><inject-state></link>'>
<!ENTITY spec.library '<link href="spec.html#spec.library"><library></link>'>
<!ENTITY spec.library-specification '<link href="spec.html#spec.library-specification"><library-specification></link>'>
<!ENTITY spec.listener-binding '<link href="spec.html#spec.listener-binding"><listener-binding></link>'>
1.9 +2 -0 jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/index.xml
Index: index.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/index.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- index.xml 18 Apr 2005 17:09:03 -0000 1.8
+++ index.xml 12 May 2005 18:18:18 -0000 1.9
@@ -307,6 +307,8 @@
A further future direction, in the Tapestry 4.0 timeframe (the far future), is to rethink the component object model
such that the classes <em>you</em> write do not sub-class Tapestry base classes. Page and component Java classes will
be simple POJOs (Plain Old Java Objects) and will have any Tapestry dependencies <em>injected</em> into them.
+ Also on the table is sidelining or entirely eliminating the XML page and component specifications in favor
+ of Java annotations.
</p>
</section>
1.15 +11 -5 jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/state.xml
Index: state.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/state.xml,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- state.xml 18 Apr 2005 17:09:03 -0000 1.14
+++ state.xml 12 May 2005 18:18:18 -0000 1.15
@@ -409,7 +409,7 @@
<note>
The two default ASOs, "visit" and "global", are defined in the hivemind.state.FactoryObjects configuration point. Definitions
- in the ApplicationObjects configuration point override the definitions in FactoryObjects.
+ in the ApplicationObjects configuration point override definitions in FactoryObjects with the same name.
</note>
</section> <!-- state.aso.defining -->
@@ -418,7 +418,7 @@
<title>Accessing Application State Objects</title>
<p>
-Tapestry provides an &spec.inject-state; element to support access to the application state objects. This
+Tapestry provides an &spec.inject; element to support access to the application state objects. This
element can be used in any page or component specification to create a new property. Reading the property
will obtain the corresponding state object (which will be created if necessary). The property may be updated,
which will store a new application state object, overwriting the automatically created one.
@@ -429,7 +429,7 @@
</p>
<source><![CDATA[
-<inject-state name="registration" object="registration-data"/>
+<inject name="registration" type="state" object="registration-data"/>
]]></source>
<p>
@@ -490,9 +490,15 @@
<p>
The application may be <em>stateless</em> even when it has persistent page properties, if those properties use the
<em>client</em> persistence strategy (which encodes pesistent page data into URLs as query parameters). This can be a
-very powerful approach.
+very powerful approach, though it introduces its own problems:
</p>
-
+
+<ul>
+ <li>The query parameters are an encoding of Java objects, and could be decoded to expose
+ privileged information.</li>
+ <li>The encoding of page state can result in very long strings included as part of URLs, possibly extending beyond the 3000 to 4000 character effective maximum
+ URL length.</li>
+</ul>
</section> <!-- state.stateless -->
</body>
1.6 +17 -5 jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/InjectSpecificationImpl.java
Index: InjectSpecificationImpl.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/InjectSpecificationImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- InjectSpecificationImpl.java 18 Apr 2005 17:06:40 -0000 1.5
+++ InjectSpecificationImpl.java 12 May 2005 18:18:19 -0000 1.6
@@ -24,16 +24,18 @@
{
private String _property;
- private String _objectReference;
+ private String _object;
- public String getObjectReference()
+ private String _type;
+
+ public String getObject()
{
- return _objectReference;
+ return _object;
}
- public void setObjectReference(String locator)
+ public void setObject(String object)
{
- _objectReference = locator;
+ _object = object;
}
public String getProperty()
@@ -45,4 +47,14 @@
{
_property = name;
}
+
+ public String getType()
+ {
+ return _type;
+ }
+
+ public void setType(String type)
+ {
+ _type = type;
+ }
}
\ No newline at end of file
1.8 +0 -18 jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/IComponentSpecification.java
Index: IComponentSpecification.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/IComponentSpecification.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- IComponentSpecification.java 18 Apr 2005 17:06:40 -0000 1.7
+++ IComponentSpecification.java 12 May 2005 18:18:19 -0000 1.8
@@ -273,22 +273,4 @@
*/
public List getInjectSpecifications();
-
- /**
- * Adds a {@link org.apache.tapestry.spec.InjectStateSpecification}s.
- *
- * @since 4.0
- */
-
- public void addInjectStateSpecification(InjectStateSpecification spec);
-
- /**
- * Returns the list of {@link org.apache.tapestry.spec.InjectStateSpecification}s. Returns an
- * empty list if no specifications have been added.
- *
- * @since 4.0
- */
-
- public List getInjectStateSpecifications();
-
}
\ No newline at end of file
1.11 +0 -6 jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/SpecFactory.java
Index: SpecFactory.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/SpecFactory.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- SpecFactory.java 18 Apr 2005 17:06:40 -0000 1.10
+++ SpecFactory.java 12 May 2005 18:18:19 -0000 1.11
@@ -183,10 +183,4 @@
{
return new InjectSpecificationImpl();
}
-
- /** @since 4.0 */
- public InjectStateSpecification createInjectStateSpecification()
- {
- return new InjectStateSpecificationImpl();
- }
}
\ No newline at end of file
1.6 +13 -4 jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/InjectSpecification.java
Index: InjectSpecification.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/InjectSpecification.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- InjectSpecification.java 18 Apr 2005 17:06:40 -0000 1.5
+++ InjectSpecification.java 12 May 2005 18:18:19 -0000 1.6
@@ -31,11 +31,20 @@
public void setProperty(String property);
/**
- * Returns the object reference used to locate the HiveMind object to be injected into the
- * enhanced class.
+ * Returns the type of injection. Different injection types interpret the
+ * {@link #getObject() object property} differently. Ultimately, the type is used to select the
+ * correct {@link org.apache.tapestry.enhance.InjectEnhancementWorker}.
*/
- public String getObjectReference();
+ public String getType();
- public void setObjectReference(String locator);
+ public void setType(String type);
+
+ /**
+ * Returns the string used to indentify a particular object.
+ */
+
+ public String getObject();
+
+ public void setObject(String object);
}
\ No newline at end of file
1.7 +0 -21 jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/ComponentSpecification.java
Index: ComponentSpecification.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/ComponentSpecification.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ComponentSpecification.java 18 Apr 2005 17:06:40 -0000 1.6
+++ ComponentSpecification.java 12 May 2005 18:18:19 -0000 1.7
@@ -150,14 +150,6 @@
private List _injectSpecifications;
/**
- * List of {@link InjectStateSpecification}.
- *
- * @since 4.0
- */
-
- private List _injectStateSpecifications;
-
- /**
* @throws IllegalArgumentException
* if the name already exists.
*/
@@ -594,19 +586,6 @@
return safeList(_injectSpecifications);
}
- public void addInjectStateSpecification(InjectStateSpecification spec)
- {
- if (_injectStateSpecifications == null)
- _injectStateSpecifications = new ArrayList();
-
- _injectStateSpecifications.add(spec);
- }
-
- public List getInjectStateSpecifications()
- {
- return safeList(_injectStateSpecifications);
- }
-
private List safeList(List input)
{
if (input == null)
1.10 +4 -4 jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestSpecifiedPropertyWorker.java
Index: TestSpecifiedPropertyWorker.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestSpecifiedPropertyWorker.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TestSpecifiedPropertyWorker.java 18 Apr 2005 17:07:50 -0000 1.9
+++ TestSpecifiedPropertyWorker.java 12 May 2005 18:18:19 -0000 1.10
@@ -183,10 +183,10 @@
op.addMethod(Modifier.PUBLIC, new MethodSignature(void.class, "setFred", new Class[]
{ List.class }, null), "{\n _$fred = $1;\n}\n");
- op.addField(
- "_$fred$initialValueBindingCreator",
- InitialValueBindingCreator.class,
- expectedCreator);
+ op.addFinalField("_$fred$initialValueBindingCreator",
+
+ expectedCreator);
+ opc.setReturnValue("_$fred$initialValueBindingCreator");
op.addField("_$fred$initialValueBinding", IBinding.class);
op
.extendMethodImplementation(
1.3 +12 -2 jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestInjectMessagesWorker.java
Index: TestInjectMessagesWorker.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestInjectMessagesWorker.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestInjectMessagesWorker.java 18 Apr 2005 17:07:50 -0000 1.2
+++ TestInjectMessagesWorker.java 12 May 2005 18:18:19 -0000 1.3
@@ -19,6 +19,7 @@
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ErrorLog;
import org.apache.hivemind.Messages;
+import org.apache.hivemind.service.BodyBuilder;
import org.apache.hivemind.test.HiveMindTestCase;
import org.apache.tapestry.BaseComponent;
import org.apache.tapestry.services.ComponentMessagesSource;
@@ -55,9 +56,18 @@
EnhancementOperation op = (EnhancementOperation) control.getMock();
op.claimProperty(w.MESSAGES_PROPERTY);
- op.addField("_$componentMessagesSource", ComponentMessagesSource.class, source);
+ op.addFinalField("_$componentMessagesSource", source);
+ control.setReturnValue("fred");
+
+ BodyBuilder builder = new BodyBuilder();
+ builder.begin();
+ builder.addln("if (_$messages == null)");
+ builder.addln(" _$messages = fred.getMessages(this);");
+ builder.addln("return _$messages;");
+ builder.end();
+
op.addField("_$messages", Messages.class);
- op.addMethod(Modifier.PUBLIC, w.METHOD_SIGNATURE, w.METHOD_CODE);
+ op.addMethod(Modifier.PUBLIC, w.METHOD_SIGNATURE, builder.toString());
replayControls();
1.3 +2 -1 jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestInjectSpecificationWorker.java
Index: TestInjectSpecificationWorker.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestInjectSpecificationWorker.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestInjectSpecificationWorker.java 18 Apr 2005 17:07:50 -0000 1.2
+++ TestInjectSpecificationWorker.java 12 May 2005 18:18:19 -0000 1.3
@@ -47,7 +47,8 @@
op.claimProperty("specification");
- op.addField("_$specification", IComponentSpecification.class, spec);
+ op.addFinalField("_$specification", spec);
+ control.setReturnValue("_$specification");
op.getAccessorMethodName("specification");
control.setReturnValue("getSpecification");
1.4 +10 -75 jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestInjectStateWorker.java
Index: TestInjectStateWorker.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestInjectStateWorker.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestInjectStateWorker.java 18 Apr 2005 17:07:50 -0000 1.3
+++ TestInjectStateWorker.java 12 May 2005 18:18:19 -0000 1.4
@@ -15,22 +15,16 @@
package org.apache.tapestry.enhance;
import java.lang.reflect.Modifier;
-import java.util.Collections;
-import java.util.List;
import java.util.Map;
-import org.apache.hivemind.ApplicationRuntimeException;
-import org.apache.hivemind.ErrorLog;
import org.apache.hivemind.Location;
import org.apache.hivemind.service.BodyBuilder;
import org.apache.hivemind.service.MethodSignature;
import org.apache.hivemind.test.HiveMindTestCase;
-import org.apache.tapestry.BaseComponent;
import org.apache.tapestry.engine.state.ApplicationStateManager;
import org.apache.tapestry.event.PageDetachListener;
-import org.apache.tapestry.spec.IComponentSpecification;
-import org.apache.tapestry.spec.InjectStateSpecification;
-import org.apache.tapestry.spec.InjectStateSpecificationImpl;
+import org.apache.tapestry.spec.InjectSpecification;
+import org.apache.tapestry.spec.InjectSpecificationImpl;
import org.easymock.MockControl;
/**
@@ -46,56 +40,34 @@
return (ApplicationStateManager) newMock(ApplicationStateManager.class);
}
- private IComponentSpecification newSpecification(List injects)
+ private InjectSpecification newSpec(String propertyName, String objectName, Location l)
{
- MockControl control = newControl(IComponentSpecification.class);
- IComponentSpecification spec = (IComponentSpecification) control.getMock();
-
- spec.getInjectStateSpecifications();
- control.setReturnValue(injects);
-
- return spec;
- }
-
- private List newInjects(String propertyName, String objectName, Location l)
- {
- InjectStateSpecification spec = new InjectStateSpecificationImpl();
+ InjectSpecification spec = new InjectSpecificationImpl();
spec.setProperty(propertyName);
- spec.setObjectName(objectName);
+ spec.setObject(objectName);
spec.setLocation(l);
- return Collections.singletonList(spec);
- }
-
- public void testNoWorkToDo()
- {
- IComponentSpecification spec = newSpecification(Collections.EMPTY_LIST);
- EnhancementOperation op = (EnhancementOperation) newMock(EnhancementOperation.class);
-
- replayControls();
-
- new InjectStateWorker().performEnhancement(op, spec);
-
- verifyControls();
+ return spec;
}
public void testSuccess()
{
- IComponentSpecification spec = newSpecification(newInjects("fred", "barney", null));
+ InjectSpecification spec = newSpec("fred", "barney", null);
MockControl opc = newControl(EnhancementOperation.class);
EnhancementOperation op = (EnhancementOperation) opc.getMock();
ApplicationStateManager asm = newASM();
- op.addField("_$applicationStateManager", ApplicationStateManager.class, asm);
-
op.getPropertyType("fred");
opc.setReturnValue(Map.class);
op.claimProperty("fred");
op.addField("_$fred", Map.class);
+ op.addFinalField("_$applicationStateManager", asm);
+ opc.setReturnValue("_$applicationStateManager");
+
op.getAccessorMethodName("fred");
opc.setReturnValue("getFred");
@@ -137,41 +109,4 @@
verifyControls();
}
-
- public void testFailure()
- {
- Throwable ex = new ApplicationRuntimeException(EnhanceMessages.claimedProperty("fred"));
- Location l = fabricateLocation(22);
-
- IComponentSpecification spec = newSpecification(newInjects("fred", "barney", l));
- MockControl opc = newControl(EnhancementOperation.class);
- EnhancementOperation op = (EnhancementOperation) opc.getMock();
-
- ErrorLog errorLog = (ErrorLog) newMock(ErrorLog.class);
-
- ApplicationStateManager asm = newASM();
-
- op.addField("_$applicationStateManager", ApplicationStateManager.class, asm);
-
- op.getPropertyType("fred");
- opc.setReturnValue(Map.class);
-
- op.claimProperty("fred");
- opc.setThrowable(ex);
-
- op.getBaseClass();
- opc.setReturnValue(BaseComponent.class);
-
- errorLog.error(EnhanceMessages.errorAddingProperty("fred", BaseComponent.class, ex), l, ex);
-
- replayControls();
-
- InjectStateWorker w = new InjectStateWorker();
- w.setApplicationStateManager(asm);
- w.setErrorLog(errorLog);
-
- w.performEnhancement(op, spec);
-
- verifyControls();
- }
}
\ No newline at end of file
1.1 jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestDispatchToInjectWorker.java
Index: TestDispatchToInjectWorker.java
===================================================================
// Copyright 2005 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.enhance;
import java.util.Collections;
import java.util.Map;
import org.apache.hivemind.ErrorLog;
import org.apache.hivemind.Location;
import org.apache.hivemind.test.HiveMindTestCase;
import org.apache.tapestry.html.BasePage;
import org.apache.tapestry.spec.IComponentSpecification;
import org.apache.tapestry.spec.InjectSpecification;
import org.apache.tapestry.spec.InjectSpecificationImpl;
import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.enhance.DispatchToInjectWorker}.
*
* @author Howard M. Lewis Ship
* @since 4.0
*/
public class TestDispatchToInjectWorker extends HiveMindTestCase
{
private InjectSpecification newInjectSpecification(String propertyName, String type,
String object)
{
return newInjectSpecification(propertyName, type, object, null);
}
private InjectSpecification newInjectSpecification(String propertyName, String type,
String object, Location location)
{
InjectSpecification result = new InjectSpecificationImpl();
result.setProperty(propertyName);
result.setType(type);
result.setObject(object);
result.setLocation(location);
return result;
}
private IComponentSpecification newSpec(InjectSpecification injectSpec)
{
MockControl control = newControl(IComponentSpecification.class);
IComponentSpecification spec = (IComponentSpecification) control.getMock();
spec.getInjectSpecifications();
control.setReturnValue(Collections.singletonList(injectSpec));
return spec;
}
private Map newMap(String key, Object value)
{
return Collections.singletonMap(key, value);
}
public void testSuccess()
{
EnhancementOperation op = newOp();
InjectSpecification is = newInjectSpecification("property", "object", "service:Foo");
InjectEnhancementWorker worker = newWorker();
Map map = newMap("object", worker);
IComponentSpecification spec = newSpec(is);
worker.performEnhancement(op, is);
replayControls();
DispatchToInjectWorker d = new DispatchToInjectWorker();
d.setInjectWorkers(map);
d.performEnhancement(op, spec);
verifyControls();
}
public void testUnknownType()
{
Location l = newLocation();
EnhancementOperation op = newOp();
InjectSpecification is = newInjectSpecification(
"injectedProperty",
"object",
"service:Foo",
l);
IComponentSpecification spec = newSpec(is);
ErrorLog log = newLog();
log.error(EnhanceMessages.unknownInjectType("injectedProperty", "object"), l, null);
replayControls();
DispatchToInjectWorker d = new DispatchToInjectWorker();
d.setInjectWorkers(Collections.EMPTY_MAP);
d.setErrorLog(log);
d.performEnhancement(op, spec);
verifyControls();
}
public void testFailure()
{
Location l = newLocation();
MockControl opc = newControl(EnhancementOperation.class);
EnhancementOperation op = (EnhancementOperation) opc.getMock();
InjectSpecification is = newInjectSpecification("myProperty", "object", "service:Foo", l);
MockControl workerc = newControl(InjectEnhancementWorker.class);
InjectEnhancementWorker worker = (InjectEnhancementWorker) workerc.getMock();
Map map = newMap("object", worker);
IComponentSpecification spec = newSpec(is);
Throwable t = new RuntimeException("Simulated failure.");
ErrorLog log = newLog();
worker.performEnhancement(op, is);
workerc.setThrowable(t);
op.getBaseClass();
opc.setReturnValue(BasePage.class);
log
.error(
"Error adding property 'myProperty' to class org.apache.tapestry.html.BasePage: Simulated failure.",
l,
t);
replayControls();
DispatchToInjectWorker d = new DispatchToInjectWorker();
d.setInjectWorkers(map);
d.setErrorLog(log);
d.performEnhancement(op, spec);
verifyControls();
}
private InjectEnhancementWorker newWorker()
{
return (InjectEnhancementWorker) newMock(InjectEnhancementWorker.class);
}
private ErrorLog newLog()
{
return (ErrorLog) newMock(ErrorLog.class);
}
private EnhancementOperation newOp()
{
return (EnhancementOperation) newMock(EnhancementOperation.class);
}
}
1.1 jakarta-tapestry/framework/src/test/org/apache/tapestry/enhance/TestInjectObjectWorker.java
Index: TestInjectObjectWorker.java
===================================================================
// Copyright 2004, 2005 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.enhance;
import java.lang.reflect.Modifier;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Location;
import org.apache.hivemind.service.MethodSignature;
import org.apache.hivemind.test.HiveMindTestCase;
import org.apache.tapestry.engine.HomeService;
import org.apache.tapestry.engine.IEngineService;
import org.apache.tapestry.services.InjectedValueProvider;
import org.apache.tapestry.spec.InjectSpecification;
import org.apache.tapestry.spec.InjectSpecificationImpl;
import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.enhance.InjectObjectWorker}.
*
* @author Howard M. Lewis Ship
* @since 4.0
*/
public class TestInjectObjectWorker extends HiveMindTestCase
{
private InjectSpecification newSpec(String name, String locator, Location location)
{
InjectSpecification is = new InjectSpecificationImpl();
is.setProperty(name);
is.setObject(locator);
is.setLocation(location);
return is;
}
public void testNoExistingProperty()
{
Location l = newLocation();
Object injectedValue = new Object();
InjectSpecification spec = newSpec("fred", "service:barney", l);
MockControl opc = newControl(EnhancementOperation.class);
EnhancementOperation op = (EnhancementOperation) opc.getMock();
MockControl pc = newControl(InjectedValueProvider.class);
InjectedValueProvider p = (InjectedValueProvider) pc.getMock();
op.getPropertyType("fred");
opc.setReturnValue(null);
op.claimProperty("fred");
p.obtainValue("service:barney", l);
pc.setReturnValue(injectedValue);
op.addFinalField("_$fred", injectedValue);
opc.setReturnValue("_$fred");
op.addMethod(
Modifier.PUBLIC,
new MethodSignature(Object.class, "getFred", null, null),
"return _$fred;");
replayControls();
InjectObjectWorker w = new InjectObjectWorker();
w.setProvider(p);
w.performEnhancement(op, spec);
verifyControls();
}
public void testWithExistingProperty()
{
Location l = newLocation();
Object injectedValue = new HomeService();
InjectSpecification spec = newSpec("wilma", "service:betty", l);
MockControl opc = newControl(EnhancementOperation.class);
EnhancementOperation op = (EnhancementOperation) opc.getMock();
MockControl pc = newControl(InjectedValueProvider.class);
InjectedValueProvider p = (InjectedValueProvider) pc.getMock();
op.getPropertyType("wilma");
opc.setReturnValue(IEngineService.class);
op.claimProperty("wilma");
p.obtainValue("service:betty", l);
pc.setReturnValue(injectedValue);
op.addFinalField("_$wilma", injectedValue);
opc.setReturnValue("_$wilma");
op.addMethod(Modifier.PUBLIC, new MethodSignature(IEngineService.class, "getWilma", null,
null), "return _$wilma;");
replayControls();
InjectObjectWorker w = new InjectObjectWorker();
w.setProvider(p);
w.performEnhancement(op, spec);
verifyControls();
}
/**
* Test what happens when the value to be injected is null (usually indicating an error in the
* locator and/or a configuration error inside the HiveMind descriptors).
*/
public void testInjectNull()
{
Location l = newLocation();
InjectSpecification spec = newSpec("fred", "service:barney", l);
MockControl opc = newControl(EnhancementOperation.class);
EnhancementOperation op = (EnhancementOperation) opc.getMock();
MockControl pc = newControl(InjectedValueProvider.class);
InjectedValueProvider p = (InjectedValueProvider) pc.getMock();
op.getPropertyType("fred");
opc.setReturnValue(null);
op.claimProperty("fred");
p.obtainValue("service:barney", l);
pc.setReturnValue(null);
replayControls();
InjectObjectWorker w = new InjectObjectWorker();
w.setProvider(p);
try
{
w.performEnhancement(op, spec);
unreachable();
}
catch (ApplicationRuntimeException ex)
{
assertEquals("Value obtained using locator 'service:barney' is null.", ex.getMessage());
assertSame(l, ex.getLocation());
}
verifyControls();
}
public void testInjectedValueWrongType()
{
Location l = newLocation();
InjectSpecification spec = newSpec("fred", "service:barney", l);
MockControl opc = newControl(EnhancementOperation.class);
EnhancementOperation op = (EnhancementOperation) opc.getMock();
MockControl pc = newControl(InjectedValueProvider.class);
InjectedValueProvider p = (InjectedValueProvider) pc.getMock();
op.getPropertyType("fred");
opc.setReturnValue(IEngineService.class);
op.claimProperty("fred");
p.obtainValue("service:barney", l);
pc.setReturnValue("INJECTED-VALUE");
replayControls();
InjectObjectWorker w = new InjectObjectWorker();
w.setProvider(p);
try
{
w.performEnhancement(op, spec);
unreachable();
}
catch (ApplicationRuntimeException ex)
{
assertEquals(
"The value obtained using locator 'service:barney' (INJECTED-VALUE) is not compatible with the existing property (of type org.apache.tapestry.engine.IEngineService).",
ex.getMessage());
assertSame(l, ex.getLocation());
}
verifyControls();
}
}
1.26 +3 -27 jakarta-tapestry/framework/src/java/org/apache/tapestry/parse/SpecificationParser.java
Index: SpecificationParser.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/parse/SpecificationParser.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- SpecificationParser.java 2 May 2005 14:18:37 -0000 1.25
+++ SpecificationParser.java 12 May 2005 18:18:19 -0000 1.26
@@ -55,7 +55,6 @@
import org.apache.tapestry.spec.IParameterSpecification;
import org.apache.tapestry.spec.IPropertySpecification;
import org.apache.tapestry.spec.InjectSpecification;
-import org.apache.tapestry.spec.InjectStateSpecification;
import org.apache.tapestry.spec.SpecFactory;
import org.apache.tapestry.util.IPropertyHolder;
import org.apache.tapestry.util.RegexpMatcher;
@@ -710,12 +709,6 @@
return;
}
- if (_elementName.equals("inject-state"))
- {
- enterInjectState();
- return;
- }
-
// <asset> is new in 4.0
if (_elementName.equals("asset"))
@@ -1419,12 +1412,14 @@
"property",
PROPERTY_NAME_PATTERN,
"invalid-property-name");
+ String type = getAttribute("type");
String objectReference = getAttribute("object");
InjectSpecification spec = _factory.createInjectSpecification();
spec.setProperty(property);
- spec.setObjectReference(objectReference);
+ spec.setType(type);
+ spec.setObject(objectReference);
IComponentSpecification cs = (IComponentSpecification) peekObject();
cs.addInjectSpecification(spec);
@@ -1432,25 +1427,6 @@
push(_elementName, spec, STATE_NO_CONTENT);
}
- private void enterInjectState()
- {
- String property = getValidatedAttribute(
- "property",
- PROPERTY_NAME_PATTERN,
- "invalid-property-name");
- String objectName = getAttribute("object");
-
- InjectStateSpecification spec = _factory.createInjectStateSpecification();
-
- spec.setProperty(property);
- spec.setObjectName(objectName);
- IComponentSpecification cs = (IComponentSpecification) peekObject();
-
- cs.addInjectStateSpecification(spec);
-
- push(_elementName, spec, STATE_NO_CONTENT);
- }
-
private void enterReservedParameter()
{
String name = getAttribute("name");
1.3 +5 -20 jakarta-tapestry/framework/src/java/org/apache/tapestry/parse/Tapestry_4_0.dtd
Index: Tapestry_4_0.dtd
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/parse/Tapestry_4_0.dtd,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Tapestry_4_0.dtd 2 May 2005 14:18:37 -0000 1.2
+++ Tapestry_4_0.dtd 12 May 2005 18:18:19 -0000 1.3
@@ -38,7 +38,6 @@
- Consolidated <context-asset>, <private-asset> and <external-asset> into <asset>
- Consolidated <set-property> and <set-message-property> into <set>
- More flexibility on the order of elements
-- Added <inject-state>
- Added property attribute to <component>, <bean> and <asset>
- Removed the type attribute from the <configure> element
- Added many alternatives to 'yes' and 'no' for boolean attributes.
@@ -223,7 +222,7 @@
allow-informal-parameters: If yes (the default), informal parameters (parameters that are not
explictily defined) are allowed.
-->
-<!ELEMENT component-specification (description?, (parameter | reserved-parameter | meta | bean | component | asset | property | inject | inject-state)*)>
+<!ELEMENT component-specification (description?, (parameter | reserved-parameter | meta | bean | component | asset | property | inject )*)>
<!ATTLIST component-specification
class CDATA #IMPLIED
allow-body %attribute-flag; "yes"
@@ -268,31 +267,17 @@
Attributes:
property The name of the property.
+ type: The type of object to be injected, used to interpret
+ the meaning of the object attribute.
object: The locator used to obtain the value.
-->
<!ELEMENT inject EMPTY>
<!ATTLIST inject
property CDATA #REQUIRED
+ type CDATA "object"
object CDATA #REQUIRED
>
-<!-- =======================================================
-Element: inject-state
-Contained by: component-specification, page-specification
-
-Defines a new property mapped to an application state object.
-Reading the property will return the current value of the state
-object, and updating the property will change the value of the state
-object.
-Attributes:
- property The name of the property.
- object: The name of the application state object.
--->
-<!ELEMENT inject-state EMPTY>
-<!ATTLIST inject-state
- property CDATA #REQUIRED
- object CDATA #REQUIRED
->
<!-- =======================================================
Element: library
Appears in: application-specification, library-specification
@@ -391,7 +376,7 @@
Attributes:
class: The Java class to instantiate for the component.
-->
-<!ELEMENT page-specification (description?, (meta| bean | component | asset | property | inject | inject-state)*)>
+<!ELEMENT page-specification (description?, (meta| bean | component | asset | property | inject )*)>
<!ATTLIST page-specification
class CDATA #IMPLIED
>
1.18 +57 -19 jakarta-tapestry/framework/src/descriptor/META-INF/tapestry.enhance.xml
Index: tapestry.enhance.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/descriptor/META-INF/tapestry.enhance.xml,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- tapestry.enhance.xml 18 Apr 2005 17:07:50 -0000 1.17
+++ tapestry.enhance.xml 12 May 2005 18:18:19 -0000 1.18
@@ -24,7 +24,7 @@
Performs enhancements on a component class as directed by the component's specification and the enhancement
workers contributed to the tapestry.enhance.EnhancementWorkers configuration point.
- <invoke-factory>
+ <invoke-factory model="primitive">
<construct class="org.apache.tapestry.services.impl.ComponentConstructorFactoryImpl">
<set-service property="classFactory" service-id="hivemind.ClassFactory"/>
<event-listener service-id="tapestry.ResetEventCoordinator"/>
@@ -39,7 +39,7 @@
The chain of enhancement workers built from the EnhancementWorkers configuration.
- <invoke-factory service-id="hivemind.lib.ChainFactory">
+ <invoke-factory service-id="hivemind.lib.ChainFactory" model="primitive">
<construct configuration-id="EnhancementWorkers"/>
</invoke-factory>
@@ -50,7 +50,7 @@
Validates that an enhanced class does implement all abstract methods inherited from super-classes.
- <invoke-factory>
+ <invoke-factory model="primitive">
<construct class="EnhancedClassValidatorImpl"/>
</invoke-factory>
</service-point>
@@ -69,8 +69,7 @@
<command id="inject-specification" object="service:InjectSpecificationWorker" before="page-detach-listener"/>
<command id="specified-property" object="service:SpecifiedPropertyWorker" before="page-detach-listener"/>
<command id="parameter" object="service:ParameterPropertyWorker" before="page-detach-listener"/>
- <command id="inject" object="service:InjectWorker" before="page-detach-listener"/>
- <command id="inject-state" object="service:InjectStateWorker" before="page-detach-listener"/>
+ <command id="dispatch-inject" object="service:DispatchToInjectWorker" before="page-detach-listener"/>
<command id="inject-component" object="service:InjectComponentWorker" before="page-detach-listener"/>
<command id="inject-bean" object="service:InjectBeanWorker" before="page-detach-listener"/>
<command id="inject-asset" object="service:InjectAssetWorker" before="page-detach-listener"/>
@@ -88,6 +87,45 @@
</contribution>
+ <configuration-point id="InjectWorkers">
+
+ Maps injection types to InjectEnhancementWorker objects.
+
+ <schema>
+ <element name="worker" key-attribute="type">
+ <attribute name="type">
+ The type of injection performed by this object. Matches against the type attribute of the
+ component specification's <inject> element.
+ </attribute>
+ <attribute name="object" required="true" translator="object">
+ The object implementing the InjectEnhancementWorker interface.
+ </attribute>
+ <rules>
+ <push-attribute attribute="object"/>
+ <invoke-parent method="addElement"/>
+ </rules>
+ </element>
+ </schema>
+
+ </configuration-point>
+
+ <contribution configuration-id="InjectWorkers">
+ <worker type="object" object="service:InjectObjectWorker"/>
+ <worker type="state" object="service:InjectStateWorker"/>
+ </contribution>
+
+ <service-point id="DispatchToInjectWorker" interface="EnhancementWorker">
+
+ Dispatches to the correct InjectEnhancementWorker, based on the injection type.
+
+ <invoke-factory model="primitive">
+ <construct class="DispatchToInjectWorker">
+ <set-object property="injectWorkers" value="configuration:InjectWorkers"/>
+ </construct>
+ </invoke-factory>
+
+ </service-point>
+
<service-point id="InjectMessagesWorker" interface="EnhancementWorker">
Injects the messages property into all components.
@@ -131,23 +169,23 @@
</service-point>
- <service-point id="InjectWorker" interface="EnhancementWorker">
+ <service-point id="InjectObjectWorker" interface="InjectEnhancementWorker">
Injects objects obtained from HiveMind into properties of the enhanced class.
- <invoke-factory>
- <construct class="InjectWorker">
+ <invoke-factory model="primitive">
+ <construct class="InjectObjectWorker">
<set-service property="provider" service-id="tapestry.InjectedValueProvider"/>
</construct>
</invoke-factory>
</service-point>
- <service-point id="InjectStateWorker" interface="EnhancementWorker">
+ <service-point id="InjectStateWorker" interface="InjectEnhancementWorker">
Injects properties that reference application state objects.
- <invoke-factory>
+ <invoke-factory model="primitive">
<construct class="InjectStateWorker">
<set-service property="applicationStateManager" service-id="tapestry.state.ApplicationStateManager"/>
</construct>
@@ -159,7 +197,7 @@
Injects contained components as properties of the containing component.
- <invoke-factory>
+ <invoke-factory model="primitive">
<construct class="InjectComponentWorker"/>
</invoke-factory>
@@ -169,7 +207,7 @@
Injects managed beans as properties of the containing component.
- <invoke-factory>
+ <invoke-factory model="primitive">
<construct class="InjectBeanWorker"/>
</invoke-factory>
@@ -179,7 +217,7 @@
Injects assets as properties of the containing component.
- <invoke-factory>
+ <invoke-factory model="primitive">
<construct class="InjectAssetWorker"/>
</invoke-factory>
@@ -191,7 +229,7 @@
Finds otherwise unclaimed abstract properties and converts them into concrete properties, as if
they were defined in the specification.
- <invoke-factory>
+ <invoke-factory model="primitive">
<construct class="AbstractPropertyWorker"/>
</invoke-factory>
</service-point>
@@ -201,7 +239,7 @@
Registers components as PageDetachListeners, if they implement
the interface.
- <invoke-factory>
+ <invoke-factory model="primitive">
<construct class="InjectListenerRegistrationWorker">
<set-object property="listenerInterface" value="class:org.apache.tapestry.event.PageDetachListener"/>
<set property="registerMethodName" value="addPageDetachListener"/>
@@ -216,7 +254,7 @@
Registers components as PageAttachListeners, if they implement
the interface.
- <invoke-factory>
+ <invoke-factory model="primitive">
<construct class="InjectListenerRegistrationWorker">
<set-object property="listenerInterface" value="class:org.apache.tapestry.event.PageAttachListener"/>
<set property="registerMethodName" value="addPageAttachListener"/>
@@ -230,7 +268,7 @@
Registers components as PageEndRenderListeners, if they implement
the interface.
- <invoke-factory>
+ <invoke-factory model="primitive">
<construct class="InjectListenerRegistrationWorker">
<set-object property="listenerInterface" value="class:org.apache.tapestry.event.PageEndRenderListener"/>
<set property="registerMethodName" value="addPageEndRenderListener"/>
@@ -245,7 +283,7 @@
Registers components as PageBeginRenderListeners, if they implement
the interface.
- <invoke-factory>
+ <invoke-factory model="primitive">
<construct class="InjectListenerRegistrationWorker">
<set-object property="listenerInterface" value="class:org.apache.tapestry.event.PageBeginRenderListener"/>
<set property="registerMethodName" value="addPageBeginRenderListener"/>
@@ -259,7 +297,7 @@
Registers components as PageValidateListeners, if they implement
the interface.
- <invoke-factory>
+ <invoke-factory model="primitive">
<construct class="InjectListenerRegistrationWorker">
<set-object property="listenerInterface" value="class:org.apache.tapestry.event.PageValidateListener"/>
<set property="registerMethodName" value="addPageValidateListener"/>
1.5 +1 -1 jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/parse/Inject.jwc
Index: Inject.jwc
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/parse/Inject.jwc,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Inject.jwc 18 Apr 2005 17:07:52 -0000 1.4
+++ Inject.jwc 12 May 2005 18:18:19 -0000 1.5
@@ -22,6 +22,6 @@
<component-specification>
<inject property="fred" object="flintstone"/>
- <inject property="barney" object="rubble"/>
+ <inject property="barney" type="state" object="rubble"/>
</component-specification>
1.15 +4 -19 jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/parse/TestSpecificationParser.java
Index: TestSpecificationParser.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/parse/TestSpecificationParser.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- TestSpecificationParser.java 2 May 2005 14:18:37 -0000 1.14
+++ TestSpecificationParser.java 12 May 2005 18:18:19 -0000 1.15
@@ -32,7 +32,6 @@
import org.apache.tapestry.spec.IParameterSpecification;
import org.apache.tapestry.spec.IPropertySpecification;
import org.apache.tapestry.spec.InjectSpecification;
-import org.apache.tapestry.spec.InjectStateSpecification;
import org.apache.tapestry.spec.ListenerBindingSpecification;
import org.apache.tapestry.util.xml.DocumentParseException;
@@ -910,12 +909,14 @@
InjectSpecification i1 = (InjectSpecification) l.get(0);
assertEquals("fred", i1.getProperty());
- assertEquals("flintstone", i1.getObjectReference());
+ assertEquals("object", i1.getType());
+ assertEquals("flintstone", i1.getObject());
assertNotNull(i1.getLocation());
InjectSpecification i2 = (InjectSpecification) l.get(1);
assertEquals("barney", i2.getProperty());
- assertEquals("rubble", i2.getObjectReference());
+ assertEquals("state", i2.getType());
+ assertEquals("rubble", i2.getObject());
assertNotNull(i2.getLocation());
}
@@ -1077,20 +1078,4 @@
assertEquals("path/to/asset", as.getPath());
assertEquals("myProperty", as.getPropertyName());
}
-
- /** @since 4.0 */
-
- public void testInjectState() throws Exception
- {
- IComponentSpecification cs = parsePage("InjectState.page");
-
- List l = cs.getInjectStateSpecifications();
-
- assertEquals(1, l.size());
-
- InjectStateSpecification s = (InjectStateSpecification) l.get(0);
-
- assertEquals("fred", s.getProperty());
- assertEquals("barney", s.getObjectName());
- }
}
\ No newline at end of file
1.13 +8 -3 jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/TestComponentMessages.java
Index: TestComponentMessages.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/TestComponentMessages.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- TestComponentMessages.java 18 Apr 2005 17:07:50 -0000 1.12
+++ TestComponentMessages.java 12 May 2005 18:18:19 -0000 1.13
@@ -33,6 +33,7 @@
import org.apache.tapestry.enhance.InjectMessagesWorker;
import org.apache.tapestry.enhance.InjectSpecificationWorker;
import org.apache.tapestry.html.BasePage;
+import org.apache.tapestry.services.ComponentMessagesSource;
import org.apache.tapestry.services.ComponentPropertySource;
import org.apache.tapestry.services.impl.ComponentMessagesSourceImpl;
import org.apache.tapestry.spec.ComponentSpecification;
@@ -115,14 +116,18 @@
* much as the full framework would do at runtime.
*/
- private IPage newPage(IComponentSpecification specification, Locale locale)
+ private IPage newPage(IComponentSpecification specification, ComponentMessagesSource source, Locale locale)
{
ClassFactory classFactory = new ClassFactoryImpl();
EnhancementOperationImpl op = new EnhancementOperationImpl(new DefaultClassResolver(),
specification, BasePage.class, classFactory);
- new InjectMessagesWorker().performEnhancement(op, specification);
+ InjectMessagesWorker injectMessages = new InjectMessagesWorker();
+ injectMessages.setComponentMessagesSource(source);
+
+ injectMessages.performEnhancement(op, specification);
+
new InjectSpecificationWorker().performEnhancement(op, specification);
IPage result = (IPage) op.getConstructor().newInstance();
@@ -140,7 +145,7 @@
IComponentSpecification spec = newSpec(location);
- IPage page = newPage(spec, locale);
+ IPage page = newPage(spec, source, locale);
INamespace namespace = new Namespace(null, null, newLibrarySpec(), null, null);
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org