01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
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: /**
37: * @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
38: * @version <tt>$Revision: 57209 $</tt>
39: * @jmx:mbean name="jboss.jdbc:service=metadata"
40: * extends="org.jboss.system.ServiceMBean"
41: */
42: public class MetaDataLibrary extends ServiceMBeanSupport implements
43: MetaDataLibraryMBean {
44: private final Hashtable typeMappings = new Hashtable();
45:
46: /**
47: * @jmx.managed-operation
48: */
49: public JDBCTypeMappingMetaData findTypeMappingMetaData(String name) {
50: return (JDBCTypeMappingMetaData) typeMappings.get(name);
51: }
52:
53: /**
54: * @jmx.managed-attribute
55: */
56: public Set getTypeMappingNames() {
57: return Collections.unmodifiableSet(typeMappings.keySet());
58: }
59:
60: public void startService() throws Exception {
61: ClassLoader classLoader = Thread.currentThread()
62: .getContextClassLoader();
63:
64: URL stdJDBCUrl = classLoader
65: .getResource("standardjbosscmp-jdbc.xml");
66: if (stdJDBCUrl == null) {
67: throw new DeploymentException(
68: "No standardjbosscmp-jdbc.xml found");
69: }
70:
71: boolean debug = log.isDebugEnabled();
72: if (debug) {
73: log.debug("Loading standardjbosscmp-jdbc.xml : "
74: + stdJDBCUrl.toString());
75: }
76: Element stdJDBCElement = XmlFileLoader.getDocument(stdJDBCUrl,
77: true).getDocumentElement();
78:
79: Element typeMaps = MetaData.getOptionalChild(stdJDBCElement,
80: "type-mappings");
81: if (typeMaps != null) {
82: for (Iterator i = MetaData.getChildrenByTagName(typeMaps,
83: "type-mapping"); i.hasNext();) {
84: Element typeMappingElement = (Element) i.next();
85: JDBCTypeMappingMetaData typeMapping = new JDBCTypeMappingMetaData(
86: typeMappingElement);
87: typeMappings.put(typeMapping.getName(), typeMapping);
88:
89: log.debug("added type-mapping: "
90: + typeMapping.getName());
91: }
92: }
93: }
94:
95: public void stopService() throws Exception {
96: typeMappings.clear();
97: }
98: }
|