1 29 30 package com.caucho.transaction.enhancer; 31 32 import com.caucho.bytecode.JAnnotation; 33 import com.caucho.bytecode.JMethod; 34 import com.caucho.config.ConfigException; 35 import com.caucho.java.gen.BaseMethod; 36 import com.caucho.java.gen.CallChain; 37 import com.caucho.java.gen.GenClass; 38 import com.caucho.loader.enhancer.MethodEnhancer; 39 import com.caucho.util.L10N; 40 41 import javax.ejb.TransactionAttributeType ; 42 import java.lang.reflect.Method ; 43 44 47 public class TransactionEnhancer implements MethodEnhancer { 48 private static final L10N L = new L10N(TransactionEnhancer.class); 49 50 private Class _annotationType; 51 52 55 public void setAnnotation(Class type) 56 throws ConfigException 57 { 58 _annotationType = type; 59 60 try { 61 Method method = type.getMethod("value"); 62 63 if (method != null && 64 method.getReturnType().equals(TransactionAttributeType .class)) 65 return; 66 } catch (Throwable e) { 67 } 68 69 throw new ConfigException(L.l("'{0}' is an illegal annotation type for TransactionEnhancer. The annotation must have a value() method returning a TransactionAttributeType.", 70 type.getName())); 71 } 72 73 80 public void enhance(GenClass genClass, 81 JMethod jMethod, 82 JAnnotation jAnn) 83 { 84 TransactionAttributeType type; 85 type = (TransactionAttributeType ) jAnn.get("value"); 86 87 BaseMethod genMethod = genClass.createMethod(jMethod); 88 CallChain call = genMethod.getCall(); 89 90 switch (type) { 91 case MANDATORY: 92 call = new MandatoryCallChain(call); 93 break; 94 case REQUIRED: 95 call = new RequiredCallChain(call); 96 break; 97 case REQUIRES_NEW: 98 call = new RequiresNewCallChain(call); 99 break; 100 case NEVER: 101 call = new NeverCallChain(call); 102 break; 103 case SUPPORTS: 104 call = new SupportsCallChain(call); 105 break; 106 case NOT_SUPPORTED: 107 call = new SuspendCallChain(call); 108 break; 109 default: 110 break; 111 } 112 113 genMethod.setCall(call); 114 } 115 } 116 | Popular Tags |