db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r992435 - in /db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration: ./ paths/
Date Fri, 03 Sep 2010 19:47:42 GMT
Author: tfischer
Date: Fri Sep  3 19:47:42 2010
New Revision: 992435

URL: http://svn.apache.org/viewvc?rev=992435&view=rev
Log:
- add possibility to define resources.
This is needed in order to access xsd schema files for xml source validation.

Modified:
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ClasspathConfigurationProvider.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ConfigurationProvider.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/DirectoryConfigurationProvider.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/JarConfigurationProvider.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/paths/DefaultTorqueGeneratorPaths.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/paths/TorqueGeneratorPaths.java

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ClasspathConfigurationProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ClasspathConfigurationProvider.java?rev=992435&r1=992434&r2=992435&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ClasspathConfigurationProvider.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ClasspathConfigurationProvider.java
Fri Sep  3 19:47:42 2010
@@ -85,94 +85,83 @@ public class ClasspathConfigurationProvi
     }
 
     public InputStream getControlConfigurationInputStream()
-        throws ConfigurationException
+            throws ConfigurationException
     {
-        String configFileName
-                = getConfigResourceBase()
-                    + "/"
-                    + configurationPaths.getConfigurationDirectory()
-                    + "/"
-                    + configurationPaths.getControlConfigurationFile();
-
-        InputStream inputStream
-                = getClass().getClassLoader().getResourceAsStream(
-                        configFileName);
-        if (inputStream == null)
-        {
-            throw new ConfigurationException("Could not read entry "
-                        + configFileName
-                        + " in classpath");
-        }
-        BufferedInputStream bis = new BufferedInputStream(inputStream);
-        if (log.isInfoEnabled())
-        {
-            log.info("Using control file: '"
-                    + configFileName
-                    + "' from classpath");
-        }
-        return bis;
+        return getInputStream(
+                configurationPaths.getControlConfigurationFile(),
+                configurationPaths.getConfigurationDirectory(),
+                "control file");
     }
 
     public InputStream getTemplateInputStream(String name)
-        throws ConfigurationException
+            throws ConfigurationException
     {
-        String templateFileName
-                = getConfigResourceBase()
-                    + "/"
-                    + configurationPaths.getTemplateSubdirectory()
-                    + "/"
-                    + name;
+        return getInputStream(
+                name,
+                configurationPaths.getTemplateDirectory(),
+                "template");
+    }
 
-        InputStream inputStream
-                = getClass().getClassLoader().getResourceAsStream(
-                        templateFileName);
+    public InputStream getOutletConfigurationInputStream(String name)
+            throws ConfigurationException
+    {
+        return getInputStream(
+                name,
+                configurationPaths.getOutletDirectory(),
+                "outlet configuration");
+   }
 
-        if (inputStream == null)
-        {
-            throw new ConfigurationException("Could not read template file "
-                        + templateFileName
-                        + " in classpath");
-        }
-        BufferedInputStream bis = new BufferedInputStream(inputStream);
-        if (log.isInfoEnabled())
-        {
-            log.info("Reading template: '"
-                    + templateFileName
-                    + "' in class path");
-        }
-        return bis;
+    public InputStream getResourceInputStream(String name)
+            throws ConfigurationException
+    {
+        return getInputStream(
+                name,
+                configurationPaths.getResourceDirectory(),
+                "resource");
     }
 
-    public InputStream getOutletConfigurationInputStream(String name)
-        throws ConfigurationException
+    public InputStream getOptionsInputStream(String name)
+            throws ConfigurationException
     {
-        String outletConfigFileName
+        return getInputStream(
+                name,
+                configurationPaths.getConfigurationDirectory(),
+                "option");
+    }
+
+    private InputStream getInputStream(
+                String name,
+                String directory,
+                String fileDescription)
+            throws ConfigurationException
+    {
+        String fileName
                 = getConfigResourceBase()
                     + "/"
-                    + configurationPaths.getOutletDirectory()
+                    + directory
                     + "/"
                     + name;
-
+    
         InputStream inputStream
                 = getClass().getClassLoader().getResourceAsStream(
-                        outletConfigFileName);
-
+                        fileName);
+    
         if (inputStream == null)
         {
             throw new ConfigurationException(
-                    "Could not read outlet configuration file "
-                        + outletConfigFileName
+                    "Could not read " + fileDescription + " file "
+                        + fileName
                         + " in classpath");
         }
         BufferedInputStream bis = new BufferedInputStream(inputStream);
