001 //Copyright 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package net.sf.tacos.annotations;
016
017 import java.lang.reflect.Method;
018
019 import org.apache.hivemind.Location;
020 import org.apache.tapestry.annotations.AnnotationUtils;
021 import org.apache.tapestry.annotations.MethodAnnotationEnhancementWorker;
022 import org.apache.tapestry.enhance.EnhancementOperation;
023 import org.apache.tapestry.spec.IComponentSpecification;
024 import org.apache.tapestry.spec.InjectSpecification;
025 import org.apache.tapestry.spec.InjectSpecificationImpl;
026
027 /**
028 *
029 * @author Patrick Moore
030 */
031 public class InjectParameterFlagAnnotationWorker implements MethodAnnotationEnhancementWorker
032 {
033 private static final String BOUND = "Bound";
034
035 public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
036 Method method, Location location)
037 {
038 String propertyName = AnnotationUtils.getPropertyName(method);
039 InjectParameterFlag ipv = method.getAnnotation(InjectParameterFlag.class);
040
041 String watchedParameterName = ipv.value();
042
043 if (watchedParameterName.equals(""))
044 {
045 watchedParameterName = propertyName;
046 if (watchedParameterName.endsWith(BOUND)) // strip it
047 {
048 int length = watchedParameterName.length();
049 watchedParameterName = watchedParameterName.substring(0, length - BOUND.length());
050 }
051 }
052
053 InjectSpecification inject = new InjectSpecificationImpl();
054
055 inject.setType("parameter-flag");
056 inject.setProperty(propertyName);
057 inject.setObject(watchedParameterName);
058 inject.setLocation(location);
059
060 spec.addInjectSpecification(inject);
061 }
062
063 }
064