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/09/29 22:32:57 UTC
svn commit: r292533 - in /jakarta/tapestry/trunk: ./
annotations/src/descriptor/META-INF/
annotations/src/documentation/content/xdocs/tapestry-annotations/
annotations/src/java/org/apache/tapestry/annotations/
annotations/src/test/org/apache/tapestry/a...
Author: hlship
Date: Thu Sep 29 13:32:42 2005
New Revision: 292533
URL: http://svn.apache.org/viewcvs?rev=292533&view=rev
Log:
TAPESTRY-680: Need an injection type comparable to the state: binding prefix
Added:
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/InjectStateFlagWorker.java
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/InjectStateFlagWorkerTest.java
Removed:
jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/TestInjectStateAnnotationWorker.java
Modified:
jakarta/tapestry/trunk/annotations/src/descriptor/META-INF/hivemodule.xml
jakarta/tapestry/trunk/annotations/src/documentation/content/xdocs/tapestry-annotations/index.xml
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateAnnotationWorker.java
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/Meta.java
jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/MetaAnnotationWorker.java
jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java
jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/BasicComponentSubclass.java
jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaAnnotationWorkerTest.java
jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaPage.java
jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaPageSubclass.java
jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MissingEqualsMetaPage.java
jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/TestSimpleAnnotationWorkers.java
jakarta/tapestry/trunk/examples/Workbench/src/context/Redirect.html
jakarta/tapestry/trunk/examples/Workbench/src/context/css/workbench.css
jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.enhance.xml
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceMessages.java
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceStrings.properties
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/InjectStateWorker.java
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/BaseEnhancementTestCase.java
jakarta/tapestry/trunk/src/documentation/content/xdocs/UsersGuide/injection.xml
jakarta/tapestry/trunk/status.xml
Modified: jakarta/tapestry/trunk/annotations/src/descriptor/META-INF/hivemodule.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/descriptor/META-INF/hivemodule.xml?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/annotations/src/descriptor/META-INF/hivemodule.xml (original)
+++ jakarta/tapestry/trunk/annotations/src/descriptor/META-INF/hivemodule.xml Thu Sep 29 13:32:42 2005
@@ -103,7 +103,6 @@
<!-- These instantiate the corresponding enhancement worker, and delegate to it. -->
<worker annotation="InjectObject" object="service:InjectObjectAnnotationWorker"/>
<worker annotation="InjectComponent" object="instance:InjectComponentAnnotationWorker"/>
- <worker annotation="InjectState" object="service:InjectStateAnnotationWorker"/>
<worker annotation="Message" object="instance:MessageAnnotationWorker"/>
<!-- These update the component specification with new sub-elements. Later, the
@@ -111,6 +110,8 @@
specified in the XML. This is actually a lot easier and just as powerful, and
the delegating style will probably go pretty soon. -->
+ <worker annotation="InjectState" object="instance:InjectStateAnnotationWorker"/>
+ <worker annotation="InjectStateFlag" object="instance:InjectStateFlagAnnotationWorker"/>
<worker annotation="InjectAsset" object="instance:InjectAssetAnnotationWorker"/>
<worker annotation="Persist" object="instance:PersistAnnotationWorker"/>
<worker annotation="Bean" object="instance:BeanAnnotationWorker"/>
@@ -132,17 +133,6 @@
</construct>
</invoke-factory>
- </service-point>
-
- <service-point id="InjectStateAnnotationWorker" interface="MethodAnnotationEnhancementWorker">
-
- Injects an application state object, based on the InjectState annotation.
-
- <invoke-factory>
- <construct class="InjectStateAnnotationWorker">
- <set-service property="applicationStateManager" service-id="tapestry.state.ApplicationStateManager"/>
- </construct>
- </invoke-factory>
</service-point>
</module>
Modified: jakarta/tapestry/trunk/annotations/src/documentation/content/xdocs/tapestry-annotations/index.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/documentation/content/xdocs/tapestry-annotations/index.xml?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/annotations/src/documentation/content/xdocs/tapestry-annotations/index.xml (original)
+++ jakarta/tapestry/trunk/annotations/src/documentation/content/xdocs/tapestry-annotations/index.xml Thu Sep 29 13:32:42 2005
@@ -365,6 +365,28 @@
</section>
<section>
+ <title>InjectStateFlag</title>
+
+ <p>
+ The <link href="&javadoc;/InjectStateFlag.html">InjectStateFlag</link> annotation
+ implements a read-only boolean property that returns true if the identified
+ application state object exists. This is useful for avoiding the accidental creation
+ of the ASO, which helps avoid the unneccessary creation of the HttpSession.
+ </p>
+
+ <source>
+ @InjectStateFlag("visit")
+ public abstract boolean getVisitExists();
+ </source>
+
+ <p>
+ The end result is equivalent to using the <link href="&spec;#spec.inject"><inject></link> element,
+ with a type of "state-flag".
+ </p>
+
+</section>
+
+<section>
<title>Message</title>
<p>
Modified: jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateAnnotationWorker.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateAnnotationWorker.java?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateAnnotationWorker.java (original)
+++ jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateAnnotationWorker.java Thu Sep 29 13:32:42 2005
@@ -17,10 +17,10 @@
import java.lang.reflect.Method;
import org.apache.hivemind.Location;
-import org.apache.tapestry.engine.state.ApplicationStateManager;
import org.apache.tapestry.enhance.EnhancementOperation;
-import org.apache.tapestry.enhance.InjectStateWorker;
import org.apache.tapestry.spec.IComponentSpecification;
+import org.apache.tapestry.spec.InjectSpecification;
+import org.apache.tapestry.spec.InjectSpecificationImpl;
/**
* Injects an Application State Object.
@@ -32,18 +32,6 @@
*/
public class InjectStateAnnotationWorker implements MethodAnnotationEnhancementWorker
{
- final InjectStateWorker _delegate;
-
- InjectStateAnnotationWorker(InjectStateWorker delegate)
- {
- _delegate = delegate;
- }
-
- public InjectStateAnnotationWorker()
- {
- this(new InjectStateWorker());
- }
-
public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
Method method, Location location)
{
@@ -51,11 +39,13 @@
String propertyName = AnnotationUtils.getPropertyName(method);
- _delegate.injectState(op, is.value(), propertyName, location);
- }
+ InjectSpecification inject = new InjectSpecificationImpl();
- public void setApplicationStateManager(ApplicationStateManager applicationStateManager)
- {
- _delegate.setApplicationStateManager(applicationStateManager);
+ inject.setType("state");
+ inject.setProperty(propertyName);
+ inject.setObject(is.value());
+ inject.setLocation(location);
+
+ spec.addInjectSpecification(inject);
}
}
Added: jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java?rev=292533&view=auto
==============================================================================
--- jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java (added)
+++ jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java Thu Sep 29 13:32:42 2005
@@ -0,0 +1,35 @@
+// 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.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(
+{ ElementType.METHOD })
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface InjectStateFlag {
+
+ /**
+ * The id of the Application State Object; the boolean accessor method to which the annotation
+ * is attached will return true when the ASO exists, false when it does not.
+ */
+
+ String value();
+}
Added: jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java?rev=292533&view=auto
==============================================================================
--- jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java (added)
+++ jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java Thu Sep 29 13:32:42 2005
@@ -0,0 +1,45 @@
+// 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.annotations;
+
+import java.lang.reflect.Method;
+
+import org.apache.hivemind.Location;
+import org.apache.tapestry.enhance.EnhancementOperation;
+import org.apache.tapestry.spec.IComponentSpecification;
+import org.apache.tapestry.spec.InjectSpecification;
+import org.apache.tapestry.spec.InjectSpecificationImpl;
+
+public class InjectStateFlagAnnotationWorker implements MethodAnnotationEnhancementWorker
+{
+
+ public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
+ Method method, Location location)
+ {
+ InjectStateFlag isv = method.getAnnotation(InjectStateFlag.class);
+
+ String propertyName = AnnotationUtils.getPropertyName(method);
+
+ InjectSpecification inject = new InjectSpecificationImpl();
+
+ inject.setType("state-flag");
+ inject.setProperty(propertyName);
+ inject.setObject(isv.value());
+ inject.setLocation(location);
+
+ spec.addInjectSpecification(inject);
+ }
+
+}
Modified: jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/Meta.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/Meta.java?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/Meta.java (original)
+++ jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/Meta.java Thu Sep 29 13:32:42 2005
@@ -1,3 +1,17 @@
+// 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.annotations;
import java.lang.annotation.Documented;
Modified: jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/MetaAnnotationWorker.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/MetaAnnotationWorker.java?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/MetaAnnotationWorker.java (original)
+++ jakarta/tapestry/trunk/annotations/src/java/org/apache/tapestry/annotations/MetaAnnotationWorker.java Thu Sep 29 13:32:42 2005
@@ -1,3 +1,17 @@
+// 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.annotations;
import java.util.ArrayList;
Modified: jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java (original)
+++ jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java Thu Sep 29 13:32:42 2005
@@ -68,6 +68,9 @@
@InjectState("barneyASO")
public abstract Map getBarney();
+ @InjectStateFlag("barneyASO")
+ public abstract boolean getBarneyExists();
+
@Parameter
public abstract String getSimpleParameter();
@@ -86,8 +89,8 @@
@Parameter(name = "fred")
public abstract double getNamedParameter();
-
- @Parameter(defaultValue="myDefault")
+
+ @Parameter(defaultValue = "myDefault")
public abstract String getDefaultValue();
@InjectPage("SomePageName")
Modified: jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/BasicComponentSubclass.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/BasicComponentSubclass.java?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/BasicComponentSubclass.java (original)
+++ jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/BasicComponentSubclass.java Thu Sep 29 13:32:42 2005
@@ -1,3 +1,17 @@
+// 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.annotations;
/**
Modified: jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaAnnotationWorkerTest.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaAnnotationWorkerTest.java?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaAnnotationWorkerTest.java (original)
+++ jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaAnnotationWorkerTest.java Thu Sep 29 13:32:42 2005
@@ -1,3 +1,17 @@
+// 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.annotations;
import org.apache.hivemind.ApplicationRuntimeException;
Modified: jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaPage.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaPage.java?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaPage.java (original)
+++ jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaPage.java Thu Sep 29 13:32:42 2005
@@ -1,3 +1,17 @@
+// 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.annotations;
import org.apache.tapestry.html.BasePage;
Modified: jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaPageSubclass.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaPageSubclass.java?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaPageSubclass.java (original)
+++ jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MetaPageSubclass.java Thu Sep 29 13:32:42 2005
@@ -1,3 +1,17 @@
+// 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.annotations;
/**
Modified: jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MissingEqualsMetaPage.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MissingEqualsMetaPage.java?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MissingEqualsMetaPage.java (original)
+++ jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/MissingEqualsMetaPage.java Thu Sep 29 13:32:42 2005
@@ -1,3 +1,17 @@
+// 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.annotations;
import org.apache.tapestry.html.BasePage;
Modified: jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/TestSimpleAnnotationWorkers.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/TestSimpleAnnotationWorkers.java?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/TestSimpleAnnotationWorkers.java (original)
+++ jakarta/tapestry/trunk/annotations/src/test/org/apache/tapestry/annotations/TestSimpleAnnotationWorkers.java Thu Sep 29 13:32:42 2005
@@ -24,7 +24,7 @@
/**
* Test for the "simple" annotation workers, that collect basic information and update the component
- * specification. {@link org.apache.tapestry.annotations.InjectPageAnnotationWorker}.
+ * specification.
*
* @author Howard Lewis Ship
* @since 4.0
@@ -69,7 +69,35 @@
assertEquals("script", is.getType());
assertEquals("foo.script", is.getObject());
assertSame(l, is.getLocation());
+ }
+
+ public void testInjectState()
+ {
+ Location l = newLocation();
+ IComponentSpecification spec = execute(new InjectStateAnnotationWorker(), "getBarney", l);
+ InjectSpecification is = (InjectSpecification) spec.getInjectSpecifications().get(0);
+
+ assertEquals("barney", is.getProperty());
+ assertEquals("state", is.getType());
+ assertEquals("barneyASO", is.getObject());
+ assertSame(l, is.getLocation());
+ }
+
+ public void testInjectStateFlag()
+ {
+ Location l = newLocation();
+ IComponentSpecification spec = execute(
+ new InjectStateFlagAnnotationWorker(),
+ "getBarneyExists",
+ l);
+
+ InjectSpecification is = (InjectSpecification) spec.getInjectSpecifications().get(0);
+
+ assertEquals("barneyExists", is.getProperty());
+ assertEquals("state-flag", is.getType());
+ assertEquals("barneyASO", is.getObject());
+ assertSame(l, is.getLocation());
}
private IComponentSpecification execute(MethodAnnotationEnhancementWorker worker,
Modified: jakarta/tapestry/trunk/examples/Workbench/src/context/Redirect.html
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Workbench/src/context/Redirect.html?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Workbench/src/context/Redirect.html (original)
+++ jakarta/tapestry/trunk/examples/Workbench/src/context/Redirect.html Thu Sep 29 13:32:42 2005
@@ -1,29 +1,22 @@
<span jwcid="@Border">
-
-<p>This page demonstrates that Tapestry can interoperate with
-traditional web applications. A listener method may redirect
-to either an internal resource within the same
-web application, or to an external URL.
-
-<p>
-Examples:
-
-<ul>
-<li><a href="#" jwcid="@DirectLink" listener="listener:redirectInternal">Forward to internal resource</a> (redirect-target.html)
-<li><a href="#" jwcid="@DirectLink" listener="listener:redirectExternal">Redirect to external URL</a> (http://jakarta.apache.org/tapestry)
-</ul>
-
-<p>
-
-The code for both these cases is very simple:
-<pre>
- public void redirectInternal(IRequestCycle cycle)
+ <p>This page demonstrates that Tapestry can interoperate with traditional web applications. A listener method may
+ redirect to either an internal resource within the same web application, or to an external URL.</p>
+ <p> Examples:</p>
+ <ul>
+ <li><a href="#" jwcid="@DirectLink" listener="listener:redirectInternal">Forward to internal resource</a>
+ (redirect-target.html)</li>
+ <li><a href="#" jwcid="@DirectLink" listener="listener:redirectExternal">Redirect to external URL</a>
+ (http://jakarta.apache.org/tapestry)</li>
+ </ul>
+ <p> The code for both these cases is very simple:</p>
+ <pre>
+ public void redirectInternal()
throws RequestCycleException
{
throw new RedirectException("redirect-target.html");
}
- public void redirectExternal(IRequestCycle cycle)
+ public void redirectExternal()
throws RequestCycleException
{
throw new RedirectException("http://jakarta.apache.org/tapestry");
Modified: jakarta/tapestry/trunk/examples/Workbench/src/context/css/workbench.css
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Workbench/src/context/css/workbench.css?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Workbench/src/context/css/workbench.css (original)
+++ jakarta/tapestry/trunk/examples/Workbench/src/context/css/workbench.css Thu Sep 29 13:32:42 2005
@@ -34,7 +34,7 @@
TABLE.tabs TD
{
- padding: 0;
+ padding: 0px;
}
BODY
@@ -159,7 +159,7 @@
{
font-family: Trebuchet MS,sans-serif;
text-decoration:none;
- font-size: 10pt;
+ font-size: 12px;
font-weight: bold;
color: black;
}
Modified: jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.enhance.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.enhance.xml?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.enhance.xml (original)
+++ jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.enhance.xml Thu Sep 29 13:32:42 2005
@@ -116,6 +116,7 @@
<contribution configuration-id="InjectWorkers">
<worker type="object" object="service:InjectObjectWorker"/>
<worker type="state" object="service:InjectStateWorker"/>
+ <worker type="state-flag" object="service:InjectStateFlagWorker"/>
<worker type="meta" object="service:InjectMetaWorker"/>
<worker type="script" object="service:InjectScriptWorker"/>
<worker type="page" object="instance:InjectPageWorker"/>
@@ -199,6 +200,19 @@
</invoke-factory>
</service-point>
+
+ <service-point id="InjectStateFlagWorker" interface="InjectEnhancementWorker">
+
+ Injects boolean properties that indicate if a particular application state object
+ exists or not.
+
+ <invoke-factory>
+ <construct class="InjectStateFlagWorker">
+ <set-service property="applicationStateManager" service-id="tapestry.state.ApplicationStateManager"/>
+ </construct>
+ </invoke-factory>
+
+ </service-point>
<service-point id="InjectMetaWorker" interface="InjectEnhancementWorker">
Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceMessages.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceMessages.java?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceMessages.java (original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceMessages.java Thu Sep 29 13:32:42 2005
@@ -113,33 +113,37 @@
.getJavaClassName(propertyType), ClassFabUtils.getJavaClassName(requiredType));
}
- public static String wrongTypeForPageInjection(String propertyName, Class propertyType)
+ static String wrongTypeForPageInjection(String propertyName, Class propertyType)
{
return _formatter.format("wrong-type-for-page-injection", propertyName, ClassFabUtils
.getJavaClassName(propertyType));
}
- public static String incompatiblePropertyType(String propertyName, Class propertyType,
+ static String incompatiblePropertyType(String propertyName, Class propertyType,
Class expectedType)
{
return _formatter.format("incompatible-property-type", propertyName, ClassFabUtils
.getJavaClassName(propertyType), ClassFabUtils.getJavaClassName(expectedType));
}
- public static String classEnhancementFailure(Class baseClass, Throwable cause)
+ static String classEnhancementFailure(Class baseClass, Throwable cause)
{
return _formatter.format("class-enhancement-failure", ClassFabUtils
.getJavaClassName(baseClass), cause);
}
- public static String methodConflict(MethodSignature sig, Location existing)
+ static String methodConflict(MethodSignature sig, Location existing)
{
return _formatter.format("method-conflict", sig, existing);
}
- public static String readonlyProperty(String propertyName, Method writeMethod)
+ static String readonlyProperty(String propertyName, Method writeMethod)
{
return _formatter.format("readonly-property", propertyName, writeMethod);
}
+ static String mustBeBoolean(String propertyName)
+ {
+ return _formatter.format("must-be-boolean", propertyName);
+ }
}
Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceStrings.properties
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceStrings.properties?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceStrings.properties (original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/EnhanceStrings.properties Thu Sep 29 13:32:42 2005
@@ -28,4 +28,5 @@
incompatible-property-type=Property {0} is type {1}, which is not compatible with the expected type, {2}.
class-enhancement-failure=Failure enhancing class {0}: {1}
method-conflict=A new implementation of method ''{0}'' conflicts with an existing implementation (at {1}).
-readonly-property=Property {0} should be read-only; remove method {1}.
\ No newline at end of file
+readonly-property=Property {0} should be read-only; remove method {1}.
+must-be-boolean=Property {0} must be type boolean for this type of injection.
\ No newline at end of file
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/InjectStateFlagWorker.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/InjectStateFlagWorker.java?rev=292533&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/InjectStateFlagWorker.java (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/InjectStateFlagWorker.java Thu Sep 29 13:32:42 2005
@@ -0,0 +1,86 @@
+// 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.lang.reflect.Modifier;
+
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.Location;
+import org.apache.hivemind.service.BodyBuilder;
+import org.apache.hivemind.service.MethodSignature;
+import org.apache.hivemind.util.Defense;
+import org.apache.tapestry.engine.state.ApplicationStateManager;
+import org.apache.tapestry.spec.InjectSpecification;
+
+/**
+ * Injects a boolean property that indicates if a particular application state object already
+ * exists. This is useful in situations where you are trying to prevent the creation of the ASO (and
+ * thus, prevent the creation of the HttpSession).
+ *
+ * @author Howard M. Lewis Ship
+ * @since 4.0
+ */
+public class InjectStateFlagWorker implements InjectEnhancementWorker
+{
+ private ApplicationStateManager _applicationStateManager;
+
+ public void performEnhancement(EnhancementOperation op, InjectSpecification spec)
+ {
+ injectStateFlag(op, spec.getObject(), spec.getProperty(), spec.getLocation());
+ }
+
+ void injectStateFlag(EnhancementOperation op, String objectName, String propertyName,
+ Location location)
+ {
+ Defense.notNull(op, "op");
+ Defense.notNull(objectName, "objectName");
+ Defense.notNull(propertyName, "propertyName");
+
+ Class propertyType = op.getPropertyType(propertyName);
+
+ // null means no property at all; it's just in the XML
+ // which is ok. Otherwise, make sure it is exactly boolean.
+
+ if (propertyType != null && propertyType != boolean.class)
+ throw new ApplicationRuntimeException(EnhanceMessages.mustBeBoolean(propertyName),
+ location, null);
+
+ op.claimReadonlyProperty(propertyName);
+
+ String managerField = op.addInjectedField(
+ "_$applicationStateManager",
+ ApplicationStateManager.class,
+ _applicationStateManager);
+
+ BodyBuilder builder = new BodyBuilder();
+ builder.begin();
+ builder.add("return {0}.exists(", managerField);
+ builder.addQuoted(objectName);
+ builder.addln(");");
+ builder.end();
+
+ String methodName = op.getAccessorMethodName(propertyName);
+
+ MethodSignature sig = new MethodSignature(boolean.class, methodName, null, null);
+
+ op.addMethod(Modifier.PUBLIC, sig, builder.toString(), location);
+ }
+
+ public void setApplicationStateManager(ApplicationStateManager applicationStateManager)
+ {
+ _applicationStateManager = applicationStateManager;
+ }
+
+}
Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/InjectStateWorker.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/InjectStateWorker.java?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/InjectStateWorker.java (original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/enhance/InjectStateWorker.java Thu Sep 29 13:32:42 2005
@@ -43,7 +43,7 @@
injectState(op, spec.getObject(), spec.getProperty(), spec.getLocation());
}
- public void injectState(EnhancementOperation op, String objectName, String propertyName,
+ void injectState(EnhancementOperation op, String objectName, String propertyName,
Location location)
{
Defense.notNull(op, "op");
@@ -54,7 +54,7 @@
String fieldName = "_$" + propertyName;
// State properties are read/write
-
+
op.claimProperty(propertyName);
op.addField(fieldName, propertyType);
Modified: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/BaseEnhancementTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/BaseEnhancementTestCase.java?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/BaseEnhancementTestCase.java (original)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/BaseEnhancementTestCase.java Thu Sep 29 13:32:42 2005
@@ -16,6 +16,7 @@
import org.apache.hivemind.Location;
import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.engine.state.ApplicationStateManager;
import org.apache.tapestry.spec.IComponentSpecification;
import org.easymock.MockControl;
@@ -41,5 +42,35 @@
protected IComponentSpecification newSpec()
{
return (IComponentSpecification) newMock(IComponentSpecification.class);
+ }
+
+ protected EnhancementOperation newOp()
+ {
+ return (EnhancementOperation) newMock(EnhancementOperation.class);
+ }
+
+ protected void trainGetAccessorMethodName(EnhancementOperation op, String propertyName, String methodName)
+ {
+ op.getAccessorMethodName(propertyName);
+ setReturnValue(op, methodName);
+
+ }
+
+ protected void trainAddInjectedField(EnhancementOperation op, String fieldName, Class fieldType, Object injectedValue, String injectedFieldName)
+ {
+ op.addInjectedField(fieldName, fieldType, injectedValue);
+ setReturnValue(op, injectedFieldName);
+
+ }
+
+ protected ApplicationStateManager newApplicationStateManager()
+ {
+ return (ApplicationStateManager) newMock(ApplicationStateManager.class);
+ }
+
+ protected void trainGetPropertyType(EnhancementOperation op, String propertyName, Class propertyType)
+ {
+ op.getPropertyType(propertyName);
+ setReturnValue(op, propertyType);
}
}
Added: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/InjectStateFlagWorkerTest.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/InjectStateFlagWorkerTest.java?rev=292533&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/InjectStateFlagWorkerTest.java (added)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/enhance/InjectStateFlagWorkerTest.java Thu Sep 29 13:32:42 2005
@@ -0,0 +1,151 @@
+// 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.lang.reflect.Modifier;
+
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.Location;
+import org.apache.hivemind.service.MethodSignature;
+import org.apache.tapestry.engine.state.ApplicationStateManager;
+import org.apache.tapestry.spec.InjectSpecification;
+import org.apache.tapestry.spec.InjectSpecificationImpl;
+
+/**
+ * Tests for {@link org.apache.tapestry.enhance.InjectStateFlagWorker}.
+ *
+ * @author Howard M. Lewis Ship
+ * @since 4.0
+ */
+public class InjectStateFlagWorkerTest extends BaseEnhancementTestCase
+{
+ public void testNoExistingProperty()
+ {
+ Location l = newLocation();
+ ApplicationStateManager asm = newApplicationStateManager();
+
+ InjectSpecification is = new InjectSpecificationImpl();
+ is.setProperty("fred");
+ is.setObject("fredASO");
+ is.setLocation(l);
+
+ EnhancementOperation op = newOp();
+
+ trainGetPropertyType(op, "fred", null);
+
+ op.claimReadonlyProperty("fred");
+
+ trainAddInjectedField(
+ op,
+ "_$applicationStateManager",
+ ApplicationStateManager.class,
+ asm,
+ "_$asm");
+
+ trainGetAccessorMethodName(op, "fred", "isFred");
+
+ MethodSignature sig = new MethodSignature(boolean.class, "isFred", null, null);
+
+ String code = "{\n return _$asm.exists(\"fredASO\");\n}\n";
+
+ op.addMethod(Modifier.PUBLIC, sig, code, l);
+
+ replayControls();
+
+ InjectStateFlagWorker worker = new InjectStateFlagWorker();
+
+ worker.setApplicationStateManager(asm);
+
+ worker.performEnhancement(op, is);
+
+ verifyControls();
+ }
+
+ public void testWithExistingProperty()
+ {
+ Location l = newLocation();
+ ApplicationStateManager asm = newApplicationStateManager();
+
+ InjectSpecification is = new InjectSpecificationImpl();
+ is.setProperty("fred");
+ is.setObject("fredASO");
+ is.setLocation(l);
+
+ EnhancementOperation op = newOp();
+
+ trainGetPropertyType(op, "fred", boolean.class);
+
+ op.claimReadonlyProperty("fred");
+
+ trainAddInjectedField(
+ op,
+ "_$applicationStateManager",
+ ApplicationStateManager.class,
+ asm,
+ "_$asm");
+
+ trainGetAccessorMethodName(op, "fred", "getFred");
+
+ MethodSignature sig = new MethodSignature(boolean.class, "getFred", null, null);
+
+ String code = "{\n return _$asm.exists(\"fredASO\");\n}\n";
+
+ op.addMethod(Modifier.PUBLIC, sig, code, l);
+
+ replayControls();
+
+ InjectStateFlagWorker worker = new InjectStateFlagWorker();
+
+ worker.setApplicationStateManager(asm);
+
+ worker.performEnhancement(op, is);
+
+ verifyControls();
+ }
+
+ public void testWithExistingPropertyWrongType()
+ {
+ Location l = newLocation();
+ ApplicationStateManager asm = newApplicationStateManager();
+
+ InjectSpecification is = new InjectSpecificationImpl();
+ is.setProperty("fred");
+ is.setObject("fredASO");
+ is.setLocation(l);
+
+ EnhancementOperation op = newOp();
+
+ trainGetPropertyType(op, "fred", int.class);
+
+ replayControls();
+
+ InjectStateFlagWorker worker = new InjectStateFlagWorker();
+
+ worker.setApplicationStateManager(asm);
+
+ try
+ {
+ worker.performEnhancement(op, is);
+ unreachable();
+ }
+ catch (ApplicationRuntimeException ex)
+ {
+ assertEquals("Property fred must be type boolean for this type of injection.", ex.getMessage());
+ assertSame(l, ex.getLocation());
+ }
+
+ verifyControls();
+ }
+}
Modified: jakarta/tapestry/trunk/src/documentation/content/xdocs/UsersGuide/injection.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/src/documentation/content/xdocs/UsersGuide/injection.xml?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/src/documentation/content/xdocs/UsersGuide/injection.xml (original)
+++ jakarta/tapestry/trunk/src/documentation/content/xdocs/UsersGuide/injection.xml Thu Sep 29 13:32:42 2005
@@ -212,6 +212,47 @@
</p>
</section>
+
+<section id="injection.state-flag">
+ <title>state-flag injection</title>
+
+ <p>
+ Using the <link href="#injection.state">state</link> injection can force the creation
+ of an application state object; this type of injection will create a <em>read only</em>
+ boolean property that indicates <em>if</em> an application state object already exists.
+ </p>
+
+ <p>
+ This is used to <em>prevent</em> the creation of an application state object until it
+ is absolutely needed.
+ </p>
+
+ <p>
+ For example; in a situtation where the user may or may not be logged in, you would
+ inject a state flag and the state in two properties and check the state flag
+ <em>first</em>:
+ </p>
+
+<source><![CDATA[
+// <inject> type state-flag in the XML
+public abstract boolean getUserIdentityExists();
+
+// <inject> type state in the XML
+public abstract WizardState getUserIdentity();
+
+public void doOperation()
+{
+ if (getUserIdentityExists() && getUserIdentity().isLoggedIn())
+ {
+ . . .
+ }
+ else
+ {
+ . . .
+ }
+}
+]]></source>
+</section> <!-- injection.state-flag -->
</body>
</document>
Modified: jakarta/tapestry/trunk/status.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/status.xml?rev=292533&r1=292532&r2=292533&view=diff
==============================================================================
--- jakarta/tapestry/trunk/status.xml (original)
+++ jakarta/tapestry/trunk/status.xml Thu Sep 29 13:32:42 2005
@@ -55,6 +55,7 @@
<action type="fix" dev="DS" fixes-bug="TAPESTRY-491">Document Inspector component</action>
<action type="fix" dev="HLS" fixes-bug="TAPESTRY-601">EnhanceUtils needs null checks in the primitive unwrapper methods</action>
<action type="fix" dev="HLS" fixes-bug="TAPESTRY-676">Tapestry Inspector can throw an exception on the properties page, if a property is an array containing nulls</action>
+ <action type="fix" dev="HLS" fixes-bug="TAPESTRY-680">Need an injection type comparable to the state: binding prefix</action>
</release>
<release version="4.0-beta-8" date="Sep 24 2005">
<action type="fix" dev="DS" fixes-bug="TAPESTRY-465">Document Foreach component</action>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org