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 30 import java.util.Set ; 31 32 import javax.ejb.TransactionAttribute ; 33 import javax.ejb.TransactionAttributeType ; 34 import javax.ejb.Timeout ; 35 import javax.ejb.TransactionManagement ; 36 import javax.ejb.MessageDriven ; 37 import javax.ejb.Stateful ; 38 import javax.ejb.Stateless ; 39 40 import com.sun.enterprise.util.TypeUtil; 41 import com.sun.enterprise.deployment.ContainerTransaction; 42 import com.sun.enterprise.deployment.EjbDescriptor; 43 import com.sun.enterprise.deployment.MethodDescriptor; 44 45 import com.sun.enterprise.deployment.annotation.AnnotationInfo; 46 import com.sun.enterprise.deployment.annotation.AnnotatedElementHandler; 47 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException; 48 import com.sun.enterprise.deployment.annotation.HandlerProcessingResult; 49 import com.sun.enterprise.deployment.annotation.context.EjbContext; 50 51 56 public class TransactionAttributeHandler extends AbstractAttributeHandler 57 implements PostProcessor { 58 59 public TransactionAttributeHandler() { 60 } 61 62 65 public Class <? extends Annotation > getAnnotationType() { 66 return TransactionAttribute .class; 67 } 68 69 protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, 70 EjbContext[] ejbContexts) throws AnnotationProcessorException { 71 72 TransactionAttribute taAn = 73 (TransactionAttribute ) ainfo.getAnnotation(); 74 75 for (EjbContext ejbContext : ejbContexts) { 76 EjbDescriptor ejbDesc = ejbContext.getDescriptor(); 77 ContainerTransaction containerTransaction = 78 getContainerTransaction(taAn.value()); 79 80 if (ElementType.TYPE.equals(ainfo.getElementType())) { 81 ejbContext.addPostProcessInfo(ainfo, this); 82 } else { 83 Method annMethod = (Method ) ainfo.getAnnotatedElement(); 84 85 Set txBusMethods = ejbDesc.getTxBusinessMethodDescriptors(); 86 for (Object next : txBusMethods) { 87 MethodDescriptor nextDesc = (MethodDescriptor) next; 88 Method m = nextDesc.getMethod(ejbDesc); 89 if( TypeUtil.sameMethodSignature(m, annMethod) && 90 ejbDesc.getContainerTransactionFor(nextDesc) == null ) { 91 ejbDesc.setContainerTransactionFor 93 (nextDesc, containerTransaction); 94 } 95 } 96 } 97 } 98 99 return getDefaultProcessedResult(); 100 } 101 102 private ContainerTransaction getContainerTransaction( 103 TransactionAttributeType taType) { 104 switch(taType) { 105 case MANDATORY: 106 return new ContainerTransaction( 107 ContainerTransaction.MANDATORY, 108 ContainerTransaction.MANDATORY); 109 case REQUIRED: 110 return new ContainerTransaction( 111 ContainerTransaction.REQUIRED, 112 ContainerTransaction.REQUIRED); 113 case REQUIRES_NEW: 114 return new ContainerTransaction( 115 ContainerTransaction.REQUIRES_NEW, 116 ContainerTransaction.REQUIRES_NEW); 117 case SUPPORTS: 118 return new ContainerTransaction( 119 ContainerTransaction.SUPPORTS, 120 ContainerTransaction.SUPPORTS); 121 case NOT_SUPPORTED: 122 return new ContainerTransaction( 123 ContainerTransaction.NOT_SUPPORTED, 124 ContainerTransaction.NOT_SUPPORTED); 125 default: return new ContainerTransaction( 127 ContainerTransaction.NEVER, 128 ContainerTransaction.NEVER); 129 } 130 } 131 132 137 public Class <? extends Annotation >[] getTypeDependencies() { 138 return new Class [] { 139 MessageDriven .class, Stateful .class, Stateless .class, 140 Timeout .class, TransactionManagement .class}; 141 142 } 143 144 protected boolean supportTypeInheritance() { 145 return true; 146 } 147 148 public void postProcessAnnotation(AnnotationInfo ainfo, 149 AnnotatedElementHandler aeHandler) 150 throws AnnotationProcessorException { 151 EjbContext ejbContext = (EjbContext)aeHandler; 152 EjbDescriptor ejbDesc = ejbContext.getDescriptor(); 153 TransactionAttribute taAn = 154 (TransactionAttribute ) ainfo.getAnnotation(); 155 ContainerTransaction containerTransaction = 156 getContainerTransaction(taAn.value()); 157 Class classAn = (Class )ainfo.getAnnotatedElement(); 158 159 Set txBusMethods = ejbDesc.getTxBusinessMethodDescriptors(); 160 for (Object mdObj : txBusMethods) { 161 MethodDescriptor md = (MethodDescriptor)mdObj; 162 if (classAn.equals(ejbContext.getDeclaringClass(md)) && 164 ejbDesc.getContainerTransactionFor(md) == null) { 165 ejbDesc.setContainerTransactionFor( 166 md, containerTransaction); 167 } 168 } 169 } 170 } 171 | Popular Tags |