1 22 package org.jboss.ejb.plugins.cmp.jdbc.metadata; 23 24 import org.jboss.system.ServiceMBeanSupport; 25 import org.jboss.deployment.DeploymentException; 26 import org.jboss.metadata.XmlFileLoader; 27 import org.jboss.metadata.MetaData; 28 import org.w3c.dom.Element ; 29 30 import java.net.URL ; 31 import java.util.Iterator ; 32 import java.util.Hashtable ; 33 import java.util.Set ; 34 import java.util.Collections ; 35 36 42 public class MetaDataLibrary 43 extends ServiceMBeanSupport 44 implements MetaDataLibraryMBean 45 { 46 private final Hashtable typeMappings = new Hashtable (); 47 48 51 public JDBCTypeMappingMetaData findTypeMappingMetaData(String name) 52 { 53 return (JDBCTypeMappingMetaData)typeMappings.get(name); 54 } 55 56 59 public Set getTypeMappingNames() 60 { 61 return Collections.unmodifiableSet(typeMappings.keySet()); 62 } 63 64 public void startService() throws Exception 65 { 66 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 67 68 URL stdJDBCUrl = classLoader.getResource("standardjbosscmp-jdbc.xml"); 69 if(stdJDBCUrl == null) 70 { 71 throw new DeploymentException("No standardjbosscmp-jdbc.xml found"); 72 } 73 74 boolean debug = log.isDebugEnabled(); 75 if(debug) 76 { 77 log.debug("Loading standardjbosscmp-jdbc.xml : " + stdJDBCUrl.toString()); 78 } 79 Element stdJDBCElement = XmlFileLoader.getDocument(stdJDBCUrl, true).getDocumentElement(); 80 81 Element typeMaps = MetaData.getOptionalChild(stdJDBCElement, "type-mappings"); 82 if(typeMaps != null) 83 { 84 for(Iterator i = MetaData.getChildrenByTagName(typeMaps, "type-mapping"); i.hasNext();) 85 { 86 Element typeMappingElement = (Element )i.next(); 87 JDBCTypeMappingMetaData typeMapping = new JDBCTypeMappingMetaData(typeMappingElement); 88 typeMappings.put(typeMapping.getName(), typeMapping); 89 90 log.debug("added type-mapping: " + typeMapping.getName()); 91 } 92 } 93 } 94 95 public void stopService() throws Exception 96 { 97 typeMappings.clear(); 98 } 99 } 100 | Popular Tags |