1 23 package com.sun.enterprise.deployment.annotation.handlers; 24 25 import java.lang.annotation.Annotation ; 26 import java.lang.annotation.ElementType ; 27 import java.lang.reflect.AnnotatedElement ; 28 import java.lang.reflect.Method ; 29 import java.util.HashMap ; 30 import java.util.HashSet ; 31 import java.util.List ; 32 import java.util.Set ; 33 import java.util.logging.Level ; 34 35 import com.sun.enterprise.deployment.EjbBundleDescriptor; 36 import com.sun.enterprise.deployment.EjbDescriptor; 37 import com.sun.enterprise.deployment.MethodDescriptor; 38 39 import com.sun.enterprise.deployment.annotation.AnnotatedElementHandler; 40 import com.sun.enterprise.deployment.annotation.AnnotationInfo; 41 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException; 42 import com.sun.enterprise.deployment.annotation.HandlerProcessingResult; 43 import com.sun.enterprise.deployment.annotation.context.ComponentContext; 44 import com.sun.enterprise.deployment.annotation.context.EjbBundleContext; 45 import com.sun.enterprise.deployment.annotation.context.EjbContext; 46 import com.sun.enterprise.deployment.annotation.context.EjbsContext; 47 import com.sun.enterprise.deployment.annotation.context.EjbInterceptorContext; 48 49 import com.sun.enterprise.util.TypeUtil; 50 51 75 abstract class AbstractAttributeHandler extends AbstractHandler { 76 83 protected abstract HandlerProcessingResult processAnnotation( 84 AnnotationInfo ainfo, EjbContext[] ejbContexts) 85 throws AnnotationProcessorException; 86 87 94 protected HandlerProcessingResult processAnnotation( 95 AnnotationInfo ainfo, EjbInterceptorContext ejbInterceptorContext) 96 throws AnnotationProcessorException { 97 if (!isDelegatee()) { 98 throw new UnsupportedOperationException (); 99 } 100 return getDefaultProcessedResult(); 101 } 102 103 112 public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) 113 throws AnnotationProcessorException { 114 115 AnnotatedElement ae = ainfo.getAnnotatedElement(); 116 Annotation annotation = ainfo.getAnnotation(); 117 118 if (logger.isLoggable(Level.FINER)) { 119 logger.finer("@process annotation " + annotation + " in " + ae); 120 } 121 122 AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler(); 123 124 if (aeHandler instanceof EjbBundleContext) { 125 EjbBundleContext ejbBundleContext = (EjbBundleContext)aeHandler; 126 AnnotatedElementHandler aeh = ejbBundleContext.createContextForEjb(); 127 if (aeh != null) { 128 aeHandler = aeh; 129 } else { 130 if (isDelegatee()) { 131 aeHandler = ejbBundleContext.createContextForEjbInterceptor(); 132 } 133 if (aeHandler == null) { 134 return getInvalidAnnotatedElementHandlerResult(aeHandler, ainfo); 135 } 136 } 137 } 138 139 if (!supportTypeInheritance() && 140 ElementType.TYPE.equals(ainfo.getElementType()) && 141 aeHandler instanceof ComponentContext) { 142 ComponentContext context = (ComponentContext)aeHandler; 143 Class clazz = (Class )ainfo.getAnnotatedElement(); 144 if (!clazz.getName().equals(context.getComponentClassName())) { 145 if (logger.isLoggable(Level.WARNING)) { 146 log(Level.WARNING, ainfo, 147 localStrings.getLocalString( 148 "enterprise.deployment.annotation.handlers.typeinhernotsupp", 149 "The annotation symbol inheritance is not supported.")); 150 } 151 return getDefaultProcessedResult(); 152 } 153 } 154 155 EjbContext[] ejbContexts = null; 156 EjbInterceptorContext ejbInterceptorContext = null; 157 if (aeHandler instanceof EjbContext) { 158 EjbContext ejbContext = (EjbContext)aeHandler; 159 ejbContexts = new EjbContext[] { ejbContext }; 160 } else if (aeHandler instanceof EjbsContext) { 161 ejbContexts = ((EjbsContext)aeHandler).getEjbContexts(); 162 } else if (isDelegatee() && aeHandler instanceof EjbInterceptorContext) { 163 ejbInterceptorContext = (EjbInterceptorContext)aeHandler; 164 } else { 165 return getInvalidAnnotatedElementHandlerResult(aeHandler, ainfo); 166 } 167 168 HandlerProcessingResult procResult = null; 169 170 if (ejbInterceptorContext != null) { 171 procResult = processAnnotation(ainfo, ejbInterceptorContext); 172 } else { 173 procResult = processAnnotation(ainfo, ejbContexts); 174 } 175 176 if (logger.isLoggable(Level.FINER)) { 177 logger.finer("New annotation for " + annotation); 178 } 179 return procResult; 180 } 181 182 186 protected boolean isDelegatee() { 187 return false; 188 } 189 190 194 protected boolean supportTypeInheritance() { 195 return false; 196 } 197 198 203 protected Set <MethodDescriptor> getMethodAllDescriptors( 204 EjbDescriptor ejbDesc) { 205 Set methodAlls = new HashSet (); 206 if (ejbDesc.isRemoteInterfacesSupported() || 207 ejbDesc.isRemoteBusinessInterfacesSupported()) { 208 methodAlls.add( 209 new MethodDescriptor(MethodDescriptor.ALL_METHODS, 210 "", MethodDescriptor.EJB_REMOTE)); 211 if (ejbDesc.isRemoteInterfacesSupported()) { 212 methodAlls.add( 213 new MethodDescriptor(MethodDescriptor.ALL_METHODS, 214 "", MethodDescriptor.EJB_HOME)); 215 } 216 } 217 218 if (ejbDesc.isLocalInterfacesSupported() || 219 ejbDesc.isLocalBusinessInterfacesSupported()) { 220 methodAlls.add( 221 new MethodDescriptor(MethodDescriptor.ALL_METHODS, 222 "", MethodDescriptor.EJB_LOCAL)); 223 if (ejbDesc.isLocalInterfacesSupported()) { 224 methodAlls.add( 225 new MethodDescriptor(MethodDescriptor.ALL_METHODS, 226 "", MethodDescriptor.EJB_LOCALHOME)); 227 } 228 } 229 230 if (ejbDesc.hasWebServiceEndpointInterface()) { 231 methodAlls.add( 232 new MethodDescriptor(MethodDescriptor.ALL_METHODS, 233 "", MethodDescriptor.EJB_WEB_SERVICE)); 234 } 235 236 return methodAlls; 237 } 238 239 protected boolean hasMethodPermissionsFromDD(MethodDescriptor methodDesc, 240 EjbDescriptor ejbDesc) { 241 HashMap methodPermissionsFromDD = ejbDesc.getMethodPermissionsFromDD(); 242 if (methodPermissionsFromDD != null) { 243 Set allMethods = ejbDesc.getMethodDescriptors(); 244 String ejbClassSymbol = methodDesc.getEjbClassSymbol(); 245 for (Object mdObjsObj : methodPermissionsFromDD.values()) { 246 List mdObjs = (List )mdObjsObj; 247 for (Object mdObj : mdObjs) { 248 MethodDescriptor md = (MethodDescriptor)mdObj; 249 for (Object style3MdObj : 250 md.doStyleConversion(ejbDesc, allMethods)) { 251 MethodDescriptor style3Md = (MethodDescriptor)style3MdObj; 252 if (methodDesc.equals(style3Md)) { 253 return true; 254 } 255 } 256 } 257 } 258 } 259 return false; 260 } 261 } 262 | Popular Tags |