1 22 package org.jboss.ejb.plugins.cmp.jdbc.metadata; 23 24 import java.net.URL ; 25 import org.jboss.deployment.DeploymentException; 26 import org.jboss.logging.Logger; 27 import org.jboss.metadata.XmlFileLoader; 28 import org.jboss.ejb.Container; 29 import org.jboss.virtual.VirtualFile; 30 import org.w3c.dom.Element ; 31 32 40 public final class JDBCXmlFileLoader { 41 private final Container container; 42 private final Logger log; 43 44 51 public JDBCXmlFileLoader(Container con, Logger log) 52 { 53 this.container = con; 54 this.log = log; 55 } 56 57 62 public JDBCApplicationMetaData load() throws DeploymentException { 63 JDBCApplicationMetaData jamd = new JDBCApplicationMetaData( 64 container.getBeanMetaData().getApplicationMetaData(), container.getClassLoader() 65 ); 66 67 URL stdJDBCUrl = container.getClassLoader().getResource("standardjbosscmp-jdbc.xml"); 70 if(stdJDBCUrl == null) { 71 throw new DeploymentException("No standardjbosscmp-jdbc.xml found"); 72 } 73 74 boolean debug = log.isDebugEnabled(); 75 if (debug) 76 log.debug("Loading standardjbosscmp-jdbc.xml : " + stdJDBCUrl.toString()); 77 Element stdJDBCElement = XmlFileLoader.getDocument(stdJDBCUrl, true).getDocumentElement(); 78 79 jamd = new JDBCApplicationMetaData(stdJDBCElement, jamd); 81 82 URL jdbcUrl = null; 84 VirtualFile dd = container.getDeploymentUnit().getMetaDataFile("jbosscmp-jdbc.xml"); 85 if(dd != null) 86 { 87 try 88 { 89 jdbcUrl = dd.toURL(); 90 } 91 catch(Exception e) 92 { 93 throw new IllegalStateException ("Failed to create URL for " + dd.getPathName(), e); 94 } 95 } 96 97 if(jdbcUrl != null) 98 { 99 if (debug) 100 log.debug(jdbcUrl.toString() + " found. Overriding defaults"); 101 Element jdbcElement = XmlFileLoader.getDocument(jdbcUrl, true).getDocumentElement(); 102 jamd = new JDBCApplicationMetaData(jdbcElement, jamd); 103 } 104 105 return jamd; 106 } 107 } 108 | Popular Tags |