1 23 24 29 30 package com.sun.enterprise.deployment.annotation.context; 31 32 import java.lang.annotation.ElementType ; 33 import java.lang.reflect.AnnotatedElement ; 34 import java.lang.reflect.Method ; 35 import java.util.ArrayList ; 36 import java.util.List ; 37 38 import com.sun.enterprise.deployment.EjbDescriptor; 39 import com.sun.enterprise.deployment.MethodDescriptor; 40 import com.sun.enterprise.deployment.WebServiceEndpoint; 41 import com.sun.enterprise.deployment.ServiceReferenceDescriptor; 42 import com.sun.enterprise.deployment.annotation.AnnotatedElementHandler; 43 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException; 44 import com.sun.enterprise.deployment.annotation.AnnotationInfo; 45 import com.sun.enterprise.deployment.annotation.ProcessingContext; 46 import com.sun.enterprise.deployment.annotation.handlers.PostProcessor; 47 import com.sun.enterprise.deployment.annotation.impl.ComponentDefinition; 48 import com.sun.enterprise.deployment.types.ServiceReferenceContainer; 49 import com.sun.enterprise.deployment.types.HandlerChainContainer; 50 import com.sun.enterprise.util.TypeUtil; 51 52 56 public class EjbContext extends ResourceContainerContextImpl { 57 private WebServiceEndpoint endpoint; 58 private Method [] methods; 59 private boolean inherited; 60 private ArrayList <PostProcessInfo> postProcessInfos = 61 new ArrayList <PostProcessInfo>(); 62 63 public EjbContext(EjbDescriptor currentEjb, Class ejbClass) { 64 super(currentEjb); 65 componentClassName = currentEjb.getEjbClassName(); 66 ComponentDefinition cdef = new ComponentDefinition(ejbClass); 67 methods = cdef.getMethods(); 68 Class superClass = ejbClass.getSuperclass(); 69 inherited = (superClass != null && !Object .class.equals(superClass)); 70 } 71 72 public EjbDescriptor getDescriptor() { 73 return (EjbDescriptor)descriptor; 74 } 75 76 public void setDescriptor(EjbDescriptor currentEjb) { 77 descriptor = currentEjb; 78 } 79 80 public void setEndpoint(WebServiceEndpoint endpoint) { 81 this.endpoint = endpoint; 82 } 83 84 public WebServiceEndpoint getEndpoint() { 85 return endpoint; 86 } 87 88 public void endElement(ElementType type, AnnotatedElement element) 89 throws AnnotationProcessorException { 90 91 if (ElementType.TYPE.equals(type)) { 92 for (PostProcessInfo ppInfo : postProcessInfos) { 93 ppInfo.postProcessor.postProcessAnnotation( 94 ppInfo.ainfo, this); 95 } 96 97 getProcessingContext().popHandler(); 99 } 100 } 101 102 public Class getDeclaringClass(MethodDescriptor md) { 103 Method method = md.getMethod(getDescriptor()); 104 Class declaringClass = null; 105 for (Method m : methods) { 106 if (TypeUtil.sameMethodSignature(m, method)) { 107 declaringClass = m.getDeclaringClass(); 108 } 109 } 110 return declaringClass; 111 } 112 113 public boolean isInherited() { 114 return inherited; 115 } 116 117 public void addPostProcessInfo(AnnotationInfo ainfo, PostProcessor postProcessor) { 118 PostProcessInfo ppInfo = new PostProcessInfo(); 119 ppInfo.ainfo = ainfo; 120 ppInfo.postProcessor = postProcessor; 121 postProcessInfos.add(ppInfo); 122 } 123 124 private class PostProcessInfo { 125 public AnnotationInfo ainfo; 126 public PostProcessor postProcessor; 127 } 128 129 public ServiceReferenceContainer[] getServiceRefContainers(String implName) { 130 return getDescriptor().getEjbBundleDescriptor().getEjbByClassName(implName); 131 } 132 133 public HandlerChainContainer[] 134 getHandlerChainContainers(boolean serviceSideHandlerChain, Class declaringClass) { 135 if(serviceSideHandlerChain) { 136 EjbDescriptor[] ejbs = getDescriptor().getEjbBundleDescriptor().getEjbByClassName(declaringClass.getName()); 137 List <WebServiceEndpoint> result = new ArrayList <WebServiceEndpoint>(); 138 for (EjbDescriptor ejb : ejbs) { 139 result.addAll(getDescriptor().getEjbBundleDescriptor().getWebServices().getEndpointsImplementedBy(ejb)); 140 } 141 return(result.toArray(new HandlerChainContainer[0])); 142 } else { 143 List <ServiceReferenceDescriptor> result = new ArrayList <ServiceReferenceDescriptor>(); 144 result.addAll(getDescriptor().getEjbBundleDescriptor().getServiceReferenceDescriptors()); 145 return(result.toArray(new HandlerChainContainer[0])); 146 } 147 } 148 } 149 | Popular Tags |