1 23 package com.sun.enterprise.deployment.annotation.handlers; 24 25 import java.lang.annotation.Annotation ; 26 import java.lang.reflect.AnnotatedElement ; 27 import java.util.logging.Level ; 28 29 import javax.ejb.MessageDriven ; 30 import javax.ejb.ActivationConfigProperty ; 31 32 import com.sun.enterprise.deployment.EjbBundleDescriptor; 33 import com.sun.enterprise.deployment.EjbDescriptor; 34 import com.sun.enterprise.deployment.EjbMessageBeanDescriptor; 35 import com.sun.enterprise.deployment.EnvironmentProperty; 36 37 import com.sun.enterprise.deployment.annotation.AnnotationInfo; 38 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException; 39 import com.sun.enterprise.deployment.annotation.HandlerProcessingResult; 40 import com.sun.enterprise.deployment.annotation.context.EjbBundleContext; 41 42 47 public class MessageDrivenHandler extends AbstractEjbHandler { 48 49 50 public MessageDrivenHandler() { 51 } 52 53 56 public Class <? extends Annotation > getAnnotationType() { 57 return MessageDriven .class; 58 } 59 60 65 protected String getAnnotatedName(Annotation annotation) { 66 MessageDriven mdAn = (MessageDriven )annotation; 67 return mdAn.name(); 68 } 69 70 76 protected boolean isValidEjbDescriptor(EjbDescriptor ejbDesc, 77 Annotation annotation) { 78 return EjbMessageBeanDescriptor.TYPE.equals(ejbDesc.getType()); 79 } 80 81 87 protected EjbDescriptor createEjbDescriptor(String elementName, 88 AnnotationInfo ainfo) throws AnnotationProcessorException { 89 90 AnnotatedElement ae = ainfo.getAnnotatedElement(); 91 EjbMessageBeanDescriptor newDescriptor = new EjbMessageBeanDescriptor(); 92 Class ejbClass = (Class )ae; 93 newDescriptor.setName(elementName); 94 newDescriptor.setEjbClassName(ejbClass.getName()); 95 return newDescriptor; 96 } 97 98 106 protected HandlerProcessingResult setEjbDescriptorInfo( 107 EjbDescriptor ejbDesc, AnnotationInfo ainfo) 108 throws AnnotationProcessorException { 109 110 MessageDriven mdAn = (MessageDriven )ainfo.getAnnotation(); 111 Class ejbClass = (Class )ainfo.getAnnotatedElement(); 112 EjbMessageBeanDescriptor ejbMsgBeanDesc = 113 (EjbMessageBeanDescriptor)ejbDesc; 114 115 HandlerProcessingResult procResult = 116 setMessageListenerInterface( 117 mdAn, ejbMsgBeanDesc, ejbClass, ainfo); 118 119 doDescriptionProcessing(mdAn.description(), ejbMsgBeanDesc); 120 doMappedNameProcessing(mdAn.mappedName(), ejbMsgBeanDesc); 121 122 for (ActivationConfigProperty acProp : mdAn.activationConfig()) { 123 EnvironmentProperty envProp = new EnvironmentProperty( 124 acProp.propertyName(), acProp.propertyValue(), ""); 125 if (ejbMsgBeanDesc.getActivationConfigValue(envProp.getName()) == null) { 128 ejbMsgBeanDesc.putActivationConfigProperty(envProp); 129 } 130 } 131 132 return procResult; 133 } 134 135 private HandlerProcessingResult setMessageListenerInterface( 136 MessageDriven mdAn, EjbMessageBeanDescriptor msgEjbDesc, 137 Class ejbClass, AnnotationInfo ainfo) 138 throws AnnotationProcessorException { 139 140 String intfName = null; 141 142 146 if( mdAn.messageListenerInterface() != Object .class ) { 147 intfName = mdAn.messageListenerInterface().getName(); 148 } else { 149 for(Class next : ejbClass.getInterfaces()) { 150 if( !excludedFromImplementsClause(next) ) { 151 if( intfName == null ) { 152 intfName = next.getName(); 153 } else { 154 EjbBundleDescriptor currentBundle = 155 ((EjbBundleContext)ainfo.getProcessingContext().getHandler()).getDescriptor(); 156 log(Level.SEVERE, ainfo, 157 localStrings.getLocalString( 158 "enterprise.deployment.annotation.handlers.ambiguousimplementsclausemdb", 159 "Implements clause for 3.x message driven bean class {0} in {1} declares more than one potential message-listener interface. In this case, the @MessageDriven.messageListenerInterface() attribute must be used to specify the message listener interface.", 160 new Object [] { ejbClass, 161 currentBundle.getModuleDescriptor().getArchiveUri() })); 162 return getDefaultFailedResult(); 163 } 164 } 165 } 166 } 167 168 if (intfName == null) { 174 intfName = msgEjbDesc.getMessageListenerType(); 175 } 176 177 msgEjbDesc.setMessageListenerType(intfName); 178 179 return getDefaultProcessedResult(); 180 } 181 } 182 | Popular Tags |