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/08/14 13:52:42 UTC
svn commit: r431325 - in /tapestry/tapestry4/trunk/tapestry-annotations/src:
java/org/apache/tapestry/annotations/ test/org/apache/tapestry/annotations/
Author: andyhot
Date: Mon Aug 14 04:52:41 2006
New Revision: 431325
URL: http://svn.apache.org/viewvc?rev=431325&view=rev
Log:
TAPESTRY-709: Do not allow ComponentClass and Parameter annotations in page classes.
Added:
tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedComponent.java
tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/PageAnnotatedAsComponent.java
Modified:
tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationMessages.java
tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationStrings.properties
tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ComponentClassAnnotationWorker.java
tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ParameterAnnotationWorker.java
tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java
tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestComponentClassAnnotationWorker.java
tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestParameterAnnotationWorker.java
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationMessages.java?rev=431325&r1=431324&r2=431325&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationMessages.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationMessages.java Mon Aug 14 04:52:41 2006
@@ -107,4 +107,9 @@
{
return _formatter.format("no-targets-found", method);
}
+
+ static String invalidAnnotationInClass(Class annotation, Class clazz)
+ {
+ return _formatter.format("invalid-annotation-in-class", annotation.getName(), clazz.getName());
+ }
}
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationStrings.properties?rev=431325&r1=431324&r2=431325&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationStrings.properties (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/AnnotationStrings.properties Mon Aug 14 04:52:41 2006
@@ -28,3 +28,4 @@
no-component-found=Unable to find component with id while enhancing method {0}: {1}
no-targets-found=No targets found for annotated method {0}. You must specify at least one of targets or elements.
no-form-found=Unable to find form with id while enhancing method bound with submitForm annotation {0}: {1}
+invalid-annotation-in-class=Annotation {0} is not allowed in a class (''{1}'') that implements the IPage interface.
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ComponentClassAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ComponentClassAnnotationWorker.java?rev=431325&r1=431324&r2=431325&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ComponentClassAnnotationWorker.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ComponentClassAnnotationWorker.java Mon Aug 14 04:52:41 2006
@@ -14,7 +14,9 @@
package org.apache.tapestry.annotations;
+import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Location;
+import org.apache.tapestry.IPage;
import org.apache.tapestry.TapestryUtils;
import org.apache.tapestry.enhance.EnhancementOperation;
import org.apache.tapestry.spec.IComponentSpecification;
@@ -33,6 +35,11 @@
public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
Class baseClass, Location location)
{
+ if (IPage.class.isAssignableFrom(baseClass))
+ {
+ throw new ApplicationRuntimeException(
+ AnnotationMessages.invalidAnnotationInClass(ComponentClass.class, baseClass));
+ }
ComponentClass component = (ComponentClass) baseClass.getAnnotation(ComponentClass.class);
spec.setAllowBody(component.allowBody());
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ParameterAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ParameterAnnotationWorker.java?rev=431325&r1=431324&r2=431325&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ParameterAnnotationWorker.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ParameterAnnotationWorker.java Mon Aug 14 04:52:41 2006
@@ -16,8 +16,10 @@
import java.lang.reflect.Method;
+import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.HiveMind;
import org.apache.hivemind.Location;
+import org.apache.tapestry.IPage;
import org.apache.tapestry.enhance.EnhancementOperation;
import org.apache.tapestry.spec.IComponentSpecification;
import org.apache.tapestry.spec.IParameterSpecification;
@@ -37,6 +39,12 @@
public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
Method method, Location location)
{
+ if (IPage.class.isAssignableFrom(method.getDeclaringClass()))
+ {
+ throw new ApplicationRuntimeException(
+ AnnotationMessages.invalidAnnotationInClass(Parameter.class, method.getDeclaringClass()));
+ }
+
Parameter parameter = method.getAnnotation(Parameter.class);
String propertyName = AnnotationUtils.getPropertyName(method);
Added: tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedComponent.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedComponent.java?rev=431325&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedComponent.java (added)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedComponent.java Mon Aug 14 04:52:41 2006
@@ -0,0 +1,48 @@
+// 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.BaseComponent;
+
+/**
+ * Used by {@link org.apache.tapestry.annotations.TestParameterAnnotatioWorker}.
+ *
+ * @author Andreas Andreou
+ * @since 4.1.1
+ */
+public abstract class AnnotatedComponent extends BaseComponent
+{
+ @Parameter
+ public abstract String getSimpleParameter();
+
+ @Parameter(required = true)
+ public abstract String getRequiredParameter();
+
+ @Parameter(cache = false)
+ public abstract Object getNonCachedParameter();
+
+ @Parameter(aliases = "fred")
+ public abstract String getAliasedParameter();
+
+ @Parameter
+ @Deprecated
+ public abstract int getDeprecatedParameter();
+
+ @Parameter(name = "fred")
+ public abstract double getNamedParameter();
+
+ @Parameter(defaultValue = "myDefault")
+ public abstract String getDefaultValue();
+}
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?rev=431325&r1=431324&r2=431325&view=diff
==============================================================================
--- 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 Mon Aug 14 04:52:41 2006
@@ -79,25 +79,6 @@
@Parameter
public abstract String getSimpleParameter();
- @Parameter(required = true)
- public abstract String getRequiredParameter();
-
- @Parameter(cache = false)
- public abstract Object getNonCachedParameter();
-
- @Parameter(aliases = "fred")
- public abstract String getAliasedParameter();
-
- @Parameter
- @Deprecated
- public abstract int getDeprecatedParameter();
-
- @Parameter(name = "fred")
- public abstract double getNamedParameter();
-
- @Parameter(defaultValue = "myDefault")
- public abstract String getDefaultValue();
-
@InjectPage("SomePageName")
public abstract IPage getMyPage();
Added: tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/PageAnnotatedAsComponent.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/PageAnnotatedAsComponent.java?rev=431325&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/PageAnnotatedAsComponent.java (added)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/PageAnnotatedAsComponent.java Mon Aug 14 04:52:41 2006
@@ -0,0 +1,28 @@
+// 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;
+
+/**
+ * Used by {@link org.apache.tapestry.annotations.TestComponentClassAnnotatioWorker}.
+ *
+ * @author Andreas Andreou
+ * @since 4.1.1
+ */
+@ComponentClass
+public abstract class PageAnnotatedAsComponent extends BasePage
+{
+}
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestComponentClassAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestComponentClassAnnotationWorker.java?rev=431325&r1=431324&r2=431325&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestComponentClassAnnotationWorker.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestComponentClassAnnotationWorker.java Mon Aug 14 04:52:41 2006
@@ -15,6 +15,8 @@
package org.apache.tapestry.annotations;
import static org.testng.AssertJUnit.*;
+
+import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Location;
import org.apache.tapestry.enhance.EnhancementOperation;
import org.apache.tapestry.spec.ComponentSpecification;
@@ -93,4 +95,24 @@
assertEquals(true, spec.isReservedParameterName("foo"));
assertEquals(true, spec.isReservedParameterName("bar"));
}
+
+ public void testComponentClassNotAllowed()
+ {
+ EnhancementOperation op = newOp();
+ IComponentSpecification spec = new ComponentSpecification();
+
+ replay();
+
+ try
+ {
+ new ComponentClassAnnotationWorker().performEnhancement(
+ op, spec, PageAnnotatedAsComponent.class, null);
+ unreachable();
+ }
+ catch (ApplicationRuntimeException ex)
+ {
+ }
+
+ verify();
+ }
}
Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestParameterAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestParameterAnnotationWorker.java?rev=431325&r1=431324&r2=431325&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestParameterAnnotationWorker.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestParameterAnnotationWorker.java Mon Aug 14 04:52:41 2006
@@ -20,6 +20,7 @@
import java.lang.reflect.Method;
+import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Location;
import org.apache.tapestry.enhance.EnhancementOperation;
import org.apache.tapestry.spec.ComponentSpecification;
@@ -44,7 +45,7 @@
private IParameterSpecification attempt(String propertyName, String parameterName,
Location location)
{
- Method m = findMethod(AnnotatedPage.class, "get"
+ Method m = findMethod(AnnotatedComponent.class, "get"
+ propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1));
EnhancementOperation op = newMock(EnhancementOperation.class);
@@ -118,6 +119,28 @@
IParameterSpecification ps = attempt("defaultValue", null);
assertEquals("myDefault", ps.getDefaultValue());
+ }
+
+ public void testParameterNotAllowed()
+ {
+ Method m = findMethod(AnnotatedPage.class, "getSimpleParameter");
+
+ EnhancementOperation op = newMock(EnhancementOperation.class);
+
+ IComponentSpecification spec = new ComponentSpecification();
+
+ replay();
+
+ try
+ {
+ new ParameterAnnotationWorker().performEnhancement(op, spec, m, null);
+ unreachable();
+ }
+ catch (ApplicationRuntimeException ex)
+ {
+ }
+
+ verify();
}
}