You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2012/10/27 20:34:58 UTC
svn commit: r1402839 -
/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/
Author: tfischer
Date: Sat Oct 27 18:34:57 2012
New Revision: 1402839
URL: http://svn.apache.org/viewvc?rev=1402839&view=rev
Log:
Refactor ConfigurationProvider classes to avoid duplicate code
Added:
db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/AbstractConfigurationProvider.java
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/DirectoryConfigurationProvider.java
db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/JarConfigurationProvider.java
Added: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/AbstractConfigurationProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/AbstractConfigurationProvider.java?rev=1402839&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/AbstractConfigurationProvider.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/configuration/AbstractConfigurationProvider.java Sat Oct 27 18:34:57 2012
@@ -0,0 +1,108 @@
+package org.apache.torque.generator.configuration;
+
+import java.io.InputStream;
+
+import org.apache.torque.generator.configuration.paths.TorqueGeneratorPaths;
+
+/*
+ * 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.
+ */
+
+/**
+ * A base class for all ConfigurationProvider implementations.
+ * @version $Id: $
+ */
+public abstract class AbstractConfigurationProvider
+ implements ConfigurationProvider
+{
+ /**
+ * The internal directory structure of the Torque generator
+ * configuration files, not null.
+ */
+ private TorqueGeneratorPaths configurationPaths;
+
+ /**
+ * Constructor.
+ *
+ * @param configurationPaths The internal directory structure of the
+ * Torque generator configuration files, not null.
+ *
+ * @throws NullPointerException if configurationPaths is null.
+ */
+ public AbstractConfigurationProvider(
+ TorqueGeneratorPaths configurationPaths)
+ {
+ if (configurationPaths == null)
+ {
+ throw new NullPointerException("configurationPaths is null");
+ }
+ this.configurationPaths = configurationPaths;
+ }
+
+ public InputStream getControlConfigurationInputStream()
+ throws ConfigurationException
+ {
+ return getInputStream(
+ configurationPaths.getControlConfigurationFile(),
+ configurationPaths.getConfigurationDirectory(),
+ "control file");
+ }
+
+ public InputStream getTemplateInputStream(String name)
+ throws ConfigurationException
+ {
+ return getInputStream(
+ name,
+ configurationPaths.getTemplateDirectory(),
+ "template");
+ }
+
+ public InputStream getOutletConfigurationInputStream(String name)
+ 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
+ {
+ return getInputStream(
+ name,
+ configurationPaths.getConfigurationDirectory(),
+ "option");
+ }
+
+ protected abstract InputStream getInputStream(
+ String name,
+ String directory,
+ String fileDescription)
+ throws ConfigurationException;
+
+}
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=1402839&r1=1402838&r2=1402839&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 Sat Oct 27 18:34:57 2012
@@ -39,7 +39,8 @@ import org.apache.torque.generator.confi
* Provides InputStreams to read a configuration of a unit of generation from a
* jar file.
*/
-public class ClasspathConfigurationProvider implements ConfigurationProvider
+public class ClasspathConfigurationProvider
+ extends AbstractConfigurationProvider
{
/** The logger. */
private static Log log
@@ -73,27 +74,15 @@ public class ClasspathConfigurationProvi
ProjectPaths projectPaths,
TorqueGeneratorPaths configurationPaths)
{
+ super(configurationPaths);
if (projectPaths == null)
{
throw new NullPointerException("projectPaths is null");
}
- if (configurationPaths == null)
- {
- throw new NullPointerException("configurationPaths is null");
- }
this.projectPaths = projectPaths;
this.configurationPaths = configurationPaths;
}
- public InputStream getControlConfigurationInputStream()
- throws ConfigurationException
- {
- return getInputStream(
- configurationPaths.getControlConfigurationFile(),
- configurationPaths.getConfigurationDirectory(),
- "control file");
- }
-
public String getControlConfigurationLocation()
{
return getFileName(
@@ -101,43 +90,7 @@ public class ClasspathConfigurationProvi
configurationPaths.getConfigurationDirectory());
}
- public InputStream getTemplateInputStream(String name)
- throws ConfigurationException
- {
- return getInputStream(
- name,
- configurationPaths.getTemplateDirectory(),
- "template");
- }
-
- public InputStream getOutletConfigurationInputStream(String name)
- 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
- {
- return getInputStream(
- name,
- configurationPaths.getConfigurationDirectory(),
- "option");
- }
-
- private String getFileName(
+ protected String getFileName(
String name,
String directory)
{
@@ -153,7 +106,7 @@ public class ClasspathConfigurationProvi
return fileName;
}
- private InputStream getInputStream(
+ protected InputStream getInputStream(
String name,
String directory,
String fileDescription)
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=1402839&r1=1402838&r2=1402839&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 Sat Oct 27 18:34:57 2012
@@ -37,7 +37,8 @@ import org.apache.torque.generator.confi
/**
* Provides InputStreams to read the configuration from a directory.
*/
-public class DirectoryConfigurationProvider implements ConfigurationProvider
+public class DirectoryConfigurationProvider
+ extends AbstractConfigurationProvider
{
/** The logger. */
private static Log log
@@ -69,27 +70,15 @@ public class DirectoryConfigurationProvi
ProjectPaths projectPaths,
TorqueGeneratorPaths configurationPaths)
{
+ super(configurationPaths);
if (projectPaths == null)
{
throw new NullPointerException("projectPaths is null");
}
- if (configurationPaths == null)
- {
- throw new NullPointerException("configurationPaths is null");
- }
this.projectPaths = projectPaths;
this.configurationPaths = configurationPaths;
}
- public InputStream getControlConfigurationInputStream()
- throws ConfigurationException
- {
- return getInputStream(
- configurationPaths.getControlConfigurationFile(),
- configurationPaths.getConfigurationDirectory(),
- "control file");
- }
-
public String getControlConfigurationLocation()
throws ConfigurationException
{
@@ -99,42 +88,6 @@ public class DirectoryConfigurationProvi
"control file").getAbsolutePath();
}
- public InputStream getTemplateInputStream(String name)
- throws ConfigurationException
- {
- return getInputStream(
- name,
- configurationPaths.getTemplateDirectory(),
- "template");
- }
-
- public InputStream getOutletConfigurationInputStream(String name)
- 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
- {
- return getInputStream(
- name,
- configurationPaths.getConfigurationDirectory(),
- "option");
- }
-
private File getFile(
String name,
String directory,
@@ -162,7 +115,7 @@ public class DirectoryConfigurationProvi
return file;
}
- private InputStream getInputStream(
+ protected InputStream getInputStream(
String name,
String directory,
String description)
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=1402839&r1=1402838&r2=1402839&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 Sat Oct 27 18:34:57 2012
@@ -38,7 +38,8 @@ import org.apache.torque.generator.confi
* Provides InputStreams to read a configuration of a unit of generation from a
* jar file.
*/
-public class JarConfigurationProvider implements ConfigurationProvider
+public class JarConfigurationProvider
+ extends AbstractConfigurationProvider
{
/** The logger. */
private static Log log
@@ -76,14 +77,11 @@ public class JarConfigurationProvider im
TorqueGeneratorPaths configurationPaths)
throws ConfigurationException
{
+ super(configurationPaths);
if (projectPaths == null)
{
throw new NullPointerException("projectPaths is null");
}
- if (configurationPaths == null)
- {
- throw new NullPointerException("configurationPaths is null");
- }
this.projectPaths = projectPaths;
this.configurationPaths = configurationPaths;
@@ -100,16 +98,6 @@ public class JarConfigurationProvider im
}
}
- public InputStream getControlConfigurationInputStream()
- throws ConfigurationException
- {
- return getInputStream(
- configurationPaths.getControlConfigurationFile(),
- configurationPaths.getConfigurationDirectory(),
- "configuration");
- }
-
-
public String getControlConfigurationLocation()
throws ConfigurationException
{
@@ -118,43 +106,7 @@ public class JarConfigurationProvider im
+ configurationPaths.getControlConfigurationFile();
}
- public InputStream getTemplateInputStream(String name)
- throws ConfigurationException
- {
- return getInputStream(
- name,
- configurationPaths.getTemplateDirectory(),
- "template");
- }
-
- public InputStream getOutletConfigurationInputStream(String name)
- 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
- {
- return getInputStream(
- name,
- configurationPaths.getConfigurationDirectory(),
- "option");
- }
-
- private InputStream getInputStream(
+ protected InputStream getInputStream(
String name,
String directory,
String description)
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org