1 25 package org.objectweb.easybeans.deployment.resolver; 26 27 import java.util.HashMap ; 28 import java.util.Map ; 29 30 import org.objectweb.easybeans.container.JContainer3; 31 import org.objectweb.easybeans.deployment.Deployment; 32 import org.objectweb.easybeans.deployment.annotations.analyzer.AnnotationDeploymentAnalyzer; 33 import org.objectweb.easybeans.deployment.annotations.impl.JCommonBean; 34 import org.objectweb.easybeans.deployment.annotations.impl.JLocal; 35 import org.objectweb.easybeans.deployment.annotations.impl.JRemote; 36 import org.objectweb.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata; 37 import org.objectweb.easybeans.deployment.annotations.metadata.EjbJarAnnotationMetadata; 38 import org.objectweb.easybeans.log.JLog; 39 import org.objectweb.easybeans.log.JLogFactory; 40 41 45 public class JNDIResolver { 46 47 50 private JLog logger = JLogFactory.getLog(JNDIResolver.class); 51 52 55 public static final String NAME = "jndi.resolver"; 56 57 60 private Map <String , String > interfaces = null; 61 62 65 private Map <String , Map <String , String >> beans = null; 66 67 70 public JNDIResolver() { 71 interfaces = new HashMap <String , String >(); 72 beans = new HashMap <String , Map <String , String >>(); 73 } 74 75 79 public JNDIResolver(final Deployment deployment) { 80 this(); 81 addDeployment(deployment); 82 } 83 84 88 public void addDeployment(final Deployment deployment) { 89 AnnotationDeploymentAnalyzer analyzer = deployment.getAnnotationDeploymentAnalyzer(); 91 92 EjbJarAnnotationMetadata ejbJarAnnotationMetadata = analyzer.getEjbJarAnnotationMetadata(); 94 addEjbJarAnnotationMetadata(ejbJarAnnotationMetadata); 95 } 96 97 101 public void addEjbJarAnnotationMetadata(final EjbJarAnnotationMetadata ejbJarAnnotationMetadata) { 102 for (ClassAnnotationMetadata classAnnotationMetadata : ejbJarAnnotationMetadata 104 .getClassAnnotationMetadataCollection()) { 105 if (classAnnotationMetadata.isBean()) { 106 107 JCommonBean jCommonBean = classAnnotationMetadata.getJCommonBean(); 109 String mappedName = null; 110 String beanName = null; 111 if (jCommonBean != null) { 112 mappedName = jCommonBean.getMappedName(); 114 beanName = jCommonBean.getName(); 116 117 } 118 119 JLocal localItfs = classAnnotationMetadata.getLocalInterfaces(); 121 JRemote remoteItfs = classAnnotationMetadata.getRemoteInterfaces(); 122 if (localItfs != null) { 123 for (String itf : localItfs.getInterfaces()) { 124 addInterface(itf, classAnnotationMetadata.getClassName(), "Local", mappedName, beanName); 125 } 126 } 127 if (remoteItfs != null) { 128 for (String itf : remoteItfs.getInterfaces()) { 129 addInterface(itf, classAnnotationMetadata.getClassName(), "Remote", mappedName, beanName); 130 } 131 } 132 } 133 } 134 } 135 136 145 private void addInterface(final String itf, final String beanClassName, final String mode, final String mappedName, 146 final String beanName) { 147 String jndiName = JContainer3.jndiNameEncode(beanClassName, itf, mode); 148 if (mappedName != null) { 149 jndiName = mappedName; 150 } 151 String itfName = itf.replace("/", "."); 152 interfaces.put(itfName, jndiName); 153 154 if (beanName != null && !beanName.equals("")) { 155 Map <String , String > tmpBeanMap = beans.get(beanName); 156 if (tmpBeanMap == null) { 157 tmpBeanMap = new HashMap <String , String >(); 158 beans.put(beanName, tmpBeanMap); 159 } 160 tmpBeanMap.put(itfName, jndiName); 161 beans.put(beanName, tmpBeanMap); 162 logger.debug("Adding jndi name {0} for beanName {1} with itf {2} and className {3}", jndiName, beanName, 163 itfName, beanClassName); 164 } else { 165 logger.debug("Adding jndi name {0} with itf {1} and className {2}", jndiName, itfName, beanClassName); 166 } 167 } 168 169 175 public String getJndiNameInterface(final String itf, final String beanName) { 176 if (beanName != null && !beanName.equals("")) { 177 Map <String , String > lst = beans.get(beanName); 178 if (lst != null) { 179 return lst.get(itf); 180 } 181 throw new IllegalStateException ("No bean with name '" + beanName + "' was found."); 182 183 } 184 return interfaces.get(itf); 185 } 186 187 190 @Override 191 public String toString() { 192 StringBuilder sb = new StringBuilder ("JNDIResolver["); 193 sb.append("Interfaces =["); 194 sb.append(interfaces); 195 sb.append("], Beans ="); 196 sb.append(beans); 197 sb.append("]]"); 198 199 return sb.toString(); 200 } 201 } 202 | Popular Tags |