1 17 18 package org.apache.geronimo.naming.deployment; 19 20 import java.util.Set ; 21 import java.util.HashSet ; 22 import java.util.Arrays ; 23 import java.util.Map ; 24 25 import javax.xml.namespace.QName ; 26 27 import org.apache.xmlbeans.XmlObject; 28 import org.apache.xmlbeans.QNameSet; 29 import org.apache.geronimo.kernel.repository.Environment; 30 import org.apache.geronimo.kernel.config.Configuration; 31 import org.apache.geronimo.kernel.GBeanNotFoundException; 32 import org.apache.geronimo.kernel.ClassLoading; 33 import org.apache.geronimo.naming.reference.GBeanReference; 34 import org.apache.geronimo.xbeans.geronimo.naming.GerGbeanRefDocument; 35 import org.apache.geronimo.xbeans.geronimo.naming.GerGbeanRefType; 36 import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType; 37 import org.apache.geronimo.common.DeploymentException; 38 import org.apache.geronimo.gbean.AbstractNameQuery; 39 import org.apache.geronimo.gbean.GBeanData; 40 import org.apache.geronimo.gbean.GBeanInfo; 41 import org.apache.geronimo.gbean.GBeanInfoBuilder; 42 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 43 import org.apache.geronimo.j2ee.deployment.Module; 44 import org.apache.geronimo.j2ee.deployment.NamingBuilder; 45 46 49 public class GBeanRefBuilder implements NamingBuilder { 50 private static final QName GBEAN_REF_QNAME = GerGbeanRefDocument.type.getDocumentElementName(); 51 private static final QNameSet GBEAN_REF_QNAME_SET = QNameSet.singleton(GBEAN_REF_QNAME); 52 53 public void buildEnvironment(XmlObject specDD, XmlObject plan, Environment environment) { 54 } 55 56 public void initContext(XmlObject specDD, XmlObject plan, Configuration localConfiguration, Configuration remoteConfiguration, Module module) throws DeploymentException { 57 } 58 59 public void buildNaming(XmlObject specDD, XmlObject plan, Configuration localConfiguration, Configuration remoteConfiguration, Module module, Map componentContext) throws DeploymentException { 60 if (plan == null) { 61 return; 62 } 63 XmlObject[] gbeanRefsUntyped = plan == null? NO_REFS: plan.selectChildren(GBEAN_REF_QNAME_SET); 64 for (int i = 0; i < gbeanRefsUntyped.length; i++) { 65 XmlObject gbeanRefUntyped = gbeanRefsUntyped[i]; 66 GerGbeanRefType gbeanRef = (GerGbeanRefType) gbeanRefUntyped.copy().changeType(GerGbeanRefType.type); 67 if (gbeanRef == null) { 68 throw new DeploymentException("Could not read gbeanRef " + gbeanRefUntyped + " as the correct xml type"); 69 } 70 GerPatternType[] gbeanLocatorArray = gbeanRef.getPatternArray(); 71 72 String [] interfaceTypesArray = gbeanRef.getRefTypeArray(); 73 Set interfaceTypes = new HashSet (Arrays.asList(interfaceTypesArray)); 74 Set queries = new HashSet (); 75 for (int j = 0; j < gbeanLocatorArray.length; j++) { 76 GerPatternType patternType = gbeanLocatorArray[j]; 77 AbstractNameQuery abstractNameQuery = ENCConfigBuilder.buildAbstractNameQuery(patternType, null, null, interfaceTypes); 78 queries.add(abstractNameQuery); 79 } 80 81 GBeanData gBeanData; 82 try { 83 gBeanData = localConfiguration.findGBeanData(queries); 84 } catch (GBeanNotFoundException e) { 85 throw new DeploymentException("Could not resolve reference at deploy time for queries " + queries, e); 86 } 87 88 if (interfaceTypes.isEmpty()) { 89 interfaceTypes.add(gBeanData.getGBeanInfo().getClassName()); 90 } 91 ClassLoader cl = module.getEarContext().getClassLoader(); 92 Class gBeanType; 93 try { 94 gBeanType = ClassLoading.loadClass(gBeanData.getGBeanInfo().getClassName(), cl); 95 } catch (ClassNotFoundException e) { 96 throw new DeploymentException("Cannot load GBean class", e); 97 } 98 99 String refName = gbeanRef.getRefName(); 100 101 ((Map )componentContext.get(JNDI_KEY)).put(ENV + refName, new GBeanReference(localConfiguration.getId(), queries, gBeanType)); 102 103 } 104 } 105 106 public QNameSet getSpecQNameSet() { 107 return QNameSet.EMPTY; 108 } 109 110 public QNameSet getPlanQNameSet() { 111 return GBEAN_REF_QNAME_SET; 112 } 113 114 public static final GBeanInfo GBEAN_INFO; 115 116 static { 117 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(GBeanRefBuilder.class, NameFactory.MODULE_BUILDER); 118 119 GBEAN_INFO = infoBuilder.getBeanInfo(); 120 } 121 122 public static GBeanInfo getGBeanInfo() { 123 return GBEAN_INFO; 124 } 125 126 } 127 | Popular Tags |