db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r965166 [3/4] - in /db/torque/torque4/trunk/torque-generator: ./ src/main/java/org/apache/torque/generator/configuration/ src/main/java/org/apache/torque/generator/configuration/controller/ src/main/java/org/apache/torque/generator/configur...
Date Sun, 18 Jul 2010 06:10:57 GMT
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/JdbcMetadataSourceProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/JdbcMetadataSourceProvider.java?rev=965166&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/JdbcMetadataSourceProvider.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/JdbcMetadataSourceProvider.java Sun Jul 18 06:10:55 2010
@@ -0,0 +1,204 @@
+package org.apache.torque.generator.source.jdbc;
+
+/*
+ * 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.generator.configuration.ConfigurationException;
+import org.apache.torque.generator.configuration.ConfigurationHandlers;
+import org.apache.torque.generator.control.ControllerState;
+import org.apache.torque.generator.source.Source;
+import org.apache.torque.generator.source.SourceProvider;
+
+/**
+ * Creates a source from JDBC metadata.
+ *
+ * @version $Id: TorqueJDBCTransformTask.java 502761 2007-02-02 21:52:05Z tfischer $
+ */
+public class JdbcMetadataSourceProvider extends SourceProvider
+{
+    /** The name of the option to retrieve the JDBC URL from. */
+    private String urlOption;
+
+    /** The name of the option to retrieve the JDBC driver from. */
+    private String driverOption;
+
+    /** The name of the option to retrieve the JDBC user name from. */
+    private String usernameOption;
+
+    /** The name of the option to retrieve the JDBC password from. */
+    private String passwordOption;
+
+    /** The name of the option to retrieve the JDBC schema from. */
+    private String schemaOption;
+
+    /** JDBC URL. */
+    private String url;
+
+    /** JDBC driver. */
+    private String driver;
+
+    /** JDBC user name. */
+    private String username;
+
+    /** JDBC password. */
+    private String password;
+
+    /** JDBC schema. */
+    private String schema;
+
+    private boolean nextCalled = false;
+
+    public JdbcMetadataSourceProvider(
+                String urlOption,
+                String driverOption,
+                String usernameOption,
+                String passwordOption,
+                String schemaOption)
+            throws ConfigurationException
+    {
+        if (urlOption == null)
+        {
+            throw new ConfigurationException(
+                    "JdbcMetadataSourceProvider: urlOption must not be null");
+        }
+        if (driverOption == null)
+        {
+            throw new ConfigurationException(
+                    "JdbcMetadataSourceProvider:"
+                    + " driverOption must not be null");
+        }
+        this.urlOption = urlOption;
+        this.driverOption = driverOption;
+        this.usernameOption = usernameOption;
+        this.passwordOption = passwordOption;
+        this.schemaOption = schemaOption;
+    }
+
+
+    /**
+     * Generates an XML database schema from JDBC metadata.
+     *
+     * @throws Exception a generic exception.
+     */
+    public void initInternal(
+                 ConfigurationHandlers configurationHandlers,
+                 ControllerState controllerState)
+            throws ConfigurationException
+    {
+        driver = controllerState.getStringOption(driverOption);
+        url = controllerState.getStringOption(urlOption);
+        if (usernameOption != null)
+        {
+            username = controllerState.getStringOption(usernameOption);
+        }
+        if (passwordOption != null)
+        {
+            password = controllerState.getStringOption(passwordOption);
+        }
+        if (schemaOption != null)
+        {
+            schema = controllerState.getStringOption(schemaOption);
+        }
+    }
+
+    public boolean hasNext()
+    {
+        return !nextCalled;
+    }
+
+    public Source next()
+    {
+        if (nextCalled)
+        {
+            throw new IndexOutOfBoundsException();
+        }
+        nextCalled = true;
+        return new JdbcMetadataSource(driver, url, username, password, schema);
+    }
+
+
+    protected void resetInternal(
+                ConfigurationHandlers configurationHandlers,
+                ControllerState controllerState)
+            throws ConfigurationException
+    {
+        driver = null;
+        url = null;
+        username = null;
+        password = null;
+        schema = null;
+        nextCalled = false;
+    }
+
+    public void remove()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+
+    public String getUrlOption()
+    {
+        return urlOption;
+    }
+
+    public String getDriverOption()
+    {
+        return driverOption;
+    }
+
+    public String getUsernameOption()
+    {
+        return usernameOption;
+    }
+
+    public String getPasswordOption()
+    {
+        return passwordOption;
+    }
+
+    public String getSchemaOption()
+    {
+        return schemaOption;
+    }
+
+    public String getUrl()
+    {
+        return url;
+    }
+
+    public String getDriver()
+    {
+        return driver;
+    }
+
+    public String getUsername()
+    {
+        return username;
+    }
+
+    public String getPassword()
+    {
+        return password;
+    }
+
+    public String getSchema()
+    {
+        return schema;
+    }
+}

Copied: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/skipDecider/SkipDecider.java (from r944873, db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/filter/SourceFilter.java)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/skipDecider/SkipDecider.java?p2=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/skipDecider/SkipDecider.java&p1=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/filter/SourceFilter.java&r1=944873&r2=965166&rev=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/filter/SourceFilter.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/skipDecider/SkipDecider.java Sun Jul 18 06:10:55 2010
@@ -1,4 +1,4 @@
-package org.apache.torque.generator.source.filter;
+package org.apache.torque.generator.source.skipDecider;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -22,14 +22,16 @@ package org.apache.torque.generator.sour
 import org.apache.torque.generator.control.ControllerState;
 
 /**
- * A filter deciding whether the generation should proceed or not.
+ * A class deciding whether the generation should be skipped or not.
+ * The class is asked for every source which is processed.
  *
- * $Id: $
+ * @version $Id: $
  */
