KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > cmp > jdbc > metadata > MetaDataLibrary


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * 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 JavaDoc;
29
30 import java.net.URL JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Hashtable JavaDoc;
33 import java.util.Set JavaDoc;
34 import java.util.Collections JavaDoc;
35
36 /**
37  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
38  * @version <tt>$Revision: 37459 $</tt>
39  * @jmx:mbean name="jboss.jdbc:service=metadata"
40  * extends="org.jboss.system.ServiceMBean"
41  */

42 public class MetaDataLibrary
43    extends ServiceMBeanSupport
44    implements MetaDataLibraryMBean
45 {
46    private final Hashtable JavaDoc typeMappings = new Hashtable JavaDoc();
47
48    /**
49     * @jmx.managed-operation
50     */

51    public JDBCTypeMappingMetaData findTypeMappingMetaData(String JavaDoc name)
52    {
53       return (JDBCTypeMappingMetaData)typeMappings.get(name);
54    }
55
56    /**
57     * @jmx.managed-attribute
58     */

59    public Set JavaDoc getTypeMappingNames()
60    {
61       return Collections.unmodifiableSet(typeMappings.keySet());
62    }
63
64    public void startService() throws Exception JavaDoc
65    {
66       ClassLoader JavaDoc classLoader = Thread.currentThread().getContextClassLoader();
67
68       URL JavaDoc 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 JavaDoc stdJDBCElement = XmlFileLoader.getDocument(stdJDBCUrl, true).getDocumentElement();
80
81       Element JavaDoc typeMaps = MetaData.getOptionalChild(stdJDBCElement, "type-mappings");
82       if(typeMaps != null)
83       {
84          for(Iterator JavaDoc i = MetaData.getChildrenByTagName(typeMaps, "type-mapping"); i.hasNext();)
85          {
86             Element JavaDoc typeMappingElement = (Element JavaDoc)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 JavaDoc
96    {
97       typeMappings.clear();
98    }
99 }
100
Popular Tags