-        if (log.isInfoEnabled())
+        if (log.isDebugEnabled())
         {
-            log.info("Reading outlet configuration file: '"
-                    + outletConfigFileName
+            log.debug("Reading " + fileDescription + " file: '"
+                    + fileName
                     + "' in classpath");
         }
         return bis;
-   }
+    }
 
     public Collection<String> getOutletConfigurationNames()
         throws ConfigurationException
@@ -263,36 +252,6 @@ public class ClasspathConfigurationProvi
         return result;
     }
 
-    public InputStream getOptionsInputStream(String name)
-        throws ConfigurationException
-    {
-        String optionsFileName
-                = getConfigResourceBase()
-                    + "/"
-                    + configurationPaths.getConfigurationDirectory()
-                    + "/"
-                    + name;
-
-        InputStream inputStream
-                = getClass().getClassLoader().getResourceAsStream(
-                        optionsFileName);
-
-        if (inputStream == null)
-        {
-            throw new ConfigurationException("Could not read options file "
-                        + optionsFileName
-                        + " in classpath");
-        }
-        BufferedInputStream bis = new BufferedInputStream(inputStream);
-        if (log.isInfoEnabled())
-        {
-            log.info("Reading options file: '"
-                    +  optionsFileName
-                     + "' in classpath");
-        }
-        return bis;
-    }
-
     /**
      * Gets the resource name for the configuration base directory from the
      * projectPaths.

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ConfigurationProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ConfigurationProvider.java?rev=992435&r1=992434&r2=992435&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ConfigurationProvider.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/ConfigurationProvider.java
Fri Sep  3 19:47:42 2010
@@ -89,4 +89,17 @@ public interface ConfigurationProvider
     InputStream getOptionsInputStream(String name)
         throws ConfigurationException;
 
+
+    /**
+     * Creates a reader to access a resource file.
+     * It is the callers responsibility to close the reader after use.
+     *
+     * @param path the path to of the resource file.
+     *
+     * @return a reader to access the options file, never null.
+     *
+     * @throws ConfigurationException if the reader can not be created.
+     */
+    InputStream getResourceInputStream(String path)
+        throws ConfigurationException;
 }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/DirectoryConfigurationProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/DirectoryConfigurationProvider.java?rev=992435&r1=992434&r2=992435&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/DirectoryConfigurationProvider.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/DirectoryConfigurationProvider.java
