You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by an...@apache.org on 2006/10/03 16:47:01 UTC
svn commit: r452519 - in /tapestry/tapestry4/trunk/tapestry-annotations/src:
java/org/apache/tapestry/annotations/ site/xdoc/
test/org/apache/tapestry/annotations/
Author: andyhot
Date: Tue Oct 3 07:47:00 2006
New Revision: 452519
URL: http://svn.apache.org/viewvc?view=rev&rev=452519
Log:
TAPESTRY-662 and TAPESTRY-1103: Make InjectMeta, InjectState, InjectStateFlag annotation value optional.
Modified:
tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationUtils.java
tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectMeta.java
tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectMetaAnnotationWorker.java
tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectState.java
tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateAnnotationWorker.java
tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java
tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java
tapestry/tapestry4/trunk/tapestry-annotations/src/site/xdoc/index.xml
tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java
tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestSimpleAnnotationWorkers.java
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationUtils.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationUtils.java?view=diff&rev=452519&r1=452518&r2=452519
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationUtils.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationUtils.java Tue Oct 3 07:47:00 2006
@@ -76,6 +76,8 @@
*
* @param methodName the method to convert
* @return the converted key
+ *
+ * @since 4.1.1
*/
public static String convertMethodNameToKeyName(String methodName)
{
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectMeta.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectMeta.java?view=diff&rev=452519&r1=452518&r2=452519
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectMeta.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectMeta.java Tue Oct 3 07:47:00 2006
@@ -34,8 +34,8 @@
public @interface InjectMeta {
/**
- * The meta key to inject.
+ * The meta key to inject. If no such value is defined, it is derived from the method name.
*/
- String value();
+ String value() default "";
}
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectMetaAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectMetaAnnotationWorker.java?view=diff&rev=452519&r1=452518&r2=452519
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectMetaAnnotationWorker.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectMetaAnnotationWorker.java Tue Oct 3 07:47:00 2006
@@ -35,11 +35,16 @@
String propertyName = AnnotationUtils.getPropertyName(method);
InjectMeta annotation = method.getAnnotation(InjectMeta.class);
+
+ String keyName = annotation.value();
+
+ if (keyName.equals(""))
+ keyName = AnnotationUtils.convertMethodNameToKeyName(method.getName());
InjectSpecification is = new InjectSpecificationImpl();
is.setProperty(propertyName);
is.setType("meta");
- is.setObject(annotation.value());
+ is.setObject(keyName);
is.setLocation(location);
spec.addInjectSpecification(is);
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectState.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectState.java?view=diff&rev=452519&r1=452518&r2=452519
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectState.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectState.java Tue Oct 3 07:47:00 2006
@@ -34,8 +34,8 @@
public @interface InjectState {
/**
- * The id of the Application State Object to inject.
+ * The id of the Application State Object to inject. If no such value is defined, it is derived from the method name.
*/
- String value();
+ String value() default "";
}
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateAnnotationWorker.java?view=diff&rev=452519&r1=452518&r2=452519
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateAnnotationWorker.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateAnnotationWorker.java Tue Oct 3 07:47:00 2006
@@ -36,6 +36,11 @@
Method method, Location location)
{
InjectState is = method.getAnnotation(InjectState.class);
+
+ String keyName = is.value();
+
+ if (keyName.equals(""))
+ keyName = AnnotationUtils.convertMethodNameToKeyName(method.getName());
String propertyName = AnnotationUtils.getPropertyName(method);
@@ -43,7 +48,7 @@
inject.setType("state");
inject.setProperty(propertyName);
- inject.setObject(is.value());
+ inject.setObject(keyName);
inject.setLocation(location);
spec.addInjectSpecification(inject);
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java?view=diff&rev=452519&r1=452518&r2=452519
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateFlag.java Tue Oct 3 07:47:00 2006
@@ -33,7 +33,8 @@
/**
* 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.
+ * If no such value is defined, it is derived from the method name.
*/
- String value();
+ String value() default "";
}
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java?view=diff&rev=452519&r1=452518&r2=452519
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/InjectStateFlagAnnotationWorker.java Tue Oct 3 07:47:00 2006
@@ -33,6 +33,18 @@
Method method, Location location)
{
InjectStateFlag isv = method.getAnnotation(InjectStateFlag.class);
+
+ String keyName = isv.value();
+
+ if (keyName.equals(""))
+ {
+ keyName = AnnotationUtils.convertMethodNameToKeyName(method.getName());
+ if (keyName.endsWith("-exists")) // strip it
+ {
+ int length = keyName.length();
+ keyName = keyName.substring(0, length - 7);
+ }
+ }
String propertyName = AnnotationUtils.getPropertyName(method);
@@ -40,7 +52,7 @@
inject.setType("state-flag");
inject.setProperty(propertyName);
- inject.setObject(isv.value());
+ inject.setObject(keyName);
inject.setLocation(location);
spec.addInjectSpecification(inject);
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/site/xdoc/index.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/site/xdoc/index.xml?view=diff&rev=452519&r1=452518&r2=452519
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/site/xdoc/index.xml (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/site/xdoc/index.xml Tue Oct 3 07:47:00 2006
@@ -489,6 +489,17 @@
The new property does not have to be type String; an automatic type conversion
takes place.
</p>
+
+ <p>
+ The <a href="apidocs/org/apache/tapestry/annotations/InjectMeta.html">InjectMeta</a>
+ annotation can also be used alone - the method name is converted into a property
+ key using the rules described at the <a href="#Message">Message</a> annotation.
+ Here's an equivalent to the previous example.
+ </p>
+ <source xml:space="preserve">
+ @InjectMeta
+ public abstract String getPageTitle();
+</source>
</subsection>
@@ -578,6 +589,17 @@
<a href="#spec.inject"><inject></a>
element, with a type of "state".
</p>
+
+ <p>
+ The <a href="apidocs/org/apache/tapestry/annotations/InjectState.html">InjectState</a>
+ annotation can also be used alone - the method name is converted into a
+ key using the rules described at the <a href="#Message">Message</a> annotation.
+ Here's an equivalent to the previous example.
+ </p>
+ <source xml:space="preserve">
+ @InjectState
+ public abstract MyAppVisit getVisit();
+</source>
</subsection>
@@ -605,6 +627,21 @@
<a href="#spec.inject"><inject></a>
element, with a type of "state-flag".
</p>
+
+ <p>
+ The <a href="apidocs/org/apache/tapestry/annotations/InjectStateFlag.html">
+ InjectStateFlag
+ </a>
+ annotation can also be used alone - the method name is converted into a
+ key using the rules described at the <a href="#Message">Message</a> annotation
+ ( with the addition that any trailing "exists" is stripped ).
+ Here's an equivalent to the previous example.
+ It also injects the flag for the visit ASO.
+ </p>
+ <source xml:space="preserve">
+ @InjectStateFlag
+ public abstract boolean getVisitExists();
+</source>
</subsection>
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java?view=diff&rev=452519&r1=452518&r2=452519
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java Tue Oct 3 07:47:00 2006
@@ -75,6 +75,12 @@
@InjectStateFlag("barneyASO")
public abstract boolean getBarneyExists();
+
+ @InjectState
+ public abstract Map getMyVisit();
+
+ @InjectStateFlag
+ public abstract boolean getMyVisitExists();
@Parameter
public abstract String getSimpleParameter();
@@ -122,6 +128,9 @@
@InjectMeta("fred")
public abstract String getMetaFred();
+
+ @InjectMeta
+ public abstract String getPageTitle();
@InjectScript("foo.script")
public abstract IScript getScript();
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestSimpleAnnotationWorkers.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestSimpleAnnotationWorkers.java?view=diff&rev=452519&r1=452518&r2=452519
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestSimpleAnnotationWorkers.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestSimpleAnnotationWorkers.java Tue Oct 3 07:47:00 2006
@@ -33,7 +33,7 @@
@Test
public class TestSimpleAnnotationWorkers extends BaseAnnotationTestCase
{
- public void testInjectPage()
+ public void test_Inject_Page()
{
Location l = newLocation();
IComponentSpecification spec = execute(new InjectPageAnnotationWorker(), "getMyPage", l);
@@ -46,7 +46,7 @@
assertSame(l, is.getLocation());
}
- public void testInjectMeta()
+ public void test_Inject_Meta()
{
Location l = newLocation();
IComponentSpecification spec = execute(new InjectMetaAnnotationWorker(), "getMetaFred", l);
@@ -59,8 +59,22 @@
assertSame(l, is.getLocation());
}
+
+ public void test_Inject_Meta_NoValue()
+ {
+ Location l = newLocation();
+ IComponentSpecification spec = execute(new InjectMetaAnnotationWorker(), "getPageTitle", l);
+
+ InjectSpecification is = (InjectSpecification) spec.getInjectSpecifications().get(0);
+
+ assertEquals("pageTitle", is.getProperty());
+ assertEquals("meta", is.getType());
+ assertEquals("page-title", is.getObject());
+ assertSame(l, is.getLocation());
- public void testInjectScript()
+ }
+
+ public void test_Inject_Script()
{
Location l = newLocation();
IComponentSpecification spec = execute(new InjectScriptAnnotationWorker(), "getScript", l);
@@ -73,7 +87,7 @@
assertSame(l, is.getLocation());
}
- public void testInjectState()
+ public void test_Inject_State()
{
Location l = newLocation();
IComponentSpecification spec = execute(new InjectStateAnnotationWorker(), "getBarney", l);
@@ -85,8 +99,21 @@
assertEquals("barneyASO", is.getObject());
assertSame(l, is.getLocation());
}
+
+ public void test_Inject_State_NoValue()
+ {
+ Location l = newLocation();
+ IComponentSpecification spec = execute(new InjectStateAnnotationWorker(), "getMyVisit", l);
- public void testInjectStateFlag()
+ InjectSpecification is = (InjectSpecification) spec.getInjectSpecifications().get(0);
+
+ assertEquals("myVisit", is.getProperty());
+ assertEquals("state", is.getType());
+ assertEquals("my-visit", is.getObject());
+ assertSame(l, is.getLocation());
+ }
+
+ public void test_Inject_State_Flag()
{
Location l = newLocation();
IComponentSpecification spec = execute(
@@ -101,6 +128,22 @@
assertEquals("barneyASO", is.getObject());
assertSame(l, is.getLocation());
}
+
+ public void test_Inject_State_Flag_NoValue()
+ {
+ Location l = newLocation();
+ IComponentSpecification spec = execute(
+ new InjectStateFlagAnnotationWorker(),
+ "getMyVisitExists",
+ l);
+
+ InjectSpecification is = (InjectSpecification) spec.getInjectSpecifications().get(0);
+
+ assertEquals("myVisitExists", is.getProperty());
+ assertEquals("state-flag", is.getType());
+ assertEquals("my-visit", is.getObject());
+ assertSame(l, is.getLocation());
+ }
private IComponentSpecification execute(MethodAnnotationEnhancementWorker worker,
String methodName, Location location)