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

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/package.html
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/package.html?rev=965166&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/package.html (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/source/package.html Sun Jul 18 06:10:55 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 generator source configuration</title>
+  </head>
+  <body>
+    <p>
+      This package provides SAXhandlers for reading the source configuration
+      snippets in the control file.
+    </p>
+  </body>
+</html>

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java?rev=965166&r1=965165&r2=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Controller.java Sun Jul 18 06:10:55 2010
@@ -37,14 +37,15 @@ import org.apache.torque.generator.confi
 import org.apache.torque.generator.configuration.controller.OutletReference;
 import org.apache.torque.generator.configuration.controller.Output;
 import org.apache.torque.generator.configuration.outlet.OutletConfiguration;
-import org.apache.torque.generator.file.Fileset;
 import org.apache.torque.generator.outlet.Outlet;
 import org.apache.torque.generator.source.Source;
 import org.apache.torque.generator.source.SourceElement;
 import org.apache.torque.generator.source.SourceException;
 import org.apache.torque.generator.source.SourcePath;
-import org.apache.torque.generator.source.Sources;
-import org.apache.torque.generator.source.TransformerDefinition;
+import org.apache.torque.generator.source.SourceProcessConfiguration;
+import org.apache.torque.generator.source.SourceProvider;
+import org.apache.torque.generator.source.SourceTransformerDefinition;
+import org.apache.torque.generator.source.skipDecider.SkipDecider;
 import org.apache.torque.generator.source.transform.SourceTransformer;
 import org.apache.torque.generator.source.transform.SourceTransformerException;
 
@@ -94,7 +95,7 @@ public class Controller
             unitConfiguration.getLoglevel().apply();
             log.debug("run() : Loglevel applied.");
             controllerState.setUnitConfiguration(unitConfiguration);
-            List<Output> outputList = unitConfiguration.getOutputFiles();
+            List<Output> outputList = unitConfiguration.getOutputList();
             for (Output output : outputList)
             {
                 log.debug("Processing output " + output.getFilename());
@@ -115,37 +116,43 @@ public class Controller
                             + targetDirectory);
                 }
 
-                Sources sources = output.getSources();
-                Fileset overrideSourceFileset
-                        = unitConfiguration.getOverrideSourceFileset();
-                if (overrideSourceFileset != null)
+                SourceProvider sourceProvider = output.getSourceProvider();
+                SourceProvider overrideSourceProvider
+                        = unitConfiguration.getOverrideSourceProvider();
+                if (overrideSourceProvider != null)
                 {
-                    File oldBasepath = sources.getSourceFileset().getBasedir();
-                    if (overrideSourceFileset.getBasedir() == null)
+                    if (overrideSourceProvider.isInit()) 
                     {
-                        overrideSourceFileset.setBasedir(oldBasepath);
+                        overrideSourceProvider.reset(
+                                configuration.getConfigurationHandlers(),
+                                controllerState);
                     }
-                    sources.setSourceFileset(overrideSourceFileset);
+                    sourceProvider = overrideSourceProvider;
                 }
-                sources.init();
-                if (!sources.hasNext())
+                sourceProvider.init(
+                        configuration.getConfigurationHandlers(),
+                        controllerState);
+                if (!sourceProvider.hasNext())
                 {
-                    log.info("No sources found");
+                    log.info("No sources found, skipping output");
                 }
 
-                while (sources.hasNext())
+                while (sourceProvider.hasNext())
                 {
-                    Source source = sources.next();
+                    Source source = sourceProvider.next();
                     log.info("Processing source " + source.getDescription());
                     SourceElement rootElement = source.getRootElement();
                     controllerState.setSourceFile(source.getSourceFile());
+                    SourceProcessConfiguration sourceProcessConfiguration
+                            = output.getSourceProcessConfiguration();
                     rootElement = transformSource(
                             rootElement,
-                            source.getTransformerDefinitions(),
+                            sourceProcessConfiguration.getTransformerDefinitions(),
                             controllerState);
                     controllerState.setRootElement(rootElement);
 
-                    String startElementsPath = source.getStartElementsPath();
+                    String startElementsPath 
+                            = sourceProcessConfiguration.getStartElementsPath();
                     List<SourceElement> startElements
                             = SourcePath.getElementsFromRoot(
                                     rootElement,
@@ -336,18 +343,22 @@ public class Controller
                         + "\"");
         }
 
