1 15 package org.apache.tapestry.annotations; 16 17 import java.lang.reflect.Method ; 18 19 import org.apache.hivemind.ApplicationRuntimeException; 20 import org.apache.hivemind.Location; 21 import org.apache.tapestry.enhance.EnhancementOperation; 22 import org.apache.tapestry.spec.BindingSpecification; 23 import org.apache.tapestry.spec.BindingType; 24 import org.apache.tapestry.spec.ContainedComponent; 25 import org.apache.tapestry.spec.IBindingSpecification; 26 import org.apache.tapestry.spec.IComponentSpecification; 27 import org.apache.tapestry.spec.IContainedComponent; 28 29 38 public class ComponentAnnotationWorker implements MethodAnnotationEnhancementWorker 39 { 40 41 public void performEnhancement(EnhancementOperation op, IComponentSpecification spec, 42 Method method, Location location) 43 { 44 Component component = method.getAnnotation(Component.class); 45 46 String propertyName = AnnotationUtils.getPropertyName(method); 47 48 IContainedComponent cc = new ContainedComponent(); 49 50 cc.setInheritInformalParameters(component.inheritInformalParameters()); 51 cc.setType(component.type()); 52 cc.setPropertyName(propertyName); 53 cc.setLocation(location); 54 55 for (String binding : component.bindings()) 56 { 57 addBinding(cc, binding, location); 58 } 59 60 String id = component.id(); 61 62 if (id.equals("")) 63 id = propertyName; 64 65 spec.addComponent(id, cc); 66 } 67 68 void addBinding(IContainedComponent component, String binding, Location location) 69 { 70 int equalsx = binding.indexOf('='); 71 72 if (equalsx < 1) 73 invalidBinding(binding); 74 75 if (equalsx + 1 >= binding.length()) 76 invalidBinding(binding); 77 78 String name = binding.substring(0, equalsx).trim(); 79 String value = binding.substring(equalsx + 1).trim(); 80 81 IBindingSpecification bs = new BindingSpecification(); 82 bs.setType(BindingType.PREFIXED); 83 bs.setValue(value); 84 bs.setLocation(location); 85 86 component.setBinding(name, bs); 87 } 88 89 private void invalidBinding(String binding) 90 { 91 throw new ApplicationRuntimeException(AnnotationMessages.bindingWrongFormat(binding)); 92 } 93 } | Popular Tags |