001: /*
002: LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
003:
004:
005: Copyright (C) 2003 Together
006:
007: This library is free software; you can redistribute it and/or
008: modify it under the terms of the GNU Lesser General Public
009: License as published by the Free Software Foundation; either
010: version 2.1 of the License, or (at your option) any later version.
011:
012: This library is distributed in the hope that it will be useful,
013: but WITHOUT ANY WARRANTY; without even the implied warranty of
014: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: Lesser General Public License for more details.
016:
017: You should have received a copy of the GNU Lesser General Public
018: License along with this library; if not, write to the Free Software
019: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021:
022: package org.webdocwf.util.loader.generator;
023:
024: import javax.xml.parsers.DocumentBuilder;
025: import javax.xml.parsers.DocumentBuilderFactory;
026: import javax.xml.parsers.ParserConfigurationException;
027:
028: import org.w3c.dom.Document;
029: import org.w3c.dom.Element;
030:
031: import org.webdocwf.util.loader.LoaderException;
032: import org.webdocwf.util.loader.logging.Logger;
033: import org.webdocwf.util.loader.logging.StandardLogger;
034:
035: /**
036: * CreateIncludeDomlFiles class creates Xml(ImportDefinition.xml) and Sql( CreateTables.sql,
037: * CreateIntegrity.sql, CreateOisAdminData.sql, CreatePrimary.sql and CreateIndex.sql) files,
038: * if the input data is doml file.
039: * @author Radoslav Dutina
040: * @version 1.0
041: */
042: public class CreateIncludeDomlFiles {
043:
044: private Document document;
045: private Logger logger;
046: private InputParameters generatorParameters;
047:
048: /**
049: * Construct object CreateIncludeDomlFiles with associated parameter.
050: * @param generatorParameters represents the references to InputParameter object.
051: * @throws LoaderException
052: */
053: public CreateIncludeDomlFiles(InputParameters generatorParameters)
054: throws LoaderException {
055:
056: DocumentBuilderFactory factory = DocumentBuilderFactory
057: .newInstance();
058: try {
059: setLogger();
060: this .logger.write("normal",
061: "CreateIncludeDomlFiles is started.");
062: createIncludeDomlFiles(generatorParameters, factory);
063: this .logger.write("normal",
064: "CreateIncludeDomlFiles is finished.");
065:
066: } catch (Exception e) {
067: String msg = "Exception in class CreateIncludeDomlFiles.";
068: LoaderException le = new LoaderException(msg
069: + e.getMessage(), (Throwable) e);
070: throw le;
071: }
072:
073: }
074:
075: /**
076: * This method will generate doml file
077: * @param generatorParameters
078: * @param factory
079: * @throws ParserConfigurationException
080: * @throws LoaderException
081: */
082: private void createIncludeDomlFiles(
083: InputParameters generatorParameters,
084: DocumentBuilderFactory factory)
085: throws ParserConfigurationException, LoaderException {
086:
087: this .logger.write("normal",
088: "\tcreateIncludeDomlFiles method is started.");
089: DocumentBuilder builder = factory.newDocumentBuilder();
090: document = builder.newDocument(); // Create from whole cloth
091: Element root = (Element) document
092: .createElement("definitionInclude");
093: document.appendChild(root);
094: DomlDesignReader domlDesignReader = new DomlDesignReader(
095: document, root, generatorParameters);
096: WriteXmlFile writeXmlFile;
097: if (generatorParameters.getGenerateXml().equalsIgnoreCase(
098: "true"))
099: writeXmlFile = new WriteXmlFile(document,
100: generatorParameters);
101: this .logger.write("normal",
102: "\tcreateIncludeDomlFiles method is finished.");
103: }
104:
105: /**
106: * This method will set logger object
107: * @param logger
108: */
109: private void setLogger() {
110: this.logger = StandardLogger.getCentralLogger();
111: }
112:
113: }
|