Fri Sep  3 19:47:42 2010
@@ -83,100 +83,81 @@ public class DirectoryConfigurationProvi
     public InputStream getControlConfigurationInputStream()
         throws ConfigurationException
     {
-        File configFile;
-        {
-            File configDirectory = new File(
-                    projectPaths.getConfigurationPath(),
-                    configurationPaths.getConfigurationDirectory());
-            configFile = new File(
-                    configDirectory,
-                    configurationPaths.getControlConfigurationFile());
-        }
-
-        InputStream inputStream = null;
-        try
-        {
-            inputStream = new FileInputStream(configFile);
-        }
-        catch (FileNotFoundException e)
-        {
-            throw new ConfigurationException("Controller configuration file "
-                    + configFile.getAbsolutePath()
-                    + " not found");
-        }
-        BufferedInputStream bis = new BufferedInputStream(inputStream);
-        if (log.isInfoEnabled())
-        {
-            log.info("Using control file: '"
-                    + configFile.getAbsolutePath() + "'");
-        }
-        return bis;
+        return getInputStream(
+                configurationPaths.getControlConfigurationFile(),
+                configurationPaths.getConfigurationDirectory(),
+                "template");
     }
 
     public InputStream getTemplateInputStream(String name)
         throws ConfigurationException
     {
-        File templateFile;
-        {
-            File templateDir =  new File(
-                    projectPaths.getConfigurationPath(),
-                    configurationPaths.getTemplateSubdirectory());
-            templateFile = new File(
-                    templateDir,
-                    name);
-        }
-
-        InputStream inputStream = null;
-        try
-        {
-            inputStream = new FileInputStream(templateFile);
-        }
-        catch (FileNotFoundException e)
-        {
-            throw new ConfigurationException("Template file "
-                    + templateFile.getAbsolutePath()
-                    + " not found");
-        }
-        BufferedInputStream bis = new BufferedInputStream(inputStream);
-        if (log.isInfoEnabled())
-        {
-            log.info("Reading Template: '"
-                    + templateFile.getAbsolutePath() + "'");
-        }
-        return bis;
+        return getInputStream(
+                name,
+                configurationPaths.getTemplateDirectory(),
+                "template");
     }
 
     public InputStream getOutletConfigurationInputStream(String name)
         throws ConfigurationException
     {
-        File outletConfigFile;
+        return getInputStream(
+                name,
+                configurationPaths.getOutletDirectory(),
+                "outlet configuration");
+    }
+
+    public InputStream getResourceInputStream(String name)
+            throws ConfigurationException
+    {
+        return getInputStream(
+                name,
+                configurationPaths.getResourceDirectory(),
+                "resource");
+    }
+
+    public InputStream getOptionsInputStream(String name)
+        throws ConfigurationException
+    {
+        return getInputStream(
+                name,
+                configurationPaths.getConfigurationDirectory(),
+                "option");
+    }
+
+    private InputStream getInputStream(
+                String name,
+                String directory,
+                String description)
+            throws ConfigurationException
+    {
+        File file;
         {
-            File outletConfigDir =  new File(
+            File configDir =  new File(
                     projectPaths.getConfigurationPath(),
-                    configurationPaths.getOutletDirectory());
+                    directory);
 
-            outletConfigFile = new File(outletConfigDir, name);
+            file = new File(configDir, name);
         }
 
-        InputStream inputStream = null;
+        InputStream inputStream;
         try
         {
-            inputStream = new FileInputStream(outletConfigFile);
+            inputStream = new FileInputStream(file);
         }
         catch (FileNotFoundException e)
         {
-            throw new ConfigurationException("Outlet configuration file "
-                    + outletConfigFile.getAbsolutePath()
+            throw new ConfigurationException(description + " file "
+                    + file.getAbsolutePath()
                     + " not found");
         }
         BufferedInputStream bis = new BufferedInputStream(inputStream);
-        if (log.isInfoEnabled())
+        if (log.isDebugEnabled())
         {
-            log.info("Reading Outlet configuration file: '"
-                    + outletConfigFile.getAbsolutePath() + "'");
+            log.debug("Reading " + description + " file: '"
+                    + file.getAbsolutePath() + "'");
         }
         return bis;
-
     }
 
     public Collection<String> getOutletConfigurationNames()
@@ -207,35 +188,4 @@ public class DirectoryConfigurationProvi
         }
         return result;
     }
-
-    public InputStream getOptionsInputStream(String name)
-        throws ConfigurationException
-    {
-        File optionsFile;
-        {
-            File configDirectory = new File(
-                    projectPaths.getConfigurationPath(),
-                    configurationPaths.getConfigurationDirectory());
-            optionsFile = new File(configDirectory, name);
-        }
-
-        InputStream inputStream = null;
-        try
-        {
-            inputStream = new FileInputStream(optionsFile);
-        }
-        catch (FileNotFoundException e)
-        {
-            throw new ConfigurationException("Options file "
-                    + optionsFile.getAbsolutePath()
-                    + " not found");
-        }
-        BufferedInputStream bis = new BufferedInputStream(inputStream);
-        if (log.isInfoEnabled())
-        {
-            log.info("Reading Options file: '"
-                    + optionsFile.getAbsolutePath() + "'");
-        }
-        return bis;
-    }
 }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/JarConfigurationProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/JarConfigurationProvider.java?rev=992435&r1=992434&r2=992435&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/JarConfigurationProvider.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/JarConfigurationProvider.java
