1 17 18 package org.apache.geronimo.connector.deployment.dconfigbean; 19 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 23 import javax.enterprise.deploy.model.DDBean ; 24 import javax.enterprise.deploy.model.DDBeanRoot ; 25 import javax.enterprise.deploy.spi.DConfigBean ; 26 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 27 28 import org.apache.geronimo.deployment.plugin.DConfigBeanRootSupport; 29 import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument; 30 import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType; 31 import org.apache.xmlbeans.SchemaTypeLoader; 32 import org.apache.xmlbeans.XmlBeans; 33 import org.apache.xmlbeans.XmlException; 34 import org.apache.xmlbeans.XmlObject; 35 36 42 public class ResourceAdapterDConfigRoot extends DConfigBeanRootSupport { 43 static final SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans.typeLoaderUnion(new SchemaTypeLoader[] { 44 XmlBeans.typeLoaderForClassLoader(org.apache.geronimo.xbeans.j2ee.String.class.getClassLoader()), 45 XmlBeans.typeLoaderForClassLoader(GerConnectorDocument.class.getClassLoader()) 46 }); 47 48 private static String [][] XPATHS = { 49 {"connector", "resourceadapter"} 50 }; 51 52 private ResourceAdapterDConfigBean resourceAdapterDConfigBean; 53 54 public ResourceAdapterDConfigRoot(DDBeanRoot ddBean) { 55 super(ddBean, loadDefaultData(ddBean)); 56 replaceResourceAdapterDConfigBean(getConnectorDocument().getConnector().getResourceadapterArray()[0]); 57 } 58 59 private static XmlObject loadDefaultData(DDBeanRoot root) { 60 InputStream in = root.getDeployableObject().getEntry("META-INF/geronimo-ra.xml"); 61 if(in == null) { 62 GerConnectorDocument doc = GerConnectorDocument.Factory.newInstance(); 63 doc.addNewConnector().addNewResourceadapter(); 64 return doc; 65 } else { 66 try { 67 XmlObject result = GerConnectorDocument.Factory.parse(in); 68 in.close(); 69 return result; 70 } catch (XmlException e) { 71 throw new RuntimeException ("Unable to load default Geronimo RA data", e); 72 } catch (IOException e) { 73 throw new RuntimeException ("Unable to load default Geronimo RA data", e); 74 } 75 } 76 } 77 78 private void replaceResourceAdapterDConfigBean(GerResourceadapterType resourceAdapter) { 79 DDBean ddBean = getDDBean(); 80 String path = getXpaths()[0]; 81 System.out.println("********** Searching XPath "+path+" -- "+ddBean.getChildBean(path)); 82 DDBean childDDBean = ddBean.getChildBean(path)[0]; 83 resourceAdapterDConfigBean = new ResourceAdapterDConfigBean(childDDBean, resourceAdapter); 84 } 85 86 GerConnectorDocument getConnectorDocument() { 87 return (GerConnectorDocument) getXmlObject(); 88 } 89 90 public String [] getXpaths() { 91 return getXPathsForJ2ee_1_4(XPATHS); 92 } 93 94 public DConfigBean getDConfigBean(DDBean bean) throws ConfigurationException { 95 if (getXpaths()[0].equals(bean.getXpath())) { 96 return resourceAdapterDConfigBean; 97 } 98 return null; 99 } 100 101 public void fromXML(InputStream inputStream) throws XmlException, IOException { 102 super.fromXML(inputStream); 103 replaceResourceAdapterDConfigBean(getConnectorDocument().getConnector().getResourceadapterArray()[0]); 105 } 106 107 protected SchemaTypeLoader getSchemaTypeLoader() { 108 return SCHEMA_TYPE_LOADER; 109 } 110 } 111 | Popular Tags |