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 java.util.ArrayList;
25: import java.util.Collections;
26: import java.util.Iterator;
27: import java.util.List;
28: import org.jboss.deployment.DeploymentException;
29: import org.jboss.metadata.MetaData;
30: import org.w3c.dom.Element;
31:
32: /**
33: * Imutable class which holds a list of the properties for a dependent value
34: * class.
35: *
36: * @author <a href="mailto:dain@daingroup.com">Dain Sundstrom</a>
37: * @version $Revision: 57209 $
38: */
39: public final class JDBCValueClassMetaData {
40: private final Class javaType;
41: private final List properties;
42:
43: /**
44: * Constructs a value class metadata class with the data contained in
45: * the dependent-value-class xml element from a jbosscmp-jdbc xml file.
46: *
47: * @param classElement the xml Element which contains the metadata about
48: * this value class
49: * @param classLoader the ClassLoader which is used to load this value class
50: * @throws DeploymentException if the xml element is not semantically correct
51: */
52: public JDBCValueClassMetaData(Element classElement,
53: ClassLoader classLoader) throws DeploymentException {
54: String className = MetaData.getUniqueChildContent(classElement,
55: "class");
56: try {
57: javaType = classLoader.loadClass(className);
58: } catch (ClassNotFoundException e) {
59: throw new DeploymentException(
60: "dependent-value-class not found: " + className);
61: }
62:
63: List propertyList = new ArrayList();
64: Iterator iterator = MetaData.getChildrenByTagName(classElement,
65: "property");
66: while (iterator.hasNext()) {
67: Element propertyElement = (Element) iterator.next();
68:
69: propertyList.add(new JDBCValuePropertyMetaData(
70: propertyElement, javaType));
71: }
72: properties = Collections.unmodifiableList(propertyList);
73: }
74:
75: /**
76: * Gets the Java Class of this value class.
77: *
78: * @return the java Class of this value class
79: */
80: public Class getJavaType() {
81: return javaType;
82: }
83:
84: /**
85: * Gets the properties of this value class which are to be saved into the database.
86: *
87: * @return an unmodifiable list which contains the JDBCValuePropertyMetaData objects
88: */
89: public List getProperties() {
90: return properties;
91: }
92: }
|