1 29 30 package com.caucho.loader.enhancer; 31 32 import java.util.logging.Logger; 33 import java.util.logging.Level; 34 35 import org.aopalliance.intercept.MethodInterceptor; 36 37 import com.caucho.aop.AopMethodEnhancer; 38 39 import com.caucho.bytecode.JAnnotation; 40 import com.caucho.bytecode.JMethod; 41 42 import com.caucho.config.ConfigException; 43 44 import com.caucho.java.gen.GenClass; 45 import com.caucho.java.gen.BaseMethod; 46 47 import com.caucho.util.L10N; 48 49 52 public class MethodEnhancerConfig implements MethodEnhancer { 53 private static final L10N L = new L10N(MethodEnhancerConfig.class); 54 55 private static final Logger log = 56 Logger.getLogger(MethodEnhancerConfig.class.getName()); 57 58 private EnhancerManager _manager; 59 60 private Class _annotation; 61 private Class _type; 62 private boolean _isStatic = true; 63 64 private MethodEnhancer _enhancer; 65 66 69 public void setEnhancerManager(EnhancerManager manager) 70 { 71 _manager = manager; 72 } 73 74 77 public void setAnnotation(Class ann) 78 { 79 _annotation = ann; 80 } 81 82 85 public Class getAnnotation() 86 { 87 return _annotation; 88 } 89 90 93 public void setType(Class type) 94 throws Exception 95 { 96 _type = type; 97 98 if (MethodEnhancer.class.isAssignableFrom(type)) { 99 _enhancer = (MethodEnhancer) type.newInstance(); 100 } 101 else if (MethodInterceptor.class.isAssignableFrom(type)) { 102 AopMethodEnhancer aopEnhancer = new AopMethodEnhancer(); 103 aopEnhancer.setType(type); 104 105 _enhancer = aopEnhancer; 106 } 107 else 108 throw new ConfigException(L.l("'{0}' is an unsupported interceptor type. MethodInterceptor is required.", 109 type.getName())); 110 } 111 112 115 public void setStatic(boolean isStatic) 116 { 117 _isStatic = isStatic; 118 } 119 120 123 public void init() 124 throws ConfigException 125 { 126 _enhancer.setAnnotation(_annotation); 127 128 if (_enhancer instanceof AopMethodEnhancer) 129 ((AopMethodEnhancer) _enhancer).setStatic(_isStatic); 130 } 131 132 139 public void enhance(GenClass genClass, 140 JMethod jMethod, 141 JAnnotation jAnn) 142 { 143 _enhancer.enhance(genClass, jMethod, jAnn); 144 } 145 } 146 | Popular Tags |