Fri Sep  3 19:47:42 2010
@@ -98,114 +98,86 @@ public class JarConfigurationProvider im
                         .getAbsolutePath());
             throw new ConfigurationException(e);
         }
-
     }
 
     public InputStream getControlConfigurationInputStream()
-        throws ConfigurationException
+            throws ConfigurationException
     {
-        String configFileName
-                = configurationPaths.getConfigurationDirectory()
-                        + "/"
-                        + configurationPaths.getControlConfigurationFile();
-
-
-        InputStream inputStream = null;
-        try
-        {
-            JarEntry jarEntry = jarFile.getJarEntry(configFileName);
-            if (jarEntry == null)
-            {
-                throw new ConfigurationException("File " + configFileName
-                        + " not found in Jar file.");
-            }
-            inputStream = jarFile.getInputStream(jarEntry);
-        }
-        catch (IOException e)
-        {
-            throw new ConfigurationException("Could not read entry "
-                        + configFileName
-                        + " in jar file "
-                        + projectPaths.getConfigurationPath(),
-                    e);
-        }
-        BufferedInputStream bis = new BufferedInputStream(inputStream);
-        if (log.isInfoEnabled())
-        {
-            log.info("Using control file: '"
-                    + configFileName
-                    + "' in jar file "
-                    + projectPaths.getConfigurationPath());
-        }
-        return bis;
+        return getInputStream(
+                configurationPaths.getControlConfigurationFile(),
+                configurationPaths.getConfigurationDirectory(),
+                "configuration");
     }
 
     public InputStream getTemplateInputStream(String name)
-        throws ConfigurationException
+            throws ConfigurationException
     {
-        String templateFileName
-                = configurationPaths.getTemplateSubdirectory()
-                    + "/"
-                    + name;
-
-        InputStream inputStream = null;
-        try
-        {
-            JarEntry jarEntry = jarFile.getJarEntry(templateFileName);
-            inputStream = jarFile.getInputStream(jarEntry);
-        }
-        catch (IOException e)
-        {
-            throw new ConfigurationException("Could not read template file "
-                        + templateFileName
-                        + " in jar file "
-                        + projectPaths.getConfigurationPath(),
-                    e);
-        }
-        BufferedInputStream bis = new BufferedInputStream(inputStream);
-        if (log.isInfoEnabled())
-        {
-            log.info("Reading template: '"
-                    + projectPaths.getConfigurationPath()
-                    + "' in jar file "
-                    + projectPaths.getConfigurationPath());
-        }
-        return bis;
+        return getInputStream(
+                name,
+                configurationPaths.getTemplateDirectory(),
+                "template");
     }
 
     public InputStream getOutletConfigurationInputStream(String name)
-        throws ConfigurationException
+            throws ConfigurationException
+    {
+        return getInputStream(
+                name,
+                configurationPaths.getOutletDirectory(),
+                "outlet configuration");
+   }
+
+    public InputStream getResourceInputStream(String name)
+            throws ConfigurationException
+    {
+        return getInputStream(
+                name,
+                configurationPaths.getResourceDirectory(),
+                "resource");
+    }
+
+    public InputStream getOptionsInputStream(String name)
+            throws ConfigurationException
     {
-        String outletConfigFileName
-                = configurationPaths.getOutletDirectory()
-                    + "/"
-                    + name;
+        return getInputStream(
+                name,
+                configurationPaths.getConfigurationDirectory(),
+                "option");
+    }
+
+    private InputStream getInputStream(
+               String name,
+               String directory,
+               String description)
+            throws ConfigurationException
+    {
+        String fileName = directory + "/" + name;
 
         InputStream inputStream = null;
         try
         {
-            JarEntry jarEntry = jarFile.getJarEntry(outletConfigFileName);
+            JarEntry jarEntry = jarFile.getJarEntry(fileName);
             inputStream = jarFile.getInputStream(jarEntry);
         }
         catch (IOException e)
         {
             throw new ConfigurationException(
-                    "Could not read outlet configuration file "
-                        + outletConfigFileName
+                    "Could not read " + description + " file "
+                        + fileName
                         + " in jar file "
                         + projectPaths.getConfigurationPath(),
                     e);
         }
         BufferedInputStream bis = new BufferedInputStream(inputStream);
-        if (log.isInfoEnabled())
+        if (log.isDebugEnabled())
         {
-            log.info("Reading outlet configuration file: '"
+            log.debug("Reading " + description + " file: '"
                     + projectPaths.getConfigurationPath()
                     + "' in jar file "
                     + projectPaths.getConfigurationPath());
         }
         return bis;
-   }
+    }
 
     public Collection<String> getOutletConfigurationNames()
         throws ConfigurationException
