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/06/10 00:53:48 UTC
cvs commit: jakarta-tapestry/annotations build.xml
hlship 2005/06/09 15:53:48
Modified: . status.xml
annotations/src/java/org/apache/tapestry/annotations
InjectObjectAnnotationWorker.java
annotations/src/test/org/apache/tapestry/annotations
BaseAnnotationTestCase.java
TestInjectObjectAnnotationWorker.java
TestAnnotationUtils.java Target.java
framework/src/java/org/apache/tapestry/enhance
InjectObjectWorker.java
annotations/src/documentation/content/xdocs/tapestry-annotations
index.xml
annotations/src/descriptor/META-INF hivemodule.xml
annotations build.xml
Added: annotations/src/java/org/apache/tapestry/annotations
InjectStateAnnotationWorker.java
PersistAnnotationWorker.java Persist.java
InjectComponentAnnotationWorker.java
InjectState.java InjectAssetAnnotationWorker.java
InjectAsset.java InjectComponent.java
annotations/src/test/org/apache/tapestry/annotations
TestInjectStateAnnotationWorker.java
TestPersistAnnotationWorker.java
TestInjectAssetAnnotationWorker.java
TestInjectComponentAnnotationWorker.java
Log:
Add more annotations: InjectAsset, InjectComponent, InjectState and Persist
Revision Changes Path
1.120 +1 -0 jakarta-tapestry/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/status.xml,v
retrieving revision 1.119
retrieving revision 1.120
diff -u -r1.119 -r1.120
--- status.xml 9 Jun 2005 18:52:50 -0000 1.119
+++ status.xml 9 Jun 2005 22:53:48 -0000 1.120
@@ -70,6 +70,7 @@
<action type="fix" dev="HLS" fixes-bug="TAPESTRY-335">Injection uses actual type of injected object, which may not be available (due to AOP, or due to use of JDK Proxies).</action>
<action type="add" dev="HLS">Add page listing the project voting history.</action>
<action type="add" dev="HLS">Add InjectObject annotation and basic annotation support (in tapestry-annotation module).</action>
+ <action type="add" dev="HLS">Add more annotations: InjectAsset, InjectComponent, InjectState and Persist</action>
</release>
<release version="4.0-alpha-3" date="May 16 2005">
<action type="add" dev="HLS">Add initial support for the validator: binding prefix.</action>
1.2 +2 -1 jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/InjectObjectAnnotationWorker.java
Index: InjectObjectAnnotationWorker.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/InjectObjectAnnotationWorker.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InjectObjectAnnotationWorker.java 9 Jun 2005 18:42:48 -0000 1.1
+++ InjectObjectAnnotationWorker.java 9 Jun 2005 22:53:48 -0000 1.2
@@ -29,6 +29,7 @@
* @author Howard M. Lewis Ship
* @since 4.0
* @see org.apache.tapestry.enhance.InjectObjectWorker
+ * @see org.apache.tapestry.annotations.InjectObject
*/
public class InjectObjectAnnotationWorker implements MethodAnnotationEnhancementWorker
@@ -54,7 +55,7 @@
String name = AnnotationUtils.getPropertyName(method);
- _delegate.injectObject(op, name, object, null);
+ _delegate.injectObject(op, object, name, null);
}
public void setProvider(InjectedValueProvider provider)
1.1 jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/InjectStateAnnotationWorker.java
Index: InjectStateAnnotationWorker.java
===================================================================
// 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.Annotation;
import java.lang.reflect.Method;
import org.apache.tapestry.enhance.EnhancementOperation;
import org.apache.tapestry.enhance.InjectStateWorker;
import org.apache.tapestry.spec.IComponentSpecification;
/**
* Injects an Application State Object.
*
* @author Howard M. Lewis Ship
* @since 4.0
* @see org.apache.tapestry.annotations.InjectState
* @see org.apache.tapestry.enhance.InjectStateWorker
*/
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,
Annotation annotation, Method method)
{
InjectState is = (InjectState) annotation;
String propertyName = AnnotationUtils.getPropertyName(method);
_delegate.injectState(op, propertyName, is.value());
}
}
1.1 jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/PersistAnnotationWorker.java
Index: PersistAnnotationWorker.java
===================================================================
// 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.Annotation;
import java.lang.reflect.Method;
import org.apache.tapestry.enhance.EnhancementOperation;
import org.apache.tapestry.spec.IComponentSpecification;
import org.apache.tapestry.spec.IPropertySpecification;
import org.apache.tapestry.spec.PropertySpecification;
/**
* Allow a property to be marked as persistent, and (optionally) allows a strategy to be set. Works
* by adding a new {@link org.apache.tapestry.spec.IPropertySpecification} to the
* {@link org.apache.tapestry.spec.IComponentSpecification}.
*
* @author Howard M. Lewis Ship
* @since 4.0
* @see org.apache.tapestry.annotations.Persist
*/
public class PersistAnnotationWorker implements MethodAnnotationEnhancementWorker
{
public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
Annotation annotation, Method method)
{
Persist p = (Persist) annotation;
String propertyName = AnnotationUtils.getPropertyName(method);
String stategy = p.value();
IPropertySpecification pspec = new PropertySpecification();
pspec.setName(propertyName);
pspec.setPersistence(stategy);
spec.addPropertySpecification(pspec);
}
}
1.1 jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/Persist.java
Index: Persist.java
===================================================================
// 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.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Allows a property to be marked as persistent (and, optionally, provide control over how the
* property is persisted).
*
* @author Howard M. Lewis Ship
* @since 4.0
*/
@Target(
{ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface Persist {
/**
* The persistence strategy, defaulting to "session" (meaning, in the HttpSession, as a session
* attribute). Tapestry includes another strategy, "client", and additional strategies can be
* defined.
*/
String value() default "session";
}
1.1 jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/InjectComponentAnnotationWorker.java
Index: InjectComponentAnnotationWorker.java
===================================================================
// 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.Annotation;
import java.lang.reflect.Method;
import org.apache.tapestry.enhance.EnhancementOperation;
import org.apache.tapestry.enhance.InjectComponentWorker;
import org.apache.tapestry.spec.IComponentSpecification;
/**
* Injects a reference to a compent.
*
* @author Howard M. Lewis Ship
* @since 4.0
* @see org.apache.tapestry.annotations.InjectComponent
* @see org.apache.tapestry.enhance.InjectComponentWorker
*/
public class InjectComponentAnnotationWorker implements MethodAnnotationEnhancementWorker
{
final InjectComponentWorker _delegate;
InjectComponentAnnotationWorker(InjectComponentWorker delegate)
{
_delegate = delegate;
}
public InjectComponentAnnotationWorker()
{
this(new InjectComponentWorker());
}
public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
Annotation annotation, Method method)
{
InjectComponent ic = (InjectComponent) annotation;
String propertyName = AnnotationUtils.getPropertyName(method);
_delegate.injectComponent(op, ic.value(), propertyName);
}
}
1.1 jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/InjectState.java
Index: InjectState.java
===================================================================
// 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.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation used to inject an Application State Object as a read/write property of the component.
*
* @author Howard M. Lewis Ship
* @since 4.0
*/
@Target(
{ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface InjectState {
/**
* The id of the Application State Object to inject.
*/
String value();
}
1.1 jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/InjectAssetAnnotationWorker.java
Index: InjectAssetAnnotationWorker.java
===================================================================
// 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.Annotation;
import java.lang.reflect.Method;
import org.apache.tapestry.enhance.EnhancementOperation;
import org.apache.tapestry.enhance.InjectAssetWorker;
import org.apache.tapestry.spec.IComponentSpecification;
/**
* Injects an asset.
*
* @author Howard M. Lewis Ship
* @since 4.0
* @see org.apache.tapestry.annotations.InjectAsset
* @see org.apache.tapestry.enhance.InjectAssetWorker
*/
public class InjectAssetAnnotationWorker implements MethodAnnotationEnhancementWorker
{
InjectAssetWorker _delegate;
InjectAssetAnnotationWorker(InjectAssetWorker delegate)
{
_delegate = delegate;
}
public InjectAssetAnnotationWorker()
{
this(new InjectAssetWorker());
}
public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
Annotation annotation, Method method)
{
InjectAsset as = (InjectAsset) annotation;
String propertyName = AnnotationUtils.getPropertyName(method);
_delegate.injectAsset(op, as.value(), propertyName);
}
}
1.1 jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/InjectAsset.java
Index: InjectAsset.java
===================================================================
// 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.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation for injecting an asset by its name.
*
* @author Howard M. Lewis Ship
* @since 4.0
*/
@Target(
{ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface InjectAsset {
/**
* The name of the asset to inject. The asset is defined in the page or component specification.
*/
String value();
}
1.1 jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/InjectComponent.java
Index: InjectComponent.java
===================================================================
// 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.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation for injecting a nested component. The component must be defined in the template or
* specification; this is effectively a wrapper around
* {@link org.apache.tapestry.IComponent#getComponent(String)}.
*
* @author Howard M. Lewis Ship
* @since 4.0
*/
@Target(
{ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface InjectComponent {
/**
* The value is the id of the component.
*/
String value();
}
1.2 +6 -0 jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/BaseAnnotationTestCase.java
Index: BaseAnnotationTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/BaseAnnotationTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BaseAnnotationTestCase.java 9 Jun 2005 18:42:48 -0000 1.1
+++ BaseAnnotationTestCase.java 9 Jun 2005 22:53:48 -0000 1.2
@@ -17,6 +17,7 @@
import java.lang.reflect.Method;
import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.enhance.EnhancementOperation;
import org.apache.tapestry.spec.IComponentSpecification;
/**
@@ -43,4 +44,9 @@
return (IComponentSpecification) newMock(IComponentSpecification.class);
}
+ protected EnhancementOperation newOp()
+ {
+ return (EnhancementOperation) newMock(EnhancementOperation.class);
+ }
+
}
1.2 +3 -3 jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/TestInjectObjectAnnotationWorker.java
Index: TestInjectObjectAnnotationWorker.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/TestInjectObjectAnnotationWorker.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestInjectObjectAnnotationWorker.java 9 Jun 2005 18:42:48 -0000 1.1
+++ TestInjectObjectAnnotationWorker.java 9 Jun 2005 22:53:48 -0000 1.2
@@ -38,9 +38,9 @@
assertNotNull(worker._delegate);
}
- public void testSuccess()
+ public void testDelegation()
{
- EnhancementOperation op = (EnhancementOperation) newMock(EnhancementOperation.class);
+ EnhancementOperation op = newOp();
IComponentSpecification spec = newSpec();
InjectObjectWorker delegate = (InjectObjectWorker) newMock(InjectObjectWorker.class);
@@ -64,7 +64,7 @@
Method m = findMethod(Target.class, "getStringValue");
- delegate.injectObject(op, "stringValue", "barney", null);
+ delegate.injectObject(op, "barney", "stringValue", null);
replayControls();
1.2 +16 -0 jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/TestAnnotationUtils.java
Index: TestAnnotationUtils.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/TestAnnotationUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestAnnotationUtils.java 9 Jun 2005 18:42:48 -0000 1.1
+++ TestAnnotationUtils.java 9 Jun 2005 22:53:48 -0000 1.2
@@ -40,6 +40,22 @@
assertEquals("booleanValue", attemptGetPropertyName(Target.class, "isBooleanValue"));
}
+ public void testGetPropertyNameNotAGetter()
+ {
+ try
+ {
+ attemptGetPropertyName(Target.class, "notAGetter");
+ unreachable();
+ }
+ catch (ApplicationRuntimeException ex)
+ {
+ assertEquals(
+ "Annotated method public abstract java.lang.String org.apache.tapestry.annotations.Target.notAGetter() "
+ + "should be an accessor (no parameters), or a mutator (single parameter, returns void).",
+ ex.getMessage());
+ }
+ }
+
public void testGetPropertyNameSetterNoParameters()
{
try
1.2 +7 -1 jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/Target.java
Index: Target.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/Target.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Target.java 9 Jun 2005 18:42:48 -0000 1.1
+++ Target.java 9 Jun 2005 22:53:48 -0000 1.2
@@ -14,6 +14,8 @@
package org.apache.tapestry.annotations;
+import org.apache.tapestry.IComponent;
+
/**
* Used by {@link org.apache.tapestry.annotations.TestAnnotationUtils}.
*
@@ -33,6 +35,10 @@
public abstract String setNonVoidMethod(String value);
public abstract String getHasParameters(String value);
-
+
public abstract void isVoidGetter();
+
+ public abstract String notAGetter();
+
+ public abstract IComponent getBarney();
}
1.1 jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/TestInjectStateAnnotationWorker.java
Index: TestInjectStateAnnotationWorker.java
===================================================================
// 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.enhance.EnhancementOperation;
import org.apache.tapestry.enhance.InjectStateWorker;
import org.apache.tapestry.spec.IComponentSpecification;
import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.annotations.InjectStateAnnotationWorker}.
*
* @author Howard M. Lewis Ship
* @since 4.0
*/
public class TestInjectStateAnnotationWorker extends BaseAnnotationTestCase
{
public void testDefault()
{
InjectStateAnnotationWorker worker = new InjectStateAnnotationWorker();
assertNotNull(worker._delegate);
}
public void testDelegation()
{
EnhancementOperation op = newOp();
IComponentSpecification spec = newSpec();
InjectStateWorker delegate = (InjectStateWorker) newMock(InjectStateWorker.class);
MockControl isc = newControl(InjectState.class);
InjectState is = (InjectState) isc.getMock();
is.value();
isc.setReturnValue("wilma");
delegate.injectState(op, "barney", "wilma");
replayControls();
InjectStateAnnotationWorker worker = new InjectStateAnnotationWorker(delegate);
worker.performEnhancement(op, spec, is, findMethod(Target.class, "getBarney"));
verifyControls();
}
}
1.1 jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/TestPersistAnnotationWorker.java
Index: TestPersistAnnotationWorker.java
===================================================================
// 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.tapestry.enhance.EnhancementOperation;
import org.apache.tapestry.spec.ComponentSpecification;
import org.apache.tapestry.spec.IComponentSpecification;
import org.apache.tapestry.spec.IPropertySpecification;
import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.annotations.PersistAnnotationWorker}.
*
* @author Howard M. Lewis Ship
* @since 4.0
*/
public class TestPersistAnnotationWorker extends TestAnnotationEnhancementWorker
{
public void testInject()
{
EnhancementOperation op = newOp();
IComponentSpecification spec = new ComponentSpecification();
MockControl pc = newControl(Persist.class);
Persist p = (Persist) pc.getMock();
p.value();
pc.setReturnValue("client");
replayControls();
Method m = findMethod(Target.class, "getBarney");
new PersistAnnotationWorker().performEnhancement(op, spec, p, m);
verifyControls();
IPropertySpecification ps = spec.getPropertySpecification("barney");
assertEquals("client", ps.getPersistence());
}
}
1.1 jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/TestInjectAssetAnnotationWorker.java
Index: TestInjectAssetAnnotationWorker.java
===================================================================
// 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.enhance.EnhancementOperation;
import org.apache.tapestry.enhance.InjectAssetWorker;
import org.apache.tapestry.spec.IComponentSpecification;
import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.annotations.InjectAssetAnnotationWorker}.
*
* @author Howard M. Lewis Ship
* @since 4.0
*/
public class TestInjectAssetAnnotationWorker extends BaseAnnotationTestCase
{
public void testDefault()
{
InjectAssetAnnotationWorker worker = new InjectAssetAnnotationWorker();
assertNotNull(worker._delegate);
}
public void testDelegation()
{
EnhancementOperation op = newOp();
IComponentSpecification spec = newSpec();
InjectAssetWorker delegate = (InjectAssetWorker) newMock(InjectAssetWorker.class);
MockControl iac = newControl(InjectAsset.class);
InjectAsset ia = (InjectAsset) iac.getMock();
ia.value();
iac.setReturnValue("wilma");
delegate.injectAsset(op, "wilma", "barney");
replayControls();
InjectAssetAnnotationWorker worker = new InjectAssetAnnotationWorker(delegate);
worker.performEnhancement(op, spec, ia, findMethod(Target.class, "getBarney"));
verifyControls();
}
}
1.1 jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/TestInjectComponentAnnotationWorker.java
Index: TestInjectComponentAnnotationWorker.java
===================================================================
// 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.enhance.EnhancementOperation;
import org.apache.tapestry.enhance.InjectComponentWorker;
import org.apache.tapestry.spec.IComponentSpecification;
import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.annotations.InjectComponentAnnotationWorker}.
*
* @author Howard M. Lewis Ship
* @since 4.0
*/
public class TestInjectComponentAnnotationWorker extends BaseAnnotationTestCase
{
public void testDefault()
{
InjectComponentAnnotationWorker worker = new InjectComponentAnnotationWorker();
assertNotNull(worker._delegate);
}
public void testDelegation()
{
EnhancementOperation op = newOp();
IComponentSpecification spec = newSpec();
InjectComponentWorker delegate = (InjectComponentWorker) newMock(InjectComponentWorker.class);
MockControl icc = newControl(InjectComponent.class);
InjectComponent ic = (InjectComponent) icc.getMock();
ic.value();
icc.setReturnValue("wilma");
delegate.injectComponent(op, "wilma", "barney");
replayControls();
InjectComponentAnnotationWorker worker = new InjectComponentAnnotationWorker(delegate);
worker.performEnhancement(op, spec, ic, findMethod(Target.class, "getBarney"));
verifyControls();
}
}
1.5 +7 -7 jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectObjectWorker.java
Index: InjectObjectWorker.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/enhance/InjectObjectWorker.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- InjectObjectWorker.java 8 Jun 2005 19:58:43 -0000 1.4
+++ InjectObjectWorker.java 9 Jun 2005 22:53:48 -0000 1.5
@@ -40,23 +40,23 @@
String objectReference = is.getObject();
Location location = is.getLocation();
- injectObject(op, name, objectReference, location);
+ injectObject(op, objectReference, name, location);
}
- public void injectObject(EnhancementOperation op, String name, String objectReference,
+ public void injectObject(EnhancementOperation op, String objectReference, String propertyName,
Location location)
{
Defense.notNull(op, "op");
- Defense.notNull(name, "name");
+ Defense.notNull(propertyName, "propertyName");
Defense.notNull(objectReference, "objectReference");
- Class propertyType = op.getPropertyType(name);
+ Class propertyType = op.getPropertyType(propertyName);
if (propertyType == null)
propertyType = Object.class;
- String fieldName = "_$" + name;
+ String fieldName = "_$" + propertyName;
- op.claimProperty(name);
+ op.claimProperty(propertyName);
Object injectedValue = _provider.obtainValue(objectReference, location);
@@ -72,7 +72,7 @@
op.addInjectedField(fieldName, propertyType, injectedValue);
- String methodName = EnhanceUtils.createAccessorMethodName(name);
+ String methodName = EnhanceUtils.createAccessorMethodName(propertyName);
op.addMethod(
Modifier.PUBLIC,
1.2 +104 -19 jakarta-tapestry/annotations/src/documentation/content/xdocs/tapestry-annotations/index.xml
Index: index.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/annotations/src/documentation/content/xdocs/tapestry-annotations/index.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- index.xml 9 Jun 2005 18:42:48 -0000 1.1
+++ index.xml 9 Jun 2005 22:53:48 -0000 1.2
@@ -35,25 +35,59 @@
<p>
The annotations are all in the package org.apache.tapestry.annotations.
</p>
+
+<p>
+ Remember that a property should only have, at most, one of these annotations! Having multiple
+ annotations, or conflicts between annotations and directives in the specification, will result
+ in runtime exceptions. In addition, annotations don't provide the kind of line precise location
+ data that the XML specifications or the templates do (but most exceptions will clearly identify the
+ class and method, which should be sufficient).
+</p>
- <table>
- <tr>
- <th>Annotation</th>
- <th>Specification Equivalent</th>
- </tr>
-
- <tr>
- <td>
- <link href="#ann.InjectObject">InjectObject</link>
- </td>
- <td>
- <link href="&spec;#spec.inject"><inject></link>
- </td>
- </tr>
- </table>
-
+<section>
+ <title>InjectAsset</title>
+
+ <p>
+ The <link href="&javadoc;InjectAsset.html">InjectAsset</link> annotation
+ allows assets defined in the page or component specification to be exposed
+ as read-only properties. It is attached to an accessor method:
+ </p>
+
+<source>
+ @InjectAsset("stylesheet")
+ public abstract IAsset getStylesheet();
+</source>
+
+<p>
+This is equivalent to specifying the property attribute of the
+<link href="&spec;#spec.asset"><asset></link> element.
+</p>
+
+</section>
+
+<section>
+ <title>InjectComponent</title>
+
+ <p>
+ The <link href="&javadoc;/InjectComponent.html">InjectComponent</link> annotation
+ allows nested components to be injected as read-only properties. It is attached
+ to an accessor method:
+ </p>
+
+<source>
+ @InjectComponent("inputUserName")
+ public abstract TextField getUserInput();
+</source>
+
+ <p>
+ This is functionally the same as providing the property attribute of the
+ <link href="&spec;#spec.component"><component></link> element.
+ </p>
+
+</section>
-<section id="ann.InjectObject">
+
+<section>
<title>InjectObject</title>
<p>
@@ -71,7 +105,58 @@
with the default type of "object".
</p>
-</section>
-
+</section>
+
+<section>
+ <title>InjectState</title>
+
+ <p>
+ The <link href="&javadoc;/InjectState.html">InjectState</link> annotation
+ allows an Application State Object to be injected and a read/write property. It
+ is attached to an accessor method:
+ </p>
+
+<source>
+ @InjectState("visit")
+ public abstract MyAppVisit getVisit();
+</source>
+
+ <p>
+ The end result is equivalent to using the <link href="&spec;#spec.inject"><inject></link> element,
+with a type of "state".
+ </p>
+
+</section>
+
+<section>
+ <title>Persist</title>
+
+ <p>
+ The <link href="&javadoc;/Persist.html">Persist</link> annotation allows a property to be
+ marked as persistent. Remember that any otherwise unclaimed abstract property will become
+ a <em>transient</em> property automatically (in Tapestry 4.0), so Persist is only need
+ to mark a property as persistent.
+ </p>
+
+ <p>
+ The value of the Persist annotation defaults to "session":
+ </p>
+
+<source>
+ @Persist
+ public abstract int getSessionPersistentProperty();
+
+ @Persist("client")
+ public abstract double getClientPersistentProperty();
+</source>
+
+<p>
+This annotation works exactly like a <link href="&spec;#spec.property"><property></link>
+element, except that the initial-value attribute can't be specified.
+</p>
+
+</section>
+
+
</body>
</document>
1.2 +7 -1 jakarta-tapestry/annotations/src/descriptor/META-INF/hivemodule.xml
Index: hivemodule.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/annotations/src/descriptor/META-INF/hivemodule.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- hivemodule.xml 9 Jun 2005 18:42:48 -0000 1.1
+++ hivemodule.xml 9 Jun 2005 22:53:48 -0000 1.2
@@ -33,7 +33,9 @@
</service-point>
<contribution configuration-id="tapestry.enhance.EnhancementWorkers">
- <command id="annotation-worker" object="service:AnnotationEnhancementWorker" before="tapestry.enhance.page-detach-listener"/>
+ <!-- Needs to come very much first, because some enhancements modify
+ the component specification, affecting what occurs in later commands. -->
+ <command id="annotation-worker" object="service:AnnotationEnhancementWorker" before="*"/>
</contribution>
<configuration-point id="MethodWorkers">
@@ -65,6 +67,10 @@
<contribution configuration-id="MethodWorkers">
<worker annotation="InjectObject" object="service:InjectObjectAnnotationWorker"/>
+ <worker annotation="InjectComponent" object="instance:InjectComponentAnnotationWorker"/>
+ <worker annotation="InjectState" object="instance:InjectStateAnnotationWorker"/>
+ <worker annotation="InjectAsset" object="instance:InjectAssetAnnotationWorker"/>
+ <worker annotation="Persist" object="instance:PersistAnnotationWorker"/>
</contribution>
1.2 +1 -2 jakarta-tapestry/annotations/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/annotations/build.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- build.xml 9 Jun 2005 18:42:48 -0000 1.1
+++ build.xml 9 Jun 2005 22:53:48 -0000 1.2
@@ -54,8 +54,7 @@
<hivedoc-report/>
<javadoc-report/>
<junit-report/>
- <!-- Clover doesn't seem ready for annotations! -->
- <!-- clover-report/ -->
+ <clover-report/>
</target>
</project>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org