-        if (source.getSourceFilter() != null)
+        SkipDecider skipDecider
+                = output.getSourceProcessConfiguration().getSkipDecider();
+        if (skipDecider != null)
         {
-            if (!source.getSourceFilter().proceed(controllerState))
+            if (!skipDecider.proceed(controllerState))
             {
-                log.debug("Source filter decided to skip "
+                log.debug("SkipDecider " + skipDecider.getClass().getName()
+                        + " decided to skip "
                         + "generation of file "
                         + controllerState.getOutputFile());
                 return;
             }
             else
             {
-                log.debug("Source filter decided to proceed");
+                log.debug("SkipDecider " + skipDecider.getClass().getName() 
+                        + " decided to proceed");
             }
         }
 
@@ -408,18 +419,18 @@ public class Controller
      */
     protected SourceElement transformSource(
                     final SourceElement rootElement,
-                    final List<TransformerDefinition> transformerDefinitions,
+                    final List<SourceTransformerDefinition> transformerDefinitions,
                     final ControllerState controllerState)
             throws SourceTransformerException, SourceException
     {
         SourceElement result = rootElement;
-        for (TransformerDefinition transformerDefinition
+        for (SourceTransformerDefinition transformerDefinition
                 : transformerDefinitions)
         {
             SourceTransformer sourceTransformer
-                    = transformerDefinition.getTransformer();
+                    = transformerDefinition.getSourceTransformer();
             String elements = transformerDefinition.getElements();
-            log.debug("Applying transformer "
+            log.debug("Applying source transformer "
                     + sourceTransformer.getClass().getName()
                     + (elements == null
                             ? " to the root element"

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/ControllerState.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/ControllerState.java?rev=965166&r1=965165&r2=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/ControllerState.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/ControllerState.java Sun Jul 18 06:10:55 2010
@@ -198,7 +198,7 @@ public class ControllerState
      * @param rootElement the the root element of the current source,
      *        or null to remove the current root element.
      */
-    void setRootElement(SourceElement rootElement)
+    public void setRootElement(SourceElement rootElement)
     {
         this.rootElement = rootElement;
     }
@@ -471,7 +471,7 @@ public class ControllerState
      * @param unitConfiguration the configuration of the currently processed
      *        generation unit.
      */
-    void setUnitConfiguration(UnitConfiguration unitConfiguration)
+    public void setUnitConfiguration(UnitConfiguration unitConfiguration)
     {
         this.unitConfiguration = unitConfiguration;
     }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/file/Fileset.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/file/Fileset.java?rev=965166&r1=965165&r2=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/file/Fileset.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/file/Fileset.java Sun Jul 18 06:10:55 2010
@@ -98,152 +98,185 @@ public class Fileset 
      * 
      * @param basedir the base directory, or null.
      */
-	public void setBasedir(File basedir) 
-	{
-		this.basedir = basedir;
-	}
+    public void setBasedir(File basedir) 
+    {
+        this.basedir = basedir;
+    }
 
-	/**
-	 * Returns the include patterns for the fileset.
-	 *  
-	 * @return the include patterns, or null if all files should be included.
-	 */
-	public Set<String> getIncludes()
-	{
-		return includes;
-	}
+    /**
+     * Returns the include patterns for the fileset.
+     *  
+     * @return the include patterns, or null if all files should be included.
+     */
+    public Set<String> getIncludes()
+    {
+        return includes;
+    }
 
-	/**
-	 * Sets the include patterns for the fileset.
-	 *  
-	 * @return the include patterns, or null if all files should be included.
-	 */
-	public void setIncludes(Set<String> includes)
-	{
-		this.includes = includes;
-	}
+    /**
+     * Sets the include patterns for the fileset.
+     *  
+     * @return the include patterns, or null if all files should be included.
+     */
+    public void setIncludes(Set<String> includes)
+    {
+        this.includes = includes;
+    }
 
-	/**
-	 * Returns the exclude patterns for the fileset.
-	 *  
-	 * @return the exclude patterns, or null if all files should be excluded.
-	 */
-	public Set<String> getExcludes()
-	{
-		return excludes;
-	}
+    /**
+     * Returns the exclude patterns for the fileset.
+     *  
+     * @return the exclude patterns, or null if all files should be excluded.
+     */
+    public Set<String> getExcludes()
+    {
+        return excludes;
+    }
 
-	/**
-	 * Sets the exclude patterns for the fileset.
-	 *  
-	 * @return the exclude patterns, or null if all files should be excluded.
-	 */
-	public void setExcludes(Set<String> excludes)
-	{
-		this.excludes = excludes;
-	}
-	
-	public List<File> getFiles() throws IOException
-	{
-		List<File> result = new ArrayList<File>();
-		if (includes == null || includes.isEmpty()) 
-		{
-			getAllFiles(basedir, result);
-			return result;
-		}
-		// process includes
-		for (String includePattern : includes)
-		{
-	        int wildcardFreeSeparatorPos 
-	        		= getWildcardFreeSeparatorPos(includePattern);
-	        String wildcardFreeIncludePart = getPathPartBefore(
+    /**
+     * Sets the exclude patterns for the fileset.
+     *  
+     * @return the exclude patterns, or null if all files should be excluded.
+     */
+    public void setExcludes(Set<String> excludes)
+    {
+        this.excludes = excludes;
+    }
+
+    /**
+     * Returns the names of all files matching this fileset.
+     * 
+     * @return the names of all matching files, not null.
+     * 
+     * @throws IOException if an error occurs reading the file names.
+     */
+    public List<File> getFiles() throws IOException
+    {
+        List<File> result = new ArrayList<File>();
+        if (includes == null || includes.isEmpty()) 
+        {
+            getAllFiles(basedir, result);
+            return result;
+        }
+        // process includes
+        for (String includePattern : includes)
+        {
+            int wildcardFreeSeparatorPos 
+                    = getWildcardFreeSeparatorPos(includePattern);
+            String wildcardFreeIncludePart = getPathPartBefore(
                     includePattern, 
                     wildcardFreeSeparatorPos);
-	        if (log.isTraceEnabled())
-	        {
-	            log.trace("getFiles() : traversing directory " 
-	                    + wildcardFreeIncludePart
-	                    + " in base dir "
-	                    + basedir);
-	        }
-	        File wildcardFreeBaseDir = new File(
-	        		basedir,
-	        		wildcardFreeIncludePart);
-	        String wildcardPattern 
-	            = getPathPartAfter(includePattern, wildcardFreeSeparatorPos);
-	        String[] wildcardParts = StringUtils.split(wildcardPattern, "\\/");
-	        List<String> wildcardPartList = Arrays.asList(wildcardParts);
-
-	        List<File> includes = getFiles(
-	        		wildcardFreeBaseDir,
-	        		wildcardPartList);
-	        result.addAll(includes);
-		}
-		// process excludes
-		if (excludes == null)
-		{
-			return result;
-		}
-		Iterator<File> fileIt = result.iterator();
-		while (fileIt.hasNext())
-		{
-			File file = fileIt.next();
-			boolean excluded = false;
-			for (String excludePattern : excludes)
-			{
-				File excludePatternFile = new File(basedir, excludePattern);
-				if (matchesPattern(file, excludePatternFile.getPath()))
-				{
-					excluded = true;
-					break;
-				}
-			}
-			if (excluded)
-			{
-				fileIt.remove();
-			}
-		}
-		return result;
-	}
-	
-	static void getAllFiles(File currentBaseDir, List<File> toAddTo)
-			throws IOException
-	{
-	    if (log.isTraceEnabled())
-	    {
-	        log.trace("getAllFiles() : traversing directory " 
-	                +  currentBaseDir.getAbsolutePath());
-	    }
-		File[] filesInDir = currentBaseDir.listFiles(
-				new WildcardFilter("*", false, true));
-	    if (filesInDir == null)
-	    {
-	        throw new IOException(
-	                "Could not list files in the following Directory "
-	                    + "while reading the sources: "
-	                    + currentBaseDir.getAbsolutePath());
-	    }
-	    if (log.isTraceEnabled())
-	    {
-	        log.trace("getAllFiles() : Adding files " 
-	                + filesInDir 
-	                + " to candidate list");
-	    }
-		toAddTo.addAll(Arrays.asList(filesInDir));
-		
-		File[] dirsInDir = currentBaseDir.listFiles(
-				new WildcardFilter("*", true, false));
-		
-		for (File dir : dirsInDir)
-		{
-			getAllFiles(dir, toAddTo);
-		}
-	}
-	
+            if (log.isTraceEnabled())
+            {
+                log.trace("getFiles() : traversing directory " 
+                        + wildcardFreeIncludePart
+                        + " in base dir "
+                        + basedir);
+            }
+            File wildcardFreeBaseDir = new File(
+                    basedir,
+                    wildcardFreeIncludePart);
+            String wildcardPattern 
+                = getPathPartAfter(includePattern, wildcardFreeSeparatorPos);
+            String[] wildcardParts = StringUtils.split(wildcardPattern, "\\/");
+            List<String> wildcardPartList = Arrays.asList(wildcardParts);
+
+            List<File> includes = getFiles(
+                    wildcardFreeBaseDir,
+                    wildcardPartList);
+            result.addAll(includes);
+        }
+        // process excludes
+        if (excludes == null)
+        {
+        	return result;
+        }
+        Iterator<File> fileIt = result.iterator();
+        while (fileIt.hasNext())
+        {
+            File file = fileIt.next();
+            boolean excluded = false;
+            for (String excludePattern : excludes)
+            {
+                File excludePatternFile = new File(basedir, excludePattern);
+                if (matchesPattern(file, excludePatternFile.getPath()))
+                {
+                    excluded = true;
+                    break;
+                }
+            }
+            if (excluded)
+            {
+            	fileIt.remove();
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Reads the names of all files in a directory and its subdirectories.
+     *
+     * @param currentBaseDir the base directory from which the files are read,
+     *        not null.
+     * @param toAddTo the list of files where the found file should be added to,
+     *        not null.
+     *
+     * @throws IOException if an error occurs during reading the directory.
+     */
+    static void getAllFiles(File currentBaseDir, List<File> toAddTo)
+            throws IOException
+    {
+        if (currentBaseDir == null)
+        {
+            currentBaseDir = new File("."); 
+        }
+        if (log.isTraceEnabled())
+        {
+            log.trace("getAllFiles() : traversing directory " 
+                    +  currentBaseDir.getAbsolutePath());
+        }
+        File[] filesInDir = currentBaseDir.listFiles(
+                new WildcardFilter("*", false, true));
+        if (filesInDir == null)
+        {
+            throw new IOException(
+                    "Could not list files in the following Directory "
+                        + "while reading the sources: "
+                        + currentBaseDir.getAbsolutePath());
+        }
+        if (log.isTraceEnabled())
+        {
+            log.trace("getAllFiles() : Adding files " 
+                    + filesInDir 
+                    + " to candidate list");
+        }
+        toAddTo.addAll(Arrays.asList(filesInDir));
+        
+        File[] dirsInDir = currentBaseDir.listFiles(
+                new WildcardFilter("*", true, false));
+        
+        for (File dir : dirsInDir)
+        {
+            getAllFiles(dir, toAddTo);
+        }
+    }
+
+    /**
+     * Reads the name of a set of files matching a path pattern.
+     *
+     * @param currentBaseDir the base directory from which the files are read,
+     *        not null.
+     * @param pathPartList the split path to the files (split where the path 
+     *        separator appears). E.g. to access resources/x.properties, 
+     *        the list would be ["resources", "x.properties"]
+     * @return the set of all files which match the pathPartList.
+     *
+     * @throws IOException if an error occurs during reading the directory.
+     */
     static List<File> getFiles(
-    		    File currentBaseDir, List<String> pathPartList)
-    		throws IOException
-	{
+                File currentBaseDir, List<String> pathPartList)
+            throws IOException
+    {
         if (log.isTraceEnabled())
         {
             log.trace("getFiles(File, List) : traversing directory " 

Copied: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/jdbc/SchemaType.java (from r944878, db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/SchemaType.java)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/jdbc/SchemaType.java?p2=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/jdbc/SchemaType.java&p1=db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/SchemaType.java&r1=944878&r2=965166&rev=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/SchemaType.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/jdbc/SchemaType.java Sun Jul 18 06:10:55 2010
@@ -1,6 +1,4 @@
-package org.apache.torque.templates.typemapping;
-
-import java.sql.Types;
+package org.apache.torque.generator.jdbc;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -21,9 +19,10 @@ import java.sql.Types;
  * under the License.
  */
 
+import java.sql.Types;
 
 /**
- * Enum for types used in Torque schema.xml files.
+ * Enum for known SQL types.
  *
  * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
  * @version $Id: SchemaType.java 473814 2006-11-11 22:30:30 +0000 (Sat, 11 Nov 2006) tv $
@@ -60,22 +59,22 @@ public enum SchemaType
     BOOLEANINT(null),
     BOOLEANCHAR(null),
     DOUBLE(Types.DOUBLE);
-    
-    /** 
+
+    /**
      * The corresponding jdbc type,
      * may be null if no corresponding type exists.
      */
     private Integer jdbcType;
-    
+
     private SchemaType(Integer jdbcType)
     {
         this.jdbcType = jdbcType;
     }
-    
+
     /**
      * Returns the corresponding jdbc type.
      *
-     * @return the corresponding jdbc type, or null if no corresponding 
+     * @return the corresponding jdbc type, or null if no corresponding
      *         type exists.
      */
     public Integer getJdbcType()
@@ -85,9 +84,9 @@ public enum SchemaType
 
     /**
      * Returns the schema type which corresponds to the given jdbc type.
-     * 
+     *
      * @param jdbcType the jdbc type.
-     * 
+     *
      * @return the corresponding schema type, or null if no schema type
      *         corresponds to the jdbc type.
      */
@@ -97,7 +96,7 @@ public enum SchemaType
         {
             return null;
         }
-        for (SchemaType schemaType : values())            
+        for (SchemaType schemaType : values())
         {
             if (jdbcType.equals(schemaType.jdbcType))
             {

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/outlet/java/XmlOutlet.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/outlet/java/XmlOutlet.java?rev=965166&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/outlet/java/XmlOutlet.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/outlet/java/XmlOutlet.java Sun Jul 18 06:10:55 2010
@@ -0,0 +1,78 @@
+package org.apache.torque.generator.outlet.java;
+
+/*
+ * 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.GeneratorException;
+import org.apache.torque.generator.control.ControllerState;
+import org.apache.torque.generator.qname.QualifiedName;
+import org.apache.torque.generator.source.stream.SourceToXml;
+
+/**
+ * Creates new lines (\n or \r\n).
+ */
+public class XmlOutlet extends OutletWithoutMergepoints
+{
+    /** Whether id attributes should be automatically created in the output. */
+    private boolean createIdAttributes = false;
+
+    /** The XML outputter. */
+    private SourceToXml sourceToXml = new SourceToXml();
+    /**
+     * Constructor.
+     *
+     * @param name the qualified name of the outlet.
+     */
+    public XmlOutlet(QualifiedName name)
+    {
+        super(name);
+    }
+
+    @Override
+    public String execute(ControllerState controllerState)
+            throws GeneratorException
+    {
+        String result = sourceToXml.toXml(
+                controllerState.getRootElement(),
+                createIdAttributes);
+
+        return result.toString();
+    }
+
+    /**
+     * Returns whether id attributes are automatically created in the output.
+     *
+     * @return true if id attributes are automatically created, false otherwise.
+     */
+    public boolean isCreateIdAttributes()
+    {
+        return createIdAttributes;
+    }
+
+    /**
+     * Sets whether id attributes should be automatically created in the output.
+     *
+     * @param  true if id attributes should be automatically created,
+     *         false otherwise.
+     */
+    public void setCreateIdAttributes(boolean createIdAttributes)
+    {
+        this.createIdAttributes = createIdAttributes;
+    }
+}

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/Source.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/Source.java?rev=965166&r1=965165&r2=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/Source.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/Source.java Sun Jul 18 06:10:55 2010
@@ -20,9 +20,6 @@ package org.apache.torque.generator.sour
  */
 
 import java.io.File;
-import java.util.List;
-
-import org.apache.torque.generator.source.filter.SourceFilter;
 
 /**
  * An entity which serves as an input for the generation process.
@@ -39,40 +36,6 @@ public interface Source
     SourceElement getRootElement() throws SourceException;
 
     /**
-     * Returns the path to the elements which are selected as start elements
-     * from the transformed source.
-     *
-     * @return a path to the start elements, null for the root element.
-     */
-    String getStartElementsPath();
-
-    /**
-     * Returns the definitions for the source transformers which are
-     * executed before the generation process
-     *
-     * @return the source transformer definitions, not null.
-     *         The first transformer in the list is executed first.
-     */
-    List<TransformerDefinition> getTransformerDefinitions()
-            throws SourceException;
-
-    /**
-     * The configured source filter, or null if there is no source filter
-     * for this source.
-     *
-     * The source filter must be executed after the file name is generated
-     * and the current source element and the options are set to the controller
-     * state.
-     *
-     * If its proceed(ControllerState) method returns false, generation of
-     * the current output file must be skipped. If no SourceFilter exists,
-     * generation proceeds.
-     *
-     * @return the source filter, or null.
-     */
-    SourceFilter getSourceFilter();
-
-    /**
      * Gets a description of this source for debugging purposes.
      *
      * @return the description, which should make it possible to identify

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceImpl.java?rev=965166&r1=965165&r2=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceImpl.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceImpl.java Sun Jul 18 06:10:55 2010
@@ -19,68 +19,19 @@ package org.apache.torque.generator.sour
  * under the License.
  */
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.torque.generator.configuration.ConfigurationException;
-import org.apache.torque.generator.source.filter.SourceFilter;
-
 /**
- * A Source which uses a file as input.
+ * The base implementation of the source interface.
+ *
+ * @version: $Id: $
  */
 public abstract class SourceImpl implements Source
 {
     /**
-     * The path to the elements which should be used as starting points
-     * for generation.
-     */
-    private String startElementsPath;
-
-    /**
      * The root element of the parsed source.
      */
     private transient SourceElement rootElement;
 
     /**
-     * The source transformers which are executed when transform() is called.
-     */
-    private List<TransformerDefinition> transformerDefinitions
-            = new ArrayList<TransformerDefinition>();
-
-    /**
-     * The source filter, or null if none exists.
-     */
-    private SourceFilter sourceFilter;
-
-    /**
-     * Constructor.
-     *
-     * @param startElementsPath the element which should be used as input,
-     *        or null if the root element should be used.
-     * @param sourceFilter the fully qualified class name of the source filter,
-     *        or null if no SourceFilter should be used.
-     *        The selected class, if any, must have a standard constructor.
-     * @param transformerDefinitions the List of transformers to be applied
-     *        to the source, not null.
-     *
-     * @throws ConfigurationException if the source filter cannot be
-     *         instantiated.
-     */
-    protected SourceImpl(
-                    String startElementsPath,
-                    SourceFilter sourceFilter,
-                    List<TransformerDefinition> transformerDefinitions)
-            throws ConfigurationException
-    {
-        this.startElementsPath = startElementsPath;
-        this.sourceFilter = sourceFilter;
-        this.transformerDefinitions = new ArrayList<TransformerDefinition>(
-                transformerDefinitions);
-
-    }
-
-    /**
      * Reads the root element and the whole untransformed source tree.
      *
      * @return the root element, not null.
@@ -98,105 +49,4 @@ public abstract class SourceImpl impleme
         }
         return rootElement;
     }
-
-    /**
-     * Returns the path to the elements which are selected as start elements
-     * from the transformed source.
-     *
-     * @return a path to the start elements, null for the root element.
-     */
-    public String getStartElementsPath()
-    {
-        return startElementsPath;
-    }
-
-    /**
-     * Return all currently registered transformer definitions.
-     *
-     * @return the transformer definitions, not null.
-     */
-    public List<TransformerDefinition> getTransformerDefinitions()
-    {
-        return Collections.unmodifiableList(transformerDefinitions);
-    }
-
-    /**
-     * Returns the current source filter.
-     *
-     * @return the current source filter, or null.
-     */
-    public SourceFilter getSourceFilter()
-    {
-        return sourceFilter;
-    }
-
-    /**
-     * Sets a new source filter.
-     *
-     * @param sourceFilter the new source filter, or null to remove the old
-     *        source filter.
-     */
-    public void setSourceFilter(SourceFilter sourceFilter)
-    {
-        this.sourceFilter = sourceFilter;
-    }
-
-    @Override
-    public int hashCode()
-    {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result
-            + ((startElementsPath == null) ? 0 : startElementsPath.hashCode());
-        result = prime * result + transformerDefinitions.hashCode();
-        result = prime * result
-            + ((sourceFilter == null) ? 0 : sourceFilter.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj)
-    {
-        if (this == obj)
-        {
-            return true;
-        }
-        if (obj == null)
-        {
-            return false;
-        }
-        if (getClass() != obj.getClass())
-        {
-            return false;
-        }
-
-        final SourceImpl other = (SourceImpl) obj;
-        if (startElementsPath == null)
-        {
-            if (other.startElementsPath != null)
-            {
-                return false;
-            }
-        }
-        else if (!startElementsPath.equals(other.startElementsPath))
-        {
-            return false;
-        }
-        if (!transformerDefinitions.equals(other.transformerDefinitions))
-        {
-            return false;
-        }
-        if (sourceFilter == null)
-        {
-            if (other.sourceFilter != null)
-            {
-                return false;
-            }
-        }
-        else if (!sourceFilter.equals(other.sourceFilter))
-        {
-            return false;
-        }
-        return true;
-    }
 }

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProcessConfiguration.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProcessConfiguration.java?rev=965166&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProcessConfiguration.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProcessConfiguration.java Sun Jul 18 06:10:55 2010
@@ -0,0 +1,142 @@
+package org.apache.torque.generator.source;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.torque.generator.configuration.ClassHelper;
+import org.apache.torque.generator.configuration.ConfigurationException;
+import org.apache.torque.generator.source.skipDecider.SkipDecider;
+
+/**
+ * Contains the configuration how a source should be processed between
+ * obtaining the original source and feeding it to the outlets.
+ *
+ * @version $Id: $
+ *
+ */
+public class SourceProcessConfiguration
+{
+    /** The elements which should be used as starting points for generation. */
+    private String startElementsPath;
+
+    /** The source transformers which are executed before transformation. */
+    private List<SourceTransformerDefinition> transformerDefinitions
+            = new ArrayList<SourceTransformerDefinition>();
+
+    /** The skip decider, or null if none exists. */
+    private SkipDecider skipDecider;
+
+    /**
+     * Sets the start element path.
+     *
+     * @param startElementsPath the path to the elements which are used
+     *        as starting points for generation,
+     *        or null if the root element should be used.
+     */
+    public void setStartElementsPath(String startElementsPath)
+    {
+        this.startElementsPath = startElementsPath;
+    }
+
+    /**
+     * Sets and instantiates the source filter class.
+     *
+     * @param skipDecider the fully qualified name of a class
+     *        which determines whether a particular source is skipped,
+     *        or null if every source should be used.
+     *
+     * @throws ConfigurationException if the class cannot be
+     *         instantiated or does not implement the
+     *         <code>SkipDecider</code> interface.
+     */
+    public void setSkipDecider(String skipDecider)
+            throws ConfigurationException
+    {
+        if (skipDecider != null)
+        {
+            this.skipDecider = (SkipDecider) ClassHelper.getInstance(
+                    skipDecider,
+                    SkipDecider.class);
+        }
+        else
+        {
+            this.skipDecider = null;
+        }
+    }
+
+    /**
+     * Sets the transformer definitions.
+     *
+     * @param transformerDefinitions the transformer definitions, or null
+     *        if the input should not be transformed before generation.
+     */
+    public void setSourceTransformerDefinitions(
+                List<SourceTransformerDefinition> transformerDefinitions)
+    {
+        if (transformerDefinitions == null)
+        {
+            this.transformerDefinitions
+                    = new ArrayList<SourceTransformerDefinition>();
+        }
+        else
+        {
+            this.transformerDefinitions
+                    = new ArrayList<SourceTransformerDefinition>(
+                            transformerDefinitions);
+        }
+    }
+
+    /**
+     * Returns the path to elements which should be used as starting points for
+     * generation.
+     *
+     * @return the elements to use, or null, in which case the root element
+     *         is used.
+     */
+    public String getStartElementsPath()
+    {
+        return startElementsPath;
+    }
+
+    /**
+     * Return all currently registered source transformer definitions.
+     *
+     * @return the source transformer definitions, not null.
+     */
+    public List<SourceTransformerDefinition> getTransformerDefinitions()
+    {
+        return Collections.unmodifiableList(transformerDefinitions);
+    }
+
+    /**
+     * Returns the current SkipDecider.
+     *
+     * @return the current SkipDecider, or null if the generation should
+     *         always be started for all source files.
+     */
+    public SkipDecider getSkipDecider()
+    {
+        return skipDecider;
+    }
+}

Copied: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProvider.java (from r944873, db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SimpleSourcesImpl.java)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProvider.java?p2=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProvider.java&p1=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SimpleSourcesImpl.java&r1=944873&r2=965166&rev=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SimpleSourcesImpl.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProvider.java Sun Jul 18 06:10:55 2010
@@ -19,104 +19,109 @@ package org.apache.torque.generator.sour
  * under the License.
  */
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.util.Iterator;
 
-import org.apache.torque.generator.configuration.ClassHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.torque.generator.configuration.ConfigurationException;
-import org.apache.torque.generator.source.filter.SourceFilter;
+import org.apache.torque.generator.configuration.ConfigurationHandlers;
+import org.apache.torque.generator.control.ControllerState;
 
 /**
- * A collection of Sources, which all have the same elements,
- * Source filters and transformerDefinitions.
+ * The input for a generation process. It can contain several sources.
+ * In order to use the sources, the init() method must be called. After
+ * this method was called, no more setters may be called.
  */
-public abstract class SimpleSourcesImpl implements Sources
+public abstract class SourceProvider implements Iterator<Source>
 {
-    /**
-     * The elements which should be used as starting points for generation.
-     */
-    private String startElementsPath;
+    /** The class log. */
+    private static Log log = LogFactory.getLog(SourceProvider.class);
 
     /**
-     * The source transformers which are executed when transform() is called.
+     * Whether the init method was already called.
      */
-    private List<TransformerDefinition> transformerDefinitions
-            = new ArrayList<TransformerDefinition>();
+    private boolean initialized;
 
     /**
-     * The source filter, or null if none exists.
+     * Initializes the source provider. Must be called before
+     * <code>hasNext()</code> or <code>next()</code> is invoked.
+     *
+     * @param configurationHandlers the configuration handlers, not null.
+     * @param controllerState the current controller state, not null.
+     *
+     * @throws ConfigurationException if initializing fails.
      */
-    private SourceFilter sourceFilter;
+    public final synchronized void init(
+            ConfigurationHandlers configurationHandlers,
+            ControllerState controllerState)
+        throws ConfigurationException
+    {
+        if (initialized)
+        {
+            log.warn("init() called more than once, ignoring this call");
+            return;
+        }
+        initInternal(configurationHandlers, controllerState);
+        initialized = true;
+    }
 
     /**
-     * Constructor.
+     * Resets the source provider. After this method is called,
+     * <code>init()</code> must be called again.
      *
-     * @param startElementsPath the path to the elements which are used
-     *        as starting points for generation,
-     *        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 the configuration handlers, not null.
+     * @param controllerState the current controller state, not null.
      *
-     * @throws ConfigurationException if the source filter cannot be
-     *         instantiated.
+     * @throws ConfigurationException if resetting fails.
      */
-    protected SimpleSourcesImpl(
-                    String startElementsPath,
-                    String sourceFilter,
-                    List<TransformerDefinition> transformerDefinitions)
+    public final synchronized void reset(
+                ConfigurationHandlers configurationHandlers,
+                ControllerState controllerState)
             throws ConfigurationException
     {
-        this.startElementsPath = startElementsPath;
-        if (transformerDefinitions == null)
-        {
-            this.transformerDefinitions
-                    = new ArrayList<TransformerDefinition>();
-        }
-        else
+        if (!initialized)
         {
-            this.transformerDefinitions
-                    = new ArrayList<TransformerDefinition>(
-                            transformerDefinitions);
-        }
-
-        if (sourceFilter != null)
-        {
-            this.sourceFilter = (SourceFilter) ClassHelper.getInstance(
-                    sourceFilter,
-                    SourceFilter.class);
+            log.warn("reset() called on uninitialized SourceProvider, "
+                    + "ignoring this call");
+            return;
         }
+        resetInternal(configurationHandlers, controllerState);
+        initialized = false;
     }
 
     /**
-     * Returns the path to elements which should be used as starting points for
-     * generation.
+     * Initializes the sources provided by this SourceProvider.
      *
-     * @return the elements to use, or null, in which case the root element
-     *         is used.
+     * @param configurationHandlers the configuration handlers, not null.
+     * @param controllerState the current controller state, not null.
+     *
+     * @throws ConfigurationException if initializing fails.
      */
-    public String getStartElementsPath()
-    {
-        return startElementsPath;
-    }
+    protected abstract void initInternal(
+            ConfigurationHandlers configurationHandlers,
+            ControllerState controllerState)
+        throws ConfigurationException;
 
     /**
-     * Return all currently registered transformer definitions.
+     * Resets the sources provided by this SourceProvider.
+     *
+     * @param configurationHandlers the configuration handlers, not null.
+     * @param controllerState the current controller state, not null.
      *
-     * @return the transformer definitions, not null.
+     * @throws ConfigurationException if resetting fails.
      */
-    public List<TransformerDefinition> getTransformerDefinitions()
-    {
-        return Collections.unmodifiableList(transformerDefinitions);
-    }
+    protected abstract void resetInternal(
+                ConfigurationHandlers configurationHandlers,
+                ControllerState controllerState)
+        throws ConfigurationException;
 
     /**
-     * Returns the current source filter.
+     * Returns whether <code>init()</code> was already called.
      *
-     * @return the current source filter, or null.
+     * @return true if init() was already called, false otherwise.
      */
-    public SourceFilter getSourceFilter()
+    public boolean isInit()
     {
-        return sourceFilter;
+        return initialized;
     }
 }

Copied: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceTransformerDefinition.java (from r944873, db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/TransformerDefinition.java)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceTransformerDefinition.java?p2=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceTransformerDefinition.java&p1=db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/TransformerDefinition.java&r1=944873&r2=965166&rev=965166&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/TransformerDefinition.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceTransformerDefinition.java Sun Jul 18 06:10:55 2010
@@ -27,33 +27,106 @@ import org.apache.torque.generator.sourc
  *
  * $Id: $
  */
-public final class TransformerDefinition
+public final class SourceTransformerDefinition
 {
     /**
      * The transformer instance.
      */
-    private SourceTransformer transformer;
+    private SourceTransformer sourceTransformer;
 
     /**
      * The path to the source elements on which the transformer is applied.
      */
     private String elements;
 
-    public TransformerDefinition(
-            SourceTransformer transformer,
+    /**
+     * Constructor.
+     *
+     * @param sourceTransformer the transformer instance, not null.
+     * @param elements the elements to which the transformer is applied,
+     *        may be null.
+     */
+    public SourceTransformerDefinition(
+            SourceTransformer sourceTransformer,
             String elements)
     {
-        this.transformer = transformer;
+        if (sourceTransformer == null)
+        {
+            throw new NullPointerException(
+                    "sourceTransformer must not be null");
+        }
+        this.sourceTransformer = sourceTransformer;
         this.elements = elements;
     }
 
-    public SourceTransformer getTransformer()
+    /**
+     * Returns the source transformer instance for this definition.
+     *
+     * @return the source transformer instance, not null.
+     */
+    public SourceTransformer getSourceTransformer()
     {
-        return transformer;
+        return sourceTransformer;
     }
 
+    /**
+     * Returns the path to the source elements to which the transformer is
+     * applied.
+     *
+     * @return The path to the transformed source elements, or null.
+     */
     public String getElements()
     {
         return elements;
     }
+
+    @Override
+    public String toString()
+    {
+        return "SourceTransformerDefinition [elements=" + elements
+                + ", sourceTransformer=" + sourceTransformer + "]";
+    }
+
+    @Override
+    public int hashCode()
+    {
+        int result = 1;
+        result = ((elements == null) ? 0 : elements.hashCode());
+        result = 31 * result + sourceTransformer.hashCode();
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj)
+        {
+            return true;
+        }
+        if (obj == null)
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        SourceTransformerDefinition other = (SourceTransformerDefinition) obj;
+        if (elements == null)
+        {
+            if (other.elements != null)
+            {
+                return false;
+            }
+        }
+        else if (!elements.equals(other.elements))
+        {
+            return false;
+        }
+        if (!sourceTransformer.equals(other.sourceTransformer))
+        {
+            return false;
+        }
+        return true;
+    }
 }

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/ColumnMetadata.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/ColumnMetadata.java?rev=965166&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/ColumnMetadata.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/ColumnMetadata.java Sun Jul 18 06:10:55 2010
@@ -0,0 +1,65 @@
+package org.apache.torque.generator.source.jdbc;
+
+public class ColumnMetadata
+{
+    private String name;
+    private Integer sqlType;
+    private Integer size;
+    private Integer nullType;
+    private String defValue;
+    private Integer decimalDigits;
+
+
+    public ColumnMetadata(
+            String name,
+            Integer sqlType,
+            Integer size,
+            Integer nullType,
+            String defValue,
+            Integer decimalDigits)
+    {
+        super();
+        this.name = name;
+        this.sqlType = sqlType;
+        this.size = size;
+        this.nullType = nullType;
+        this.defValue = defValue;
+        this.decimalDigits = decimalDigits;
+    }
+
+
+    public String getName()
+    {
+        return name;
+    }
+
+
+    public Integer getSqlType()
+    {
+        return sqlType;
+    }
+
+
+    public Integer getSize()
+    {
+        return size;
+    }
+
+
+    public Integer getNullType()
+    {
+        return nullType;
+    }
+
+
+    public String getDefValue()
+    {
+        return defValue;
+    }
+
+
+    public Integer getDecimalDigits()
+    {
+        return decimalDigits;
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/ForeignKeyMetadata.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/ForeignKeyMetadata.java?rev=965166&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/ForeignKeyMetadata.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/ForeignKeyMetadata.java Sun Jul 18 06:10:55 2010
@@ -0,0 +1,45 @@
+package org.apache.torque.generator.source.jdbc;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ForeignKeyMetadata
+{
+    private String referencedTable;
+
+    private String foreignKeyName;
+
+    private List<String> localColumns = new ArrayList<String>();
+
+    private List<String> foreignColumns = new ArrayList<String>();
+
+    public String getReferencedTable()
+    {
+        return referencedTable;
+    }
+
+    public void setReferencedTable(String referencedTable)
+    {
+        this.referencedTable = referencedTable;
+    }
+
+    public String getForeignKeyName()
+    {
+        return foreignKeyName;
+    }
+
+    public void setForeignKeyName(String foreignKeyName)
+    {
+        this.foreignKeyName = foreignKeyName;
+    }
+
+    public List<String> getLocalColumns()
+    {
+        return localColumns;
+    }
+
+    public List<String> getForeignColumns()
+    {
+        return foreignColumns;
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/JdbcMetadataSource.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/JdbcMetadataSource.java?rev=965166&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/JdbcMetadataSource.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/jdbc/JdbcMetadataSource.java Sun Jul 18 06:10:55 2010
@@ -0,0 +1,388 @@
+package org.apache.torque.generator.source.jdbc;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.generator.jdbc.SchemaType;
+import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.SourceException;
+import org.apache.torque.generator.source.SourceImpl;
+
+public class JdbcMetadataSource extends SourceImpl
+{
+    private static Log log = LogFactory.getLog(JdbcMetadataSource.class);
+
+    private String driver;
+
+    private String url;
+    private String username;
+    private String password;
+    private String schema;
+
+
+    public JdbcMetadataSource(
+            String driver,
+            String url,
+            String username,
+            String password,
+            String schema)
+    {
+        this.driver = driver;
+        this.url = url;
+        this.username = username;
+        this.password = password;
+        this.schema = schema;
+    }
+
+    @Override
+    protected SourceElement createRootElement() throws SourceException
+    {
+        SourceElement rootElement = new SourceElement("database");
+        {
+            try
+            {
+                Class.forName(driver);
+            }
+            catch (ClassNotFoundException e)
+            {
+                throw new SourceException(
+                        "Could not find database driver class" + driver, e);
+            }
+            log.debug("DB driver " + driver + " loaded");
+        }
+
+        Connection con = null;
+        try
+        {
+
+            con = DriverManager.getConnection(url, username, password);
+            log.debug("DB connection to database " + url + " established");
+
+            DatabaseMetaData dbMetaData = con.getMetaData();
+
+            List<String> tableList = getTableNames(dbMetaData, schema);
+
+            for (int i = 0; i < tableList.size(); i++)
+            {
+                // Add Table.
+                String tableName = (String) tableList.get(i);
+                log.debug("Processing table: " + tableName);
+
+                SourceElement table = new SourceElement("table");
+                rootElement.getChildren().add(table);
+                table.setAttribute("name", tableName);
+
+                List<ColumnMetadata> columns
+                        = getColumns(dbMetaData, tableName, schema);
+                Set<String> primaryKeys
+                        = getPrimaryKeys(dbMetaData, tableName, schema);
+
+                for (ColumnMetadata col : columns)
+                {
+                    String name = col.getName();
+                    Integer type = col.getSqlType();
+                    int size = col.getSize().intValue();
+                    int scale = col.getDecimalDigits().intValue();
+
+                    Integer nullType = col.getNullType();
+                    String defValue = col.getDefValue();
+
+                    SourceElement column = new SourceElement("column");
+                    column.setAttribute("name", name);
+
+                    column.setAttribute(
+                            "type",
+                            SchemaType.getByJdbcType(type).toString());
+
+                    if (size > 0 && (type.intValue() == Types.CHAR
+                            || type.intValue() == Types.VARCHAR
+                            || type.intValue() == Types.LONGVARCHAR
+                            || type.intValue() == Types.DECIMAL
+                            || type.intValue() == Types.NUMERIC))
+                    {
+                        column.setAttribute("size", String.valueOf(size));
+                    }
+
+                    if (scale > 0 && (type.intValue() == Types.DECIMAL
+                            || type.intValue() == Types.NUMERIC))
+                    {
+                        column.setAttribute("scale", String.valueOf(scale));
+                    }
+
+                    if (primaryKeys.contains(name))
+                    {
+                        column.setAttribute("primaryKey", "true");
+                    }
+                    else if (nullType.intValue() == 0)
+                    {
+                        column.setAttribute("required", "true");
+                    }
+
+                    if (StringUtils.isNotEmpty(defValue))
+                    {
+                        // trim out parens & quotes out of def value.
+                        // makes sense for MSSQL. not sure about others.
+                        if (defValue.startsWith("(") && defValue.endsWith(")"))
+                        {
+                            defValue = defValue.substring(1, defValue.length() - 1);
+                        }
+
+                        if (defValue.startsWith("'") && defValue.endsWith("'"))
+                        {
+                            defValue = defValue.substring(1, defValue.length() - 1);
+                        }
+
+                        column.setAttribute("default", defValue);
+                    }
+                    table.getChildren().add(column);
+                }
+
+                // Foreign keys for this table.
+                Collection<ForeignKeyMetadata> forgnKeys
+                        = getForeignKeys(dbMetaData, tableName, schema);
+                for (ForeignKeyMetadata foreignKeyMetadata : forgnKeys)
+                {
+                    SourceElement fk = new SourceElement("foreign-key");
+                    fk.setAttribute(
+                            "foreignTable",
+                            foreignKeyMetadata.getReferencedTable());
+                    for (int m = 0; m < foreignKeyMetadata.getLocalColumns().size(); m++)
+                    {
+                        SourceElement ref = new SourceElement("reference");
+                        ref.setAttribute("local", foreignKeyMetadata.getLocalColumns().get(m));
+                        ref.setAttribute("foreign", foreignKeyMetadata.getForeignColumns().get(m));
+                        fk.getChildren().add(ref);
+                    }
+                    table.getChildren().add(fk);
+                }
+            }
+        }
+        catch (SQLException e)
+        {
+            throw new SourceException(
+                    "Could not retrieve JDBC Metadata from url " + url, e);
+        }
+        finally
+        {
+            if (con != null)
+            {
+                try
+                {
+                    con.close();
+                }
+                catch (SQLException e)
+                {
+                    log.warn("Could not close database connection", e);
+                }
+                con = null;
+            }
+        }
+        return rootElement;
+    }
+
+    public String getDescription()
+    {
+        return "JdbcMetadataSource using url " + url;
+    }
+
+    public File getSourceFile()
+    {
+        return null;
+    }
+
+    /**
+     * Get all the table names in the current database that are not
+     * system tables.
+     *
+     * @param dbMeta JDBC database metadata.
+     * @return The list of all the tables in a database.
+     * @throws SQLException
+     */
+    List<String> getTableNames(DatabaseMetaData dbMeta, String dbSchema)
+        throws SQLException
+    {
+        log.debug("Getting table list...");
+        List<String> tables = new ArrayList<String>();
+        ResultSet tableNames = null;
+        // these are the entity types we want from the database
+        String[] types = {"TABLE", "VIEW"};
+        try
+        {
+            tableNames = dbMeta.getTables(null, dbSchema, "%", types);
+            while (tableNames.next())
+            {
+                String name = tableNames.getString(3);
+                tables.add(name);
+            }
+        }
+        finally
+        {
+            if (tableNames != null)
+            {
+                tableNames.close();
+            }
+        }
+        return tables;
+    }
+
+    /**
+     * Retrieves all the column names and types for a given table from
+     * JDBC metadata.
+     *
+     * @param dbMeta JDBC metadata.
+     * @param tableName Table from which to retrieve column information.
+     *
+     * @return The list of columns in <code>tableName</code>.
+     *
+     * @throws SQLException if an sql error occurs during information retrieval.
+     */
+    List<ColumnMetadata> getColumns(
+            DatabaseMetaData dbMeta,
+            String tableName,
+            String dbSchema)
+            throws SQLException
+    {
+        List<ColumnMetadata> columns = new ArrayList<ColumnMetadata>();
+        ResultSet columnSet = null;
+        try
+        {
+            columnSet = dbMeta.getColumns(null, dbSchema, tableName, null);
+            while (columnSet.next())
+            {
+                String name = columnSet.getString(4);
+                Integer sqlType = new Integer(columnSet.getString(5));
+                Integer size = new Integer(columnSet.getInt(7));
+                Integer decimalDigits = new Integer(columnSet.getInt(9));
+                Integer nullType = new Integer(columnSet.getInt(11));
+                String defValue = columnSet.getString(13);
+
+                ColumnMetadata column = new ColumnMetadata(
+                        name,
+                        sqlType,
+                        size,
+                        nullType,
+                        defValue,
+                        decimalDigits);
+                columns.add(column);
+            }
+        }
+        finally
+        {
+            if (columnSet != null)
+            {
+                columnSet.close();
+            }
+        }
+        return columns;
+    }
+
+    /**
+     * Retrieves a list of the columns composing the primary key for a given
+     * table.
+     *
+     * @param dbMeta JDBC metadata.
+     * @param tableName Table from which to retrieve PK information.
+     * @return A list of the primary key parts for <code>tableName</code>.
+     * @throws SQLException
+     */
+    Set<String> getPrimaryKeys(
+                DatabaseMetaData dbMeta,
+                String tableName,
+                String schemaName)
+            throws SQLException
+    {
+        Set<String> pk = new HashSet<String>();
+        ResultSet parts = null;
+        try
+        {
+            parts = dbMeta.getPrimaryKeys(null, schemaName, tableName);
+            while (parts.next())
+            {
+                pk.add(parts.getString(4));
+            }
+        }
+        finally
+        {
+            if (parts != null)
+            {
+                parts.close();
+            }
+        }
+        return pk;
+    }
+
+    /**
+     * Retrieves a list of foreign key columns for a given table.
+     *
+     * @param dbMeta JDBC metadata.
+     * @param tableName Table from which to retrieve FK information.
+     * @return A list of foreign keys in <code>tableName</code>.
+     * @throws SQLException
+     */
+    Collection<ForeignKeyMetadata> getForeignKeys(
+                DatabaseMetaData dbMeta,
+                String tableName,
+                String schemaName)
+            throws SQLException
+    {
+        Map<String, ForeignKeyMetadata> foreignKeys
+                = new HashMap<String, ForeignKeyMetadata>();
+        ResultSet resultSet = null;
+        try
+        {
+            resultSet = dbMeta.getImportedKeys(null, schemaName, tableName);
+            while (resultSet.next())
+            {
+                String refTableName = resultSet.getString(3);
+                String fkName = resultSet.getString(12);
+                // if FK has no name - make it up (use tablename instead)
+                if (fkName == null)
+                {
+                    fkName = refTableName;
+                }
+                ForeignKeyMetadata fk = foreignKeys.get(fkName);
+                if (fk == null)
+                {
+                    fk = new ForeignKeyMetadata();
+                    fk.setReferencedTable(refTableName);
+                    fk.setForeignKeyName(fkName);
+                    foreignKeys.put(fkName, fk);
+                }
+                fk.getLocalColumns().add(resultSet.getString(8));
+                fk.getForeignColumns().add(resultSet.getString(4));
+            }
+        }
+        catch (SQLException e)
+        {
+            // this seems to be happening in some db drivers (sybase)
+            // when retrieving foreign keys from views.
+            log.warn("WARN: Could not read foreign keys for Table "
+                        + tableName
+                        + " : "
+                        + e.getMessage());
+        }
+        finally
+        {
+            if (resultSet != null)
+            {
+                resultSet.close();
+            }
+        }
+        return foreignKeys.values();
+    }
+}



---------------------------------------------------------------------
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