@@ -273,37 +245,4 @@ public class JarConfigurationProvider im
         }
         return result;
     }
-
-    public InputStream getOptionsInputStream(String name)
-        throws ConfigurationException
-    {
-        String optionsFileName
-                = configurationPaths.getConfigurationDirectory()
-                    + "/"
-                    + name;
-
-        InputStream inputStream = null;
-        try
-        {
-            JarEntry jarEntry = jarFile.getJarEntry(optionsFileName);
-            inputStream = jarFile.getInputStream(jarEntry);
-        }
-        catch (IOException e)
-        {
-            throw new ConfigurationException("Could not read options file "
-                        + optionsFileName
-                        + " in jar file "
-                        + projectPaths.getConfigurationPath(),
-                    e);
-        }
-        BufferedInputStream bis = new BufferedInputStream(inputStream);
-        if (log.isInfoEnabled())
-        {
-            log.info("Reading options file: '"
-                    + projectPaths.getConfigurationPath()
-                    + "' in jar file "
-                    + projectPaths.getConfigurationPath());
-        }
-        return bis;
-    }
 }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/paths/DefaultTorqueGeneratorPaths.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/paths/DefaultTorqueGeneratorPaths.java?rev=992435&r1=992434&r2=992435&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/paths/DefaultTorqueGeneratorPaths.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/paths/DefaultTorqueGeneratorPaths.java
Fri Sep  3 19:47:42 2010
@@ -27,6 +27,7 @@ package org.apache.torque.generator.conf
  * - - - control.xml<br/>
  * - - outlets<br/>
  * - - templates<br/>
+ * - - resources<br/>
  */
 public class DefaultTorqueGeneratorPaths implements TorqueGeneratorPaths
 {
@@ -56,12 +57,19 @@ public class DefaultTorqueGeneratorPaths
     private static final String OUTLET_DIRECTORY
         = "outlets";
 
+    /**
+     * The path to the resource directory, relative to the
+     * configuration root directory.
+     */
+    private static final String RESOURCE_DIRECTORY
+        = "resources";
+
     public String getControlConfigurationFile()
     {
         return CONTROL_CONFIGURATION_FILE_NAME;
     }
 
-    public String getTemplateSubdirectory()
+    public String getTemplateDirectory()
     {
         return TEMPLATES_DIRECTORY;
     }
@@ -75,4 +83,9 @@ public class DefaultTorqueGeneratorPaths
     {
         return OUTLET_DIRECTORY;
     }
+
+    public String getResourceDirectory()
+    {
+        return RESOURCE_DIRECTORY;
+    }
 }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/paths/TorqueGeneratorPaths.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/paths/TorqueGeneratorPaths.java?rev=992435&r1=992434&r2=992435&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/paths/TorqueGeneratorPaths.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/paths/TorqueGeneratorPaths.java
Fri Sep  3 19:47:42 2010
@@ -39,7 +39,7 @@ public interface TorqueGeneratorPaths
      *
      * @return the path to the template directory. not null.
      */
-    String getTemplateSubdirectory();
+    String getTemplateDirectory();
 
     /**
      * Returns the path to the directory containing the configuration,
@@ -57,4 +57,11 @@ public interface TorqueGeneratorPaths
      */
     String getOutletDirectory();
 
+    /**
+     * Returns the path to the directory containing the resources,
+     * relative to the Torque generator configuration directory.
+     *
+     * @return the path to the resources directory, not null.
+     */
+    String getResourceDirectory();
 }



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