001 package net.sf.tacos.seam.annotations; 002 003 import java.lang.reflect.Method; 004 005 import net.sf.tacos.seam.Bijection; 006 007 import org.apache.hivemind.Location; 008 import org.apache.hivemind.service.BodyBuilder; 009 import org.apache.tapestry.annotations.AnnotationUtils; 010 import org.apache.tapestry.annotations.MethodAnnotationEnhancementWorker; 011 import org.apache.tapestry.enhance.EnhanceUtils; 012 import org.apache.tapestry.enhance.EnhancementOperation; 013 import org.apache.tapestry.event.PageDetachListener; 014 import org.apache.tapestry.spec.IComponentSpecification; 015 import org.jboss.seam.ScopeType; 016 import org.jboss.seam.Seam; 017 import org.jboss.seam.annotations.Out; 018 019 /** 020 * Outjects a Seam component 021 * 022 * @author Igor Drobiazko 023 */ 024 public class OutAnnotationWorker implements MethodAnnotationEnhancementWorker { 025 026 public void performEnhancement(EnhancementOperation op, 027 IComponentSpecification spec, Method method, Location location) { 028 outjectSeamComponent(op, method, location); 029 } 030 031 public void outjectSeamComponent(EnhancementOperation op, 032 Method method, Location location) { 033 String property = AnnotationUtils.getPropertyName(method); 034 Out annotation = method.getAnnotation(Out.class); 035 Class<?> propertyType = op.getPropertyType(property); 036 if (propertyType == null) 037 propertyType = Object.class; 038 String name = annotation.value(); 039 if(name.equals("")){ 040 name = property; 041 } 042 ScopeType scope = annotation.scope(); 043 if(scope==ScopeType.UNSPECIFIED){ 044 scope = Seam.getComponentScope(propertyType); 045 } 046 BodyBuilder builder = new BodyBuilder(); 047 builder.add(Bijection.class.getName()+".outject({0},", method.getName()+"()"); 048 builder.addQuoted(name); 049 builder.add(","); 050 builder.addQuoted(scope.toString()); 051 builder.add(","); 052 builder.addQuoted(String.valueOf(annotation.required())); 053 builder.add(");"); 054 op.extendMethodImplementation(PageDetachListener.class, 055 EnhanceUtils.PAGE_DETACHED_SIGNATURE, builder.toString()); 056 } 057 }