1 17 18 package org.apache.geronimo.naming.deployment; 19 20 import java.util.HashMap ; 21 import java.util.Map ; 22 import javax.enterprise.deploy.model.DDBean ; 23 import javax.enterprise.deploy.spi.DConfigBean ; 24 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException ; 25 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 26 27 import org.apache.geronimo.xbeans.geronimo.naming.GerEjbLocalRefType; 28 import org.apache.geronimo.xbeans.geronimo.naming.GerEjbRefType; 29 import org.apache.geronimo.xbeans.geronimo.naming.GerResourceEnvRefType; 30 import org.apache.geronimo.xbeans.geronimo.naming.GerResourceRefType; 31 import org.apache.xmlbeans.SchemaTypeLoader; 32 import org.apache.xmlbeans.XmlBeans; 33 34 37 public class ENCHelper { 38 static final SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans.typeLoaderUnion(new SchemaTypeLoader[]{ 39 XmlBeans.typeLoaderForClassLoader(org.apache.geronimo.xbeans.j2ee.String.class.getClassLoader()), 40 }); 41 42 43 public static final String [][] ENC_XPATHS = { 44 {"ejb-ref"}, 45 {"ejb-local-ref"}, 46 {"resource-env-ref"}, 47 {"resource-ref"}, 48 }; 49 50 public static final String [][] NAME_XPATHS = { 51 {"ejb-ref-name"}, 52 {"ejb-ref-name"}, 53 {"resource-env-ref-name"}, 54 {"res-ref-name"} 55 }; 56 57 58 private final String [] xpaths; 59 private final String [] namePaths; 60 61 private RemoteRefDConfigBean[] ejbRefs; 62 63 private LocalRefDConfigBean[] ejbLocalRefs; 64 private LocalRefDConfigBean[] resourceEnvRefs; 65 private LocalRefDConfigBean[] resourceRefs; 66 67 public ENCHelper(DDBean ddBean, XmlEnvRefs envRefs, String [] xpaths, String [] namePaths) { 68 this.xpaths = xpaths; 69 this.namePaths = namePaths; 70 DDBean [] ddEjbRefs = ddBean.getChildBean(xpaths[0]); 71 if (ddEjbRefs == null) { 72 ddEjbRefs = new DDBean [0]; 73 } 74 ejbRefs = new RemoteRefDConfigBean[ddEjbRefs.length]; 75 GerEjbRefType[] xmlEjbRefs = envRefs.getEjbRefs(); 76 Map ejbRefMap = new HashMap (); 77 for (int i = 0; i < xmlEjbRefs.length; i++) { 78 GerEjbRefType refAdapter = xmlEjbRefs[i]; 79 ejbRefMap.put(refAdapter.getRefName(), refAdapter); 80 } 82 175 } 176 177 public DConfigBean getDConfigBean(DDBean ddBean) throws ConfigurationException { 178 String xpath = ddBean.getXpath(); 179 if (xpath.equals(xpaths[0])) { 180 String name = ddBean.getText(namePaths[0])[0]; 181 for (int i = 0; i < ejbRefs.length; i++) { 182 RemoteRefDConfigBean ejbRef = ejbRefs[i]; 183 if (ejbRef.getRefName().equals(name)) { 184 return ejbRef; 185 } 186 } 187 throw new ConfigurationException ("no such ejb-ref-name" + name); 188 } else if (xpath.equals(xpaths[1])) { 189 String name = ddBean.getText(namePaths[1])[0]; 190 for (int i = 0; i < ejbLocalRefs.length; i++) { 191 LocalRefDConfigBean ejbLocalRef = ejbLocalRefs[i]; 192 if (ejbLocalRef.getRefName().equals(name)) { 193 return ejbLocalRef; 194 } 195 } 196 throw new ConfigurationException ("no such ejb-ref-name" + name); 197 } else if (xpath.equals(xpaths[2])) { 198 String name = ddBean.getText(namePaths[2])[0]; 199 for (int i = 0; i < resourceEnvRefs.length; i++) { 200 LocalRefDConfigBean resourceEnvRef = resourceEnvRefs[i]; 201 if (resourceEnvRef.getRefName().equals(name)) { 202 return resourceEnvRef; 203 } 204 } 205 throw new ConfigurationException ("no such ejb-ref-name" + name); 206 } else if (xpath.equals(xpaths[3])) { 207 String name = ddBean.getText(namePaths[3])[0]; 208 for (int i = 0; i < resourceRefs.length; i++) { 209 LocalRefDConfigBean resourceRef = resourceRefs[i]; 210 if (resourceRef.getRefName().equals(name)) { 211 return resourceRef; 212 } 213 } 214 throw new ConfigurationException ("no such res-ref-name" + name); 215 } else { 216 throw new ConfigurationException ("Unrecognized XPath: " + ddBean.getXpath()); 217 } 218 } 219 220 public void removeDConfigBean(DConfigBean dcBean) throws BeanNotFoundException { 221 245 } 246 247 248 public static class XmlEnvRefs { 249 private final GerEjbRefType[] ejbRefs; 250 private final GerEjbLocalRefType[] ejbLocalRefs; 251 private final GerResourceRefType[] resourceRefs; 252 private final GerResourceEnvRefType[] resourceEnvRefs; 253 254 public XmlEnvRefs(GerEjbRefType[] ejbRefs, GerEjbLocalRefType[] ejbLocalRefs, GerResourceRefType[] resourceRefs, GerResourceEnvRefType[] resourceEnvRefs) { 255 this.ejbRefs = ejbRefs; 256 this.ejbLocalRefs = ejbLocalRefs; 257 this.resourceRefs = resourceRefs; 258 this.resourceEnvRefs = resourceEnvRefs; 259 } 260 261 public GerEjbRefType[] getEjbRefs() { 262 return ejbRefs; 263 } 264 265 public GerEjbLocalRefType[] getEjbLocalRefs() { 266 return ejbLocalRefs; 267 } 268 269 public GerResourceRefType[] getResourceRefs() { 270 return resourceRefs; 271 } 272 273 public GerResourceEnvRefType[] getResourceEnvRefs() { 274 return resourceEnvRefs; 275 } 276 277 } 278 } 279 | Popular Tags |