You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2010/02/16 18:16:02 UTC

svn commit: r910600 [4/29] - in /db/torque/torque4/trunk: maven-torque-gf-plugin/ maven-torque-gf-plugin/src/ maven-torque-gf-plugin/src/main/ maven-torque-gf-plugin/src/main/java/ maven-torque-gf-plugin/src/main/java/org/ maven-torque-gf-plugin/src/ma...

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/ControlConfigurationXmlParser.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/ControlConfigurationXmlParser.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/ControlConfigurationXmlParser.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/ControlConfigurationXmlParser.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,153 @@
+package org.apache.torque.gf.configuration.controller;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.gf.configuration.ConfigurationException;
+import org.apache.torque.gf.configuration.ConfigurationHandlers;
+import org.apache.torque.gf.configuration.ConfigurationProvider;
+import org.apache.torque.gf.configuration.paths.ProjectPaths;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Parses the xml file which provides the control configuration.
+ */
+public class ControlConfigurationXmlParser
+{
+    /**
+     * The SaxParserFactory to create the SAX parsers for reading in the
+     * generator configuration files.
+     */
+    private static SAXParserFactory saxFactory;
+
+    /** The logger. */
+    private static Log log
+            = LogFactory.getLog(ControlConfigurationXmlParser.class);
+
+    static
+    {
+        saxFactory = SAXParserFactory.newInstance();
+        saxFactory.setNamespaceAware(true);
+        try
+        {
+            saxFactory.setFeature(
+                    "http://xml.org/sax/features/validation",
+                    true);
+            saxFactory.setFeature(
+                    "http://apache.org/xml/features/validation/schema", true);
+        }
+        catch (SAXNotSupportedException e)
+        {
+            throw new RuntimeException(e);
+        }
+        catch (SAXNotRecognizedException e)
+        {
+            throw new RuntimeException(e);
+        }
+        catch (ParserConfigurationException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * Reads the controller configuration out of a configurationProvider.
+     *
+     * @param configurationProvider the object for accessing the configuration,
+     *        not null.
+     * @param projectPaths the paths inside the configuration, not null.
+     * @param configurationHandlers the available configuration handlers,
+     *        not null.
+     *
+     * @return the Controller configuration.
+
+     * @throws ConfigurationException if an error in the configuration
+     *         is encountered.
+     * @throws NullPointerException if an argument is null.
+     */
+    public ControlConfiguration readControllerConfiguration(
+            ConfigurationProvider configurationProvider,
+            ProjectPaths projectPaths,
+            ConfigurationHandlers configurationHandlers)
+        throws ConfigurationException
+    {
+        InputStream controlConfigurationInputStream
+                = configurationProvider.getControlConfigurationInputStream();
+        try
+        {
+            ControlConfiguration result = new ControlConfiguration();
+            try
+            {
+                SAXParser parser = saxFactory.newSAXParser();
+                InputSource is
+                        = new InputSource(controlConfigurationInputStream);
+                parser.parse(
+                        is,
+                        new ControlConfigurationSaxHandler(
+                                result,
+                                configurationProvider,
+                                projectPaths,
+                                configurationHandlers));
+            }
+            catch (SAXParseException e)
+            {
+                throw new ConfigurationException(
+                        "Error parsing controller Configuration at line "
+                            + e.getLineNumber()
+                            + " column "
+                            + e.getColumnNumber()
+                            + " : "
+                            + e.getMessage(),
+                        e);
+
+            }
+            catch (Exception e)
+            {
+                throw new ConfigurationException(
+                        "Error parsing controller Configuration : "
+                            + e.getMessage(),
+                        e);
+            }
+            return result;
+        }
+        finally
+        {
+            try
+            {
+                controlConfigurationInputStream.close();
+            }
+            catch (IOException e)
+            {
+                log.warn("Could not close controlConfigurationInputStream", e);
+            }
+        }
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/GeneratorReference.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/GeneratorReference.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/GeneratorReference.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/GeneratorReference.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,101 @@
+package org.apache.torque.gf.configuration.controller;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.torque.gf.qname.Namespace;
+import org.apache.torque.gf.qname.QualifiedName;
+
+/**
+ * Represents a reference to a generator.
+ *
+ * @version $Id: XmlToAppData.java 239626 2005-08-24 12:19:51Z henning $
+ */
+public class GeneratorReference
+{
+    /** The name of the referenced generator. */
+    private QualifiedName name;
+
+    /**
+     * The namespace under which the generator should execute.
+     * Defaults to the namespace in the generator's name.
+     */
+    private Namespace namespace;
+
+    /**
+     * Constructor.
+     *
+     * @param name the name of the referenced generator, not null.
+     */
+    public GeneratorReference(String name)
+    {
+        if (name == null)
+        {
+            throw new IllegalArgumentException("name must not be null");
+        }
+        this.name = new QualifiedName(name, Namespace.ROOT_NAMESPACE);
+        namespace = this.name.getNamespace();
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param name the name of the referenced generator, not null.
+     */
+    public GeneratorReference(QualifiedName name)
+    {
+        if (name == null)
+        {
+            throw new IllegalArgumentException("name must not be null");
+        }
+        this.name = name;
+        namespace = this.name.getNamespace();
+    }
+
+    /**
+     * Returns the qualified name of the generator.
+     *
+     * @return the qualified name of the generator, not null.
+     */
+    public QualifiedName getName()
+    {
+        return name;
+    }
+
+    /**
+     * Returns the namespace under which the generator executes.
+     *
+     * @return the namespace under which the generator executes.
+     */
+    public Namespace getNamespace()
+    {
+        return namespace;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString()
+    {
+        StringBuffer result = new StringBuffer();
+        result.append("(name=").append(name).append(")");
+        return result.toString();
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/GeneratorReferenceSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/GeneratorReferenceSaxHandler.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/GeneratorReferenceSaxHandler.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/GeneratorReferenceSaxHandler.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,100 @@
+package org.apache.torque.gf.configuration.controller;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.torque.gf.configuration.controller.OutputConfigurationTags.GENERATOR_TAG;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Reads a Generator reference file from the controller
+ * configuration file.
+ */
+public class GeneratorReferenceSaxHandler extends DefaultHandler
+{
+    /**
+     * The generator reference which is currently populated,
+     * or null if no generator reference is currently populated.
+     */
+    private GeneratorReference generatorReference;
+
+    /**
+     * Whether the complete XML snippet which should be parsed by this
+     * Handler has been parsed..
+     */
+    private boolean finished = false;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void startElement(String uri, String localName, String rawName,
+                             Attributes attributes)
+            throws SAXException
+    {
+        if (GENERATOR_TAG.equals(rawName))
+        {
+            String name = attributes.getValue("name");
+            generatorReference
+                    = new GeneratorReference(name);
+        }
+        else
+        {
+            throw new SAXException("Unknown element " + rawName);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void endElement(String uri, String localName, String rawName)
+        throws SAXException
+    {
+        if (GENERATOR_TAG.equals(rawName))
+        {
+            finished = true;
+        }
+    }
+
+    /**
+     * Returns the generator reference which was filled by this handler.
+     *
+     * @return the generator reference which was filled by this handler,
+     *         not null.
+     */
+    public GeneratorReference getGeneratorReference()
+    {
+        return generatorReference;
+    }
+
+    /**
+     * Returns whether the handler has already parsed the end of the snippet
+     * for which it is responsible.
+     *
+     * @return true if the end of the snippet is reached, false otherwise.
+     */
+    public boolean isFinished()
+    {
+        return finished;
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/Loglevel.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/Loglevel.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/Loglevel.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/Loglevel.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,127 @@
+package org.apache.torque.gf.configuration.controller;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+/**
+ * The possible log levels. This implementation uses log4j internally,
+ * but the interface is agnostic of the logging framework.
+ */
+public enum Loglevel
+{
+    /** Loglevel trace. */
+    TRACE("trace", Level.TRACE),
+    /** Loglevel debug. */
+    DEBUG("debug", Level.DEBUG),
+    /** Loglevel info. */
+    INFO("info", Level.INFO),
+    /** Loglevel warn. */
+    WARN("warn", Level.WARN),
+    /** Loglevel error. */
+    ERROR("error", Level.ERROR);
+
+    /** The key of the loglevel. */
+    private String key;
+
+    /** The log4j loglevel. */
+    private Level log4jLevel;
+
+    /** The logger. */
+    private static Log log = LogFactory.getLog(Loglevel.class);
+
+    /**
+     * Constructor.
+     *
+     * @param key the key, not null.
+     */
+    private Loglevel(String key, Level log4jLevel)
+    {
+        this.key = key;
+        this.log4jLevel = log4jLevel;
+    }
+
+    /**
+     * Returns the key of the Loglevel.
+     *
+     * @return the key of the Loglevel, not null.
+     */
+    public String getKey()
+    {
+        return key;
+    }
+
+    /**
+     * Applies the log level.
+     */
+    public void apply()
+    {
+        if (Logger.getRootLogger().getLevel() != log4jLevel)
+        {
+            log.info("apply() : Setting loglevel to " + this);
+            Logger.getRootLogger().setLevel(log4jLevel);
+        }
+    }
+
+    /**
+     * Returns the Loglevel for a given key.
+     *
+     * @param key the key to look for.
+     *
+     * @return the corresponding Loglevel, not null.
+     *
+     * @throws IllegalArgumentException if no Loglevel can be found
+     *         for the key.
+     */
+    public static Loglevel getByKey(String key)
+    {
+        for (Loglevel loglevel : values())
+        {
+            if (loglevel.getKey().equals(key))
+            {
+                return loglevel;
+            }
+        }
+        throw new IllegalArgumentException(
+                "Key " + key + " does not exist");
+    }
+
+    /**
+     * Returns the current loglevel.
+     *
+     * @return the current loglevel, or INFO if the current loglevel cannot
+     *         be determined.
+     */
+    public static Loglevel getCurrentLoglevel()
+    {
+        Level level = Logger.getRootLogger().getLevel();
+        for (Loglevel loglevel : values())
+        {
+            if (loglevel.log4jLevel.equals(level))
+            {
+                return loglevel;
+            }
+        }
+        return INFO;
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/Output.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/Output.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/Output.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/Output.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,226 @@
+package org.apache.torque.gf.configuration.controller;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.torque.gf.generator.Generator;
+import org.apache.torque.gf.qname.QualifiedName;
+import org.apache.torque.gf.source.Sources;
+
+/**
+ * The configuration for an output (typically one or more files).
+ */
+public class Output
+{
+    /**
+     * The name by which this output can be identified.
+     */
+    private QualifiedName name;
+
+    /**
+     * The sources to be used as input.
+     */
+    private Sources sources;
+
+    /**
+     * The generator which generates the content.
+     */
+    private GeneratorReference contentGenerator;
+
+    /**
+     * The generator which generates the filename, or null if the
+     * path to the generated file is explicitly given in <code>path</code>.
+     */
+    private Generator filenameGenerator;
+
+    /**
+     * The filename of the generated file, or null if the filename must
+     * still be generated using a filenameGenerator.
+     * This attribute is also used to store the generated filename
+     * if it was generated using the filenameGenerator.
+     */
+    private String filename;
+
+    /**
+     * Whether generation should be skipped if the file already exists.
+     */
+    private boolean skipIfExists;
+
+    /**
+     * Constructor.
+     *
+     * @param name the name by which this output can be identified.
+     */
+    public Output(QualifiedName name)
+    {
+        this.name = name;
+    }
+
+    /**
+     * Returns the name by which this output can be identified.
+     *
+     * @return the name by which this output can be identified, not null.
+     */
+    public QualifiedName getName()
+    {
+        return name;
+    }
+
+    /**
+     * Returns the sources which should be used as input for generating the
+     * output file's contents.
+     *
+     * @return the sources which should be used as input for generation.
+     */
+    public Sources getSources()
+    {
+        return sources;
+    }
+
+    /**
+     * Sets the sources which should be used as input for generating the
+     * output file's contents.
+     *
+     * @param sources the sources which should be used as input for generation.
+     */
+    public void setSources(Sources sources)
+    {
+        this.sources = sources;
+    }
+
+    /**
+     * Sets the name of the file to generate.
+     * This is also used to store the generated filename
+     * if it was generated using the filenameGenerator.
+     *
+     * @param filename the name of the file to generate.
+     */
+    public void setFilename(String filename)
+    {
+        this.filename = filename;
+    }
+
+    /**
+     * Returns the name of the file to generate. Either this name was
+     * given explicitly or it was set using the filenameGenerator.
+     *
+     * @return the name of the file to generate.
+     */
+    public String getFilename()
+    {
+        return filename;
+    }
+
+    /**
+     * Returns the reference to the generator which should produce the content.
+     *
+     * @return the reference to the generator responsible for producing the
+     *         content.
+     */
+    public GeneratorReference getContentGenerator()
+    {
+        return contentGenerator;
+    }
+
+    /**
+     * Sets the reference to the generator which should produce the content.
+     *
+     * @param contentGenerator the reference to the generator responsible
+     *        for producing the content.
+     */
+    public void setContentGenerator(GeneratorReference contentGenerator)
+    {
+        this.contentGenerator = contentGenerator;
+    }
+
+    /**
+     * Returns the reference to the generator which should produce
+     * the file name. If this attribute is set, it takes precedence over a
+     * set filename.
+     *
+     * @return the reference to the generator responsible for producing the
+     *         file name, or null if the file name is explicitly given.
+     */
+    public Generator getFilenameGenerator()
+    {
+        return filenameGenerator;
+    }
+
+    /**
+     * Sets the reference to the generator which should produce
+     * the file name.
+     *
+     * @param filenameGenerator the reference to the generator responsible
+     *        for producing the file name.
+     */
+    public void setFilenameGenerator(Generator filenameGenerator)
+    {
+        this.filenameGenerator = filenameGenerator;
+    }
+
+    /**
+     * Returns whether the generation of this file should be skipped
+     * if the file already exists.
+     *
+     * @return true if generation should be skipped if the file already exists.
+     */
+    public boolean isSkipIfExists()
+    {
+        return skipIfExists;
+    }
+
+    /**
+     * Sets whether the generation of this file should be skipped
+     * if the file already exists.
+     *
+     * @param skipIfExists true if generation should be skipped if the file
+     *        already exists, false otherwise.
+     */
+    public void setSkipIfExists(boolean skipIfExists)
+    {
+        this.skipIfExists = skipIfExists;
+    }
+
+    /**
+     * Returns whether the target file is always generated anew.
+     *
+     * @return true if the target file is always generated anew,
+     *         false otherwise.
+     */
+    public boolean isAlwaysNew()
+    {
+        return !skipIfExists;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString()
+    {
+        StringBuffer result = new StringBuffer();
+        result.append("(OutputFile: sources=").append(sources)
+                .append(",skipIfExists=").append(skipIfExists)
+                .append(",filenameGenerator=")
+                .append(filenameGenerator)
+                .append(",contentGenerator=")
+                .append(contentGenerator).append(")");
+        return result.toString();
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/OutputConfigurationTags.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/OutputConfigurationTags.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/OutputConfigurationTags.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/OutputConfigurationTags.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,51 @@
+package org.apache.torque.gf.configuration.controller;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * The tag and attribute names used for configuring an Output unit.
+ */
+public final class OutputConfigurationTags
+{
+    /**
+     * private constructor for utility class.
+     */
+    private OutputConfigurationTags()
+    {
+    }
+
+    /** Tag name for the "output" tag. */
+    public static final String OUTPUT_TAG = "output";
+
+    /** Attribute name for the "name" attribute. */
+    public static final String NAME_ATTRIBUTE = "name";
+
+    /** Attribute name for the "skipIfExists" attribute. */
+    public static final String SKIP_IF_EXISTS_ATTRIBUTE = "skipIfExists";
+
+    /** Attribute name for the "file" attribute. */
+    public static final String FILE_ATTRIBUTE = "file";
+
+    /** Tag name for the "generator" tag. */
+    public static final String GENERATOR_TAG = "generator";
+
+    /** Tag name for the "filenameGenerator" tag. */
+    public static final String FILENAME_GENERATOR_TAG = "filenameGenerator";
+}

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/OutputSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/OutputSaxHandler.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/OutputSaxHandler.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/OutputSaxHandler.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,295 @@
+package org.apache.torque.gf.configuration.controller;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.torque.gf.configuration.controller.OutputConfigurationTags.FILENAME_GENERATOR_TAG;
+import static org.apache.torque.gf.configuration.controller.OutputConfigurationTags.FILE_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.controller.OutputConfigurationTags.GENERATOR_TAG;
+import static org.apache.torque.gf.configuration.controller.OutputConfigurationTags.NAME_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.controller.OutputConfigurationTags.OUTPUT_TAG;
+import static org.apache.torque.gf.configuration.controller.OutputConfigurationTags.SKIP_IF_EXISTS_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.controller.SourceConfigurationTags.SOURCE_TAG;
+import static org.apache.torque.gf.configuration.generator.GeneratorConfigurationTags.INPUT_TAG;
+
+import org.apache.torque.gf.configuration.ConfigurationHandlers;
+import org.apache.torque.gf.configuration.ConfigurationProvider;
+import org.apache.torque.gf.configuration.generator.GeneratorConfigurationSaxHandler;
+import org.apache.torque.gf.configuration.generator.GeneratorSaxHandler;
+import org.apache.torque.gf.configuration.paths.ProjectPaths;
+import org.apache.torque.gf.qname.QualifiedName;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Reads an output declaration from the controller configuration file.
+ */
+public class OutputSaxHandler extends DefaultHandler
+{
+    /** The qualified name for the filename generator. */
+    private static final QualifiedName FILENAME_GENERATOR_NAME
+            = new QualifiedName(
+                "org.apache.torque.gf.configuration.filenameGenerator");
+
+    /** The access object for the configuration files, not null. */
+    private ConfigurationProvider configurationProvider;
+
+    /** The paths of the surrounding project, not null. */
+    private ProjectPaths projectPaths;
+
+    /** All known configuration handlers. */
+    private ConfigurationHandlers configurationHandlers;
+
+    /** The output declaration which is currently parsed. */
+    private Output output;
+
+    /**
+     * The SAX handler which handles the reference to the content generator,
+     * or null if no content generator is currently processed.
+     */
+    private GeneratorReferenceSaxHandler contentGeneratorSaxHandler;
+
+    /**
+     * The SAX handler which handles source tags, or null if source tags
+     * need not be handled in the current context.
+     */
+    private SourceSaxHandler sourceSaxHandler;
+
+    /**
+     * The SAX handler which handles the filename generator configuration,
+     * or null if filename generator tags need not be handled
+     * in the current context.
+     */
+    private GeneratorSaxHandler filenameGeneratorSaxHandler;
+
+    /**
+     * Constructor.
+     *
+     * @param configurationProvider The access object for the configuration
+     *        files, not null.
+     * @param projectPaths The paths of the surrounding project, not null.
+     * @param generatorTypes the configured types of generators, not null.
+     * @param sourceTypes All known source types, not null.
+     *
+     * @throws NullPointerException if an argument is null.
+     */
+    public OutputSaxHandler(
+            ConfigurationProvider configurationProvider,
+            ProjectPaths projectPaths,
+            ConfigurationHandlers configurationHandlers)
+    {
+        if (configurationProvider == null)
+        {
+            throw new NullPointerException(
+                    "configurationProvider must not be null");
+        }
+        if (projectPaths == null)
+        {
+            throw new NullPointerException(
+                    "projectPaths must not be null");
+        }
+        if (configurationHandlers == null)
+        {
+            throw new NullPointerException(
+                    "configurationHandlers must not be null");
+        }
+        this.configurationProvider = configurationProvider;
+        this.configurationHandlers = configurationHandlers;
+        this.projectPaths = projectPaths;
+    }
+
+    /**
+     * Returns the Configuration filled with the contents of the parsed snippet.
+     *
+     * @return the configuration representing the parsed snippet.
+     *         Not null if the mathcing xml snippet was parsed.
+     */
+    public Output getOutputFile()
+    {
+        return output;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void startElement(
+            String uri,
+            String localName,
+            String rawName,
+            Attributes attributes)
+        throws SAXException
+    {
+        if (contentGeneratorSaxHandler != null)
+        {
+            contentGeneratorSaxHandler.startElement(
+                    uri,
+                    localName,
+                    rawName,
+                    attributes);
+        }
+        else if (filenameGeneratorSaxHandler != null)
+        {
+            filenameGeneratorSaxHandler.startElement(
+                    uri,
+                    localName,
+                    rawName,
+                    attributes);
+        }
+        else if (sourceSaxHandler != null)
+        {
+            sourceSaxHandler.startElement(
+                    uri,
+                    localName,
+                    rawName,
+                    attributes);
+        }
+        else if (OUTPUT_TAG.equals(rawName))
+        {
+            String name = attributes.getValue(NAME_ATTRIBUTE);
+            if (name == null)
+            {
+                throw new SAXException("The attribute "
+                        + NAME_ATTRIBUTE
+                        + " must be set for the tag "
+                        + INPUT_TAG);
+            }
+            this.output = new Output(new QualifiedName(name));
+
+            if (attributes.getValue(FILE_ATTRIBUTE) != null)
+            {
+                output.setFilename(attributes.getValue(FILE_ATTRIBUTE));
+            }
+            if (attributes.getValue(SKIP_IF_EXISTS_ATTRIBUTE) != null)
+            {
+                output.setSkipIfExists(
+                        Boolean.parseBoolean(
+                            attributes.getValue(SKIP_IF_EXISTS_ATTRIBUTE)));
+            }
+        }
+        else if (SOURCE_TAG.equals(rawName))
+        {
+            sourceSaxHandler = new SourceSaxHandler(
+                    configurationProvider,
+                    projectPaths,
+                    configurationHandlers);
+            sourceSaxHandler.startElement(uri, localName, rawName, attributes);
+        }
+        else if (GENERATOR_TAG.equals(rawName))
+        {
+            contentGeneratorSaxHandler
+                    = new GeneratorReferenceSaxHandler();
+            contentGeneratorSaxHandler.startElement(
+                    uri,
+                    localName,
+                    rawName,
+                    attributes);
+        }
+        else if (FILENAME_GENERATOR_TAG.equals(rawName))
+        {
+            GeneratorConfigurationSaxHandler generatorConfigurationSaxHandler
+                    = new GeneratorConfigurationSaxHandler(
+                            configurationProvider,
+                            projectPaths,
+                            configurationHandlers);
+            String generatorType
+                    = GeneratorConfigurationSaxHandler.getGeneratorType(
+                            attributes);
+            filenameGeneratorSaxHandler
+                    = generatorConfigurationSaxHandler.getGeneratorHandler(
+                            FILENAME_GENERATOR_NAME,
+                            generatorType);
+            filenameGeneratorSaxHandler.startElement(
+                    uri,
+                    localName,
+                    rawName,
+                    attributes);
+        }
+        else
+        {
+            throw new SAXException("Unknown element " + rawName);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void endElement(String uri, String localName, String rawName)
+        throws SAXException
+    {
+        if (contentGeneratorSaxHandler != null)
+        {
+            contentGeneratorSaxHandler.endElement(
+                    uri,
+                    localName,
+                    rawName);
+            if (contentGeneratorSaxHandler.isFinished())
+            {
+                output.setContentGenerator(
+                        contentGeneratorSaxHandler
+                            .getGeneratorReference());
+                contentGeneratorSaxHandler = null;
+            }
+        }
+        else if (sourceSaxHandler != null)
+        {
+            sourceSaxHandler.endElement(uri, localName, rawName);
+            if (sourceSaxHandler.isFinished())
+            {
+                output.setSources(sourceSaxHandler.getSources());
+                sourceSaxHandler = null;
+            }
+        }
+        else if (filenameGeneratorSaxHandler != null)
+        {
+            filenameGeneratorSaxHandler.endElement(uri, localName, rawName);
+            if (filenameGeneratorSaxHandler.isFinished())
+            {
+                output.setFilenameGenerator(
+                        filenameGeneratorSaxHandler
+                            .getGenerator());
+                filenameGeneratorSaxHandler = null;
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void characters(char[] ch, int start, int length)
+            throws SAXException
+    {
+        if (contentGeneratorSaxHandler != null)
+        {
+            contentGeneratorSaxHandler.characters(
+                    ch, start, length);
+        }
+        else if (sourceSaxHandler != null)
+        {
+            sourceSaxHandler.characters(ch, start, length);
+        }
+        else if (filenameGeneratorSaxHandler != null)
+        {
+            filenameGeneratorSaxHandler.characters(ch, start, length);
+        }
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/SourceConfigurationTags.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/SourceConfigurationTags.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/SourceConfigurationTags.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/SourceConfigurationTags.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,54 @@
+package org.apache.torque.gf.configuration.controller;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Contains tag and attribute names for the Source configuration.
+ */
+public final class SourceConfigurationTags
+{
+    /**
+     * private constructor for utility class.
+     */
+    private SourceConfigurationTags()
+    {
+    }
+
+    /** Tag name for the "source" tag. */
+    public static final String SOURCE_TAG = "source";
+
+    /** Attribute name for the "type" attribute. */
+    public static final String TYPE_ATTRIBUTE = "type";
+
+    /** Attribute name for the "path" attribute. */
+    public static final String PATH_ATTRIBUTE = "path";
+
+    /** Attribute name for the "elements" attribute. */
+    public static final String ELEMENTS_ATTRIBUTE = "elements";
+
+    /** Attribute name for the "sourceFilter" attribute. */
+    public static final String SOURCE_FILTER_ATTRIBUTE = "filter";
+
+    /** Tag name for the "transformer" tag. */
+    public static final String TRANSFORMER_TAG = "transformer";
+
+    /** Tag name for the "class" attribute of the "transformer" tag. */
+    public static final String TRANSFORMER_CLASS_ATTRIBUTE = "class";
+}

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/SourceSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/SourceSaxHandler.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/SourceSaxHandler.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/SourceSaxHandler.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,264 @@
+package org.apache.torque.gf.configuration.controller;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.torque.gf.configuration.controller.SourceConfigurationTags.ELEMENTS_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.controller.SourceConfigurationTags.PATH_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.controller.SourceConfigurationTags.SOURCE_FILTER_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.controller.SourceConfigurationTags.SOURCE_TAG;
+import static org.apache.torque.gf.configuration.controller.SourceConfigurationTags.TRANSFORMER_TAG;
+import static org.apache.torque.gf.configuration.controller.SourceConfigurationTags.TYPE_ATTRIBUTE;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.torque.gf.configuration.ConfigurationException;
+import org.apache.torque.gf.configuration.ConfigurationHandlers;
+import org.apache.torque.gf.configuration.ConfigurationProvider;
+import org.apache.torque.gf.configuration.paths.ProjectPaths;
+import org.apache.torque.gf.source.FileSourcesImpl;
+import org.apache.torque.gf.source.SourceType;
+import org.apache.torque.gf.source.Sources;
+import org.apache.torque.gf.source.TransformerDefinition;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Reads an Source from the controller configuration file.
+ */
+public class SourceSaxHandler extends DefaultHandler
+{
+    /** The access object for the configuration files, not null. */
+    private ConfigurationProvider configurationProvider;
+
+    /** The paths of the surrounding project, not null. */
+    private ProjectPaths projectPaths;
+
+    /** The known configuration handlers. */
+    private ConfigurationHandlers configurationHandlers;
+
+    /** The file type of the sources element which is currently parsed. */
+    private String type;
+
+    /** The file path of the sources element which is currently parsed. */
+    private String path;
+
+    /**
+     * The start elements path of the sources element
+     * which is currently parsed.
+     */
+    private String startElementsPath;
+
+    /**
+     * The source filter for the sources Element which is currently parsed.
+     */
+    private String sourceFilter;
+
+    /**
+     * The transformer definitions from inside the source file configuration.
+     */
+    private List<TransformerDefinition> transformerDefinitions
+            = new ArrayList<TransformerDefinition>();
+
+    /**
+     * The sources element with the configuration in the current element.
+     */
+    private Sources sources;
+
+    /** The handler which handles transformer elements. */
+    private TransformerSaxHandler transformerSaxHandler;
+
+    /** whether this handler has completed its task. */
+    private boolean finished = false;
+
+    /**
+     * Constructor.
+     *
+     * @param configurationProvider The access object for the configuration
+     *        files, not null.
+     * @param projectPaths The paths of the surrounding project, not null.
+     * @param configurationHandlers All known configuration handlers, not null.
+     *
+     * @throws NullPointerException if an argument is null.
+     */
+    public SourceSaxHandler(
+            ConfigurationProvider configurationProvider,
+            ProjectPaths projectPaths,
+            ConfigurationHandlers configurationHandlers)
+    {
+        if (configurationProvider == null)
+        {
+            throw new NullPointerException(
+                    "configurationProvider must not be null");
+        }
+        if (projectPaths == null)
+        {
+            throw new NullPointerException(
+                    "projectPaths must not be null");
+        }
+        if (configurationHandlers == null)
+        {
+            throw new NullPointerException(
+                    "configurationHandlers must not be null");
+        }
+        this.configurationProvider = configurationProvider;
+        this.projectPaths = projectPaths;
+        this.configurationHandlers = configurationHandlers;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void startElement(String uri, String localName, String rawName,
+                             Attributes attributes)
+            throws SAXException
+    {
+        if (transformerSaxHandler != null)
+        {
+            transformerSaxHandler.startElement(
+                    uri, localName, rawName, attributes);
+        }
+        else if (TRANSFORMER_TAG.equals(rawName))
+        {
+            transformerSaxHandler
+                    = new TransformerSaxHandler(
+                            configurationProvider, projectPaths);
+            transformerSaxHandler.startElement(
+                    uri, localName, rawName, attributes);
+        }
+        else if (rawName.equals(SOURCE_TAG))
+        {
+            type = attributes.getValue(TYPE_ATTRIBUTE);
+            path = attributes.getValue(PATH_ATTRIBUTE);
+            if (path == null)
+            {
+                throw new SAXException(
+                        "path must not be null for source");
+            }
+            startElementsPath = attributes.getValue(ELEMENTS_ATTRIBUTE);
+            sourceFilter = attributes.getValue(SOURCE_FILTER_ATTRIBUTE);
+        }
+        else
+        {
+            throw new SAXException("Unknown element " + rawName);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void endElement(String uri, String localName, String rawName)
+        throws SAXException
+    {
+        if (transformerSaxHandler != null)
+        {
+            transformerSaxHandler.endElement(
+                    uri,
+                    localName,
+                    rawName);
+            if (transformerSaxHandler.isFinished())
+            {
+                transformerDefinitions.add(new TransformerDefinition(
+                        transformerSaxHandler.getSourceTransformer(),
+                        transformerSaxHandler.getElements()));
+                transformerSaxHandler = null;
+            }
+        }
+        else if (rawName.equals(SOURCE_TAG))
+        {
+            try
+            {
+                SourceType sourceType = null;
+                if (type != null)
+                {
+                    Set<SourceType> sourceTypes
+                            = configurationHandlers.getSourceTypes();
+                    for (SourceType candidate : sourceTypes)
+                    {
+                        if (type.equals(candidate.getKey()))
+                        {
+                            sourceType = candidate;
+                            break;
+                        }
+                    }
+                    if (sourceType == null)
+                    {
+                        throw new SAXException("Unknown source type : " + type
+                                + " Known types are: " + sourceTypes);
+                    }
+                }
+                sources = new FileSourcesImpl(
+                        sourceType,
+                        path,
+                        startElementsPath,
+                        sourceFilter,
+                        transformerDefinitions,
+                        configurationHandlers,
+                        projectPaths.getDefaultSourcePath());
+            }
+            catch (ConfigurationException e)
+            {
+                throw new SAXException("Could not create source: "
+                            + e.getMessage(),
+                        e);
+            }
+            finished = true;
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void characters(char[] ch, int start, int length)
+            throws SAXException
+    {
+        if (transformerSaxHandler != null)
+        {
+            transformerSaxHandler.characters(ch, start, length);
+        }
+    }
+
+    /**
+     * Returns the configuration filled with the contents of the parsed snippet.
+     *
+     * @return the configuration which was filled, not null if a
+     *         matching snippet was processed.
+     */
+    public Sources getSources()
+    {
+        return sources;
+    }
+
+    /**
+     * Returns whether the matching snippet was completely parsed.
+     *
+     * @return true if the matching snippet was completely parsed,
+     *         false otherwise.
+     */
+    public boolean isFinished()
+    {
+        return finished;
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/TransformerSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/TransformerSaxHandler.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/TransformerSaxHandler.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/TransformerSaxHandler.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,338 @@
+package org.apache.torque.gf.configuration.controller;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.torque.gf.configuration.controller.SourceConfigurationTags.ELEMENTS_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.controller.SourceConfigurationTags.TRANSFORMER_CLASS_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.controller.SourceConfigurationTags.TRANSFORMER_TAG;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.gf.configuration.ConfigurationProvider;
+import org.apache.torque.gf.configuration.paths.ProjectPaths;
+import org.apache.torque.gf.source.transform.SourceTransformer;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Reads an Transformer from the controller configuration file.
+ */
+public class TransformerSaxHandler extends DefaultHandler
+{
+    /** the logger for this class. */
+    private static Log log = LogFactory.getLog(DefaultHandler.class);
+
+    /** The SourceTransformer which is currently configured. */
+    private SourceTransformer sourceTransformer;
+
+    /** on which Elements the sourceTransformer should be applied. */
+    private String elements;
+
+    /** The current nesting level inside the processed element. */
+    private int level = 0;
+
+    /**
+     * The name of the currently read bean property of the transformer,
+     * or null if no property is currently read.
+     */
+    private String propertyName;
+
+    /**
+     * The value of the currently read bean property of the transformer,
+     * or null if no property is currently read.
+     */
+    private StringBuilder propertyValue;
+
+    /**
+     * Constructor.
+     *
+     * @param configurationProvider The access object for the configuration
+     *        files, not null.
+     * @param projectPaths The paths of the surrounding project, not null.
+     *
+     * @throws NullPointerException if an argument is null.
+     */
+    public TransformerSaxHandler(
+            ConfigurationProvider configurationProvider,
+            ProjectPaths projectPaths)
+    {
+        if (configurationProvider == null)
+        {
+            throw new NullPointerException("configurationProvider must not be null");
+        }
+        if (projectPaths == null)
+        {
+            throw new NullPointerException("projectPaths must not be null");
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void startElement(String uri, String localName, String rawName,
+                             Attributes attributes)
+            throws SAXException
+    {
+        if (level == 0)
+        {
+            level++;
+            if (rawName.equals(TRANSFORMER_TAG))
+            {
+                String className = attributes.getValue(
+                        TRANSFORMER_CLASS_ATTRIBUTE);
+                if (className == null)
+                {
+                    throw new SAXException(
+                            "The attribute " + TRANSFORMER_CLASS_ATTRIBUTE
+                            + " must not be null for the element "
+                            + TRANSFORMER_TAG);
+                }
+                elements = attributes.getValue(ELEMENTS_ATTRIBUTE);
+                sourceTransformer = createJavaSourceTransformer(className);
+            }
+            else
+            {
+                throw new SAXException("Unknown element " + rawName);
+            }
+        }
+        else if (level == 1)
+        {
+            level++;
+            propertyName = rawName;
+            propertyValue = new StringBuilder();
+        }
+        else
+        {
+            throw new SAXException("unknown Element " + rawName);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void endElement(String uri, String localName, String rawName)
+        throws SAXException
+    {
+        level--;
+        if (level == 1)
+        {
+            if (!PropertyUtils.isWriteable(sourceTransformer, propertyName))
+            {
+                throw new SAXException("No setter found for property "
+                        + propertyName
+                        + " in class "
+                        + sourceTransformer.getClass().getName());
+            }
+            try
+            {
+                BeanUtils.copyProperty(
+                        sourceTransformer,
+                        propertyName,
+                        propertyValue.toString());
+            }
+            catch (InvocationTargetException e)
+            {
+                throw new SAXException("error while setting Property "
+                        + propertyName
+                        + " for java generator "
+                        + sourceTransformer.getClass().getName()
+                        + " with value "
+                        + propertyValue.toString(),
+                    e);
+            }
+            catch (IllegalAccessException e)
+            {
+                throw new SAXException("error while setting Property "
+                        + propertyName
+                        + " for java generator "
+                        + sourceTransformer.getClass().getName()
+                        + " with value "
+                        + propertyValue.toString(),
+                    e);
+            }
+            propertyName = null;
+            propertyValue = null;
+        }
+        else if (level != 0)
+        {
+            throw new SAXException("endElemend reached Level" + level);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void characters(char[] ch, int start, int length)
+            throws SAXException
+    {
+        if (propertyName == null)
+        {
+            return;
+        }
+        for (int i = start; i < start + length; ++i)
+        {
+            propertyValue.append(ch[i]);
+        }
+    }
+
+    /**
+     * Returns the configuration filled with the contents of the parsed snippet.
+     *
+     * @return the configuration which was filled, not null if a
+     *         matching snippet was processed.
+     */
+    public SourceTransformer getSourceTransformer()
+    {
+        return sourceTransformer;
+    }
+
+    public String getElements()
+    {
+        return elements;
+    }
+
+    /**
+     * Returns the configuration filled with the contents of the parsed snippet.
+     *
+     * @return the configuration which was filled, not null if a
+     *         matching snippet was processed.
+     */
+    public boolean isFinished()
+    {
+        return (sourceTransformer != null && level == 0);
+    }
+
+    /**
+     * Creates an instance of a transformer.
+     *
+     * @param className the name of the transformer to be created.
+     *
+     * @return the instance of the transformer, not null.
+     *
+     * @throws ExceptionInInitializerError if an error occurs in the
+     *        initializer of the transformer.
+     * @throws LinkageError if the linkage fails.
+     * @throws SAXException if any other  error occurs during instantiation
+     *         of the class.
+     */
+    private static SourceTransformer createJavaSourceTransformer(
+            String className)
+        throws SAXException
+    {
+        Class<?> transformerClass;
+        try
+        {
+            transformerClass = Class.forName(className);
+        }
+        catch (ClassNotFoundException e)
+        {
+            throw new SAXException(
+                    "Error  while initializing a source transformer :"
+                    + " Could not load class " + className, e);
+        }
+        catch (ExceptionInInitializerError e)
+        {
+            log.error(
+                    "Error  while initializing a source transformer :"
+                    + " Could not initialize class " + className
+                    + " : " + e.getMessage());
+            throw e;
+        }
+        catch (LinkageError e)
+        {
+            log.error(
+                    "Error  while initializing a source transformer :"
+                    + " Could not link class " + className
+                    + " : " + e.getMessage());
+            throw e;
+        }
+
+        SourceTransformer result;
+        try
+        {
+            Constructor<?> constructor
+                    = transformerClass.getConstructor();
+            result = (SourceTransformer) constructor.newInstance();
+        }
+        catch (NoSuchMethodException e)
+        {
+            throw new SAXException(
+                    "Error  while instantiating a source transformer :"
+                    + " The class " + className
+                    + " has no default constructor",
+                e);
+        }
+        catch (ClassCastException e)
+        {
+            throw new SAXException(
+                    "Error  while instantiating a source transformer :"
+                    + " The class " + className
+                    + " is not an instance of "
+                    + SourceTransformer.class.getName(),
+                e);
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new SAXException(
+                    "Error  while instantiating a source transformer :"
+                    + " The constructor of class "
+                    + className + " could not be accessed",
+                e);
+        }
+        catch (InvocationTargetException e)
+        {
+            throw new SAXException(
+                    "Error  while instantiating a source transformer :"
+                    + " The constructor of class "
+                    + className + " could not be called",
+                e);
+        }
+        catch (InstantiationException e)
+        {
+            throw new SAXException(
+                    "Error  while instantiating a source transformer :"
+                    + " The class " + className
+                    + " represents an abstract class, "
+                    + "an interface, an array class, a primitive type, "
+                    + "or void, or the class has no parameterless constructor, "
+                    + "or the instantiation fails for some other reason.",
+                e);
+        }
+        catch (SecurityException e)
+        {
+            throw new SAXException(
+                    "Error  while instantiating a source transformer :"
+                    + " The security manager denies instantiation of the class "
+                    + className,
+                e);
+        }
+
+        return result;
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/package.html
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/package.html?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/package.html (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/controller/package.html Tue Feb 16 17:15:43 2010
@@ -0,0 +1,26 @@
+<!--
+ Copyright 2001-2006 The Apache Software Foundation.
+
+ Licensed under the Apache License, Version 2.0 (the "License")
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+  <head>
+    <title>Accessing Torque-gf control configuration</title>
+  </head>
+  <body>
+    <p>
+      This package contains the classes for reading control configuration of
+      Torque-gf units of generation.
+    </p>
+  </body>
+</html>

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfiguration.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfiguration.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfiguration.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfiguration.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,225 @@
+package org.apache.torque.gf.configuration.generator;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.torque.gf.configuration.ConfigurationException;
+import org.apache.torque.gf.configuration.mergepoint.MergepointMapping;
+import org.apache.torque.gf.generator.Generator;
+import org.apache.torque.gf.qname.QualifiedName;
+
+/**
+ * Administers the available Generators.
+ */
+public class GeneratorConfiguration
+{
+    /** A map containing all generators, keyed by their name. */
+    private Map<QualifiedName, Generator> generators
+            = new HashMap<QualifiedName, Generator>();
+
+    /** A map containing all isolated mergepoint mappings,
+     *  keyed by their name. */
+    private Map<String, MergepointMapping> mergepointMappings
+            = new HashMap<String, MergepointMapping>();
+
+    /**
+     * Whether the mergepoint mappings have been resolved and added to
+     * the respective generators.
+     */
+    private boolean mergepointMappingsResolved = false;
+
+    /**
+     * Creates a GeneratorConfiguration containing a list of Generators.
+     *
+     * @param generators the list of generators, not null.
+     *
+     * @throws NullPointerException if generatorList is null.
+     */
+    public GeneratorConfiguration(Collection<Generator> generators,
+            Collection<MergepointMapping> mergepointMappings)
+    {
+        if (generators == null)
+        {
+            throw new NullPointerException("generators must not be null");
+        }
+        if (mergepointMappings == null)
+        {
+            throw new NullPointerException(
+                    "mergepointMappings must not be null");
+        }
+        for (Generator generator : generators)
+        {
+            this.generators.put(generator.getName(), generator);
+        }
+        for (MergepointMapping mergepointMapping : mergepointMappings)
+        {
+            this.mergepointMappings.put(
+                    mergepointMapping.getName(),
+                    mergepointMapping);
+        }
+    }
+
+    /**
+     * Resolves the isolated mergepoint mappings and adds them to
+     * the relevant generators.
+     * @throws ConfigurationException
+     */
+    public void resolveMergepointMappings() throws ConfigurationException
+    {
+        for (Map.Entry<String, MergepointMapping> entry
+                : mergepointMappings.entrySet())
+        {
+            String name = entry.getKey();
+            QualifiedName qualifiedMergepointName
+                = new QualifiedName(name);
+            if (qualifiedMergepointName.getNamespace().isRoot())
+            {
+                // generator name is missing
+                throw new ConfigurationException(
+                        "The isolated mergepoint mapping with the name "
+                        + name
+                        + " needs to be qualified with the generator name");
+            }
+            QualifiedName generatorName = new QualifiedName(
+                    qualifiedMergepointName.getNamespace().toString());
+            Generator generator = generators.get(generatorName);
+            if (generator == null)
+            {
+                throw new ConfigurationException(
+                        "No generator with name "
+                        + generatorName
+                        + "exists (required by the isolated mergepoint mapping"
+                        + " with the name "
+                        + name
+                        + ")");
+            }
+            MergepointMapping originalMergepointMapping = entry.getValue();
+            MergepointMapping resolvedMergepointMapping
+                    = new MergepointMapping(
+                            qualifiedMergepointName.getName(),
+                            originalMergepointMapping.getActions());
+            generator.setMergepointMapping(resolvedMergepointMapping);
+        }
+        mergepointMappingsResolved = true;
+        mergepointMappings.clear();
+    }
+
+    /**
+     * Returns a map containing all the configured generators, keyed by their
+     * name.
+     *
+     * @return all generators, not null.
+     *
+     * @throws IllegalStateException if the mergepoint mappings have not
+     *         yet been resolved.
+     */
+    public Map<QualifiedName, Generator> getGenerators()
+    {
+        if (!mergepointMappingsResolved)
+        {
+            throw new IllegalStateException(
+                    "Mergepoint mappings must be resoved first");
+        }
+        return Collections.unmodifiableMap(generators);
+    }
+
+    /**
+     * Returns the generator with the name <code>name</code>.
+     *
+     * @param name the name of the generator to be returned.
+     *
+     * @return The generator with the given name, or null if it does not
+     *         exist.
+     *
+     * @throws IllegalStateException if the mergepoint mappings have not
+     *         yet been resolved.
+     */
+    public Generator getGenerator(QualifiedName name)
+    {
+        if (!mergepointMappingsResolved)
+        {
+            throw new IllegalStateException(
+                    "Mergepoint mappings must be resoved first");
+        }
+        return generators.get(name);
+    }
+
+    /**
+     * Adds a generator.
+     *
+     * @param generator the generator to be added, not null.
+     *
+     * @throws ConfigurationException if a generator with the generator's name
+     *         already exists in the configuration.
+     * @throws NullPointerException if generator is null.
+     */
+    public void addGenerator(Generator generator)
+        throws ConfigurationException
+    {
+        if (generator == null)
+        {
+            throw new NullPointerException("generator must not be null");
+        }
+        if (generators.get(generator.getName()) != null)
+        {
+            throw new ConfigurationException("Trying to add the generator "
+                    + generator.getName()
+                    + " and class "
+                    + generator.getClass().getName()
+                    + " : A generator with the same name "
+                    + " already exists, it has the class "
+                    + getGenerator(generator.getName()).getClass().getName());
+        }
+        generators.put(generator.getName(), generator);
+    }
+
+    /**
+     * Creates a String view of this object for debuggung purposes.
+     *
+     * @return a String view of this object, never null.
+     *
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString()
+    {
+        StringBuffer result = new StringBuffer("(generators=[")
+                .append(generators)
+                .append(")");
+        return result.toString();
+    }
+
+    /**
+     * returns whether a generator for the given name exists.
+     * Name and namespace must match exactly.
+     *
+     * @param qualifiedName the name of the generator.
+     *
+     * @return true if a generator with the name exists, false otherwise.
+     */
+    public boolean generatorExists(QualifiedName qualifiedName)
+    {
+        return generators.containsKey(qualifiedName);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org