You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by dr...@apache.org on 2010/04/29 23:50:01 UTC
svn commit: r939490 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/annotations/
main/java/org/apache/tapestry5/internal/transform/
main/java/org/apache/tapestry5/services/ test/app1/
test/java/org/apache/tapestry5/inte...
Author: drobiazko
Date: Thu Apr 29 21:50:01 2010
New Revision: 939490
URL: http://svn.apache.org/viewvc?rev=939490&view=rev
Log:
TAP5-1121: Provide an annotation to support automatic discarding of the persistent fields after a component or page method invocation
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java (with props)
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java (with props)
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DiscardAfterDemo.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java (with props)
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java?rev=939490&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java Thu Apr 29 21:50:01 2010
@@ -0,0 +1,37 @@
+// Copyright 2010 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.tapestry5.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Marks a method of a page or a component to discard all persistent field changes. The changes are
+ * eliminated from persistent storage after the marked method is invoked.
+ *
+ * @see org.apache.tapestry5.ComponentResources#discardPersistentFieldChanges()
+ * @since 5.2.0
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+@Documented
+public @interface DiscardAfter
+{
+
+}
Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java?rev=939490&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java Thu Apr 29 21:50:01 2010
@@ -0,0 +1,58 @@
+// Copyright 2010 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
+
+package org.apache.tapestry5.internal.transform;
+
+import java.util.List;
+
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.annotations.DiscardAfter;
+import org.apache.tapestry5.model.MutableComponentModel;
+import org.apache.tapestry5.services.ClassTransformation;
+import org.apache.tapestry5.services.ComponentClassTransformWorker;
+import org.apache.tapestry5.services.ComponentMethodAdvice;
+import org.apache.tapestry5.services.ComponentMethodInvocation;
+import org.apache.tapestry5.services.TransformMethod;
+
+public class DiscardAfterWorker implements ComponentClassTransformWorker
+{
+
+ private final ComponentMethodAdvice advice = new ComponentMethodAdvice()
+ {
+
+ public void advise(ComponentMethodInvocation invocation)
+ {
+ invocation.proceed();
+
+ ComponentResources resources = invocation.getComponentResources();
+
+ resources.discardPersistentFieldChanges();
+
+ }
+
+ };
+
+ public void transform(final ClassTransformation transformation, final MutableComponentModel model)
+ {
+ final List<TransformMethod> methods = transformation.matchMethodsWithAnnotation(DiscardAfter.class);
+
+ if (methods.isEmpty())
+ return;
+
+ for (final TransformMethod metod : methods)
+ {
+ metod.addAdvice(advice);
+ }
+
+ }
+}
Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=939490&r1=939489&r2=939490&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java Thu Apr 29 21:50:01 2010
@@ -631,6 +631,8 @@ public final class TapestryModule
configuration.add("Retain", new RetainWorker());
configuration.addInstance("Persist", PersistWorker.class);
+
+ configuration.addInstance("DiscardAfter", DiscardAfterWorker.class);
configuration.addInstance("IncludeStylesheet", IncludeStylesheetWorker.class, "after:SetupRender");
configuration
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DiscardAfterDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DiscardAfterDemo.tml?rev=939490&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DiscardAfterDemo.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DiscardAfterDemo.tml Thu Apr 29 21:50:01 2010
@@ -0,0 +1,18 @@
+<html t:type="Border"
+ xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+
+ <h1>@DiscardAfter Demo</h1>
+
+ <t:form>
+
+ <t:textfield t:id="stringValue"/>
+
+ <t:submit t:id="keep" value="Keep Values"/>
+ <t:submit t:id="discard" value="Discard Values"/>
+ </t:form>
+
+ <p>
+ Value is: '${stringValue}'
+ </p>
+</html>
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java?rev=939490&r1=939489&r2=939490&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java Thu Apr 29 21:50:01 2010
@@ -1436,4 +1436,21 @@ public class CoreBehaviorsTests extends
assertText("status", "Application Catalog Working");
}
+
+ /** TAP5-1121 */
+ @Test
+ public void discard_after()
+ {
+ clickThru("@DiscardAfter Demo");
+
+ type("stringValue", "foo bar baz");
+
+ clickAndWait("//input[@id='keep']");
+
+ assertTextPresent("Value is: 'foo bar baz'");
+
+ clickAndWait("//input[@id='discard']");
+
+ assertTextPresent("Value is: ''");
+ }
}
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java?rev=939490&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java Thu Apr 29 21:50:01 2010
@@ -0,0 +1,32 @@
+// Copyright 2010 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.tapestry5.integration.app1.pages;
+
+import org.apache.tapestry5.annotations.DiscardAfter;
+import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.Property;
+
+
+public class DiscardAfterDemo
+{
+ @Property
+ @Persist
+ private String stringValue;
+
+ @DiscardAfter
+ void onSelectedFromDiscard()
+ {
+
+ }
+}
Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java?rev=939490&r1=939489&r2=939490&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java Thu Apr 29 21:50:01 2010
@@ -430,7 +430,10 @@ public class Index
"User represenation of enum values is correctly read from messages"),
new Item("unavailablecomponentdemo", "Report Location of Unavailable Component",
- "Report Location of Unavailable Component")
+ "Report Location of Unavailable Component"),
+
+ new Item("discardafterdemo", "@DiscardAfter Demo",
+ "Demo using @DiscardAfter annotation")
);