001: /*
002: * argun 1.0
003: * Web 2.0 delivery framework
004: * Copyright (C) 2007 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.biz
021: * e-Mail: support@hammurapi.biz
022: */
023: package biz.hammurapi.web.mda.db.model;
024:
025: import java.sql.DatabaseMetaData;
026: import java.sql.ResultSet;
027: import java.sql.SQLException;
028: import java.util.ArrayList;
029: import java.util.Collection;
030: import java.util.Iterator;
031: import java.util.Properties;
032:
033: import org.apache.xpath.CachedXPathAPI;
034: import org.w3c.dom.Element;
035:
036: import biz.hammurapi.config.ConfigurationException;
037: import biz.hammurapi.sql.DataAccessObject;
038: import biz.hammurapi.sql.SQLProcessor;
039: import biz.hammurapi.util.CollectionVisitable;
040: import biz.hammurapi.util.Visitable;
041: import biz.hammurapi.util.Visitor;
042: import biz.hammurapi.web.metadata.DbmCatalogImpl;
043: import biz.hammurapi.web.metadata.MetadataEngine;
044: import biz.hammurapi.xml.dom.AbstractDomObject;
045: import biz.hammurapi.xml.dom.CompositeDomSerializer;
046:
047: public class Catalog extends DbmCatalogImpl implements Visitable,
048: DataAccessObject {
049:
050: private Collection schemas = new ArrayList();
051: private Database owner;
052:
053: public Catalog() {
054: super ();
055: }
056:
057: public Catalog(boolean force) {
058: super (force);
059: }
060:
061: public Catalog(Element holder, boolean force)
062: throws ConfigurationException {
063: super (holder, force);
064: }
065:
066: public Catalog(Element holder, Properties nameMap,
067: CachedXPathAPI cxpa, boolean force)
068: throws ConfigurationException {
069: super (holder, nameMap, cxpa, force);
070: }
071:
072: public Catalog(ResultSet rs) throws SQLException {
073: super (rs);
074: }
075:
076: public boolean accept(Visitor visitor) {
077: if (!visitor.visit(this )) {
078: return false;
079: }
080:
081: new CollectionVisitable(schemas, false).accept(visitor);
082: return true;
083: }
084:
085: public void setSQLProcessor(SQLProcessor processor)
086: throws SQLException {
087: MetadataEngine engine = new MetadataEngine(processor);
088: engine.getDbmSchemaByCatalog(getId(), schemas, Schema.class);
089: Iterator it = schemas.iterator();
090: while (it.hasNext()) {
091: ((Schema) it.next()).setOwner(this );
092: }
093: }
094:
095: public Collection getSchemas() {
096: return schemas;
097: }
098:
099: void loadMetaData(DatabaseMetaData metaData) throws SQLException {
100: Iterator it = schemas.iterator();
101: while (it.hasNext()) {
102: ((Schema) it.next()).loadMetaData(metaData);
103: }
104: }
105:
106: public void toDom(Element holder) {
107: super .toDom(holder);
108: CompositeDomSerializer.getThreadInstance().toDomSerializable(
109: schemas).toDom(
110: AbstractDomObject.addElement(holder, "schemas"));
111: }
112:
113: void setOwner(Database owner) {
114: this .owner = owner;
115: }
116:
117: public Database getOwner() {
118: return owner;
119: }
120: }
|