KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > setup > impl > dl > dbloader > DbStatementMetaData


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.setup.impl.dl.dbloader;
10
11 import org.w3c.dom.Element JavaDoc;
12 import org.w3c.dom.NodeList JavaDoc;
13 import org.jboss.portal.common.util.XML;
14 import org.jboss.portal.setup.PortalSetupException;
15 import org.jboss.portal.setup.impl.dl.dbloader.ColumnMetaData;
16 import org.jboss.portal.setup.impl.dl.StatementMetaData;
17 import org.jboss.portal.setup.impl.dl.StatementType;
18
19 import java.util.List JavaDoc;
20 import java.util.ArrayList JavaDoc;
21
22 /**
23  * @author <a HREF="mailto:palber@novell.com">Polina Alber</a>
24  * Date: Apr 14, 2005; Time: 3:32:38 PM
25  * @since JBoss portal 2.0
26  * Class org.jboss.portal.setup.impl.dl.dbloader.DbStatementMetaData
27  */

28 public abstract class DbStatementMetaData extends StatementMetaData
29 {
30    private StatementType m_type = null;
31    private String JavaDoc m_tableName = null;
32    private List JavaDoc m_columns = new ArrayList JavaDoc();
33    private List JavaDoc m_values = new ArrayList JavaDoc();
34
35
36    protected DbStatementMetaData(Element JavaDoc config) throws PortalSetupException
37    {
38       super(config);
39       buildMetaData(config);
40    }
41
42
43    /**
44     * @return type of a statement (INSERT, UPDATE, ALTER, and etc;
45     */

46    public StatementType getType()
47    {
48       return m_type;
49    }
50
51    /**
52     * @return a database table name this table corresponds to
53     */

54    public String JavaDoc getTableName()
55    {
56       return m_tableName;
57    }
58
59    /**
60     * @return a List of column meta data
61     */

62    public List JavaDoc getColumns()
63    {
64       return m_columns;
65    }
66
67    /**
68     * @return a List of Statement row values meta data objects
69     */

70    public List JavaDoc getValues()
71    {
72       return m_values;
73    }
74
75    /**
76     * @param config an XML element;
77     * Builds statement metadata by parsing xml estatement element
78     */

79    protected void buildMetaData(Element JavaDoc config) throws PortalSetupException
80    {
81       String JavaDoc strType = XML.asString(XML.getUniqueChild(config, "type", true));
82       m_type = StatementType.parseString(strType);
83       m_tableName = XML.asString(XML.getUniqueChild(config, "table-name", true));
84       Element JavaDoc columns = XML.getUniqueChild(config, "columns", true);
85       List JavaDoc columnsDef = XML.getChildren(columns, "column");
86
87       for (int i = 0; i < columnsDef.size(); i++)
88       {
89          Element JavaDoc column = (Element JavaDoc)columnsDef.get(i);
90
91          m_columns.add(buildColumnMetaData(column));
92       }
93
94       Element JavaDoc values = XML.getUniqueChild(config, "values", true);
95       List JavaDoc rows = XML.getChildren(values, "row");
96       for (int j = 0; j < rows.size(); j++)
97       {
98          Element JavaDoc row = (Element JavaDoc)rows.get(j);
99          m_values.add(buildValueRowMetaData(row));
100       }
101
102    }
103
104    /**
105     * @param column an XML element describing column referenced by a statement
106     * @return
107     */

108    protected abstract ColumnMetaData buildColumnMetaData(Element JavaDoc column);
109
110    protected abstract ValueRowMetaData buildValueRowMetaData(Element JavaDoc row) throws PortalSetupException;
111 }
112
Popular Tags