View Javadoc

1   //Copyright 2005 The Apache Software Foundation
2   //
3   // Licensed under the Apache License, Version 2.0 (the "License");
4   // you may not use this file except in compliance with the License.
5   // You may obtain a copy of the License at
6   //
7   //     http://www.apache.org/licenses/LICENSE-2.0
8   //
9   // Unless required by applicable law or agreed to in writing, software
10  // distributed under the License is distributed on an "AS IS" BASIS,
11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  // See the License for the specific language governing permissions and
13  // limitations under the License.
14  
15  package net.sf.tacos.annotations;
16  
17  import java.lang.reflect.Method;
18  
19  import org.apache.hivemind.Location;
20  import org.apache.tapestry.annotations.AnnotationUtils;
21  import org.apache.tapestry.annotations.MethodAnnotationEnhancementWorker;
22  import org.apache.tapestry.enhance.EnhancementOperation;
23  import org.apache.tapestry.spec.IComponentSpecification;
24  import org.apache.tapestry.spec.InjectSpecification;
25  import org.apache.tapestry.spec.InjectSpecificationImpl;
26  
27  /**
28   * 
29   * @author Patrick Moore
30   */
31  public class InjectParameterFlagAnnotationWorker implements MethodAnnotationEnhancementWorker
32  {
33      private static final String BOUND = "Bound";
34  
35      public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
36              Method method, Location location)
37      {
38          String propertyName = AnnotationUtils.getPropertyName(method);
39          InjectParameterFlag ipv = method.getAnnotation(InjectParameterFlag.class);
40          
41          String watchedParameterName = ipv.value();
42  
43          if (watchedParameterName.equals(""))
44          {
45              watchedParameterName = propertyName;
46              if (watchedParameterName.endsWith(BOUND)) // strip it
47              {
48                  int length = watchedParameterName.length();
49                  watchedParameterName = watchedParameterName.substring(0, length - BOUND.length());
50              }
51          }
52  
53          InjectSpecification inject = new InjectSpecificationImpl();
54  
55          inject.setType("parameter-flag");
56          inject.setProperty(propertyName);
57          inject.setObject(watchedParameterName);
58          inject.setLocation(location);
59  
60          spec.addInjectSpecification(inject);
61      }
62  
63  }
64