Return-Path: Delivered-To: apmail-jakarta-tapestry-dev-archive@www.apache.org Received: (qmail 22679 invoked from network); 3 Nov 2004 13:53:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 3 Nov 2004 13:53:49 -0000 Received: (qmail 83639 invoked by uid 500); 3 Nov 2004 13:53:48 -0000 Delivered-To: apmail-jakarta-tapestry-dev-archive@jakarta.apache.org Received: (qmail 83591 invoked by uid 500); 3 Nov 2004 13:53:47 -0000 Mailing-List: contact tapestry-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tapestry development" Reply-To: "Tapestry development" Delivered-To: mailing list tapestry-dev@jakarta.apache.org Received: (qmail 83578 invoked by uid 500); 3 Nov 2004 13:53:46 -0000 Received: (qmail 83574 invoked by uid 99); 3 Nov 2004 13:53:46 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Wed, 03 Nov 2004 05:53:44 -0800 Received: (qmail 22652 invoked by uid 1616); 3 Nov 2004 13:53:43 -0000 Date: 3 Nov 2004 13:53:43 -0000 Message-ID: <20041103135343.22651.qmail@minotaur.apache.org> From: hlship@apache.org To: jakarta-tapestry-cvs@apache.org Subject: cvs commit: jakarta-tapestry/framework/src/java/org/apache/tapestry/parse Tapestry_3_1.dtd X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N hlship 2004/11/03 05:53:43 Modified: src/documentation/content/xdocs/UsersGuide spec.xml state.xml framework/src/java/org/apache/tapestry/enhance SpecifiedPropertyWorker.java framework/src/test/org/apache/tapestry/enhance TestSpecifiedPropertyWorker.java framework/src/java/org/apache/tapestry/spec PropertySpecification.java framework/src/test/org/apache/tapestry/junit/parse TestSpecificationParser.java Property.page framework/src/java/org/apache/tapestry/parse Tapestry_3_1.dtd Log: Remove the type attribute from the element; make specified properties match abstract accessors (if any), or just be type Object. Revision Changes Path 1.6 +5 -16 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- spec.xml 2 Nov 2004 03:32:42 -0000 1.5 +++ spec.xml 3 Nov 2004 13:53:43 -0000 1.6 @@ -120,7 +120,8 @@
  • The <inherited-binding> element has been removed; parameters of parent components may be accessed as properties.
  • The <property> element (in 3.0) has been renamed to &spec.meta;.
  • -
  • The <property-specification; element (in 3.0) has been renamed to &spec.property;.
  • +
  • The <property-specification; element (in 3.0) has been renamed to &spec.property;, and the type + attribute has been dropped.
  • The &spec.inject; element has been added.
  • @@ -1406,18 +1407,6 @@ The name of the property to create. - type - string - no - java.lang.Object - - The type of the property. If abstract accessors exist, they must exactly match - this type. The type may be either a fully qualified class name, or the name - of one of the basic scalar types (int, boolean, etc.). It may be suffixed with - [] to indicate an array of the indicated type. - - - persistent yes|no no @@ -1440,9 +1429,9 @@ - - In the Tapestry 3.0 DTD, this element was named <property-specification>. - + In the Tapestry 3.0 DTD, this element was named <property-specification> and had an additional attribute, + type. In Tapestry 3.1, the type of the implemented property will simply match the type of any existing (abstract) + property, or will simply be type Object. 1.4 +16 -19 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- state.xml 2 Nov 2004 03:32:42 -0000 1.3 +++ state.xml 3 Nov 2004 13:53:43 -0000 1.4 @@ -437,7 +437,7 @@ + initial-value="10"/> ]]> @@ -450,28 +450,19 @@ always include both a getter and a setter.

    - + In Tapestry 3.0, many users were frustrated that they had to specify the type of property in both the Java code and in the page specification. This is a violation of the Dont Repeat Yourself principal -- requiring -coordination is just an inviation for the two sides to get out of synchronization. In Tapestry 3.1, it -is likely that any abstract property in the Java code will become a transient property, even when -there's no corresponding &spec.property; element. The &spec.property; element will -be used to mark a property as persistent (the type will still not have to be defined), to provide an initial value, -or specify a property that isn't referenced from Java code (and even here, type will be optional and default to Object). - +coordination is just an inviation for the two sides to get out of synchronization. Starting with Tapestry 3.1, +there is no type attribute on the &spec.property; element; instead Tapestry matches the type to the +property type of any existing accessor methods, and simply uses Object when there are no accessor methods. In +this example, the persistent itemsPerPage property will be type int, because of the abstract accessor methods. +

    -This exact same technique can be used with components as well as pages. -

    - -

    -A last note about initialization. After Tapestry invokes the finishLoad() -method, it processes the initial value provided in the specification. If -the initial-value attribute is ommitted or blank, no change takes place. -Tapestry then takes a snapshot of the property value, which it retains -and uses at the end of each request cycle -to reset the property back to its "pristine" state. +This exact same technique can be used with components as well as pages, the component specification also supports +the &spec.property; element.

    @@ -586,7 +577,7 @@ { _itemsPerPage = itemsPerPage; - Tapestry.fireObservedChange(this, "itemsPerPage", itemsPerPage); + Tapestry.fireObservedChange(this, "itemsPerPage", new Integer(itemsPerPage)); } protected void initialize() @@ -731,6 +722,12 @@ organized in such a way that the Visit object is not created, and no persistent state is stored). This will help speed the initial display of the application, since no processing time will be used in creating the HttpSession.

    + + +There are plans for Tapestry 3.1 to allow some persistent state to be stored as HTTP cookies or in hidden form fields (and as query parameters +inside URLs). In these cases, a web application would be "stateful" without necessarily using an HttpSession. What remains to be seen +is whether this will be practical. + 1.3 +19 -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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SpecifiedPropertyWorker.java 2 Nov 2004 18:59:14 -0000 1.2 +++ SpecifiedPropertyWorker.java 3 Nov 2004 13:53:43 -0000 1.3 @@ -75,9 +75,8 @@ Defense.notNull(ps, "ps"); String propertyName = ps.getName(); - Class propertyType = op.convertTypeName(ps.getType()); - op.validateProperty(propertyName, propertyType); + Class propertyType = extractPropertyType(op, propertyName, ps.getType()); op.claimProperty(propertyName); @@ -91,6 +90,24 @@ addAccessor(op, propertyName, propertyType, field); addMutator(op, propertyName, propertyType, field, ps.isPersistent()); + } + + // Package private for testing purposes + + Class extractPropertyType(EnhancementOperation op, String propertyName, String typeName) + { + if (typeName != null) + { + Class propertyType = op.convertTypeName(typeName); + + op.validateProperty(propertyName, propertyType); + + return propertyType; + } + + Class propertyType = op.getPropertyType(propertyName); + + return propertyType == null ? Object.class : propertyType; } private void addAccessor(EnhancementOperation op, String name, Class type, String field) 1.3 +61 -0 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TestSpecifiedPropertyWorker.java 2 Nov 2004 18:59:13 -0000 1.2 +++ TestSpecifiedPropertyWorker.java 3 Nov 2004 13:53:43 -0000 1.3 @@ -19,6 +19,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.apache.hivemind.ApplicationRuntimeException; import org.apache.hivemind.ErrorLog; @@ -214,5 +215,65 @@ w.performEnhancement(op); verifyControls(); + } + + public void testTypeUnspecifiedWithNoExistingProperty() + { + MockControl opc = newControl(EnhancementOperation.class); + EnhancementOperation op = (EnhancementOperation) opc.getMock(); + + op.getPropertyType("wilma"); + opc.setReturnValue(null); + + replayControls(); + + SpecifiedPropertyWorker w = new SpecifiedPropertyWorker(); + + Class result = w.extractPropertyType(op, "wilma", null); + + assertEquals(Object.class, result); + + verifyControls(); + } + + public void testTypeUnspecifiedButExistingProperty() + { + MockControl opc = newControl(EnhancementOperation.class); + EnhancementOperation op = (EnhancementOperation) opc.getMock(); + + op.getPropertyType("fred"); + opc.setReturnValue(Map.class); + + replayControls(); + + SpecifiedPropertyWorker w = new SpecifiedPropertyWorker(); + + Class result = w.extractPropertyType(op, "fred", null); + + assertEquals(Map.class, result); + + verifyControls(); + } + + public void testTypeSpecified() + { + MockControl opc = newControl(EnhancementOperation.class); + EnhancementOperation op = (EnhancementOperation) opc.getMock(); + + op.convertTypeName("int[]"); + opc.setReturnValue(int[].class); + + op.validateProperty("betty", int[].class); + + replayControls(); + + SpecifiedPropertyWorker w = new SpecifiedPropertyWorker(); + + Class result = w.extractPropertyType(op, "betty", "int[]"); + + assertEquals(int[].class, result); + + verifyControls(); + } } 1.3 +26 -20 jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/PropertySpecification.java Index: PropertySpecification.java =================================================================== RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/spec/PropertySpecification.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PropertySpecification.java 16 Sep 2004 00:26:28 -0000 1.2 +++ PropertySpecification.java 3 Nov 2004 13:53:43 -0000 1.3 @@ -17,22 +17,24 @@ import org.apache.hivemind.impl.BaseLocatable; /** - * Defines a transient or persistant property of a component or page. - * A {@link org.apache.tapestry.engine.IComponentClassEnhancer} uses this information - * to create a subclass with the necessary instance variables and methods. - * - * @author Howard Lewis Ship - * @since 3.0 + * Defines a transient or persistant property of a component or page. A + * {@link org.apache.tapestry.engine.IComponentClassEnhancer}uses this information to create a + * subclass with the necessary instance variables and methods. * - **/ + * @author Howard Lewis Ship + * @since 3.0 + */ public class PropertySpecification extends BaseLocatable implements IPropertySpecification { - private String _name; - private String _type = "java.lang.Object"; - private boolean _persistent; - private String _initialValue; - + private String _name; + + private String _type; + + private boolean _persistent; + + private String _initialValue; + public String getInitialValue() { return _initialValue; @@ -48,6 +50,12 @@ return _persistent; } + /** + * The type of property to create, or null if no type was specified. The value is the name of a + * primitive type, a fully qualified class name, or an array name for either. Type is only + * specified for 3.0 DTDs, in 3.1 the only behavior is for the new property to match the type + * defined by an abstract accessor, or to be java.lang.Object. + */ public String getType() { return _type; @@ -58,13 +66,11 @@ _initialValue = initialValue; } - /** - * Sets the name of the property. This should not be changed - * once this IPropertySpecification is added to - * a {@link org.apache.tapestry.spec.ComponentSpecification}. - * - **/ - + /** + * Sets the name of the property. This should not be changed once this IPropertySpecification is + * added to a {@link org.apache.tapestry.spec.ComponentSpecification}. + */ + public void setName(String name) { _name = name; @@ -80,4 +86,4 @@ _type = type; } -} +} \ No newline at end of file 1.4 +11 -14 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestSpecificationParser.java 2 Nov 2004 13:30:00 -0000 1.3 +++ TestSpecificationParser.java 3 Nov 2004 13:53:43 -0000 1.4 @@ -516,14 +516,14 @@ ps = spec.getPropertySpecification("init"); assertEquals("name", "init", ps.getName()); assertEquals("persistent", false, ps.isPersistent()); - assertEquals("type", "java.lang.Object", ps.getType()); + assertNull("type", ps.getType()); assertEquals("initialValue", "pageName", ps.getInitialValue()); checkLine(ps, 26); ps = spec.getPropertySpecification("persist"); assertEquals("name", "persist", ps.getName()); assertEquals("persistent", true, ps.isPersistent()); - assertEquals("type", "java.lang.Object", ps.getType()); + assertNull("type", ps.getType()); assertNull("initialValue", ps.getInitialValue()); checkLine(ps, 25); @@ -847,10 +847,10 @@ assertEquals("rubble", i2.getObjectReference()); assertNotNull(i2.getLocation()); } - + /** - * Test that the new <property> element (was <property-specification>) - * works correctly. + * Test that the new <property> element (was <property-specification> in release + * 3.0) works correctly. * * @since 3.1 */ @@ -865,31 +865,28 @@ IPropertySpecification ps = spec.getPropertySpecification("bool"); assertEquals("name", "bool", ps.getName()); assertEquals("persistent", false, ps.isPersistent()); - assertEquals("type", "boolean", ps.getType()); + + // In a 3.1 DTD, type is always null. + assertNull("type", ps.getType()); assertNull("initialValue", ps.getInitialValue()); checkLine(ps, 24); ps = spec.getPropertySpecification("init"); assertEquals("name", "init", ps.getName()); assertEquals("persistent", false, ps.isPersistent()); - - // Note: this will like change to null as the default, to differentiate - // explicitly "java.lang.Object" from "no value specified" - - assertEquals("type", "java.lang.Object", ps.getType()); + assertEquals("initialValue", "pageName", ps.getInitialValue()); checkLine(ps, 26); ps = spec.getPropertySpecification("persist"); assertEquals("name", "persist", ps.getName()); assertEquals("persistent", true, ps.isPersistent()); - assertEquals("type", "java.lang.Object", ps.getType()); assertNull("initialValue", ps.getInitialValue()); checkLine(ps, 25); ps = spec.getPropertySpecification("unknown"); assertNull("Unknown PropertySpecification", ps); - } - + } + } 1.2 +3 -3 jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/parse/Property.page Index: Property.page =================================================================== RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/parse/Property.page,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Property.page 2 Nov 2004 03:32:43 -0000 1.1 +++ Property.page 3 Nov 2004 13:53:43 -0000 1.2 @@ -21,9 +21,9 @@ - - - + + + 1.5 +23 -26 jakarta-tapestry/framework/src/java/org/apache/tapestry/parse/Tapestry_3_1.dtd Index: Tapestry_3_1.dtd =================================================================== RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/parse/Tapestry_3_1.dtd,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Tapestry_3_1.dtd 2 Nov 2004 03:32:42 -0000 1.4 +++ Tapestry_3_1.dtd 3 Nov 2004 13:53:43 -0000 1.5 @@ -31,6 +31,7 @@ There is now just , whose value attribute contains a prefix to interpret how the remainder of the value is interpreted (no prefix meaning a literal, or static, value). - renamed to and renamed to +- Removed the type attribute from - Added --> @@ -346,6 +347,28 @@ language CDATA #IMPLIED > + + + - - -