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 [5/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/generator/GeneratorConfigurationSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationSaxHandler.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationSaxHandler.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationSaxHandler.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,354 @@
+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 static org.apache.torque.gf.configuration.generator.GeneratorConfigurationTags.GENERATORS_TAG;
+import static org.apache.torque.gf.configuration.generator.GeneratorConfigurationTags.GENERATOR_TAG;
+import static org.apache.torque.gf.configuration.mergepoint.MergepointConfigurationTags.MERGEPOINT_TAG;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.gf.configuration.ConfigurationEntityResolver;
+import org.apache.torque.gf.configuration.ConfigurationHandlers;
+import org.apache.torque.gf.configuration.ConfigurationProvider;
+import org.apache.torque.gf.configuration.SaxHelper;
+import org.apache.torque.gf.configuration.XMLConstants;
+import org.apache.torque.gf.configuration.mergepoint.MergepointMapping;
+import org.apache.torque.gf.configuration.mergepoint.MergepointSaxHandler;
+import org.apache.torque.gf.configuration.paths.ProjectPaths;
+import org.apache.torque.gf.generator.Generator;
+import org.apache.torque.gf.qname.QualifiedName;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * A SAX handler which parses Generator configuration files.
+ * Relies on delegate handlers for parsing the configuration for
+ * the different generator types.
+ */
+public class GeneratorConfigurationSaxHandler 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 list of generators which configuration was already parsed. */
+ private List<Generator> generators = new ArrayList<Generator>();
+
+ /**
+ * The list of separate mergepoint mappings (outside the generators)
+ * which configuration was already parsed.
+ */
+ private List<MergepointMapping> mergepointMappings
+ = new ArrayList<MergepointMapping>();
+
+ /** The available configuration handlers. */
+ private ConfigurationHandlers configurationHandlers;
+
+ /**
+ * The current delegate handler for parsing the current generator's
+ * configuration. Is null if no generator is currently parsed.
+ */
+ private GeneratorSaxHandler generatorHandler;
+
+ /**
+ * The current delegate handler for parsing the current mergepoint's
+ * configuration. Is null if no mergepoint is currently parsed.
+ */
+ private MergepointSaxHandler mergepointHandler;
+
+ /** The log. */
+ private static Log log = LogFactory.getLog(GeneratorSaxHandler.class);
+
+ /**
+ * Constructor.
+ *
+ * @param configurationProvider The access object for the configuration
+ * files, not null.
+ * @param projectPaths The paths of the surrounding project, not null.
+ * @param configurationHandlers The available configuration handlers,
+ * not null.
+ *
+ * @throws NullPointerException if an argument is null.
+ */
+ public GeneratorConfigurationSaxHandler(
+ ConfigurationProvider configurationProvider,
+ ProjectPaths projectPaths,
+ ConfigurationHandlers configurationHandlers)
+ {
+ if (configurationProvider == null)
+ {
+ log.error("GeneratorConfigurationSaxHandler: "
+ + " configurationProvider is null");
+ throw new NullPointerException("configurationProvider is null");
+ }
+ if (projectPaths == null)
+ {
+ log.error("GeneratorConfigurationSaxHandler: "
+ + " projectPaths is null");
+ throw new NullPointerException("projectPaths is null");
+ }
+ if (configurationHandlers == null)
+ {
+ log.error("GeneratorConfigurationSaxHandler: "
+ + " configurationHandlers is null");
+ throw new NullPointerException("configurationHandlers is null");
+ }
+ this.configurationProvider = configurationProvider;
+ this.projectPaths = projectPaths;
+ this.configurationHandlers = configurationHandlers;
+ }
+
+ /**
+ * Returns all generators which were configured in the parsed generator
+ * configuration file.
+ *
+ * @return all created generators, not null.
+ */
+ public List<Generator> getGenerators()
+ {
+ return generators;
+ }
+
+ /**
+ * Returns all mergepoint mappings which were configured
+ * outside the generators in the parsed generator configuration file.
+ *
+ * @return all created mergepoint mappings, not null.
+ */
+ public List<MergepointMapping> getMergepointMappings()
+ {
+ return mergepointMappings;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void startElement(String uri, String localName, String qName,
+ Attributes attributes)
+ throws SAXException
+ {
+ String unqualifiedName = SaxHelper.getUnqualifiedName(localName, qName);
+ if (generatorHandler != null)
+ {
+ generatorHandler.startElement(
+ uri, localName, qName, attributes);
+ }
+ else if (mergepointHandler != null)
+ {
+ mergepointHandler.startElement(
+ uri, localName, qName, attributes);
+ }
+ else if (GENERATOR_TAG.equals(unqualifiedName))
+ {
+ String generatorType = getGeneratorType(attributes);
+ generatorHandler = getGeneratorHandler(
+ null,
+ generatorType);
+ generatorHandler.startElement(
+ uri, localName, qName, attributes);
+ }
+ else if (MERGEPOINT_TAG.equals(unqualifiedName))
+ {
+ mergepointHandler = new MergepointSaxHandler(
+ configurationProvider,
+ projectPaths,
+ configurationHandlers);
+ mergepointHandler.startElement(
+ uri, localName, qName, attributes);
+ }
+ else if (!GENERATORS_TAG.equals(unqualifiedName))
+ {
+ throw new SAXException(
+ "Unknown element : " + unqualifiedName
+ + ". First element must be "
+ + GENERATORS_TAG
+ + " or "
+ + GENERATOR_TAG);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void endElement(String uri, String localName, String rawName)
+ throws SAXException
+ {
+ if (generatorHandler != null)
+ {
+ generatorHandler.endElement(uri, localName, rawName);
+ if (generatorHandler.isFinished())
+ {
+ Generator generator = generatorHandler.getGenerator();
+ generators.add(generator);
+ if (log.isDebugEnabled())
+ {
+ log.debug("Parsed configuration for the generator "
+ + generator.getName());
+ }
+ generatorHandler = null;
+ }
+ }
+ else if (mergepointHandler != null)
+ {
+ mergepointHandler.endElement(uri, localName, rawName);
+ if (mergepointHandler.isFinished())
+ {
+ MergepointMapping mergepointMapping
+ = mergepointHandler.getMergepointMapping();
+ mergepointMappings.add(mergepointMapping);
+ if (log.isDebugEnabled())
+ {
+ log.debug("Parsed configuration for the mergepoint "
+ + mergepointMapping.getName());
+ }
+ mergepointHandler = null;
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void characters (char[] ch, int start, int length)
+ throws SAXException
+ {
+ if (generatorHandler != null)
+ {
+ generatorHandler.characters(ch, start, length);
+ }
+ }
+
+ /**
+ * Returns the correct handler for a generator tag.
+ * The method uses the type attribute to determine which handler is needed.
+ * I.e. it looks up the handler factory type in the generator types,
+ * and asks the factory for a handler.
+ *
+ * @param generatorName the name for the generator which configuration
+ * will be read in by the generated SaxHandlerFactory,
+ * or null if the name of the generator should be determined from
+ * the parsed XML.
+ * @param generatorType the type of the generator, not null.
+ *
+ * @return the handler for the tag, not null.
+ *
+ * @throws SAXException if no matching handler can be identified,
+ * or if an error occurs while creating the handler.
+ */
+ public GeneratorSaxHandler getGeneratorHandler(
+ QualifiedName generatorName,
+ String generatorType)
+ throws SAXException
+ {
+ GeneratorSaxHandlerFactory delegateHandlerFactory
+ = configurationHandlers.getGeneratorTypes()
+ .getGeneratorHandlerFactories()
+ .get(generatorType);
+ if (delegateHandlerFactory == null)
+ {
+ throw new SAXException(
+ "Unknown generator type: "
+ + generatorType);
+ }
+ GeneratorSaxHandler generatorSaxHandler
+ = delegateHandlerFactory.getGeneratorSaxHandler(
+ generatorName,
+ configurationProvider,
+ projectPaths,
+ configurationHandlers);
+ return generatorSaxHandler;
+ }
+
+ /**
+ * Reads the generator type from the attributes of the generator XML tag.
+ *
+ * @param attributes the attributes of the XML tag, not null.
+ *
+ * @return the generator type, not null.
+ *
+ * @throws SAXException if the xsi:type attribute is not set.
+ */
+ public static String getGeneratorType(Attributes attributes)
+ throws SAXException
+ {
+ String generatorType
+ = attributes.getValue(
+ XMLConstants.XSI_NAMESPACE,
+ XMLConstants.XSI_TYPE_ATTRBUTE_NAME);
+ if (generatorType == null)
+ {
+ throw new SAXException("The tag " + GENERATOR_TAG
+ + " requires the attribute "
+ + XMLConstants.XSI_NAMESPACE
+ + ":"
+ + XMLConstants.XSI_TYPE_ATTRBUTE_NAME);
+ }
+ return generatorType;
+ }
+
+ /**
+ * EntityResolver implementation. Called by the XML parser
+ *
+ * @param publicId The public identifier of the external entity.
+ * @param systemId The system identifier of the external entity.
+ *
+ * @return an InputSource for the entity, or null if the URI is not known.
+ *
+ * @see ConfigurationEntityResolver#resolveEntity(String, String)
+ */
+ public InputSource resolveEntity(String publicId, String systemId)
+ throws SAXException, IOException
+ {
+ return new ConfigurationEntityResolver().resolveEntity(
+ publicId, systemId);
+ }
+
+ @Override
+ public void error(SAXParseException exception) throws SAXParseException
+ {
+ throw exception;
+ }
+
+ @Override
+ public void fatalError(SAXParseException exception)
+ throws SAXParseException
+ {
+ throw exception;
+ }
+
+ @Override
+ public void warning(SAXParseException exception) throws SAXParseException
+ {
+ throw exception;
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationTags.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationTags.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationTags.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationTags.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,82 @@
+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.
+ */
+
+/**
+ * Tag names for the generator configuration files.
+ */
+public final class GeneratorConfigurationTags
+{
+ /**
+ * private constructor for utility class.
+ */
+ private GeneratorConfigurationTags()
+ {
+ }
+
+ /** Tag name for the "generators" tag. */
+ public static final String GENERATORS_TAG = "generators";
+
+ /** Tag name for the "generator" tag. */
+ public static final String GENERATOR_TAG = "generator";
+
+ /** Attribute name for the attribute "name" of the "generator" tag. */
+ public static final String GENERATOR_NAME_ATTRIBUTE = "name";
+
+ /** Attribute name for the attribute "type" of the "generator" tag. */
+ public static final String GENERATOR_TYPE_ATTRIBUTE = "type";
+
+ /** Attribute name for the attribute "path" of the "generator" tag. */
+ public static final String GENERATOR_PATH_ATTRIBUTE = "path";
+
+ /** Attribute name for the attribute "encoding" of the "generator" tag. */
+ public static final String GENERATOR_ENCODING_ATTRIBUTE = "encoding";
+
+ /** Attribute name for the attribute "class" of the "generator" tag. */
+ public static final String GENERATOR_CLASS_ATTRIBUTE = "class";
+
+ /**
+ * Attribute name for the attribute "optionsInContext"
+ * of the "generator" tag.
+ */
+ public static final String GENERATOR_OPTIONS_IN_CONTEXT_ATTRIBUTE
+ = "optionsInContext";
+
+ /**
+ * Attribute name for the attribute "sourceAttributesInContext"
+ * of the "generator" tag.
+ */
+ public static final String
+ GENERATOR_SOURCE_ATTRIBUTES_IN_CONTEXT_ATTRIBUTE
+ = "sourceAttributesInContext";
+
+ /**
+ * Attribute name for the attribute "variablesInContext"
+ * of the "generator" tag.
+ */
+ public static final String GENERATOR_VARIABLES_IN_CONTEXT_ATTRIBUTE
+ = "variablesInContext";
+
+ /** Tag name for the "input" tag. */
+ public static final String INPUT_TAG = "input";
+
+ /** Attribute name for the attribute "elementName" of the "input" tag. */
+ public static final String INPUT_ELEMENT_NAME_ATTRIBUTE = "elementName";
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationXmlParser.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationXmlParser.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationXmlParser.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationXmlParser.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,285 @@
+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.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+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.mergepoint.MergepointMapping;
+import org.apache.torque.gf.configuration.paths.ProjectPaths;
+import org.apache.torque.gf.generator.Generator;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Parses generator configuration files and creates a GeneratorConfiguration.
+ */
+public class GeneratorConfigurationXmlParser
+{
+ /**
+ * 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(GeneratorConfigurationXmlParser.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 all generator configuration files creates the generator
+ * configuration from them.
+ * All the generator configuration files known to the provide are parsed.
+ * These are typically all XML files in the generator configuration
+ * directory and its subdirectories.
+ *
+ * @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.
+ *
+ * @return the generator configuration.
+ *
+ * @throws ConfigurationException if the Configuration cannot be read
+ * or errors exists in the generator configuration files.
+ */
+ public GeneratorConfiguration readGeneratorConfiguration(
+ ConfigurationProvider configurationProvider,
+ ProjectPaths projectPaths,
+ ConfigurationHandlers configurationHandlers)
+ throws ConfigurationException
+ {
+ if (configurationHandlers == null)
+ {
+ log.error("GeneratorConfiguration: "
+ + " configurationHandlers is null");
+ throw new NullPointerException("generatorTypes is null");
+ }
+ if (configurationProvider == null)
+ {
+ log.error("GeneratorConfiguration: "
+ + " configurationProvider is null");
+ throw new NullPointerException("configurationProvider is null");
+ }
+ if (projectPaths == null)
+ {
+ log.error("GeneratorConfiguration: "
+ + " projectPaths is null");
+ throw new NullPointerException("projectPaths is null");
+ }
+
+ List<Generator> allGenerators = new ArrayList<Generator>();
+ List<MergepointMapping> allMergepointMappings
+ = new ArrayList<MergepointMapping>();
+
+ // Generators from all files
+ Collection<String> generatorConfigNames
+ = configurationProvider.getGeneratorConfigurationNames();
+
+ for (String generatorConfigName : generatorConfigNames)
+ {
+ InputStream inputStream = null;
+ try
+ {
+ inputStream
+ = configurationProvider.getGeneratorConfigurationInputStream(
+ generatorConfigName);
+ GeneratorConfigFileContent fileContent
+ = readGeneratorConfig(
+ inputStream,
+ configurationProvider,
+ projectPaths,
+ configurationHandlers);
+ allGenerators.addAll(fileContent.getGenerators());
+ allMergepointMappings.addAll(
+ fileContent.getMergepointMappings());
+ }
+ catch (SAXParseException e)
+ {
+ throw new ConfigurationException(
+ "Error parsing generator configuration "
+ + generatorConfigName
+ + " at line "
+ + e.getLineNumber()
+ + " column "
+ + e.getColumnNumber()
+ + " : "
+ + e.getMessage(),
+ e);
+
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException(
+ "Error parsing generator configuration "
+ + generatorConfigName,
+ e);
+ }
+ finally
+ {
+ if (inputStream != null)
+ {
+ try
+ {
+ inputStream.close();
+ }
+ catch (IOException e)
+ {
+ log.warn("Could not close "
+ + "generatorConfigurationInputStream "
+ + generatorConfigName,
+ e);
+ }
+ }
+ }
+ }
+ return new GeneratorConfiguration(allGenerators, allMergepointMappings);
+ }
+
+
+ /**
+ * Reads a generator configuration file and returns the generators
+ * and isolated mergepoint mappings which are configured in this file.
+ *
+ * @param generatorConfigurationInputStream the stream containing the
+ * generator configuration.
+ * @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.
+ *
+ * @return All the generators and isolated mergepoint mappings
+ * configured in the file.
+ * @throws SAXException if an error occurs while parsing the configuration
+ * file.
+ * @throws IOException if the file cannot be read.
+ * @throws ParserConfigurationException if a serious parser configuration
+ * error occurs..
+ */
+ private GeneratorConfigFileContent readGeneratorConfig(
+ InputStream generatorConfigurationInputStream,
+ ConfigurationProvider configurationProvider,
+ ProjectPaths projectPaths,
+ ConfigurationHandlers configurationHandlers)
+ throws SAXException, IOException, ParserConfigurationException
+ {
+ SAXParser parser = saxFactory.newSAXParser();
+ GeneratorConfigurationSaxHandler saxHandler
+ = new GeneratorConfigurationSaxHandler(
+ configurationProvider,
+ projectPaths,
+ configurationHandlers);
+ InputSource is = new InputSource(generatorConfigurationInputStream);
+ parser.parse(is, saxHandler);
+
+ return new GeneratorConfigFileContent(
+ saxHandler.getGenerators(),
+ saxHandler.getMergepointMappings());
+ }
+
+ /**
+ * The parsed content of a generator definition file.
+ * Contains the parsed generators and the isolated
+ * (i.e. outside generator context) mergepoints.
+ */
+ private static final class GeneratorConfigFileContent
+ {
+ /** The parsed generators. */
+ private List<Generator> generators;
+
+ /** The parsed isolated mergepoint mappings. */
+ private List<MergepointMapping> mergepointMappings;
+
+ /**
+ * Constructor.
+ *
+ * @param generators the parsed generators.
+ * @param mergepointMappings the isolated mergepoint mappings.
+ */
+ public GeneratorConfigFileContent(
+ List<Generator> generators,
+ List<MergepointMapping> mergepointMappings)
+ {
+ this.generators = generators;
+ this.mergepointMappings = mergepointMappings;
+ }
+
+ /**
+ * Returns the parsed generators.
+ *
+ * @return the parsed generators.
+ */
+ public List<Generator> getGenerators()
+ {
+ return generators;
+ }
+
+ /**
+ * Returns the parsed isolated mergepoint mappings.
+ *
+ * @return the isolated mergepoint mappings.
+ */
+ public List<MergepointMapping> getMergepointMappings()
+ {
+ return mergepointMappings;
+ }
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorSaxHandler.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorSaxHandler.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorSaxHandler.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,299 @@
+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 static org.apache.torque.gf.configuration.generator.GeneratorConfigurationTags.INPUT_ELEMENT_NAME_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.generator.GeneratorConfigurationTags.INPUT_TAG;
+import static org.apache.torque.gf.configuration.mergepoint.MergepointConfigurationTags.MERGEPOINT_TAG;
+
+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.mergepoint.MergepointSaxHandler;
+import org.apache.torque.gf.configuration.paths.ProjectPaths;
+import org.apache.torque.gf.generator.Generator;
+import org.apache.torque.gf.qname.QualifiedName;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Handles a generator declaration within the generator configuration.
+ * Base class for more specific handlers.
+ */
+public abstract class GeneratorSaxHandler extends DefaultHandler
+{
+ /** the logger for the class. */
+ private static Log log = LogFactory.getLog(GeneratorSaxHandler.class);
+
+ /**
+ * the name for the generator which configuration will be read in
+ * by the generated SaxHandlerFactory, or null if the name
+ * of the generator should be determined from the parsed XML.
+ */
+ private QualifiedName generatorName;
+
+ /** the generator to be configured. */
+ private Generator generator;
+
+ /** The access object for the configuration files, not null. */
+ private ConfigurationProvider configurationProvider;
+
+ /** The paths of the surrounding project, not null. */
+ private ProjectPaths projectPaths;
+
+ /** The available configuration handlers. */
+ private ConfigurationHandlers configurationHandlers;
+
+ /**
+ * The SAX handler for processing mergepoint declarations.
+ * Not null only if a mergepoint declaration is currently processed.
+ */
+ private MergepointSaxHandler mergepointSaxHandler;
+
+ /** whether we are past the end of the generator declaration. */
+ private boolean finished = false;
+
+ /**
+ * The raw name of the XML element which started the generator definition.
+ */
+ private String startTagRawName = null;
+
+ /**
+ * Creates a GeneratorSaxHandler.
+ *
+ * @param generatorName the name for the generator which configuration
+ * will be read in by the generated SaxHandlerFactory,
+ * or null if the name of the generator should be determined from
+ * the parsed XML.
+ * @param configurationProvider The access object for the configuration
+ * files, not null.
+ * @param projectPaths The paths of the surrounding project, not null.
+ * @param configurationHandlers the available configuration handlers,
+ * not null.
+ *
+ * @throws NullPointerException if an argument is null.
+ */
+ public GeneratorSaxHandler(
+ QualifiedName generatorName,
+ ConfigurationProvider configurationProvider,
+ ProjectPaths projectPaths,
+ ConfigurationHandlers configurationHandlers)
+ {
+ if (configurationProvider == null)
+ {
+ log.error("GeneratorSaxHandler: "
+ + " configurationProvider is null");
+ throw new NullPointerException("configurationProvider is null");
+ }
+ if (projectPaths == null)
+ {
+ log.error("GeneratorSaxHandler: "
+ + " projectPaths is null");
+ throw new NullPointerException("projectPaths is null");
+ }
+ if (configurationHandlers == null)
+ {
+ log.error("GeneratorSaxHandler: "
+ + " configurationHandlers is null");
+ throw new NullPointerException("configurationHandlers is null");
+ }
+ this.generatorName = generatorName;
+ 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 (startTagRawName == null)
+ {
+ startTagRawName = rawName;
+ generator = createGenerator(
+ generatorName,
+ uri,
+ localName,
+ rawName,
+ attributes);
+ }
+ else if (INPUT_TAG.equals(rawName))
+ {
+ String element = attributes.getValue(INPUT_ELEMENT_NAME_ATTRIBUTE);
+ if (element == null)
+ {
+ throw new SAXException("The attribute "
+ + INPUT_ELEMENT_NAME_ATTRIBUTE
+ + " must be set for the tag "
+ + INPUT_TAG);
+ }
+ generator.setInputElementName(element);
+ }
+ else if (MERGEPOINT_TAG.equals(rawName))
+ {
+ mergepointSaxHandler = new MergepointSaxHandler(
+ configurationProvider,
+ projectPaths,
+ configurationHandlers);
+ mergepointSaxHandler.startElement(uri, localName, rawName, attributes);
+ }
+ else if (mergepointSaxHandler != null)
+ {
+ mergepointSaxHandler.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 (mergepointSaxHandler != null)
+ {
+ mergepointSaxHandler.endElement(uri, localName, rawName);
+ if (mergepointSaxHandler.isFinished())
+ {
+ try
+ {
+ generator.addMergepointMapping(
+ mergepointSaxHandler.getMergepointMapping());
+ }
+ catch (ConfigurationException e)
+ {
+ throw new SAXException(
+ "Could not get mergepoint mapping from the "
+ + "mergepoint Sax handler",
+ e);
+ }
+ mergepointSaxHandler = null;
+ }
+ }
+ else if (startTagRawName.equals(rawName))
+ {
+ finished = true;
+ }
+ }
+
+ /**
+ * @param generatorName the name for the generator which configuration
+ * will be read in by the generated SaxHandlerFactory,
+ * or null if the name of the generator should be determined from
+ * the parsed xml.
+ * @param uri - The Namespace URI, or the empty string if the
+ * element has no Namespace URI or if Namespace processing is not
+ * being performed.
+ * @param localName - The local name (without prefix), or
+ * the empty string if Namespace processing is not being performed.
+ * @param rawName - The qualified name (with prefix), or the empty string if
+ * qualified names are not available.
+ * @param attributes - The attributes attached to the element.
+ * If there are no attributes, it shall be an empty Attributes
+ * object.
+ *
+ * @return the generator, not null.
+ *
+ * @throws SAXException if the generator cannot be created.
+ */
+ protected abstract Generator createGenerator(
+ QualifiedName generatorName,
+ String uri,
+ String localName,
+ String rawName,
+ Attributes attributes)
+ throws SAXException;
+
+ /**
+ * Returns the generator being configured.
+ *
+ * @return the generator, not null.
+ */
+ public Generator getGenerator()
+ {
+ return generator;
+ }
+
+ /**
+ * Returns whether we are currently processing a mergepoint tag.
+ *
+ * @return true if we are currently processing a mergepoint tag,
+ * false otherwise.
+ */
+ protected boolean isProcessingMergepointTag()
+ {
+ return (mergepointSaxHandler != null);
+ }
+
+ /**
+ * Returns whether we are past the end of the generator configuration XML
+ * snippet which we are parsing.
+ *
+ * @return true if the whole snippet has been processed, false otherwise.
+ */
+ public boolean isFinished()
+ {
+ return finished;
+ }
+
+ /**
+ * Returns the ConfigurationProvider.
+ *
+ * @return the ConfigurationProvider, not null.
+ */
+ public ConfigurationProvider getConfigurationProvider()
+ {
+ return configurationProvider;
+ }
+
+ /**
+ * Returns the paths of the surrounding project.
+ *
+ * @return the paths of the surrounding project, not null.
+ */
+ public ProjectPaths getProjectPaths()
+ {
+ return projectPaths;
+ }
+
+ /**
+ * Returns the configuration handlers.
+ *
+ * @return the configuration handlers, not null.
+ */
+ public ConfigurationHandlers getConfigurationHandlers()
+ {
+ return configurationHandlers;
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorSaxHandlerFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorSaxHandlerFactory.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorSaxHandlerFactory.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorSaxHandlerFactory.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,69 @@
+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 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.qname.QualifiedName;
+import org.xml.sax.SAXException;
+
+/**
+ * Classes implementing this interface are responsible for creating
+ * <code>GeneratorSaxHandler</code>s for a specific generator type.
+ */
+public abstract interface GeneratorSaxHandlerFactory
+{
+ /**
+ * Returns the generator type handled by the GeneratorSaxHandlers which are
+ * created by this factory.
+ *
+ * @return the type of the generators, not null.
+ */
+ String getType();
+
+ /**
+ * Returns a GeneratorSaxHandler for reading in the configuration of
+ * a generator. The SAX Handler is used as a delegate handler
+ * whenever a generator element with the matching type
+ * is encountered in a generator configuration file.
+ *
+ * @param generatorName the name for the generator which configuration
+ * will be read in by the generated SaxHandlerFactory,
+ * or null if the name of the generator should be determined from
+ * the parsed xml.
+ * @param configurationProvider The access object for the configuration
+ * files, not null.
+ * @param projectPaths The paths of the surrounding project, not null.
+ * @param configurationHandlers the available configuration handlers,
+ * not null.
+ *
+ * @return a SAX delegate handler for parsing the configuration with the
+ * given type.
+ * @throws SAXException if the SAX Handler for the generator can
+ * not be created from the given XML element.
+ */
+ GeneratorSaxHandler getGeneratorSaxHandler(
+ QualifiedName generatorName,
+ ConfigurationProvider configurationProvider,
+ ProjectPaths projectPaths,
+ ConfigurationHandlers configurationHandlers)
+ throws SAXException;
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/JavaGeneratorSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/JavaGeneratorSaxHandler.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/JavaGeneratorSaxHandler.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/JavaGeneratorSaxHandler.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,345 @@
+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 static org.apache.torque.gf.configuration.generator.GeneratorConfigurationTags.GENERATOR_CLASS_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.generator.GeneratorConfigurationTags.GENERATOR_NAME_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.mergepoint.MergepointConfigurationTags.MERGEPOINT_TAG;
+import static org.apache.torque.gf.configuration.generator.GeneratorConfigurationTags.INPUT_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.ConfigurationHandlers;
+import org.apache.torque.gf.configuration.ConfigurationProvider;
+import org.apache.torque.gf.configuration.paths.ProjectPaths;
+import org.apache.torque.gf.generator.Generator;
+import org.apache.torque.gf.qname.QualifiedName;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ * Handles a declaration of a java generator within a generator configuration
+ * file.
+ */
+class JavaGeneratorSaxHandler extends GeneratorSaxHandler
+{
+ /** The logger of the class. */
+ private static Log log = LogFactory.getLog(JavaGeneratorSaxHandler.class);
+
+ /** the name of the property which is currently processed. */
+ private String propertyName;
+
+ /** The value of the property which is currently processed. */
+ private StringBuffer propertyValue;
+
+ /** The current nesting level inside the processed element. */
+ private int level = 0;
+
+ /**
+ * Constructor.
+ *
+ * @param generatorName the name for the generator which configuration
+ * will be read in by the generated SaxHandlerFactory,
+ * or null if the name of the generator should be determined from
+ * the parsed xml.
+ * @param configurationProvider The access object for the configuration
+ * files, not null.
+ * @param projectPaths The paths of the surrounding project, not null.
+ * @param configurationHandlers the available configuration handlers,
+ * not null.
+ *
+ * @throws SAXException if an error occurs during creation of the generator.
+ */
+ public JavaGeneratorSaxHandler(
+ QualifiedName generatorName,
+ ConfigurationProvider configurationProvider,
+ ProjectPaths projectPaths,
+ ConfigurationHandlers configurationHandlers)
+ throws SAXException
+ {
+ super(generatorName,
+ configurationProvider,
+ projectPaths,
+ configurationHandlers);
+ }
+
+ /**
+ * Instantiates a java generator.
+ *
+ * @param generatorName the name for the generator which configuration
+ * will be read in by the generated SaxHandlerFactory,
+ * or null if the name of the generator should be determined from
+ * the parsed xml.
+ * @param uri - The Namespace URI, or the empty string if the
+ * element has no Namespace URI or if Namespace processing is not
+ * being performed.
+ * @param localName - The local name (without prefix), or
+ * the empty string if Namespace processing is not being performed.
+ * @param rawName - The qualified name (with prefix), or the empty string if
+ * qualified names are not available.
+ * @param attributes - The attributes attached to the element.
+ * If there are no attributes, it shall be an empty Attributes
+ * object.
+ *
+ * @return the created generator, not null.
+ *
+ * @throws SAXException if an error occurs during creation.
+ */
+ protected Generator createGenerator(
+ QualifiedName generatorName,
+ String uri,
+ String localName,
+ String rawName,
+ Attributes attributes)
+ throws SAXException
+ {
+ if (generatorName == null)
+ {
+ String nameAttribute
+ = attributes.getValue(GENERATOR_NAME_ATTRIBUTE);
+ if (nameAttribute == null)
+ {
+ throw new SAXException("The attribute "
+ + GENERATOR_NAME_ATTRIBUTE
+ + " must be set on the element "
+ + rawName
+ + " for Java Generators");
+ }
+ generatorName = new QualifiedName(nameAttribute);
+ }
+
+
+ String className;
+ {
+ className = attributes.getValue(GENERATOR_CLASS_ATTRIBUTE);
+ if (className == null)
+ {
+ throw new SAXException("The attribute "
+ + GENERATOR_CLASS_ATTRIBUTE
+ + " must be set on the element "
+ + rawName
+ + " for java Generators");
+ }
+ }
+
+ Class<?> generatorClass;
+ try
+ {
+ generatorClass = Class.forName(className);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new SAXException(
+ "Error while initializing the java generator "
+ + generatorName
+ + " : Could not load class " + className, e);
+ }
+ catch (ExceptionInInitializerError e)
+ {
+ log.error(
+ "Error while initializing the java generator "
+ + generatorName
+ + " : Could not initialize class " + className
+ + " : " + e.getMessage());
+ throw e;
+ }
+ catch (LinkageError e)
+ {
+ log.error(
+ "Error while initializing the java generator "
+ + generatorName
+ + " : Could not link class " + className
+ + " : " + e.getMessage());
+ throw e;
+ }
+
+ Generator result;
+ try
+ {
+ Constructor<?> constructor
+ = generatorClass.getConstructor(QualifiedName.class);
+ result = (Generator) constructor.newInstance(generatorName);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new SAXException(
+ "Error while instantiating the java generator "
+ + generatorName
+ + " : The class " + className
+ + " has no constructor which takes a qualified name",
+ e);
+ }
+ catch (ClassCastException e)
+ {
+ throw new SAXException(
+ "Error while instantiating the java generator "
+ + generatorName
+ + " : The class " + className
+ + " is not an instance of "
+ + Generator.class.getName(),
+ e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new SAXException(
+ "Error while instantiating the java generator "
+ + generatorName
+ + " : The constructor of class "
+ + className + " could not be accessed",
+ e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new SAXException(
+ "Error while instantiating the java generator "
+ + generatorName
+ + " : The constructor of class "
+ + className + " could not be called",
+ e);
+ }
+ catch (InstantiationException e)
+ {
+ throw new SAXException(
+ "Error while instantiating the java generator "
+ + generatorName
+ + " : 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 the java generator "
+ + generatorName
+ + " : The security manager denies instantiation",
+ e);
+ }
+
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void startElement(
+ String uri,
+ String localName,
+ String rawName,
+ Attributes attributes)
+ throws SAXException
+ {
+ level++;
+ if ((level == 2 && MERGEPOINT_TAG.equals(rawName))
+ || super.isProcessingMergepointTag())
+ {
+ super.startElement(uri, localName, rawName, attributes);
+ }
+ else if (level == 2 && INPUT_TAG.equals(rawName))
+ {
+ super.startElement(uri, localName, rawName, attributes);
+ }
+ else if (level > 1)
+ {
+ propertyName = rawName;
+ propertyValue = new StringBuffer();
+ }
+ else
+ {
+ super.startElement(uri, localName, rawName, attributes);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void endElement(String uri, String localName, String rawName)
+ throws SAXException
+ {
+ level--;
+ if (propertyName != null)
+ {
+ if (!PropertyUtils.isWriteable(getGenerator(), propertyName))
+ {
+ throw new SAXException("No setter found for property "
+ + propertyName
+ + " in class "
+ + getGenerator().getClass().getName());
+ }
+ try
+ {
+ BeanUtils.copyProperty(
+ getGenerator(), propertyName, propertyValue.toString());
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new SAXException("error while setting Property "
+ + propertyName
+ + " for java generator "
+ + getGenerator().getName()
+ + " with value "
+ + propertyValue.toString(),
+ e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new SAXException("error while setting Property "
+ + propertyName
+ + " for java generator "
+ + getGenerator().getName()
+ + " with value "
+ + propertyValue.toString(),
+ e);
+ }
+ propertyName = null;
+ propertyValue = null;
+ }
+ else
+ {
+ super.endElement(uri, localName, rawName);
+ }
+ }
+
+ /**
+ * {@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]);
+ }
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/JavaGeneratorSaxHandlerFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/JavaGeneratorSaxHandlerFactory.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/JavaGeneratorSaxHandlerFactory.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/JavaGeneratorSaxHandlerFactory.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,80 @@
+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 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.qname.QualifiedName;
+import org.xml.sax.SAXException;
+
+/**
+ * Creates Java generator SAX handlers.
+ */
+public class JavaGeneratorSaxHandlerFactory
+ implements GeneratorSaxHandlerFactory
+{
+ /**
+ * The type of the generators which can be processed by the
+ * GeneratorSaxHandlers created by this factory.
+ */
+ private static final String GENERATOR_TYPE = "javaGenerator";
+
+ /**
+ * Returns the generator type which can be handled by the
+ * GeneratorSaxHandlers created by this factory.
+ * @return "javaGenerator".
+ */
+ public String getType()
+ {
+ return GENERATOR_TYPE;
+ }
+
+ /**
+ * Returns a JavaGeneratorSaxHandler for reading the configuration of
+ * Java generators. This implementation uses the provided name
+ * as generator name.
+ *
+ * @param generatorName the name for the generator which configuration
+ * will be read in by the generated SaxHandlerFactory,
+ * or null if the name of the generator should be determined from
+ * the parsed XML.
+ * @param configurationProvider The access object for the configuration
+ * files, not null.
+ * @param projectPaths The paths of the surrounding project, not null.
+ * @param configurationHandlers the available configuration handlers,
+ * not null.
+ *
+ * @return a new JavaGeneratorSaxHandler.
+ */
+ public final GeneratorSaxHandler getGeneratorSaxHandler(
+ QualifiedName generatorName,
+ ConfigurationProvider configurationProvider,
+ ProjectPaths projectPaths,
+ ConfigurationHandlers configurationHandlers)
+ throws SAXException
+ {
+ return new JavaGeneratorSaxHandler(
+ generatorName,
+ configurationProvider,
+ projectPaths,
+ configurationHandlers);
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/VelocityGeneratorSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/VelocityGeneratorSaxHandler.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/VelocityGeneratorSaxHandler.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/VelocityGeneratorSaxHandler.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,162 @@
+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 static org.apache.torque.gf.configuration.generator.GeneratorConfigurationTags.GENERATOR_ENCODING_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.generator.GeneratorConfigurationTags.GENERATOR_NAME_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.generator.GeneratorConfigurationTags.GENERATOR_OPTIONS_IN_CONTEXT_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.generator.GeneratorConfigurationTags.GENERATOR_PATH_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.generator.GeneratorConfigurationTags.GENERATOR_SOURCE_ATTRIBUTES_IN_CONTEXT_ATTRIBUTE;
+import static org.apache.torque.gf.configuration.generator.GeneratorConfigurationTags.GENERATOR_VARIABLES_IN_CONTEXT_ATTRIBUTE;
+
+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.SaxHelper;
+import org.apache.torque.gf.configuration.paths.ProjectPaths;
+import org.apache.torque.gf.qname.QualifiedName;
+import org.apache.torque.gf.template.velocity.VelocityGenerator;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ * Handles a declaration of a velocity generator within a generator
+ * configuration file.
+ */
+class VelocityGeneratorSaxHandler extends GeneratorSaxHandler
+{
+ /**
+ * Constructor.
+ *
+ * @param generatorName the name for the generator which configuration
+ * will be read in by the generated SaxHandlerFactory,
+ * or null if the name of the generator should be determined from
+ * the parsed XML.
+ * @param configurationProvider The access object for the configuration
+ * files, not null.
+ * @param projectPaths The paths of the surrounding project, not null.
+ * @param configurationHandlers the available configuration handlers,
+ * not null.
+ *
+ * @throws SAXException if an error occurs during creation of the generator.
+ */
+ public VelocityGeneratorSaxHandler(
+ QualifiedName generatorName,
+ ConfigurationProvider configurationProvider,
+ ProjectPaths projectPaths,
+ ConfigurationHandlers configurationHandlers)
+ throws SAXException
+ {
+ super(generatorName,
+ configurationProvider,
+ projectPaths,
+ configurationHandlers);
+ }
+
+ /**
+ * Instantiates and configures a velocity generator.
+ *
+ * @param generatorName the name for the generator which configuration
+ * will be read in by the generated SaxHandlerFactory,
+ * or null if the name of the generator should be determined from
+ * the parsed xml.
+ * @param uri - The Namespace URI, or the empty string if the
+ * element has no Namespace URI or if Namespace processing is not
+ * being performed.
+ * @param localName - The local name (without prefix), or
+ * the empty string if Namespace processing is not being performed.
+ * @param rawName - The qualified name (with prefix), or the empty string if
+ * qualified names are not available.
+ * @param attributes - The attributes attached to the element.
+ * If there are no attributes, it shall be an empty Attributes
+ * object.
+ *
+ * @return the created generator, not null.
+ *
+ * @throws SAXException if an error occurs during creation.
+ */
+ protected VelocityGenerator createGenerator(
+ QualifiedName generatorName,
+ String uri,
+ String localName,
+ String rawName,
+ Attributes attributes)
+ throws SAXException
+ {
+ if (generatorName == null)
+ {
+ String nameAttribute
+ = attributes.getValue(GENERATOR_NAME_ATTRIBUTE);
+ if (nameAttribute == null)
+ {
+ throw new SAXException("The attribute "
+ + GENERATOR_NAME_ATTRIBUTE
+ + " must be set on the element "
+ + rawName
+ + " for Velocity Generators");
+ }
+ generatorName = new QualifiedName(nameAttribute);
+ }
+
+ String encoding = attributes.getValue(GENERATOR_ENCODING_ATTRIBUTE);
+ String path = attributes.getValue(GENERATOR_PATH_ATTRIBUTE);
+
+ try
+ {
+ VelocityGenerator result
+ = new VelocityGenerator(
+ generatorName,
+ getConfigurationProvider(),
+ path,
+ encoding);
+ Boolean optionsInContext = SaxHelper.getBooleanAttribute(
+ GENERATOR_OPTIONS_IN_CONTEXT_ATTRIBUTE,
+ attributes,
+ "the velocityGenerator" + generatorName);
+ if (optionsInContext != null)
+ {
+ result.setOptionsInContext(optionsInContext);
+ }
+ Boolean sourceElementAttributesInContext
+ = SaxHelper.getBooleanAttribute(
+ GENERATOR_SOURCE_ATTRIBUTES_IN_CONTEXT_ATTRIBUTE,
+ attributes,
+ "the velocityGenerator" + generatorName);
+ if (sourceElementAttributesInContext != null)
+ {
+ result.setSourceAttributesInContext(
+ sourceElementAttributesInContext);
+ }
+ Boolean variablesInContext = SaxHelper.getBooleanAttribute(
+ GENERATOR_VARIABLES_IN_CONTEXT_ATTRIBUTE,
+ attributes,
+ "the velocityGenerator" + generatorName);
+ if (variablesInContext != null)
+ {
+ result.setVariablesInContext(variablesInContext);
+ }
+ return result;
+ }
+ catch (ConfigurationException e)
+ {
+ throw new SAXException(e);
+ }
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/VelocityGeneratorSaxHandlerFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/VelocityGeneratorSaxHandlerFactory.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/VelocityGeneratorSaxHandlerFactory.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/VelocityGeneratorSaxHandlerFactory.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,80 @@
+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 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.qname.QualifiedName;
+import org.xml.sax.SAXException;
+
+/**
+ * Creates Velocity generator SAX handlers.
+ */
+public class VelocityGeneratorSaxHandlerFactory
+ implements GeneratorSaxHandlerFactory
+{
+ /**
+ * The type of the generators which can be processed by the
+ * GeneratorSaxHandlers created by this factory.
+ */
+ private static final String GENERATOR_TYPE = "velocityGenerator";
+
+ /**
+ * Returns the generator type which can be handled by the
+ * GeneratorSaxHandlers created by this factory.
+ * @return "velocityGenerator".
+ */
+ public String getType()
+ {
+ return GENERATOR_TYPE;
+ }
+
+ /**
+ * Returns a VelocityGeneratorSaxHandler for reading the configuration of
+ * Velocity generators. This implementation uses the provided name
+ * as generator name.
+ *
+ * @param generatorName the name for the generator which configuration
+ * will be read in by the generated SaxHandlerFactory,
+ * or null if the name of the generator should be determined from
+ * the parsed xml.
+ * @param configurationProvider The access object for the configuration
+ * files, not null.
+ * @param projectPaths The paths of the surrounding project, not null.
+ * @param configurationHandlers the available configuration handlers,
+ * not null.
+ *
+ * @return a new VelocityGeneratorSaxHandler.
+ */
+ public final GeneratorSaxHandler getGeneratorSaxHandler(
+ QualifiedName generatorName,
+ ConfigurationProvider configurationProvider,
+ ProjectPaths projectPaths,
+ ConfigurationHandlers configurationHandlers)
+ throws SAXException
+ {
+ return new VelocityGeneratorSaxHandler(
+ generatorName,
+ configurationProvider,
+ projectPaths,
+ configurationHandlers);
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/package.html
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/package.html?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/package.html (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/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>Configuring Torque-gf generators</title>
+ </head>
+ <body>
+ <p>
+ This package contains the classes for reading the generator mappings for
+ Torque-gf units of generation.
+ </p>
+ </body>
+</html>
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/mergepoint/ActionSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/mergepoint/ActionSaxHandler.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/mergepoint/ActionSaxHandler.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/mergepoint/ActionSaxHandler.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,130 @@
+package org.apache.torque.gf.configuration.mergepoint;
+
+/*
+ * 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.torque.gf.configuration.ConfigurationProvider;
+import org.apache.torque.gf.configuration.paths.ProjectPaths;
+import org.apache.torque.gf.control.action.MergepointAction;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * A SAX Handler which handles for the action element in mergepoints.
+ *
+ */
+public abstract class ActionSaxHandler extends DefaultHandler
+{
+ /** The logger of the class. */
+ private static Log log = LogFactory.getLog(ActionSaxHandler.class);
+
+ /** The action which configured by this handler, not null. */
+ private MergepointAction action;
+
+ /** The paths of the underlying project, not null. */
+ private ProjectPaths projectPaths;
+
+ /** The configuration provider for accessing the configuration, not null. */
+ private ConfigurationProvider configurationProvider;
+
+ /**
+ * Constructor.
+ *
+ * @param action paths of the underlying project, not null.
+ * @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 ActionSaxHandler(
+ MergepointAction action,
+ ConfigurationProvider configurationProvider,
+ ProjectPaths projectPaths)
+ {
+ if (action == null)
+ {
+ log.error("ActionSaxHandler: "
+ + " action is null");
+ throw new NullPointerException("Action is null");
+ }
+ if (configurationProvider == null)
+ {
+ log.error("ActionSaxHandler: "
+ + " configurationProvider is null");
+ throw new NullPointerException("configurationProvider is null");
+ }
+ if (projectPaths == null)
+ {
+ log.error("ActionSaxHandler: "
+ + " projectPaths is null");
+ throw new NullPointerException("projectPaths is null");
+ }
+ this.action = action;
+ this.configurationProvider = configurationProvider;
+ this.projectPaths = projectPaths;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void startElement(
+ String uri,
+ String localName,
+ String rawName,
+ Attributes attributes)
+ throws SAXException
+ {
+ throw new SAXException("unknown Element " + rawName);
+ }
+
+ /**
+ * Returns the action which was configured by this handler.
+ *
+ * @return the action configured by this handler, not null.
+ */
+ public MergepointAction getAction()
+ {
+ return action;
+ }
+
+ /**
+ * Returns the configuration provider used by this handler.
+ *
+ * @return the configuration provider, not null.
+ */
+ protected ConfigurationProvider getConfigurationProvider()
+ {
+ return configurationProvider;
+ }
+
+ /**
+ * Returns the project paths used by this handler.
+ *
+ * @return the project paths, not null.
+ */
+ protected ProjectPaths getProjectPaths()
+ {
+ return projectPaths;
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/mergepoint/ActionSaxHandlerFactories.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/mergepoint/ActionSaxHandlerFactories.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/mergepoint/ActionSaxHandlerFactories.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/mergepoint/ActionSaxHandlerFactories.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,110 @@
+package org.apache.torque.gf.configuration.mergepoint;
+
+/*
+ * 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.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.gf.configuration.ConfigurationException;
+
+/**
+ * A registry of ActionSaxHandlerFactories.
+ *
+ * $Id: $
+ */
+public class ActionSaxHandlerFactories
+{
+ /** The class log. */
+ private static Log log = LogFactory.getLog(ActionSaxHandlerFactories.class);
+
+ /**
+ * A map containing all known ActionSaxHandlerFactories,
+ * keyed by the type of the action.
+ */
+ private Map<String, ActionSaxHandlerFactory> actionSaxHandlerFactories
+ = new HashMap<String, ActionSaxHandlerFactory>();
+
+ /**
+ * Constructor. Registers the default Factories.
+ */
+ public ActionSaxHandlerFactories()
+ {
+ try
+ {
+ register(new TraverseAllActionSaxHandlerFactory());
+ register(new ApplyActionSaxHandlerFactory());
+ register(new OptionActionSaxHandlerFactory());
+ register(new SourceElementAttributeActionSaxHandlerFactory());
+ register(new OutputActionSaxHandlerFactory());
+ }
+ catch (ConfigurationException e)
+ {
+ // should not happen
+ log.error("caught ConfigurationException while registering "
+ + "the default Action Sax Handler Factories", e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Registers a handler for a new action type.
+ *
+ * @param factory the factory which handles the action of the
+ * given type.
+ *
+ * @throws ConfigurationException if a factory already exists
+ * for the type of the action.
+ */
+ public void register(
+ ActionSaxHandlerFactory factory)
+ throws ConfigurationException
+ {
+ ActionSaxHandlerFactory oldFactory
+ = actionSaxHandlerFactories.get(factory.getType());
+ if (oldFactory != null)
+ {
+ throw new ConfigurationException(
+ "Attempted to register an ActionSaxHandlerFactory "
+ + "of type "
+ + factory.getType()
+ + " and class "
+ + factory.getClass().getName()
+ + " : A factory with this type already exists, "
+ + " it has the class "
+ + oldFactory.getClass().getName());
+ }
+ actionSaxHandlerFactories.put(factory.getType(), factory);
+ }
+
+ /**
+ * Returns the ActionSaxHandlerFactory associated with the given type.
+ *
+ * @param type the type top look for, not null.
+ *
+ * @return the ActionSaxHandlerFactory associated with the given type,
+ * or null if no ActionSaxHandlerFactory exists for the given type.
+ */
+ public ActionSaxHandlerFactory getActionSaxHandlerFactory(String type)
+ {
+ return actionSaxHandlerFactories.get(type);
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/mergepoint/ActionSaxHandlerFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/mergepoint/ActionSaxHandlerFactory.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/mergepoint/ActionSaxHandlerFactory.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/mergepoint/ActionSaxHandlerFactory.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,78 @@
+package org.apache.torque.gf.configuration.mergepoint;
+
+/*
+ * 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.configuration.ConfigurationProvider;
+import org.apache.torque.gf.configuration.paths.ProjectPaths;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ * Classes implementing this interface are responsible for creating
+ * <code>ActionSaxHandler</code>s for a specific action type.
+ *
+ * When a action configuration needs to be parsed, a sax handler will read
+ * the type of the action and check it against the types of the registered
+ * ActionSaxHandlers. The first matching handler will then be used to parse
+ * the action configuration.
+ */
+public abstract interface ActionSaxHandlerFactory
+{
+ /**
+ * Returns the action type handled by the ActionSaxHandlers which are
+ * created by this factory.
+ *
+ * @return the type of the action, not null.
+ */
+ String getType();
+
+ /**
+ * Returns a ActionSaxHandler for reading in the configuration of
+ * an action. The SAX Handler is used as a delegate handler
+ * whenever an action element with the matching type
+ * is encountered in a configuration file.
+ *
+ * @param uri The namespace URI of the action element,
+ * or the empty string if the element has no namespace URI
+ * or if namespace processing is not being performed.
+ * @param localName The local name (without prefix), or
+ * the empty string if namespace processing is not being performed.
+ * @param qName The qualified name (with prefix, if present),
+ * or the empty string if qualified names are not available.
+ * @param attributes The attributes attached to the element.
+ * @param configurationProvider for accessing the configuration files,
+ * not null.
+ * @param projectPaths The organization of the surrounding project,
+ * not null.
+ *
+ * @return a SAX delegate handler for parsing the configuration with the
+ * given type.
+ * @throws SAXException if the SAX Handler for the generator can
+ * not be created from the given XML element.
+ */
+ ActionSaxHandler getActionSaxHandler(
+ String uri,
+ String localName,
+ String qName,
+ Attributes attributes,
+ ConfigurationProvider configurationProvider,
+ ProjectPaths projectPaths)
+ throws SAXException;
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org