-public interface SourceFilter
+public interface SkipDecider
 {
     /**
-     * Decides whether generation should proceed.
+     * Decides whether the source file should be skipped and not used for
+     *        generation.
      * @param controllerState the current controller state, containing e.g.
      *        the current source element.
      * @return true if the current generation should proceed,

Copied: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/skipDecider/StopGenerationDecider.java (from r944873, db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/filter/StopGenerationSourceFilter.java)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/skipDecider/StopGenerationDecider.java?p2=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/skipDecider/StopGenerationDecider.java&p1=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/filter/StopGenerationSourceFilter.java&r1=944873&r2=965166&rev=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/filter/StopGenerationSourceFilter.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/skipDecider/StopGenerationDecider.java Sun Jul 18 06:10:55 2010
@@ -1,4 +1,4 @@
-package org.apache.torque.generator.source.filter;
+package org.apache.torque.generator.source.skipDecider;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -22,11 +22,11 @@ package org.apache.torque.generator.sour
 import org.apache.torque.generator.control.ControllerState;
 
 /**
- * A filter which always stops the current generation.
+ * A SkipDecider which always stops the current generation.
  *
  * $Id: $
  */
-public class StopGenerationSourceFilter implements SourceFilter
+public class StopGenerationDecider implements SkipDecider
 {
     /**
      * Decides whether generation should proceed. This implementation

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/FileSource.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/FileSource.java?rev=965166&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/FileSource.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/FileSource.java Sun Jul 18 06:10:55 2010
@@ -0,0 +1,185 @@
+package org.apache.torque.generator.source.stream;
+
+/*
+ * 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.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.SourceException;
+import org.apache.torque.generator.source.SourceImpl;
+
+/**
+ * A Source which uses a file as input.
+ */
+public class FileSource extends SourceImpl
+{
+    /**
+     * The log of the class.
+     */
+    private static Log log = LogFactory.getLog(FileSource.class);
+
+    /**
+     * The format of the file, e.g. properties or XML.
+     */
+    private StreamSourceFormat format;
+
+    /**
+     * The path of the file.
+     */
+    private File path;
+
+    /**
+     * Constructor.
+     *
+     * @param format the source format, not null.
+     * @param path the path to the file to read, not null.
+     *
+     * @throws NullPointerException if path or format is null.
+     */
+    public FileSource(
+            StreamSourceFormat format,
+            File path)
+    {
+        if (path == null)
+        {
+            throw new NullPointerException("path must not be null");
+        }
+        if (format == null)
+        {
+            throw new NullPointerException("format must not be null");
+        }
+        this.format = format;
+        this.path = path;
+    }
+
+    /**
+     * Returns the format of the source.
+     *
+     * @return the source format, not null.
+     */
+    public StreamSourceFormat getSourceFormat()
+    {
+        return format;
+    }
+
+    /**
+     * Returns the path to the source file.
+     *
+     * @return the path to the source file, not null.
+     */
+    public File getPath()
+    {
+        return path;
+    }
+
+    /**
+     * Reads and parses the input file and creates the element tree from it.
+     *
+     * @throws SourceException if the input file cannot be read or parsed.
+     *
+     * @return the root element of the element tree.
+     */
+    @Override
+    public SourceElement createRootElement() throws SourceException
+    {
+        if (log.isDebugEnabled())
+        {
+            log.debug("start creating root Element");
+        }
+        SourceElement result;
+        InputStream inputStream = null;
+        try
+        {
+            inputStream = new FileInputStream(path);
+            log.debug("Reading file "
+                    + path.getAbsolutePath()
+                    + " of type "
+                    + format.getKey());
+            result = format.parse(inputStream);
+        }
+        catch (FileNotFoundException e)
+        {
+            throw new SourceException(
+                    "File not found: " + path.getAbsolutePath(),
+                    e);
+        }
+        finally
+        {
+            if (inputStream != null)
+            {
+                try
+                {
+                    inputStream.close();
+                }
+                catch (IOException e)
+                {
+                    log.error("error closing input stream", e);
+                }
+            }
+        }
+
+
+        if (log.isDebugEnabled())
+        {
+            log.debug("finished creating root Element, source is\n"
+                    + new SourceToXml().toXml(result, true));
+        }
+        return result;
+    }
+
+    /**
+     * Returns the path of the file as a description.
+     *
+     * @return path of the file, not null.
+     *
+     * @see org.apache.torque.generator.source.Source#getDescription()
+     */
+    public String getDescription()
+    {
+        return path.getAbsolutePath();
+    }
+
+    /**
+     * Returns the source file, if it exists.
+     *
+     * @return the source file, or null if the source is not read from a file.
+     * @return
+     */
+    public File getSourceFile()
+    {
+        return path;
+    }
+
+
+    @Override
+    public String toString()
+    {
+        StringBuffer result = new StringBuffer();
+        result.append("(path=").append(path)
+                .append(",type=").append(format);
+        return result.toString();
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/FileSourceProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/FileSourceProvider.java?rev=965166&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/FileSourceProvider.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/FileSourceProvider.java Sun Jul 18 06:10:55 2010
@@ -0,0 +1,259 @@
+package org.apache.torque.generator.source.stream;
+
+/*
+ * 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.IOException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.generator.configuration.ConfigurationException;
+import org.apache.torque.generator.configuration.ConfigurationHandlers;
+import org.apache.torque.generator.control.ControllerState;
+import org.apache.torque.generator.file.Fileset;
+import org.apache.torque.generator.source.Source;
+import org.apache.torque.generator.source.SourceProvider;
+
+/**
+ * Contains sources which are read from files in the file system.
+ *
+ * $Id: $
+ */
+public class FileSourceProvider extends SourceProvider
+{
+    /** The class log. */
+    private static Log log = LogFactory.getLog(FileSourceProvider.class);
+
+    /**
+     * The type of the file(s), or null if the type should be determined
+     * from the file name extension.
+     */
+    private StreamSourceFormat sourceFormat;
+
+    /** The fileset defining the source files, not null. */
+    private Fileset sourceFileset;
+
+    /** The paths of all contained Files. */
+    private List<File> paths;
+
+    /** The iterator over all contained Files. */
+    private Iterator<File> pathIt;
+
+    /** The known stream source formats. */
+    private Set<StreamSourceFormat> streamSourceFormats;
+
+    /**
+     * Constructor.
+     *
+     * @param sourceFormat the source format, or null if the source format
+     *        should be determined from the file extension.
+     * @param sourceFileset the fileset defining the source files, not null.
+     * @param elements the path to the source elements to read, or null
+     *        if the root element should be used.
+     * @param sourceFilter the fully qualified class name of the source filter,
+     *        or null. The referenced class must have a standard constructor.
+     * @param configurationHandlers All known configuration handlers, not null.
+     *
+     * @throws IllegalArgumentException if the source type is unknown.
+     * @throws NullPointerException if path is null.
+     * @throws ConfigurationException if the source filter cannot be
+     *         instantiated.
+     */
+    public FileSourceProvider(
+                    StreamSourceFormat sourceFormat,
+                    Fileset sourceFileset)
+            throws ConfigurationException
+    {
+        if (sourceFileset == null)
+        {
+            throw new NullPointerException("sourceFileset must not be null");
+        }
+        this.sourceFormat = sourceFormat;
+        this.sourceFileset = sourceFileset;
+    }
+
+    /**
+     * Determines the files which match the source fileset.
+     *
+     * @param configurationHandlers the configuration handlers, not null.
+     * @param controllerState the current controller state, not null.
+     *
+     * @throws ConfigurationException if the sourceFileset has no basedir or
+     *         if the files cannot be determined.
+     */
+    protected void initInternal(
+                ConfigurationHandlers configurationHandlers,
+                ControllerState controllerState)
+            throws ConfigurationException
+    {
+        if (sourceFileset.getBasedir() == null)
+        {
+            throw new ConfigurationException(
+                    "Basedir of sourceFileset must not be null");
+        }
+        try
+        {
+            paths = sourceFileset.getFiles();
+        }
+        catch (IOException e)
+        {
+            throw new ConfigurationException(e);
+        }
+        log.debug("initInternal(): " + paths.size() + " matching files found.");
+        pathIt = paths.iterator();
+        streamSourceFormats = configurationHandlers.getStreamSourceFormats();
+    }
+
+    public void resetInternal(
+            ConfigurationHandlers configurationHandlers,
+            ControllerState controllerState)
+    {
+        paths = null;
+        pathIt = null;
+        streamSourceFormats = null;
+    }
+
+    public boolean hasNext()
+    {
+        if (!isInit())
+        {
+            throw new IllegalStateException(
+                    "init() must be called on this SourceProvider "
+                    + "before hasNext can be called");
+        }
+        return pathIt.hasNext();
+    }
+
+    public Source next()
+    {
+        if (!isInit())
+        {
+            throw new IllegalStateException(
+                    "init() must be called on this SourceProvider "
+                    + "before hasNext can be called");
+        }
+        File currentPath = pathIt.next();
+        StreamSourceFormat currentSourceFormat = sourceFormat;
+        if (currentSourceFormat == null)
+        {
+            for (StreamSourceFormat candidate : streamSourceFormats)
+            {
+                String filenameExtension = candidate.getFilenameExtension();
+                if (filenameExtension != null
+                        && currentPath.getName().endsWith(
+                                "." + filenameExtension))
+                {
+                    currentSourceFormat = candidate;
+                    break;
+                }
+            }
+        }
+        if (currentSourceFormat == null)
+        {
+            throw new RuntimeException(
+                    "format is not set and file extension is unknown for file "
+                        + currentPath.getName());
+        }
+        return new FileSource(
+                currentSourceFormat,
+                currentPath);
+    }
+
+    public void remove()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public String toString()
+    {
+        StringBuffer result = new StringBuffer();
+        result.append("(sourceFileset=").append(sourceFileset)
+                .append(",sourceFormat=").append(sourceFormat)
+                .append(")");
+        return result.toString();
+    }
+
+    /**
+     * Returns the source format for this provider.
+     *
+     * @return the source format, or null if the format is determined
+     *         from file extensions.
+     */
+    public StreamSourceFormat getSourceFormat()
+    {
+        return sourceFormat;
+    }
+
+    /**
+     * Returns the fileset which determines the source files to read.
+     *
+     * @return the fileset which determines the source files to read.
+     */
+    public Fileset getSourceFileset()
+    {
+        return sourceFileset;
+    }
+
+    /**
+     * Sets the fileset which determines the source files to read.
+     *
+     * @param sourceFileset the new source fileset, not null.
+     *
+     * @throws NullPointerException if sourceFileset is null.
+     * @throws IllegalStateException if init() was called before.
+     */
+    public void setSourceFileset(Fileset sourceFileset)
+    {
+        if (sourceFileset == null)
+        {
+            throw new NullPointerException("sourceFileset is null");
+        }
+        if (isInit())
+        {
+            throw new IllegalStateException(
+                    "Source files are already determined");
+        }
+        this.sourceFileset = sourceFileset;
+    }
+
+    /**
+     * Returns all paths in the source Fileset. The method init() must be
+     * called beforehand.
+     *
+     * @return all Paths in the source fileset, not null.
+     *
+     * @throws IllegalStateException if the init method was not yet called.
+     */
+    public List<File> getPaths()
+    {
+        if (!isInit())
+        {
+            throw new IllegalStateException(
+                    "init() must be called on this SourceProvider "
+                    + "before hasNext can be called");
+        }
+        return Collections.unmodifiableList(paths);
+    }
+}

Copied: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/PropertiesSourceFormat.java (from r944873, db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/properties/PropertiesSourceType.java)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/PropertiesSourceFormat.java?p2=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/PropertiesSourceFormat.java&p1=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/properties/PropertiesSourceType.java&r1=944873&r2=965166&rev=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/properties/PropertiesSourceType.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/PropertiesSourceFormat.java Sun Jul 18 06:10:55 2010
@@ -1,4 +1,4 @@
-package org.apache.torque.generator.source.properties;
+package org.apache.torque.generator.source.stream;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -19,15 +19,22 @@ package org.apache.torque.generator.sour
  * under the License.
  */
 
-import org.apache.torque.generator.source.SourceParser;
-import org.apache.torque.generator.source.SourceType;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.collections.set.ListOrderedSet;
+import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.SourceException;
 
 /**
  * The source type representing an properties source.
  *
  * $Id: $
  */
-public final class PropertiesSourceType implements SourceType
+public final class PropertiesSourceFormat implements StreamSourceFormat
 {
     /** The key for a properties source. */
     private static final String KEY = "properties";
@@ -36,6 +43,21 @@ public final class PropertiesSourceType 
     private static final String FILENAME_EXTENSION = "properties";
 
     /**
+     * The name of the root element.
+     */
+    public static final String ROOT_ELEMENT_NAME = "properties";
+
+    /**
+     * The name of the entry element.
+     */
+    public static final String ENTRY_ELEMENT_NAME = "entry";
+
+    /**
+     * The name of the key attribute of the entry element.
+     */
+    public static final String KEY_ATTRIBUTE_NAME = "key";
+
+    /**
      * Returns an unique key for the source type.
      *
      * @return "properties".
@@ -56,13 +78,57 @@ public final class PropertiesSourceType 
     }
 
     /**
-     * Returns a parser for this type of source.
+     * Parses a Stream in Properties format and returns the root element of the
+     * created element tree.
+     *
+     * @param inputStream the input stream to parse, not null.
      *
-     * @return a source parser, not null.
+     * @return the root element of the created tree, not null.
+     *
+     * @throws SourceException if an error occurred when reading from the
+     *         input stream.
+     * @throws IllegalArgumentException if the input stream contains a
+     *         malformed unicode escape sequence.
+     * @throws NullPointerException if inputStream is null.
      */
-    public SourceParser getParser()
+    public SourceElement parse(InputStream inputStream)
+            throws SourceException
     {
-        return new PropertiesSourceParser();
+        if (inputStream == null)
+        {
+            throw new NullPointerException("inputStream is null");
+        }
+        OrderedProperties properties = new OrderedProperties();
+        try
+        {
+            properties.load(inputStream);
+        }
+        catch (IOException e)
+        {
+            throw new SourceException(
+                    "Error parsing Properties source file: " + e.getMessage(),
+                    e);
+        }
+        catch (IllegalArgumentException e)
+        {
+            throw new SourceException(
+                    "Error parsing Properties source file: " + e.getMessage(),
+                    e);
+        }
+
+        SourceElement result
+                = new SourceElement(ROOT_ELEMENT_NAME);
+
+        for (String key : properties.orderedKeySet())
+        {
+            String value = properties.getProperty(key);
+            SourceElement entryElement
+                    = new SourceElement(ENTRY_ELEMENT_NAME);
+            entryElement.setAttribute(KEY_ATTRIBUTE_NAME, key);
+            entryElement.setAttribute((String) null, value);
+            result.getChildren().add(entryElement);
+        }
+        return result;
     }
 
     /**
@@ -92,10 +158,55 @@ public final class PropertiesSourceType 
         {
             return false;
         }
-        if (!other.getClass().equals(PropertiesSourceType.class))
+        if (!other.getClass().equals(PropertiesSourceFormat.class))
         {
             return false;
         }
         return true;
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString()
+    {
+        return getClass().getSimpleName();
+    }
+
+    /**
+     * Properties which remember the order of the added elements.
+     *
+     * The class is NOT serializable although it implements the
+     * <code>Serializable</code> interface.
+     */
+    private static class OrderedProperties extends Properties
+    {
+        /**
+         * version for serialization and deserialisation purposes.
+         */
+        private static final long serialVersionUID = 1L;
+
+        /**
+         * The ordered set of keys.
+         */
+        @SuppressWarnings("unchecked")
+        private Set<String> keySet = new ListOrderedSet();
+
+        @Override
+        public Object put(Object key, Object value)
+        {
+            keySet.add(key.toString());
+            return super.put(key, value);
+        }
+
+        /**
+         * Returns the set of keys, ordered by the order of addition.
+         * @return the ordered set of keys, not null.
+         *         The returned set is unmodifiable.
+         */
+        public Set<String> orderedKeySet()
+        {
+            return Collections.unmodifiableSet(keySet);
+        }
+    }
 }

Copied: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/SourceToXml.java (from r944873, db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/xml/SourceToXml.java)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/SourceToXml.java?p2=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/SourceToXml.java&p1=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/xml/SourceToXml.java&r1=944873&r2=965166&rev=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/xml/SourceToXml.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/SourceToXml.java Sun Jul 18 06:10:55 2010
@@ -1,4 +1,4 @@
-package org.apache.torque.generator.source.xml;
+package org.apache.torque.generator.source.stream;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.SourceException;
 
 /**
  * Creates an xml String out of a source tree.
@@ -70,16 +71,28 @@ public class SourceToXml
      * Renders a source element and its children as XML.
      *
      * @param rootElement the element to render.
+     * @param createIdAttributes whether id attributes should be created
+     *        and filled automatically.
      *
      * @return the created XML.
+     *
+     * @throws SourceException if automaticIds is false and an element
+     *         is encountered twice in the source tree.
      */
-    public String toXml(SourceElement rootElement)
+    public String toXml(SourceElement rootElement, boolean createIdAttributes)
+            throws SourceException
     {
         Map<SourceElement, Integer> knownElements
             = new HashMap<SourceElement, Integer>();
         StringBuilder result = new StringBuilder();
         String currentIndent = "";
-        outputElement(rootElement, knownElements, result, currentIndent, true);
+        outputElement(
+                rootElement,
+                knownElements,
+                result,
+                currentIndent,
+                true,
+                createIdAttributes);
         result.append("\n"); // end with newline
         return result.toString();
     }
@@ -92,13 +105,21 @@ public class SourceToXml
      *        been rendered as key, and their id as value
      * @param result the buffer to which the XML should be appended.
      * @param currentIndent the current indentation.
+     * @param identAtStart Whether the start element should be idented.
+     * @param createIdAttributes whether id attributes should be created
+     *        and filled automatically.
+     *
+     * @throws SourceException if createIdAttributes is false and an element
+     *         is encountered twice in the source tree.
      */
     private void outputElement(
-            SourceElement currentElement,
-            Map<SourceElement, Integer> knownElements,
-            StringBuilder result,
-            String currentIndent,
-            boolean identAtStart)
+                SourceElement currentElement,
+                Map<SourceElement, Integer> knownElements,
+                StringBuilder result,
+                String currentIndent,
+                boolean identAtStart,
+                boolean automaticIds)
+            throws SourceException
     {
         // check whether element is already known, output reference if yes
         Integer currentId;
@@ -107,6 +128,13 @@ public class SourceToXml
 
             if (knownElementId != null)
             {
+                if (!automaticIds)
+                {
+                    throw new SourceException(
+                            "An element with name " + currentElement.getName()
+                            + " occurs at least twice in the source graph,"
+                            + " but createIdAttributes is false.");
+                }
                 result.append(currentIndent)
                         .append("<")
                         .append(currentElement.getName())
@@ -146,14 +174,18 @@ public class SourceToXml
                 result.append("\"");
             }
         }
-        result.append(" ")
-                .append(ID_ATTRIBUTE)
-                .append("=\"")
-                .append(currentId);
+        if (automaticIds)
+        {
+            result.append(" ")
+                    .append(ID_ATTRIBUTE)
+                    .append("=\"")
+                    .append(currentId)
+                    .append("\"");
+        }
         boolean hasChildren = !currentElement.getChildren().isEmpty();
         if (hasChildren || hasTextAttribute)
         {
-            result.append("\">");
+            result.append(">");
             if (hasTextAttribute)
             {
                 appendWithEscaping(
@@ -163,7 +195,7 @@ public class SourceToXml
         }
         else
         {
-            result.append("\"/>");
+            result.append("/>");
         }
 
         // process children
@@ -181,7 +213,8 @@ public class SourceToXml
                         knownElements,
                         result,
                         childIndent,
-                        previousChild != null || !hasTextAttribute);
+                        previousChild != null || !hasTextAttribute,
+                        automaticIds);
                 previousChild = child;
             }
             if (previousChild != null)

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/StreamSourceFormat.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/StreamSourceFormat.java?rev=965166&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/StreamSourceFormat.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/StreamSourceFormat.java Sun Jul 18 06:10:55 2010
@@ -0,0 +1,62 @@
+package org.apache.torque.generator.source.stream;
+
+/*
+ * 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.InputStream;
+
+import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.SourceException;
+
+/**
+ * A format for a stream-based source, e.g. properties or XML.
+ *
+ * $Id: $
+ */
+public interface StreamSourceFormat
+{
+    /**
+     * Returns an unique key for the source format.
+     *
+     * @return an unique key for the source format, not null.
+     */
+    String getKey();
+
+    /**
+     * Gets the filename extension this source type typically has.
+     *
+     * @return the filename extension without leading dot,
+     *         or null if no typical extension exists.
+     */
+    String getFilenameExtension();
+
+    /**
+     * Parses a source file and returns its root element.
+     *
+     * @param inputStream the stream to read the source file from, not null.
+     *
+     * @return the root element of the source, containing the rest of
+     *         the source as linked elements.
+     *
+     * @throws SourceException if reading or parsing the source fails.
+     * @throws NullPointerException if <code>inputStream</code> is null.
+     */
+    SourceElement parse(InputStream inputStream) throws SourceException;
+}

Copied: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/XmlSourceFormat.java (from r944873, db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/xml/XmlSourceType.java)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/XmlSourceFormat.java?p2=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/XmlSourceFormat.java&p1=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/xml/XmlSourceType.java&r1=944873&r2=965166&rev=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/xml/XmlSourceType.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/XmlSourceFormat.java Sun Jul 18 06:10:55 2010
@@ -1,4 +1,4 @@
-package org.apache.torque.generator.source.xml;
+package org.apache.torque.generator.source.stream;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -19,15 +19,23 @@ package org.apache.torque.generator.sour
  * under the License.
  */
 
-import org.apache.torque.generator.source.SourceParser;
-import org.apache.torque.generator.source.SourceType;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.SourceException;
+import org.xml.sax.SAXException;
 
 /**
  * The source type representing an XML source.
  *
  * $Id: $
  */
-public final class XmlSourceType implements SourceType
+public final class XmlSourceFormat implements StreamSourceFormat
 {
     /** The key for a XML source. */
     private static final String KEY = "xml";
@@ -36,6 +44,17 @@ public final class XmlSourceType impleme
     private static final String FILENAME_EXTENSION = "xml";
 
     /**
+     * The factory from which the parser is created.
+     */
+    private static final SAXParserFactory SAX_FACTORY;
+
+    static
+    {
+        SAX_FACTORY = SAXParserFactory.newInstance();
+        SAX_FACTORY.setValidating(true);
+    }
+
+    /**
      * Returns an unique key for the source type.
      *
      * @return "xml".
@@ -56,13 +75,53 @@ public final class XmlSourceType impleme
     }
 
     /**
-     * Returns a parser for this type of source.
+     * Parses a stream containing xml data and creates a source element
+     * hierarchy from it.
      *
-     * @return a source parser, not null.
+     * @param inputStream the stream containing the xml data.
+     *
+     * @return the root element of the created hierarchy.
+     *
+     * @throws SourceException if an error occurs reading the input stream,
+     *         parsing the XML data or if the SAX parser is not configured
+     *         correctly.
      */
-    public SourceParser getParser()
+    public SourceElement parse(InputStream inputStream)
+            throws SourceException
     {
-        return new XmlSourceParser();
+        if (inputStream == null)
+        {
+            throw new NullPointerException("No Input path specified");
+        }
+        try
+        {
+            SAXParser parser = SAX_FACTORY.newSAXParser();
+
+            XmlSourceSaxHandler handler = new XmlSourceSaxHandler();
+
+            parser.parse(inputStream, handler);
+            return handler.getRoot();
+        }
+        catch (IOException e)
+        {
+            throw new SourceException(
+                    "Error reading XML source file: " + e.getMessage(),
+                    e);
+        }
+        catch (SAXException e)
+        {
+            throw new SourceException(
+                    "Error parsing XML source file: " + e.getMessage(),
+                    e);
+        }
+        catch (ParserConfigurationException e)
+        {
+            throw new SourceException(
+                    "Parser configuration error parsing Properties"
+                        + " source file: "
+                        + e.getMessage(),
+                    e);
+        }
     }
 
     /**
@@ -92,10 +151,18 @@ public final class XmlSourceType impleme
         {
             return false;
         }
-        if (!other.getClass().equals(XmlSourceType.class))
+        if (!other.getClass().equals(XmlSourceFormat.class))
         {
             return false;
         }
         return true;
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString()
+    {
+        return getClass().getSimpleName();
+    }
 }

Copied: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/XmlSourceSaxHandler.java (from r944873, db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/xml/XmlSourceSaxHandler.java)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/XmlSourceSaxHandler.java?p2=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/XmlSourceSaxHandler.java&p1=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/xml/XmlSourceSaxHandler.java&r1=944873&r2=965166&rev=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/xml/XmlSourceSaxHandler.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/XmlSourceSaxHandler.java Sun Jul 18 06:10:55 2010
@@ -1,4 +1,4 @@
-package org.apache.torque.generator.source.xml;
+package org.apache.torque.generator.source.stream;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -30,12 +30,12 @@ import org.xml.sax.helpers.DefaultHandle
 public class XmlSourceSaxHandler extends DefaultHandler
 {
     /**
-     * the root element of the tree.
+     * The currently parsed element.
      */
     private SourceElement element;
 
     /**
-     * the currently parsed element.
+     * The root element of the tree.
      */
     private SourceElement root;
 
@@ -93,11 +93,10 @@ public class XmlSourceSaxHandler extends
     public void ignorableWhitespace(char[] ch, int start, int length)
             throws SAXException
     {
-
     }
 
     /**
-     * returns the root element of the tree.
+     * Returns the root element of the tree.
      *
      * @return the root element (may be null if no elements were in the xml)
      *         or null if the xml was not yet parsed.

Copied: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/package.html (from r944873, db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/properties/package.html)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/package.html?p2=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/package.html&p1=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/properties/package.html&r1=944873&r2=965166&rev=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/properties/package.html (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/stream/package.html Sun Jul 18 06:10:55 2010
@@ -15,11 +15,12 @@
 -->
 <html>
   <head>
-    <title>Torque generator properties sources</title>
+    <title>Torque generator stream sources</title>
   </head>
   <body>
     <p>
-      This package contains the handling of properties source files.
+      This package contains the handling of stream-based sources, 
+      such as file sources.
     </p>
   </body>
 </html>

Modified: db/torque/torque4/trunk/torque-generator/src/main/resources/org/apache/torque/generator/configuration/configuration.xsd
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/resources/org/apache/torque/generator/configuration/configuration.xsd?rev=965166&r1=965165&r2=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/resources/org/apache/torque/generator/configuration/configuration.xsd (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/resources/org/apache/torque/generator/configuration/configuration.xsd Sun Jul 18 06:10:55 2010
@@ -101,26 +101,38 @@
     </attribute>
   </complexType>
   
-  <complexType name="fileset">
+  <complexType name="source" abstract="true">
     <sequence>
-      <element name="include" type="string" minOccurs="0" maxOccurs="unbounded"/>
-      <element name="exclude" type="string" minOccurs="0" maxOccurs="unbounded"/>
+      <element name="transformer" type="configuration:transformer" minOccurs="0" maxOccurs="unbounded"/>
     </sequence>
+    <attribute name="elements" type="string" use="optional"/>
+    <attribute name="skipDecider" type="string" use="optional"/>
   </complexType>
-
-  <complexType name="source">
+  
+  <complexType name="fileSource">
     <complexContent>
-      <extension base="configuration:fileset">
+      <extension base="configuration:source">
         <sequence>
-          <element name="transformer" type="configuration:transformer" minOccurs="0" maxOccurs="unbounded"/>
+          <element name="include" type="string" minOccurs="0" maxOccurs="unbounded"/>
+          <element name="exclude" type="string" minOccurs="0" maxOccurs="unbounded"/>
         </sequence>
-        <attribute name="type" type="string" use="optional"/>
-        <attribute name="elements" type="string" use="optional"/>
-        <attribute name="filter" type="string" use="optional"/>
+        <attribute name="format" type="string" use="optional"/>
       </extension>
     </complexContent>
   </complexType>
-  
+
+  <complexType name="jdbcMetadataSource">
+    <complexContent>
+      <extension base="configuration:source">
+        <attribute name="driverOption" type="string" use="required"/>
+        <attribute name="urlOption" type="string" use="required"/>
+        <attribute name="usernameOption" type="string" use="optional"/>
+        <attribute name="passwordOption" type="string" use="optional"/>
+        <attribute name="schemaOption" type="string" use="optional"/>
+      </extension>
+    </complexContent>
+  </complexType>
+
   <complexType name="transformer">
     <attribute name="class" type="string" use="required"/>
     <attribute name="elements" type="string" use="optional"/>

Modified: db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen-parent/conf/control.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen-parent/conf/control.xml?rev=965166&r1=965165&r2=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen-parent/conf/control.xml (original)
+++ db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen-parent/conf/control.xml Sun Jul 18 06:10:55 2010
@@ -30,14 +30,23 @@
       <foo>ParentFoo</foo>
       <bar>ParentBar</bar>
     </filenameOutlet>
-    <source elements="parentSourceElement" type="xml">
+    <source xsi:type="fileSource"
+        elements="parentSourceElement"
+        format="xml"
+        skipDecider="org.apache.torque.generator.configuration.OtherConfigurationTestSkipDecider">
+      <transformer elements="parent/database" 
+          class="org.apache.torque.generator.configuration.OtherConfigurationTestTransformer" />
       <include>parentSource</include>
     </source>
     <outlet name="org.apache.torque.generator.test.readConfiguration.testParentOutlet"/>
   </output>
   <output name="secondOutput">
     <filenameOutlet xsi:type="velocityOutlet" path="testTemplate.vm"/>
-    <source type="properties">
+    <source xsi:type="fileSource"
+        format="properties"
+        skipDecider="org.apache.torque.generator.configuration.OtherConfigurationTestSkipDecider">
+      <transformer elements="second/parent/database" 
+          class="org.apache.torque.generator.configuration.ConfigurationTestTransformer" />
       <include>secondParentSource</include>
       <exclude>secondParentExclude</exclude>
     </source>

Modified: db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen/conf/control.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen/conf/control.xml?rev=965166&r1=965165&r2=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen/conf/control.xml (original)
+++ db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen/conf/control.xml Sun Jul 18 06:10:55 2010
@@ -30,21 +30,30 @@
       <foo>Foo</foo>
       <bar>Bar</bar>
     </filenameOutlet>
-    <source type="xml"/>
+    <source xsi:type="fileSource" format="xml"/>
     <outlet name="org.apache.torque.generator.test.readConfiguration.javaOutlet"/>
   </output>
   <output name="secondOutput">
     <filenameOutlet xsi:type="velocityOutlet" path="testTemplate.vm"/>
-    <source elements="properties/entry" type="properties">
+    <source xsi:type="fileSource" 
+        elements="properties/entry"
+        format="properties"
+        skipDecider="org.apache.torque.generator.configuration.ConfigurationTestSkipDecider">
+      <transformer class="org.apache.torque.generator.configuration.ConfigurationTestTransformer" />
+      <transformer elements="database" 
+          class="org.apache.torque.generator.configuration.OtherConfigurationTestTransformer" />
       <include>second.source.path.properties</include>
       <exclude>second.excluded.properties</exclude>
     </source>
     <outlet name="org.apache.torque.generator.test.readConfiguration.anotherOutlet"/>
   </output>
   <output name="thirdOutput" file="outputFileName">
-    <source>
-      <include>third.source.path.properties</include>
-      <exclude>third.excluded.properties</exclude>
+    <source xsi:type="jdbcMetadataSource"
+        driverOption="jdbcDriver"
+        urlOption="jdbcUrl"
+        usernameOption="jdbcUsername"
+        passwordOption="jdbcPassword"
+        schemaOption="jdbcSchema">
     </source>
     <outlet name="org.apache.torque.generator.test.readConfiguration.thirdOutlet"/>
   </output>

Modified: db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen/conf/options.properties
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen/conf/options.properties?rev=965166&r1=965165&r2=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen/conf/options.properties (original)
+++ db/torque/torque4/trunk/torque-generator/src/test/configuration/src/main/torque-gen/conf/options.properties Sun Jul 18 06:10:55 2010
@@ -24,3 +24,7 @@ org.apache.optionWithNamespace = org.apa
 
 #options to test option precedences
 optionPrecedenceLastFile = value from properties
+
+#options for jdbcMetadataSourceProvider
+jdbcDriver=jdbc.driver.option.value
+jdbcUrl=jdbc.url.option.value

Modified: db/torque/torque4/trunk/torque-generator/src/test/deeplyNestedMergepoints/src/main/torque-gen/conf/control.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/deeplyNestedMergepoints/src/main/torque-gen/conf/control.xml?rev=965166&r1=965165&r2=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/deeplyNestedMergepoints/src/main/torque-gen/conf/control.xml (original)
+++ db/torque/torque4/trunk/torque-generator/src/test/deeplyNestedMergepoints/src/main/torque-gen/conf/control.xml Sun Jul 18 06:10:55 2010
@@ -23,7 +23,7 @@
     xsi:schemaLocation="http://db.apache.org/torque/4.0/generator/configuration http://db.apache.org/torque/4.0/generator/configuration.xsd"
     xmlns="http://db.apache.org/torque/4.0/generator/configuration">
   <output name="output" file="output.txt">
-    <source elements="sourceElement" type="xml">
+    <source xsi:type="fileSource" elements="sourceElement" format="xml">
       <include>source.xml</include>
     </source>
     <outlet name="nestingOutlet0"/>

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ConfigurationTestSkipDecider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ConfigurationTestSkipDecider.java?rev=965166&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ConfigurationTestSkipDecider.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ConfigurationTestSkipDecider.java Sun Jul 18 06:10:55 2010
@@ -0,0 +1,13 @@
+package org.apache.torque.generator.configuration;
+
+import org.apache.torque.generator.control.ControllerState;
+import org.apache.torque.generator.source.skipDecider.SkipDecider;
+
+public class ConfigurationTestSkipDecider implements SkipDecider
+{
+
+    public boolean proceed(ControllerState controllerState)
+    {
+        return false;
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ConfigurationTestTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ConfigurationTestTransformer.java?rev=965166&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ConfigurationTestTransformer.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/ConfigurationTestTransformer.java Sun Jul 18 06:10:55 2010
@@ -0,0 +1,47 @@
+package org.apache.torque.generator.configuration;
+
+import org.apache.torque.generator.control.ControllerState;
+import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.transform.SourceTransformer;
+import org.apache.torque.generator.source.transform.SourceTransformerException;
+
+/**
+ * A source transformer for testing the configuration class. Does nothing.
+ * 
+ * @version $Id: $
+ */
+public class ConfigurationTestTransformer implements SourceTransformer
+{
+    public SourceElement transform(SourceElement toTransformRoot,
+            ControllerState controllerState) throws SourceTransformerException
+    {
+        return toTransformRoot;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        // All instances of this class are equal to each other so always 
+        // the same number is returned
+        return 1;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj)
+        {
+            return true;
+        }
+        if (obj == null)
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        // All instances of this class are equal to each other 
+        return true;
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/OtherConfigurationTestSkipDecider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/OtherConfigurationTestSkipDecider.java?rev=965166&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/OtherConfigurationTestSkipDecider.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/OtherConfigurationTestSkipDecider.java Sun Jul 18 06:10:55 2010
@@ -0,0 +1,14 @@
+package org.apache.torque.generator.configuration;
+
+import org.apache.torque.generator.control.ControllerState;
+import org.apache.torque.generator.source.skipDecider.SkipDecider;
+
+public class OtherConfigurationTestSkipDecider implements SkipDecider
+{
+
+    public boolean proceed(ControllerState controllerState)
+    {
+        return false;
+    }
+
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/OtherConfigurationTestTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/OtherConfigurationTestTransformer.java?rev=965166&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/OtherConfigurationTestTransformer.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/configuration/OtherConfigurationTestTransformer.java Sun Jul 18 06:10:55 2010
@@ -0,0 +1,47 @@
+package org.apache.torque.generator.configuration;
+
+import org.apache.torque.generator.control.ControllerState;
+import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.transform.SourceTransformer;
+import org.apache.torque.generator.source.transform.SourceTransformerException;
+
+/**
+ * A source transformer for testing the configuration class. Does nothing.
+ * 
+ * @version $Id: $
+ */
+public class OtherConfigurationTestTransformer implements SourceTransformer
+{
+    public SourceElement transform(SourceElement toTransformRoot,
+            ControllerState controllerState) throws SourceTransformerException
+    {
+        return toTransformRoot;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        // All instances of this class are equal to each other so always 
+        // the same number is returned
+        return 1;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj)
+        {
+            return true;
+        }
+        if (obj == null)
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        // All instances of this class are equal to each other 
+        return true;
+    }
+}



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


Mime
View raw message