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/09 20:42:48 UTC

cvs commit: jakarta-tapestry/annotations/src/descriptor/META-INF hivemodule.xml

hlship      2005/06/09 11:42:48

  Added:       annotations/src/test/org/apache/tapestry/annotations
                        BaseAnnotationTestCase.java
                        TestInjectObjectAnnotationWorker.java
                        AnnotatedPage.java TestAnnotationUtils.java
                        TestAnnotationEnhancementWorker.java Target.java
                        AnnotatedPageSubclass.java
               annotations .cvsignore build.xml
               annotations/src/java/org/apache/tapestry/annotations
                        AnnotationMessages.java
                        MethodAnnotationEnhancementWorker.java
                        InjectObject.java AnnotationStrings.properties
                        AnnotationUtils.java
                        InjectObjectAnnotationWorker.java
                        AnnotationEnhancementWorker.java
               annotations/src/documentation/content/xdocs/tapestry-annotations
                        index.xml
               annotations/src/descriptor/META-INF hivemodule.xml
  Log:
  Add initial JDK 1.5 annotation support.
  
  Revision  Changes    Path
  1.1                  jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/BaseAnnotationTestCase.java
  
  Index: BaseAnnotationTestCase.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.hivemind.test.HiveMindTestCase;
  import org.apache.tapestry.spec.IComponentSpecification;
  
  /**
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  
  public abstract class BaseAnnotationTestCase extends HiveMindTestCase
  {
  
      protected Method findMethod(Class clazz, String name)
      {
          for (Method m : clazz.getMethods())
          {
              if (m.getName().equals(name))
                  return m;
          }
  
          throw new IllegalArgumentException("No method " + name + " in " + clazz);
      }
  
      protected IComponentSpecification newSpec()
      {
          return (IComponentSpecification) newMock(IComponentSpecification.class);
      }
  
  }
  
  
  
  1.1                  jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/TestInjectObjectAnnotationWorker.java
  
  Index: TestInjectObjectAnnotationWorker.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.enhance.InjectObjectWorker;
  import org.apache.tapestry.services.InjectedValueProvider;
  import org.apache.tapestry.spec.IComponentSpecification;
  import org.easymock.MockControl;
  
  /**
   * Tests for {@link org.apache.tapestry.annotations.InjectObjectAnnotationWorker}.
   * 
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  
  public class TestInjectObjectAnnotationWorker extends BaseAnnotationTestCase
  {
      public void testDefault()
      {
          InjectObjectAnnotationWorker worker = new InjectObjectAnnotationWorker();
  
          assertNotNull(worker._delegate);
      }
  
      public void testSuccess()
      {
          EnhancementOperation op = (EnhancementOperation) newMock(EnhancementOperation.class);
          IComponentSpecification spec = newSpec();
  
          InjectObjectWorker delegate = (InjectObjectWorker) newMock(InjectObjectWorker.class);
  
          InjectedValueProvider provider = (InjectedValueProvider) newMock(InjectedValueProvider.class);
  
          delegate.setProvider(provider);
  
          replayControls();
  
          InjectObjectAnnotationWorker worker = new InjectObjectAnnotationWorker(delegate);
          worker.setProvider(provider);
  
          verifyControls();
  
          MockControl ioc = newControl(InjectObject.class);
          InjectObject io = (InjectObject) ioc.getMock();
  
          io.value();
          ioc.setReturnValue("barney");
  
          Method m = findMethod(Target.class, "getStringValue");
  
          delegate.injectObject(op, "stringValue", "barney", null);
  
          replayControls();
  
          worker.performEnhancement(op, spec, io, m);
  
          verifyControls();
      }
  
  }
  
  
  
  1.1                  jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java
  
  Index: AnnotatedPage.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.html.BasePage;
  
  /**
   * Used by {@link org.apache.tapestry.annotations.TestAnnotationEnhancementWorker}.
   * 
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  public abstract class AnnotatedPage extends BasePage
  {
      @InjectObject("barney")
      public abstract Object getInjectedObject();
  }
  
  
  
  1.1                  jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/TestAnnotationUtils.java
  
  Index: TestAnnotationUtils.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.hivemind.ApplicationRuntimeException;
  
  /**
   * Tests for {@link org.apache.tapestry.annotations.AnnotationUtils}.
   * 
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  public class TestAnnotationUtils extends BaseAnnotationTestCase
  {
      private String attemptGetPropertyName(Class clazz, String name)
      {
          Method m = findMethod(clazz, name);
  
          return AnnotationUtils.getPropertyName(m);
      }
  
      public void testGetPropertyName()
      {
          assertEquals("stringValue", attemptGetPropertyName(Target.class, "getStringValue"));
          assertEquals("intValue", attemptGetPropertyName(Target.class, "setIntValue"));
          assertEquals("booleanValue", attemptGetPropertyName(Target.class, "isBooleanValue"));
      }
  
      public void testGetPropertyNameSetterNoParameters()
      {
          try
          {
              attemptGetPropertyName(Target.class, "setNoParameters");
              unreachable();
          }
          catch (ApplicationRuntimeException ex)
          {
              assertEquals(
                      "Annotated method public abstract void org.apache.tapestry.annotations.Target.setNoParameters() is named like a mutator method,"
                              + " but takes an incorrect number of parameters (it should have exactly one parameter).",
                      ex.getMessage());
          }
      }
  
      public void testNonVoidSetter()
      {
          try
          {
              attemptGetPropertyName(Target.class, "setNonVoidMethod");
              unreachable();
          }
          catch (ApplicationRuntimeException ex)
          {
              assertEquals(
                      "Annotated method public abstract java.lang.String org.apache.tapestry.annotations.Target.setNonVoidMethod(java.lang.String) "
                              + "is named like a mutator method, but does not return void.",
                      ex.getMessage());
          }
      }
  
      public void testGetterWithParameters()
      {
          try
          {
              attemptGetPropertyName(Target.class, "getHasParameters");
              unreachable();
          }
          catch (ApplicationRuntimeException ex)
          {
              assertEquals(
                      "Annotated method public abstract java.lang.String org.apache.tapestry.annotations.Target.getHasParameters(java.lang.String) "
                              + "is expected to be an accessor, and should have no parameters.",
                      ex.getMessage());
          }
      }
  
      public void testGetterReturnsVoid()
      {
          try
          {
              attemptGetPropertyName(Target.class, "isVoidGetter");
              unreachable();
          }
          catch (ApplicationRuntimeException ex)
          {
              assertEquals(
                      "Annotated method public abstract void org.apache.tapestry.annotations.Target.isVoidGetter() "
                              + "is named like an accessor method, but returns void.",
                      ex.getMessage());
          }
      }
  
  }
  
  
  
  1.1                  jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/TestAnnotationEnhancementWorker.java
  
  Index: TestAnnotationEnhancementWorker.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 java.util.Collections;
  import java.util.Map;
  
  import org.apache.hivemind.ErrorLog;
  import org.apache.tapestry.enhance.EnhancementOperation;
  import org.apache.tapestry.spec.IComponentSpecification;
  import org.easymock.MockControl;
  
  /**
   * Tests for {@link org.apache.tapestry.annotations.AnnotationEnhancementWorker}.
   * 
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  
  public class TestAnnotationEnhancementWorker extends BaseAnnotationTestCase
  {
      protected EnhancementOperation newOp(Class baseClass)
      {
          MockControl control = newControl(EnhancementOperation.class);
          EnhancementOperation op = (EnhancementOperation) control.getMock();
  
          op.getBaseClass();
          control.setReturnValue(baseClass);
  
          return op;
      }
  
      protected Map newMap(Class annotationClass, MethodAnnotationEnhancementWorker worker)
      {
          return Collections.singletonMap(annotationClass, worker);
      }
  
      /**
       * No method annotations registered.
       */
      public void testNoAnnotations()
      {
          EnhancementOperation op = newOp(AnnotatedPage.class);
          IComponentSpecification spec = newSpec();
  
          replayControls();
  
          AnnotationEnhancementWorker worker = new AnnotationEnhancementWorker();
          worker.setMethodWorkers(Collections.EMPTY_MAP);
  
          worker.performEnhancement(op, spec);
  
          verifyControls();
      }
  
      public void testAnnotationMatch()
      {
          EnhancementOperation op = newOp(AnnotatedPage.class);
          IComponentSpecification spec = newSpec();
  
          MethodAnnotationEnhancementWorker methodWorker = (MethodAnnotationEnhancementWorker) newMock(MethodAnnotationEnhancementWorker.class);
  
          Method m = findMethod(AnnotatedPage.class, "getInjectedObject");
          Annotation a = m.getAnnotations()[0];
  
          methodWorker.performEnhancement(op, spec, a, m);
  
          replayControls();
  
          AnnotationEnhancementWorker worker = new AnnotationEnhancementWorker();
          worker.setMethodWorkers(newMap(InjectObject.class, methodWorker));
  
          worker.performEnhancement(op, spec);
  
          verifyControls();
      }
  
      public void testAnnotationWithSubclass()
      {
          EnhancementOperation op = newOp(AnnotatedPageSubclass.class);
          IComponentSpecification spec = newSpec();
  
          MethodAnnotationEnhancementWorker methodWorker = (MethodAnnotationEnhancementWorker) newMock(MethodAnnotationEnhancementWorker.class);
  
          Method m = findMethod(AnnotatedPageSubclass.class, "getInjectedObject");
          Annotation a = m.getAnnotations()[0];
  
          methodWorker.performEnhancement(op, spec, a, m);
  
          replayControls();
  
          AnnotationEnhancementWorker worker = new AnnotationEnhancementWorker();
          worker.setMethodWorkers(newMap(InjectObject.class, methodWorker));
  
          worker.performEnhancement(op, spec);
  
          verifyControls();
      }
  
      public void testAnnotationFailure()
      {
          ErrorLog log = (ErrorLog) newMock(ErrorLog.class);
          Throwable t = new RuntimeException("Woops!");
  
          EnhancementOperation op = newOp(AnnotatedPage.class);
          IComponentSpecification spec = newSpec();
  
          MockControl methodWorkerc = newControl(MethodAnnotationEnhancementWorker.class);
          MethodAnnotationEnhancementWorker methodWorker = (MethodAnnotationEnhancementWorker) methodWorkerc
                  .getMock();
  
          Method m = findMethod(AnnotatedPage.class, "getInjectedObject");
          Annotation a = m.getAnnotations()[0];
  
          methodWorker.performEnhancement(op, spec, a, m);
          methodWorkerc.setThrowable(t);
  
          log
                  .error(
                          "An error occured processing annotation "
                                  + "@org.apache.tapestry.annotations.InjectObject(value=barney) of "
                                  + "public abstract java.lang.Object org.apache.tapestry.annotations.AnnotatedPage.getInjectedObject(): Woops!",
                          null,
                          t);
  
          replayControls();
  
          AnnotationEnhancementWorker worker = new AnnotationEnhancementWorker();
          worker.setMethodWorkers(newMap(InjectObject.class, methodWorker));
          worker.setErrorLog(log);
  
          worker.performEnhancement(op, spec);
  
          verifyControls();
      }
  }
  
  
  
  1.1                  jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/Target.java
  
  Index: Target.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;
  
  /**
   * Used by {@link org.apache.tapestry.annotations.TestAnnotationUtils}.
   * 
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  public abstract class Target
  {
      public abstract String getStringValue();
  
      public abstract void setIntValue(int value);
  
      public abstract boolean isBooleanValue();
  
      public abstract void setNoParameters();
  
      public abstract String setNonVoidMethod(String value);
  
      public abstract String getHasParameters(String value);
      
      public abstract void isVoidGetter();
  }
  
  
  
  1.1                  jakarta-tapestry/annotations/src/test/org/apache/tapestry/annotations/AnnotatedPageSubclass.java
  
  Index: AnnotatedPageSubclass.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;
  
  /**
   * Subclass of {@link org.apache.tapestry.annotations.AnnotatedPage}, used to ensure that
   * annotations inhereted from base classes are honored.
   * 
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  public abstract class AnnotatedPageSubclass extends AnnotatedPage
  {
  
  }
  
  
  
  1.1                  jakarta-tapestry/annotations/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  target
  
  
  
  1.1                  jakarta-tapestry/annotations/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
     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.
  -->
  
  <project name="Tapestry Annotations" default="jar">
    
    <property name="module.name" value="tapestry-annotations"/>
    <property name="module.javac.target" value="1.5"/>
    <property name="module.javac.source" value="1.5"/>
  	
    <property name="javadoc.package" value="org.apache.tapestry.annotations.*"/>
      
    <property name="root.dir" value=".."/>
  	<property file="${root.dir}/config/build.properties"/>
  	<property file="${root.dir}/config/common.properties"/>
    
  	<import file="${hivebuild.dir}/jar-module.xml"/>
  	<import file="${hivebuild.dir}/javadoc-report.xml"/>
  	<import file="${hivebuild.dir}/clover-report.xml"/>  
  	<import file="${hivebuild.dir}/hivedoc-report.xml"/>    
  	<import file="${hivebuild.dir}/junit-report.xml"/>    
  	
  	<target name="compile-dependencies">
      <project-dependency artifact="tapestry"/>
  
      <ibiblio-dependency artifact="commons-logging"    version="${logging.version}"  group="commons-logging"/>
      <ibiblio-dependency artifact="hivemind"           version="${hivemind.version}" group="hivemind"/>
      <ibiblio-dependency artifact="hivemind-lib"       version="${hivemind.version}" group="hivemind"/>
      <ibiblio-dependency artifact="commons-codec"      version="${codec.version}"    group="commons-codec"/>
      <ibiblio-dependency artifact="ognl"               version="${ognl.version}"     group="ognl"/>
      <ibiblio-dependency artifact="oro"                version="${oro.version}"      group="oro"/>
      
      <ibiblio-dependency artifact="easymock"           version="1.1"                 group="easymock" use="test"/>
      <ibiblio-dependency artifact="easymockclassextension" version="1.1"             group="easymock" use="test"/>
      <ibiblio-dependency artifact="cglib-full"         version="2.0.1"               group="cglib"    use="test"/>
      <ibiblio-dependency artifact="log4j"              version="${log4j.version}"    group="log4j"    use="test"/>
  		
  	</target>	
    
    <target name="run-reports">
      <hivedoc-report/>    	
      <javadoc-report/>
    	<junit-report/>
    	<!-- Clover doesn't seem ready for annotations! -->
  	<!-- clover-report/ -->  	  
    </target> 
      
  </project>
  
  
  
  1.1                  jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/AnnotationMessages.java
  
  Index: AnnotationMessages.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.hivemind.impl.MessageFormatter;
  
  /**
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  
  class AnnotationMessages
  {
      private static final MessageFormatter _formatter = new MessageFormatter(
              AnnotationMessages.class, "AnnotationStrings");
  
      public static String noParametersExpected(Method m)
      {
          return _formatter.format("no-parameters-expected", m);
      }
  
      public static String notAccessor(Method method)
      {
          return _formatter.format("no-accessor", method);
      }
  
      public static String voidAccessor(Method method)
      {
          return _formatter.format("void-accessor", method);
      }
  
      public static String nonVoidMutator(Method method)
      {
          return _formatter.format("non-void-mutator", method);
      }
  
      public static String wrongParameterCount(Method method)
      {
          return _formatter.format("wrong-parameter-count", method);
      }
  
      public static String failureProcessingAnnotation(Annotation annotation, Method method,
              Throwable cause)
      {
          return _formatter.format("failure-processing-annotation", annotation, method, cause);
      }
  }
  
  
  
  1.1                  jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/MethodAnnotationEnhancementWorker.java
  
  Index: MethodAnnotationEnhancementWorker.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;
  
  /**
   * Defines workers that perform annotation enhancements at the class level.
   * 
   * @author Howard Lewis Ship
   * @since 4.0
   */
  public interface MethodAnnotationEnhancementWorker
  {
      /**
       * Performs a particular enhancement based on a registered annotation. Exception reporting is
       * the responsibility of the caller.
       * 
       * @param op
       *            the enhancement operaration
       * @param spec
       *            the specification of the component for which a class is being enhanced
       * @param annotation
       *            the annotation that will guide the enhancement
       * @param method
       *            the method to which the annotation is attached
       */
  
      public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
              Annotation annotation, Method method);
  }
  
  
  
  1.1                  jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/InjectObject.java
  
  Index: InjectObject.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;
  
  /**
   * Method level annotation used to inject an object, equivalent to te &lt;inject&gt; element in a
   * specification.
   * 
   * @author Howard Lewis Ship
   * @since 4.0
   */
  
  @Target(
  { ElementType.METHOD })
  @Retention(RetentionPolicy.RUNTIME)
  public @interface InjectObject {
  
      /**
       * The object to inject, as a HiveMind object reference.
       */
  
      String value();
  }
  
  
  
  1.1                  jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/AnnotationStrings.properties
  
  Index: AnnotationStrings.properties
  ===================================================================
  # 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.
  
  no-parameters-expected=Annotated method {0} is expected to be an accessor, and should have no parameters.
  no-accessor=Annotated method {0} should be an accessor (no parameters), or a mutator (single parameter, returns void).
  void-accessor=Annotated method {0} is named like an accessor method, but returns void.
  non-void-mutator=Annotated method {0} is named like a mutator method, but does not return void.
  wrong-parameter-count=Annotated method {0} is named like a mutator method, but takes an incorrect number of parameters (it should have exactly one parameter).
  failure-processing-annotation=An error occured processing annotation {0} of {1}: {2}
  
  
  1.1                  jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/AnnotationUtils.java
  
  Index: AnnotationUtils.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.beans.Introspector;
  import java.lang.reflect.Method;
  
  import org.apache.hivemind.ApplicationRuntimeException;
  
  /**
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  
  public class AnnotationUtils
  {
      public static String getPropertyName(Method method)
      {
          String name = method.getName();
  
          if (name.startsWith("is"))
          {
              checkGetter(method);
              return Introspector.decapitalize(name.substring(2));
          }
  
          if (name.startsWith("get"))
          {
              checkGetter(method);
              return Introspector.decapitalize(name.substring(3));
          }
  
          if (name.startsWith("set"))
          {
              checkSetter(method);
              return Introspector.decapitalize(name.substring(3));
          }
  
          throw new ApplicationRuntimeException(AnnotationMessages.notAccessor(method));
      }
  
      private static void checkGetter(Method method)
      {
          if (method.getParameterTypes().length > 0)
              throw new ApplicationRuntimeException(AnnotationMessages.noParametersExpected(method));
  
          if (method.getReturnType().equals(void.class))
              throw new ApplicationRuntimeException(AnnotationMessages.voidAccessor(method));
  
      }
  
      private static void checkSetter(Method method)
      {
          if (!method.getReturnType().equals(void.class))
              throw new ApplicationRuntimeException(AnnotationMessages.nonVoidMutator(method));
  
          if (method.getParameterTypes().length != 1)
              throw new ApplicationRuntimeException(AnnotationMessages.wrongParameterCount(method));
      }
  }
  
  
  
  1.1                  jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/InjectObjectAnnotationWorker.java
  
  Index: InjectObjectAnnotationWorker.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.InjectObjectWorker;
  import org.apache.tapestry.services.InjectedValueProvider;
  import org.apache.tapestry.spec.IComponentSpecification;
  
  /**
   * Performs injection of objects, in much the same way as the &lt;inject&gt; element in a
   * specification.
   * 
   * @author Howard M. Lewis Ship
   * @since 4.0
   * @see org.apache.tapestry.enhance.InjectObjectWorker
   */
  
  public class InjectObjectAnnotationWorker implements MethodAnnotationEnhancementWorker
  {
      final InjectObjectWorker _delegate;
  
      public InjectObjectAnnotationWorker()
      {
          this(new InjectObjectWorker());
      }
  
      InjectObjectAnnotationWorker(InjectObjectWorker delegate)
      {
          _delegate = delegate;
      }
  
      public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
              Annotation annotation, Method method)
      {
          InjectObject io = (InjectObject) annotation;
  
          String object = io.value();
  
          String name = AnnotationUtils.getPropertyName(method);
  
          _delegate.injectObject(op, name, object, null);
      }
  
      public void setProvider(InjectedValueProvider provider)
      {
          _delegate.setProvider(provider);
      }
  }
  
  
  
  1.1                  jakarta-tapestry/annotations/src/java/org/apache/tapestry/annotations/AnnotationEnhancementWorker.java
  
  Index: AnnotationEnhancementWorker.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 java.util.Map;
  
  import org.apache.hivemind.ErrorLog;
  import org.apache.tapestry.enhance.EnhancementOperation;
  import org.apache.tapestry.enhance.EnhancementWorker;
  import org.apache.tapestry.spec.IComponentSpecification;
  
  /**
   * Implementation of {@link org.apache.tapestry.enhance.EnhancementWorker} that finds annotations on
   * methods and delegates out to specific
   * {@link org.apache.tapestry.annotations.MethodAnnotationEnhancementWorker}s.
   * 
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  public class AnnotationEnhancementWorker implements EnhancementWorker
  {
      private ErrorLog _errorLog;
  
      private Map _methodWorkers;
  
      public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
      {
          Class clazz = op.getBaseClass();
  
          for (Method m : clazz.getMethods())
          {
              performEnhancement(op, spec, m);
          }
      }
  
      void performEnhancement(EnhancementOperation op, IComponentSpecification spec, Method method)
      {
          for (Annotation a : method.getAnnotations())
          {
              performEnhancement(op, spec, method, a);
          }
      }
  
      void performEnhancement(EnhancementOperation op, IComponentSpecification spec, Method method,
              Annotation annotation)
      {
          MethodAnnotationEnhancementWorker worker = (MethodAnnotationEnhancementWorker) _methodWorkers
                  .get(annotation.annotationType());
  
          if (worker != null)
          {
              try
              {
                  worker.performEnhancement(op, spec, annotation, method);
              }
              catch (Exception ex)
              {
                  _errorLog.error(AnnotationMessages.failureProcessingAnnotation(
                          annotation,
                          method,
                          ex), null, ex);
              }
          }
      }
  
      public void setMethodWorkers(Map methodWorkers)
      {
          _methodWorkers = methodWorkers;
      }
  
      public void setErrorLog(ErrorLog errorLog)
      {
          _errorLog = errorLog;
      }
  }
  
  
  
  1.1                  jakarta-tapestry/annotations/src/documentation/content/xdocs/tapestry-annotations/index.xml
  
  Index: index.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
     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.
  -->
  
  <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.2//EN" "./dtd/document-v12.dtd" [
    
  <!ENTITY spec '../UsersGuide/spec.html'>
  <!ENTITY javadoc 'apidocs/org/apache/tapestry/annotations'>  
    
   ]>
  <document>
  
    <header>
      <title>Tapestry Annotations</title>
  	</header>
  	
    <body>
      <p> This library does not contain components; instead it provides <em>annotations</em>, 
        a <link href="http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html">new feature 
          in JDK 1.5</link>. Annotations allow you to perform some operations inside Java code that otherwise would be specified in the page or component specification. This is very useful when using inheritance, because base classes can provide annotations that are inherited by subclasses. </p>
          
          <p>
            The annotations are all in the package org.apache.tapestry.annotations.
          </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">&lt;inject&gt;</link>
        </td>
      </tr>
    </table>        
          
          
  <section id="ann.InjectObject">
    <title>InjectObject</title>
    
    <p>
    The <link href="&javadoc;/InjectObject.html">InjectObject</link> annotation
    allows HiveMind objects to be injected. It is attached to an accessor method:
    </p>
    
  <source>
    @InjectObject("infrastructure:request")
    public abstract WebRequest getRequest();
  </source>  
      
  <p>
  The end result is the same as using the <link href="&spec;#spec.inject">&lt;inject&gt;</link> element,
  with the default type of "object".
  </p>    
      
  </section>      
          
    </body>
  </document>
  
  
  
  1.1                  jakarta-tapestry/annotations/src/descriptor/META-INF/hivemodule.xml
  
  Index: hivemodule.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
     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.
  -->
  
  <module id="tapestry.annotation" version="4.0.0" package="org.apache.tapestry.annotations">
    
    JDK 1.5 annotation support for Tapestry, allowing classes (including base classes) to provide details normally
    specified in the XML component or page specification.
    
    <service-point id="AnnotationEnhancementWorker" interface="org.apache.tapestry.enhance.EnhancementWorker">
      
      Bridge from ordinary specification-based enhancements, to annotation-driven enhancements.
      
      <invoke-factory>
        <construct class="AnnotationEnhancementWorker">
          <set-configuration property="methodWorkers" configuration-id="MethodWorkers"/>
        </construct>
      </invoke-factory>
      
    </service-point>
    
    <contribution configuration-id="tapestry.enhance.EnhancementWorkers">    
      <command id="annotation-worker" object="service:AnnotationEnhancementWorker" before="tapestry.enhance.page-detach-listener"/>
    </contribution>
    
    <configuration-point id="MethodWorkers">
      
      Maps from a specific Annotation class, to a particular MethodAnnotationEnhancementWorker (typically,
      a service).
      <schema>
        <element name="worker" key-attribute="annotation">
          
          <attribute name="annotation" translator="class">
            The name of an Annotation class which triggers the enhancement worker's behavior.
          </attribute>
          
          <attribute name="object" translator="object">
            
            An object that implements the MethodAnnotationEnhancementWorker interface.
          </attribute>
          
          <rules>
            <push-attribute attribute="object"/>
            <invoke-parent method="addElement"/>
          </rules>
          
        </element>
      </schema>
      
    </configuration-point>
    
    <contribution configuration-id="MethodWorkers">
      
      <worker annotation="InjectObject" object="service:InjectObjectAnnotationWorker"/>
      
    </contribution>
    
    <service-point id="InjectObjectAnnotationWorker" interface="MethodAnnotationEnhancementWorker">
      
      Injects HiveMind objects, based on the InjectObject annotation.
      
      <invoke-factory>
        <construct class="InjectObjectAnnotationWorker">
          <set-service property="provider" service-id="tapestry.InjectedValueProvider"/>
        </construct>
      </invoke-factory>
      
    </service-point>
    
  </module>
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org