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 [7/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/option/OptionsSaxHandler.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/OptionsSaxHandler.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/OptionsSaxHandler.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/OptionsSaxHandler.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,91 @@
+package org.apache.torque.gf.configuration.option;
+
+/*
+ * 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.xml.sax.helpers.DefaultHandler;
+
+/**
+ * A SAX handler for reading the options tag in the control configuration.
+ *
+ * $Id: $
+ */
+public class OptionsSaxHandler extends DefaultHandler
+{
+ /** The OptionsConfiguration to be filled by this SAX handler. */
+ private OptionsConfiguration optionsConfiguration;
+
+ /**
+ * Whether the SAX handler has finished reading the options configuration.
+ */
+ private boolean finished = false;
+
+ /**
+ * Constructor.
+ *
+ * @param optionsConfiguration the OptionsConfiguration to be filled,
+ * not null.
+ */
+ public OptionsSaxHandler(OptionsConfiguration optionsConfiguration)
+ {
+ if (optionsConfiguration == null)
+ {
+ throw new NullPointerException("optionsConfiguration is null");
+ }
+ this.optionsConfiguration = optionsConfiguration;
+ }
+
+ /**
+ * Returns the options configuration read by this SAX handler.
+ *
+ * @return the options configuration, not null.
+ *
+ * @throws IllegalStateException if the SAX handler has not yet finished
+ * reading the configuration.
+ */
+ public OptionsConfiguration getOptionsConfiguration()
+ {
+ if (!finished)
+ {
+ throw new IllegalStateException(
+ "Not finished reading the options configuration");
+ }
+ return optionsConfiguration;
+ }
+
+ /**
+ * Returns whether the SAX handler has finished reading the options
+ * configuration.
+ *
+ * @return true if whether the SAX handler has finished, false otherwise.
+ */
+ public boolean isFinished()
+ {
+ return finished;
+ }
+
+ /**
+ * Marks that the SAX handler has finished reading the options
+ * configuration.
+ */
+ void finished()
+ {
+ this.finished = true;
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/OptionsSaxHandlerFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/OptionsSaxHandlerFactory.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/OptionsSaxHandlerFactory.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/OptionsSaxHandlerFactory.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,56 @@
+package org.apache.torque.gf.configuration.option;
+
+/*
+ * 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.xml.sax.SAXException;
+
+/**
+ * Classes implementing this interface are responsible for creating
+ * <code>OptionsSaxHandler</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
+ * OptionsSaxHandlers. The first matching handler will then be used to parse
+ * the action configuration.
+ */
+public abstract interface OptionsSaxHandlerFactory
+{
+ /**
+ * 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 OptionsSaxHandler for reading the configuration of
+ * options. The SAX Handler is used as a delegate handler
+ * whenever an options element with the matching type
+ * is encountered in a configuration file.
+ *
+ * @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.
+ */
+ OptionsSaxHandler getOptionsSaxHandler()
+ throws SAXException;
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/PropertiesOptionConfiguration.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/PropertiesOptionConfiguration.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/PropertiesOptionConfiguration.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/PropertiesOptionConfiguration.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,97 @@
+package org.apache.torque.gf.configuration.option;
+
+/*
+ * 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.Collection;
+import java.util.Properties;
+
+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.ConfigurationProvider;
+import org.apache.torque.gf.option.Option;
+
+/**
+ * An option configuration which reads the options from a properties file.
+ *
+ * $Id: $
+ */
+public class PropertiesOptionConfiguration extends FileOptionsConfiguration
+{
+ /** The class log. */
+ private static Log log
+ = LogFactory.getLog(PropertiesOptionConfiguration.class);
+
+ /**
+ * Reads the options from the property file given in the path and
+ * returns them.
+ *
+ * @param configurationProvider the provider to access configuration files,
+ * not null.
+ *
+ * @return the options contained in the file, not null.
+ *
+ * @throws ConfigurationException if the file cannot be accessed or parsed.
+ */
+ public Collection<Option> getOptions(
+ ConfigurationProvider configurationProvider)
+ throws ConfigurationException
+ {
+ Properties properties = new Properties();
+ InputStream optionsInputStream = null;
+ try
+ {
+ optionsInputStream
+ = configurationProvider.getOptionsInputStream(getPath());
+ properties.load(optionsInputStream);
+ }
+ catch (IOException e)
+ {
+ throw new ConfigurationException("Error reading options file "
+ + getPath(),
+ e);
+ }
+ catch (RuntimeException e)
+ {
+ throw new ConfigurationException("Error reading options file "
+ + getPath(),
+ e);
+ }
+ finally
+ {
+ if (optionsInputStream != null)
+ {
+ try
+ {
+ optionsInputStream.close();
+ }
+ catch (IOException e)
+ {
+ log.warn("Could not close OptionsInputStream "
+ + optionsInputStream,
+ e);
+ }
+ }
+ }
+ return toOptions(properties);
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/PropertiesOptionsSaxHandlerFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/PropertiesOptionsSaxHandlerFactory.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/PropertiesOptionsSaxHandlerFactory.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/PropertiesOptionsSaxHandlerFactory.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,56 @@
+package org.apache.torque.gf.configuration.option;
+
+/*
+ * 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.xml.sax.SAXException;
+
+/**
+ * A Factory which creates a SAX handler for properties options.
+ */
+public class PropertiesOptionsSaxHandlerFactory
+ implements OptionsSaxHandlerFactory
+{
+ /** The type of the configuration. */
+ private static final String TYPE = "propertiesOptions";
+
+
+ /**
+ * Returns the options type which can be handled by the
+ * OptionsSaxHandlers created by this factory.
+ *
+ * @return "propertiesOptions".
+ */
+ public String getType()
+ {
+ return TYPE;
+ }
+
+ /**
+ * Returns a FileOptionsSaxHandler for reading the configuration of
+ * XML options.
+ *
+ * @return a new FileOptionsSaxHandler.
+ */
+ public final FileOptionsSaxHandler getOptionsSaxHandler()
+ throws SAXException
+ {
+ return new FileOptionsSaxHandler(new PropertiesOptionConfiguration());
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/XmlOptionConfiguration.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/XmlOptionConfiguration.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/XmlOptionConfiguration.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/XmlOptionConfiguration.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,98 @@
+package org.apache.torque.gf.configuration.option;
+
+/*
+ * 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.Collection;
+import java.util.Properties;
+
+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.ConfigurationProvider;
+import org.apache.torque.gf.option.Option;
+
+/**
+ * An option configuration which reads the options from a XML file.
+ *
+ * $Id: $
+ */
+public class XmlOptionConfiguration extends FileOptionsConfiguration
+{
+ /** The class log. */
+ private static Log log = LogFactory.getLog(XmlOptionConfiguration.class);
+
+ /**
+ * Reads the options from the XML file given in the path and
+ * returns them.
+ *
+ * @param configurationProvider the provider to access configuration files,
+ * not null.
+ *
+ * @return the options contained in the file, not null.
+ *
+ * @throws ConfigurationException if the file cannot be accessed or parsed.
+ */
+ public Collection<Option> getOptions(
+ ConfigurationProvider configurationProvider)
+ throws ConfigurationException
+ {
+ Properties properties = new Properties();
+ InputStream optionsInputStream = null;
+ try
+ {
+ optionsInputStream
+ = configurationProvider.getOptionsInputStream(getPath());
+ properties.loadFromXML(optionsInputStream);
+ }
+ catch (IOException e)
+ {
+ throw new ConfigurationException("Error reading options file "
+ + getPath(),
+ e);
+
+ }
+ catch (RuntimeException e)
+ {
+ throw new ConfigurationException("Error reading options file "
+ + getPath(),
+ e);
+
+ }
+ finally
+ {
+ if (optionsInputStream != null)
+ {
+ try
+ {
+ optionsInputStream.close();
+ }
+ catch (IOException e)
+ {
+ log.warn("Could not close OptionsInputStream "
+ + optionsInputStream,
+ e);
+ }
+ }
+ }
+ return toOptions(properties);
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/XmlOptionsSaxHandlerFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/XmlOptionsSaxHandlerFactory.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/XmlOptionsSaxHandlerFactory.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/XmlOptionsSaxHandlerFactory.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,56 @@
+package org.apache.torque.gf.configuration.option;
+
+/*
+ * 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.xml.sax.SAXException;
+
+/**
+ * A Factory which creates a SAX handler for XML Options.
+ */
+public class XmlOptionsSaxHandlerFactory
+ implements OptionsSaxHandlerFactory
+{
+ /** The type of the configuration. */
+ private static final String TYPE = "xmlOptions";
+
+
+ /**
+ * Returns the options type which can be handled by the
+ * OptionsSaxHandlers created by this factory.
+ *
+ * @return "xmlOptions".
+ */
+ public String getType()
+ {
+ return TYPE;
+ }
+
+ /**
+ * Returns a FileOptionsSaxHandler for reading the configuration of
+ * XML options.
+ *
+ * @return a new FileOptionsSaxHandler.
+ */
+ public final FileOptionsSaxHandler getOptionsSaxHandler()
+ throws SAXException
+ {
+ return new FileOptionsSaxHandler(new XmlOptionConfiguration());
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/package.html
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/package.html?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/package.html (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/option/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 options</title>
+ </head>
+ <body>
+ <p>
+ This package contains the classes for reading the options for
+ Torque-gf units of generation.
+ </p>
+ </body>
+</html>
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/package.html
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/package.html?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/package.html (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/package.html Tue Feb 16 17:15:43 2010
@@ -0,0 +1,25 @@
+<!--
+ 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</title>
+ </head>
+ <body>
+ <p>
+ This package contains the classes for configuring Torque-gf.
+ </p>
+ </body>
+</html>
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/CustomProjectPaths.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/CustomProjectPaths.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/CustomProjectPaths.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/CustomProjectPaths.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,270 @@
+package org.apache.torque.gf.configuration.paths;
+
+/*
+ * 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.File;
+
+/**
+ * Implementation of ProjectPaths with custom paths.
+ */
+public class CustomProjectPaths implements ProjectPaths
+{
+ /**
+ * The configuration root directory.
+ */
+ private File configurationDir;
+
+ /**
+ * the configuration root package.
+ */
+ private String configurationPackage;
+
+ /**
+ * The directory where the source files are located.
+ */
+ private File sourceDir;
+
+ /**
+ * The output directory for the files which are generated each time anew.
+ */
+ private File newFileTargetDir;
+
+ /**
+ * The output directory for the files which are modified on generation.
+ */
+ private File modifiedFileTargetDir;
+
+ /**
+ * Copy-constructor.
+ * @param toCopy the default project paths to copy, not null.
+ *
+ * @throws NullPointerException if toCopy is null.
+ */
+ public CustomProjectPaths(ProjectPaths toCopy)
+ {
+ this.configurationDir = toCopy.getConfigurationPath();
+ this.configurationPackage = toCopy.getConfigurationPackage();
+ this.sourceDir = toCopy.getDefaultSourcePath();
+ this.newFileTargetDir = toCopy.getNewFileTargetPath();
+ this.modifiedFileTargetDir = toCopy.getModifiedFileTargetPath();
+ }
+
+ /**
+ * Constructor.
+ * @param configurationDir the configuration directory for the Torque
+ * generator files, or null.
+ * @param sourceDir the default directory for the source files, or null.
+ * @param targetDir the default directory for the generated files, or null.
+ */
+ public CustomProjectPaths(
+ File configurationDir,
+ String configurationPackage,
+ File sourceDir,
+ File newFileTargetDir,
+ File modifiedFileTargetDir)
+ {
+ this.configurationDir = configurationDir;
+ this.configurationPackage = configurationPackage;
+ this.sourceDir = sourceDir;
+ this.newFileTargetDir = newFileTargetDir;
+ this.modifiedFileTargetDir = modifiedFileTargetDir;
+ }
+
+ /**
+ * Sets the root directory for the Torque generator files,
+ * absolute or relative to the project root.
+ *
+ * @param configurationDir the configuration directory for the Torque
+ * generator files, null to invalidate the current setting.
+ */
+ public void setConfigurationDir(File configurationDir)
+ {
+ this.configurationDir = configurationDir;
+ }
+
+ /**
+ * Sets the root package for the Torque generator files,
+ * relative to the project root.
+ *
+ * @param configurationPackage the configuration root package
+ * for the Torque generator files.
+ */
+ public void setConfigurationPackage(String configurationPackage)
+ {
+ this.configurationPackage = configurationPackage;
+ }
+
+ /**
+ * Sets the default directory for the source files,
+ * relative to the current directory, or absolute.
+ * "Default" means that the setting can be overridden in a unit of
+ * generation.
+ *
+ * @param sourceDir the default directory for the source files,
+ * null to invalidate the current setting.
+ */
+ public void setSourceDir(File sourceDir)
+ {
+ this.sourceDir = sourceDir;
+ }
+
+ /**
+ * Sets the default directory for the files which are generated each time
+ * anew, relative to the current directory, or absolute.
+ *
+ * @param targetDir the directory for the files which are generated
+ * each time anew, null to invalidate the current setting.
+ */
+ public void setNewFileTargetDir(File targetDir)
+ {
+ this.newFileTargetDir = targetDir;
+ }
+
+ /**
+ * Sets the default directory for the files which are modified on
+ * generation, relative to the current directory, or absolute.
+ *
+ * @param targetDir the default directory for the generated files,
+ * null to invalidate the current setting.
+ */
+ public void setModifiedFileTargetDir(File targetDir)
+ {
+ this.modifiedFileTargetDir = targetDir;
+ }
+
+ /**
+ * Returns the root directory for the Torque generator files,
+ * relative to the project root.
+ *
+ * @return the directory for the Torque generator files, not null.
+ * @throws IllegalStateException if one of the required parameters
+ * is not set.
+ */
+ public File getConfigurationPath()
+ {
+ if (!isInit())
+ {
+ throw new IllegalStateException(
+ "CustomProjectPaths is not initialized");
+ }
+ return configurationDir;
+ }
+
+ /**
+ * Returns the root package of the Torque generator files.
+ *
+ * @return the root package of the Torque generator files.
+ * @throws IllegalStateException if one of the required parameters
+ * is not set.
+ */
+ public String getConfigurationPackage()
+ {
+ if (!isInit())
+ {
+ throw new IllegalStateException(
+ "CustomProjectPaths is not initialized");
+ }
+ return configurationPackage;
+ }
+
+
+ /**
+ * Returns the default directory for the source files,
+ * relative to the project root. "Default" means that the setting
+ * can be overridden in a unit of generation.
+ *
+ * @return the directory for the source files, not null.
+ * @throws IllegalStateException if one of the required parameters
+ * is not set.
+ */
+ public File getDefaultSourcePath()
+ {
+ if (!isInit())
+ {
+ throw new IllegalStateException(
+ "CustomProjectPaths is not initialized");
+ }
+ return sourceDir;
+ }
+
+ /**
+ * Returns the default subdirectory for files which are generated each
+ * time anew, relative to the project root.
+ *
+ * @return the subdirectory for the files which are generated each
+ * time anew, not null.
+ * @throws IllegalStateException if one of the required parameters
+ * is not set.
+ */
+ public File getNewFileTargetPath()
+ {
+ if (!isInit())
+ {
+ throw new IllegalStateException(
+ "CustomProjectPaths is not initialized");
+ }
+ return newFileTargetDir;
+ }
+
+ /**
+ * Returns the default subdirectory for files which are not generated each
+ * time anew, relative to the project root.
+ *
+ * @return the subdirectory for the files which are not generated each
+ * time anew, not null.
+ * @throws IllegalStateException if one of the required parameters
+ * is not set.
+ */
+ public File getModifiedFileTargetPath()
+ {
+ if (!isInit())
+ {
+ throw new IllegalStateException(
+ "CustomProjectPaths is not initialized");
+ }
+ return modifiedFileTargetDir;
+ }
+
+ /**
+ * returns whether the current settings are valid.
+ *
+ * It is checked whether all necessary informations are set.
+ *
+ * @return true if the current settings are valid, false otherwise.
+ */
+ public boolean isInit()
+ {
+ return (configurationDir != null || configurationPackage != null)
+ && sourceDir != null
+ && newFileTargetDir != null
+ && modifiedFileTargetDir != null;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "(CustomProjectPaths: configurationDir=" + configurationDir
+ + ", configurationPackage=" + configurationPackage
+ + ", sourceDir=" + sourceDir
+ + ", newFileTargetDir=" + newFileTargetDir
+ + ", modifiedFileTargetDir=" + modifiedFileTargetDir
+ + ")";
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/DefaultTorqueGfPaths.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/DefaultTorqueGfPaths.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/DefaultTorqueGfPaths.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/DefaultTorqueGfPaths.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,77 @@
+package org.apache.torque.gf.configuration.paths;
+
+/*
+ * 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 default organization of the torque-gf directory.
+ * This is:<br/>
+ * - torque-gf root<br/>
+ * - - conf<br/>
+ * - - - control.xml<br/>
+ * - - generatorDefs<br/>
+ * - - templates<br/>
+ */
+public class DefaultTorqueGfPaths implements TorqueGfPaths
+{
+ /**
+ * The path to the control configuration file, relative to the
+ * configuration directory.
+ */
+ private static final String CONTROL_CONFIGURATION_FILE_NAME
+ = "control.xml";
+
+ /**
+ * The path to the template directory, relative to the torque-gf directory.
+ */
+ private static final String TEMPLATES_DIRECTORY = "templates";
+
+ /**
+ * The path to the configuration directory, relative to the
+ * torque-gf directory.
+ */
+ private static final String CONFIGURATION_DIRECTORY = "conf";
+
+ /**
+ * The path to the generator definitions directory, relative to the
+ * configuration root directory.
+ */
+ private static final String GENERATOR_DEFS_DIRECTORY
+ = "generatorDefs";
+
+ public String getControlConfigurationFile()
+ {
+ return CONTROL_CONFIGURATION_FILE_NAME;
+ }
+
+ public String getTemplateSubdirectory()
+ {
+ return TEMPLATES_DIRECTORY;
+ }
+
+ public String getConfigurationDirectory()
+ {
+ return CONFIGURATION_DIRECTORY;
+ }
+
+ public String getGeneratorDefDirectory()
+ {
+ return GENERATOR_DEFS_DIRECTORY;
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/Maven2DirectoryProjectPaths.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/Maven2DirectoryProjectPaths.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/Maven2DirectoryProjectPaths.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/Maven2DirectoryProjectPaths.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,64 @@
+package org.apache.torque.gf.configuration.paths;
+
+/*
+ * 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.File;
+
+/**
+ * Implementation of ProjectPaths if the configuration is located
+ * in a directory of a maven 2 project.
+ */
+public class Maven2DirectoryProjectPaths extends Maven2ProjectPaths
+{
+ /**
+ * Constructor.
+ *
+ * @param projectRoot path to the project root directory, not null.
+ * The path must either be absolute or relative to the current
+ * working directory.
+ */
+ public Maven2DirectoryProjectPaths(File projectRoot)
+ {
+ super(projectRoot);
+ }
+
+ /**
+ * Returns the subdirectory for the Torque generator files,
+ * relative to the project root.
+ *
+ * @return the subdirectory for the Torque generator files, not null.
+ */
+ @Override
+ public File getConfigurationPath()
+ {
+ return new File(getProjectRoot(), CONFIG_DIR);
+ }
+
+ /**
+ * Returns the package of the Torque generator files.
+ *
+ * @return null.
+ */
+ @Override
+ public String getConfigurationPackage()
+ {
+ return null;
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/Maven2JarProjectPaths.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/Maven2JarProjectPaths.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/Maven2JarProjectPaths.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/Maven2JarProjectPaths.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,78 @@
+package org.apache.torque.gf.configuration.paths;
+
+/*
+ * 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.File;
+
+/**
+ * Implementation of ProjectPaths if the configuration is located
+ * in a jar file inside of a Maven 2 project.
+ */
+public class Maven2JarProjectPaths extends Maven2ProjectPaths
+{
+ /**
+ * The path to the jar file, relative to the configuration root directory.
+ */
+ private String jarFileName;
+
+ /**
+ * Constructor.
+ *
+ * @param projectRoot path to the project root directory, not null.
+ * The path must either be absolute or relative to the current
+ * working directory.
+ * @param jarFileName the name of the jar file, relative to the
+ * configuration root directory.
+ */
+ public Maven2JarProjectPaths(File projectRoot, String jarFileName)
+ {
+ super(projectRoot);
+ if (jarFileName == null)
+ {
+ throw new NullPointerException("jarFileName must not be null");
+ }
+ this.jarFileName = jarFileName;
+ }
+
+ /**
+ * Returns the subdirectory for the Torque generator files,
+ * relative to the project root.
+ *
+ * @return the subdirectory for the Torque generator files, not null.
+ */
+ @Override
+ public File getConfigurationPath()
+ {
+ return new File(
+ getProjectRoot(),
+ CONFIG_DIR + jarFileName);
+ }
+
+ /**
+ * Returns the package of the Torque generator files.
+ *
+ * @return null.
+ */
+ @Override
+ public String getConfigurationPackage()
+ {
+ return null;
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/Maven2ProjectPaths.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/Maven2ProjectPaths.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/Maven2ProjectPaths.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/Maven2ProjectPaths.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,132 @@
+package org.apache.torque.gf.configuration.paths;
+
+/*
+ * 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.File;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Contains information of the default integration of the generator
+ * into a maven 2 project.
+ */
+public abstract class Maven2ProjectPaths implements ProjectPaths
+{
+ /** The log for the class. */
+ private static Log log
+ = LogFactory.getLog(Maven2ProjectPaths.class);
+
+ /**
+ * Default configuration root directory,
+ * relative to the project root.
+ */
+ protected static final String CONFIG_DIR = "src/main/torque-gf/";
+
+ /**
+ * Default generation source file directory,
+ * relative to the configuration root directory.
+ */
+ protected static final String SOURCE_DIR = CONFIG_DIR + "src";
+
+ /**
+ * Default generation target directory for new files,
+ * relative to the project root.
+ */
+ protected static final String NEW_FILE_TARGET_DIR
+ = "target/generated-sources";
+
+ /**
+ * Default generation target directory for modified files,
+ * relative to the project root.
+ */
+ protected static final String MODIFIED_FILE_TARGET_DIR
+ = "src/main/generated-sources";
+
+ /**
+ * the root directory of the whole maven2 project.
+ */
+ private File projectRoot;
+
+ /**
+ * Constructor.
+ *
+ * @param projectRoot path to the project root directory, not null.
+ * The path must either be absolute or relative to the current
+ * working directory.
+ *
+ * @throws NullPointerException if projectRoot is null.
+ */
+ protected Maven2ProjectPaths(File projectRoot)
+ {
+ if (projectRoot == null)
+ {
+ log.error("projectRoot is null");
+ throw new NullPointerException("projectRoot is null");
+ }
+ this.projectRoot = projectRoot;
+ }
+
+ public abstract File getConfigurationPath();
+
+ public abstract String getConfigurationPackage();
+
+ /**
+ * Returns the path to the source files.
+ *
+ * @return the path to for the source files, not null.
+ */
+ public File getDefaultSourcePath()
+ {
+ return new File(projectRoot, SOURCE_DIR);
+ }
+
+ /**
+ * Returns the default subdirectory for the files which are generated
+ * each time anew, relative to the project root.
+ *
+ * @return the subdirectory for the generated files, not null.
+ */
+ public File getNewFileTargetPath()
+ {
+ return new File(projectRoot, NEW_FILE_TARGET_DIR);
+ }
+
+ /**
+ * Returns the default subdirectory for files which are not generated
+ * each time anew, relative to the project root.
+ *
+ * @return the subdirectory for the generated files, not null.
+ */
+ public File getModifiedFileTargetPath()
+ {
+ return new File(projectRoot, MODIFIED_FILE_TARGET_DIR);
+ }
+
+ /**
+ * returns the root directory of the whole maven 2 project.
+ *
+ * @return the root directory of the whole project, not null.
+ */
+ protected File getProjectRoot()
+ {
+ return projectRoot;
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/ProjectPaths.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/ProjectPaths.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/ProjectPaths.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/ProjectPaths.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,86 @@
+package org.apache.torque.gf.configuration.paths;
+
+/*
+ * 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.File;
+
+/**
+ * Provides the default paths which the code generator needs to interact with
+ * its surrounding project.
+ * "Default" means that the settings can be overridden in a unit of generation.
+ * NB: This object does not contain any information about how the code generator
+ * configuration is organized internally.
+ */
+public interface ProjectPaths
+{
+ /**
+ * Returns the path to the generator configuration directory.
+ * The path must either be absolute or relative to the current working
+ * directory.
+ *
+ * @return the path to the generator configuration; may (but must not)
+ * be null if no configuration is contained in the surrounding
+ * project; must be null if the configuration is read from the
+ * class path.
+ */
+ File getConfigurationPath();
+
+ /**
+ * Returns the package of the generator configuration.
+ *
+ * @return the package to the generator configuration. Must be null
+ * if the configuration is read from the file system or from
+ * a jar file. Must not be null if the configuration is read
+ * from the class path.
+ */
+ String getConfigurationPackage();
+
+ /**
+ * Returns the path to the default source directory for the generator.
+ * The path must either be absolute or relative to the current working
+ * directory.
+ * "Default" means that the setting
+ * can be overridden in a unit of generation. This usually points to a
+ * subdirectory where the sources are located.
+ *
+ * @return the path for the source files, not null.
+ */
+ File getDefaultSourcePath();
+
+ /**
+ * Returns the path to the default directory for the generated output
+ * if the generated output is created anew each time.
+ * The path must either be absolute or relative to the current working
+ * directory.
+ *
+ * @return the path for the generated files, not null.
+ */
+ File getNewFileTargetPath();
+
+ /**
+ * Returns the path to the default directory for the generated output
+ * if the generated output is not created anew each time.
+ * The path must either be absolute or relative to the current working
+ * directory.
+ *
+ * @return the path for the generated files, not null.
+ */
+ File getModifiedFileTargetPath();
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/TorqueGfPaths.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/TorqueGfPaths.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/TorqueGfPaths.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/TorqueGfPaths.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,60 @@
+package org.apache.torque.gf.configuration.paths;
+
+/*
+ * 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 paths describing the internal organization (i.e. file paths)
+ * of the orque-gf files.
+ */
+public interface TorqueGfPaths
+{
+ /**
+ * Returns the path to the file containing the control configuration,
+ * relative to the configuration directory.
+ *
+ * @return the path to the control configuration file, not null.
+ */
+ String getControlConfigurationFile();
+
+ /**
+ * Returns the path to the directory containing the templates,
+ * relative to the torque-gf directory.
+ *
+ * @return the path to the template directory. not null.
+ */
+ String getTemplateSubdirectory();
+
+ /**
+ * Returns the path to the directory containing the configuration,
+ * relative to the torque-gf directory.
+ *
+ * @return the path to the configuration directory. not null.
+ */
+ String getConfigurationDirectory();
+
+ /**
+ * Returns the path to the directory containing the generator definitions,
+ * relative to the torque-gf directory.
+ *
+ * @return the path to the generator definition directory. not null.
+ */
+ String getGeneratorDefDirectory();
+
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/package.html
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/package.html?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/package.html (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/paths/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>Torque-gf configuration paths</title>
+ </head>
+ <body>
+ <p>
+ This package defines the directory structure of the Torque-gf
+ configuration and its surrounding project.
+ </p>
+ </body>
+</html>
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/control/Controller.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/control/Controller.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/control/Controller.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/control/Controller.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,451 @@
+package org.apache.torque.gf.control;
+
+/*
+ * 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.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.PropertyConfigurator;
+import org.apache.torque.gf.configuration.Configuration;
+import org.apache.torque.gf.configuration.ConfigurationException;
+import org.apache.torque.gf.configuration.UnitConfiguration;
+import org.apache.torque.gf.configuration.UnitDescriptor;
+import org.apache.torque.gf.configuration.controller.GeneratorReference;
+import org.apache.torque.gf.configuration.controller.Output;
+import org.apache.torque.gf.configuration.generator.GeneratorConfiguration;
+import org.apache.torque.gf.generator.Generator;
+import org.apache.torque.gf.generator.GeneratorException;
+import org.apache.torque.gf.source.Source;
+import org.apache.torque.gf.source.SourceElement;
+import org.apache.torque.gf.source.SourceException;
+import org.apache.torque.gf.source.SourcePath;
+import org.apache.torque.gf.source.Sources;
+import org.apache.torque.gf.source.TransformerDefinition;
+import org.apache.torque.gf.source.transform.SourceTransformer;
+import org.apache.torque.gf.source.transform.SourceTransformerException;
+
+/**
+ * Reads the configuration and generates the output accordingly.
+ */
+public class Controller
+{
+ /** The logger. */
+ private static Log log = LogFactory.getLog(Controller.class);
+
+
+ /**
+ * Executes the controller action.
+ *
+ * @param unitDescriptors the units of generation to execute.
+ *
+ * @throws ControllerException if a ControllerException occurs during
+ * processing.
+ * @throws ConfigurationException if a ConfigurationException occurs during
+ * processing.
+ * @throws GeneratorException if a GeneratorException occurs during
+ * processing.
+ * @throws SourceException if a SourceException occurs during
+ * processing.
+ * @throws SourceTransformerException if a SourceTransformerException
+ * occurs during processing.
+ * @throws IOException if a IOException occurs during processing.
+ */
+ public void run(List<UnitDescriptor> unitDescriptors)
+ throws ControllerException, GeneratorException, SourceException,
+ SourceTransformerException, IOException
+ {
+ initLogging();
+
+ log.info("run() : Starting to read configuration files");
+ Configuration configuration = new Configuration();
+ configuration.addUnits(unitDescriptors);
+ configuration.read();
+ log.info("run() : Configuration read.");
+
+ List<UnitConfiguration> unitConfigurations
+ = configuration.getUnitConfigurations();
+ ControllerState controllerState = new ControllerState();
+ for (UnitConfiguration unitConfiguration : unitConfigurations)
+ {
+ unitConfiguration.getLoglevel().apply();
+ log.debug("run() : Loglevel applied.");
+ controllerState.setUnitConfiguration(unitConfiguration);
+ List<Output> outputList = unitConfiguration.getOutputFiles();
+ for (Output output : outputList)
+ {
+ log.debug("Processing output " + output.getFilename());
+ controllerState.setOutput(output);
+ File targetDirectory;
+ if (output.isAlwaysNew())
+ {
+ targetDirectory
+ = unitConfiguration.getNewFileTargetDirectory();
+ log.debug("Using newFileTargetDirectory "
+ + targetDirectory);
+ }
+ else
+ {
+ targetDirectory
+ = unitConfiguration.getModifiedFileTargetDirectory();
+ log.debug("Using modifiedFileTargetDirectory "
+ + targetDirectory);
+ }
+
+ Sources sources = output.getSources();
+ if (!sources.hasNext())
+ {
+ log.info("No sources found");
+ }
+
+ while (sources.hasNext())
+ {
+ Source source = sources.next();
+ log.debug("Processing source " + source.getDescription());
+ SourceElement rootElement = source.getRootElement();
+ controllerState.setSourceFile(source.getSourceFile());
+ rootElement = transformSource(
+ rootElement,
+ source.getTransformerDefinitions(),
+ controllerState);
+ controllerState.setRootElement(rootElement);
+
+ String startElementsPath = source.getStartElementsPath();
+ List<SourceElement> startElements
+ = SourcePath.getElementsFromRoot(
+ rootElement,
+ startElementsPath);
+ if (startElements.isEmpty())
+ {
+ log.info("No start Elements found for path "
+ + startElementsPath);
+ }
+ for (SourceElement startElement : startElements)
+ {
+ processStartElement(
+ startElement,
+ output,
+ source,
+ targetDirectory,
+ unitConfiguration,
+ controllerState);
+ }
+ }
+ }
+ }
+ controllerState.getVariableStore().endGeneration();
+ }
+
+ /**
+ * Initializes the Logging.
+ */
+ protected void initLogging()
+ {
+ InputStream log4jStream
+ = Controller.class.getClassLoader().getResourceAsStream(
+ "org/apache/torque/gf/log4j.properties");
+ Properties log4jProperties = new Properties();
+ try
+ {
+ log4jProperties.load(log4jStream);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ PropertyConfigurator.configure(log4jProperties);
+ }
+
+ /**
+ * Creates the output file name and sets it in the output.
+ * The filename is calculated either by the filenameConfigurator in
+ * <code>output</code> or is given explicitly (in the latter case
+ * nothing needs to be done).
+ *
+ * @param controllerState the controller state, not null.
+ * @param output The output to process, not null.
+ *
+ * @throws ConfigurationException if an incorrect configuration is
+ * encountered, e.g. if neither filename nor filenameGenerator is
+ * set in output.
+ * @throws GeneratorException if an error occurs during generation of
+ * the output filename.
+ */
+ protected void createOutputFilename(
+ Output output,
+ ControllerState controllerState)
+ throws GeneratorException
+ {
+ if (output.getFilenameGenerator() == null)
+ {
+ if (output.getFilename() == null)
+ {
+ throw new ConfigurationException(
+ "neither filename nor filenameGenerator are set"
+ + " on output" + output);
+ }
+ }
+ else
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Start generation of Output File path");
+ }
+ controllerState.setOutputFile(null);
+
+ Generator filenameGenerator
+ = output.getFilenameGenerator();
+ GeneratorReference contentGeneratorReference
+ = new GeneratorReference(
+ filenameGenerator.getName());
+ controllerState.setRootGeneratorReference(
+ contentGeneratorReference);
+ // use the namespace not of the filenameGenerator
+ // but of the real generator
+ // TODO: is this a good idea ? make configurable ?
+ controllerState.setGeneratorNamespace(
+ output.getContentGenerator().getNamespace());
+ filenameGenerator.beforeExecute(controllerState);
+ String filename = filenameGenerator.execute(controllerState);
+ filenameGenerator.afterExecute(controllerState);
+ if (log.isDebugEnabled())
+ {
+ log.debug("End generation of Output File path, result is "
+ + filename);
+ }
+ output.setFilename(filename);
+ }
+ }
+
+ /**
+ * Processes the generation for a single start Element in a source.
+ *
+ * @param startElement the start element to process.
+ * @param output the current output, not null.
+ * @param source the current source, not null.
+ * @param targetDirectory the directory in which the output files
+ * should be processed, not null
+ * @param unitConfiguration the current unit configuration, not null.
+ * @param controllerState the current controller state, not null.
+ *
+ * @throws ControllerException if startElement is null or the configured
+ * generator does not exist.
+ * @throws GeneratorException if the generator throws an exception
+ * during execution.
+ * @throws IOException if the output directory cannot be created or the
+ * output file cannot be written.
+ */
+ private void processStartElement(
+ SourceElement startElement,
+ Output output,
+ Source source,
+ File targetDirectory,
+ UnitConfiguration unitConfiguration,
+ ControllerState controllerState)
+ throws ControllerException, GeneratorException, IOException
+ {
+ if (startElement == null)
+ {
+ throw new ControllerException(
+ "Null start element found in source "
+ + "for generating the filename "
+ + "of output file "
+ + output);
+ }
+ controllerState.setSourceElement(startElement);
+ log.debug("Processing new startElement "
+ + startElement.getName());
+
+ createOutputFilename(output, controllerState);
+ controllerState.setOutputFile(
+ new File(
+ targetDirectory,
+ output.getFilename()));
+
+ if (output.isSkipIfExists())
+ {
+ File outputFile
+ = controllerState.getOutputFile();
+ if (outputFile.exists())
+ {
+ log.info("Output file "
+ + outputFile.getAbsolutePath()
+ + " exists and skipIfExists"
+ + " is set to true, skipping");
+ return;
+ }
+ }
+ if (log.isInfoEnabled())
+ {
+ log.info("Start generation of File "
+ + controllerState.getOutputFile());
+ }
+
+ GeneratorReference contentGeneratorConfiguration
+ = output.getContentGenerator();
+ controllerState.setGeneratorNamespace(
+ contentGeneratorConfiguration.getNamespace());
+ controllerState.setRootGeneratorReference(
+ contentGeneratorConfiguration);
+
+ GeneratorConfiguration generatorConfiguration
+ = unitConfiguration.getGeneratorConfiguration();
+
+ Generator generator
+ = generatorConfiguration.getGenerator(
+ contentGeneratorConfiguration.getName());
+ if (generator == null)
+ {
+ throw new ControllerException(
+ "No generator configured for generator name \""
+ + contentGeneratorConfiguration.getName()
+ + "\"");
+ }
+
+ if (source.getSourceFilter() != null)
+ {
+ if (!source.getSourceFilter().proceed(controllerState))
+ {
+ log.debug("Source filter decided to skip "
+ + "generation of file "
+ + controllerState.getOutputFile());
+ return;
+ }
+ else
+ {
+ log.debug("Source filter decided to proceed");
+ }
+ }
+
+ {
+ File parentOutputDir
+ = controllerState.getOutputFile().getParentFile();
+ if (parentOutputDir != null
+ && !parentOutputDir.isDirectory())
+ {
+ boolean success = parentOutputDir.mkdirs();
+ if (!success)
+ {
+ throw new IOException(
+ "Could not create directory \""
+ + parentOutputDir.getAbsolutePath()
+ + "\"");
+ }
+ }
+ }
+
+ generator.beforeExecute(controllerState);
+ String result = generator.execute(controllerState);
+ generator.afterExecute(controllerState);
+
+ FileWriter fileWriter = null;
+ try
+ {
+ fileWriter = new FileWriter(
+ controllerState.getOutputFile());
+ fileWriter.append(result);
+ }
+ finally
+ {
+ if (fileWriter != null)
+ {
+ fileWriter.close();
+ }
+ }
+
+ controllerState.getVariableStore().endFile();
+ if (log.isDebugEnabled())
+ {
+ log.debug("End generation of Output File "
+ + controllerState.getOutputFile());
+ }
+ }
+
+ /**
+ * Applies all tarnsformer definitions to the current source.
+ *
+ * @param rootElement the root element of the source to transform,
+ * not null.
+ * @param transformerDefinitions the transformer definitions to apply,
+ * not null.
+ * @param controllerState the current controller state, not null.
+ *
+ * @return the transformed root element, not null.
+ */
+ protected SourceElement transformSource(
+ final SourceElement rootElement,
+ final List<TransformerDefinition> transformerDefinitions,
+ final ControllerState controllerState)
+ throws SourceTransformerException, SourceException
+ {
+ SourceElement result = rootElement;
+ for (TransformerDefinition transformerDefinition
+ : transformerDefinitions)
+ {
+ SourceTransformer sourceTransformer
+ = transformerDefinition.getTransformer();
+ String elements = transformerDefinition.getElements();
+ log.debug("Applying transformer "
+ + sourceTransformer.getClass().getName()
+ + (elements == null
+ ? " to the root element"
+ : " to the elements " + elements));
+
+ List<SourceElement> toTransform
+ = SourcePath.getElementsFromRoot(rootElement, elements);
+ if (toTransform.isEmpty())
+ {
+ log.debug("No element found, nothing transformed");
+ }
+ for (SourceElement sourceElement : toTransform)
+ {
+ log.debug("transforming element " + sourceElement);
+ SourceElement transformedElement = sourceTransformer.transform(
+ sourceElement,
+ controllerState);
+ if (transformedElement == null)
+ {
+ throw new SourceTransformerException("Transformer "
+ + sourceTransformer.getClass().getName()
+ + " returned null for element "
+ + sourceElement.getName());
+ }
+ SourceElement parent = sourceElement.getParent();
+ if (parent == null)
+ {
+ result = transformedElement;
+ }
+ else
+ {
+ int index = parent.getChildIndex(sourceElement);
+ parent.removeChild(sourceElement);
+ parent.addChild(index, transformedElement);
+ }
+ }
+ log.debug("Transformation ended");
+ }
+ return result;
+ }
+}
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/control/ControllerException.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/control/ControllerException.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/control/ControllerException.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/control/ControllerException.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,81 @@
+package org.apache.torque.gf.control;
+
+/*
+ * 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.
+ */
+
+/**
+ * This Exception is thrown when an error occurs within the Controller of
+ * the Torque GF.
+ */
+public class ControllerException extends Exception
+{
+ /**
+ * The version of the class
+ * (for serialization and deserialization purposes).
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructs a ConfigurationException without error message.
+ *
+ * @see Exception#Exception()
+ */
+ public ControllerException()
+ {
+ super();
+ }
+
+ /**
+ * Constructs a ConfigurationException with the given error message.
+ *
+ * @param message the error message
+ *
+ * @see Exception#Exception(java.lang.String)
+ */
+ public ControllerException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Constructs a ControllerException which wraps another exception.
+ *
+ * @param cause The exception to wrap. May be null.
+ *
+ * @see Exception#Exception(java.lang.Throwable)
+ */
+ public ControllerException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * Constructs a ControllerException which wraps another exception,
+ * and which has its own error message.
+ *
+ * @param message The error message.
+ * @param cause The exception to wrap, may be null.
+ *
+ * @see Exception#Exception(java.lang.String, java.lang.Throwable)
+ */
+ public ControllerException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org