You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by am...@apache.org on 2007/12/08 16:44:07 UTC

svn commit: r602484 - in /incubator/tuscany/java/das: ./ distribution/binary/ distribution/binary/src/main/assembly/ plugin/ plugin/src/ plugin/src/main/ plugin/src/main/java/ plugin/src/main/java/org/ plugin/src/main/java/org/apache/ plugin/src/main/j...

Author: amita
Date: Sat Dec  8 07:44:04 2007
New Revision: 602484

URL: http://svn.apache.org/viewvc?rev=602484&view=rev
Log:
TUSCANY-1923 Plugin for DBtoXSDGenerator tool and modifications to tool itself

Added:
    incubator/tuscany/java/das/plugin/
    incubator/tuscany/java/das/plugin/pom.xml
    incubator/tuscany/java/das/plugin/src/
    incubator/tuscany/java/das/plugin/src/main/
    incubator/tuscany/java/das/plugin/src/main/java/
    incubator/tuscany/java/das/plugin/src/main/java/org/
    incubator/tuscany/java/das/plugin/src/main/java/org/apache/
    incubator/tuscany/java/das/plugin/src/main/java/org/apache/tuscany/
    incubator/tuscany/java/das/plugin/src/main/java/org/apache/tuscany/das/
    incubator/tuscany/java/das/plugin/src/main/java/org/apache/tuscany/das/plugin/
    incubator/tuscany/java/das/plugin/src/main/java/org/apache/tuscany/das/plugin/GeneratorMojo.java
    incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ModelXSDGenOption.java
Modified:
    incubator/tuscany/java/das/distribution/binary/pom.xml
    incubator/tuscany/java/das/distribution/binary/src/main/assembly/das.xml
    incubator/tuscany/java/das/pom.xml
    incubator/tuscany/java/das/tools/readme.htm
    incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToSchemaFile.java
    incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToXSDGenerator.java
    incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/SchemaFileToXSD.java
    incubator/tuscany/java/das/tools/src/test/resources/DBConnectionConfig.xml
    incubator/tuscany/java/das/tools/src/test/resources/dbConfig.xml

Modified: incubator/tuscany/java/das/distribution/binary/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/distribution/binary/pom.xml?rev=602484&r1=602483&r2=602484&view=diff
==============================================================================
--- incubator/tuscany/java/das/distribution/binary/pom.xml (original)
+++ incubator/tuscany/java/das/distribution/binary/pom.xml Sat Dec  8 07:44:04 2007
@@ -63,6 +63,12 @@
           <artifactId>tuscany-das-sample-transaction</artifactId>
           <version>${das.version}</version>
       </dependency>
+      
+       <dependency>
+          <groupId>org.apache.tuscany.das</groupId>
+          <artifactId>tuscany-das-tools</artifactId>
+          <version>${das.version}</version>
+      </dependency>      
     </dependencies>
 
     <build>

Modified: incubator/tuscany/java/das/distribution/binary/src/main/assembly/das.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/distribution/binary/src/main/assembly/das.xml?rev=602484&r1=602483&r2=602484&view=diff
==============================================================================
--- incubator/tuscany/java/das/distribution/binary/src/main/assembly/das.xml (original)
+++ incubator/tuscany/java/das/distribution/binary/src/main/assembly/das.xml Sat Dec  8 07:44:04 2007
@@ -83,7 +83,7 @@
                <outputDirectory>tuscany-das-${das.version}/samples/customer</outputDirectory>
                <fileMode>0644</fileMode>
             </file>
-            <!-- include ajax das sample -->
+            <!-- include customer sample -->
             <file>
                <source>../../samples/customer/target/sample-customer.jar</source>
                <outputDirectory>tuscany-das-${das.version}/samples/customer</outputDirectory>
@@ -112,6 +112,20 @@
                <outputDirectory>tuscany-das-${das.version}/samples/transaction</outputDirectory>
                <fileMode>0644</fileMode>
             </file>
+            
+            <!-- include readme for tuscany-das-tools -->
+            <file>
+               <source>../../tools/readme.htm</source>
+               <outputDirectory>tuscany-das-${das.version}/tuscany-das-tools</outputDirectory>
+               <fileMode>0644</fileMode>
+            </file>
+            <!-- include das-tools -->
+            <file>
+               <source>../../tools/target/tuscany-das-tools.jar</source>
+               <outputDirectory>tuscany-das-${das.version}/tuscany-das-tools</outputDirectory>
+               <fileMode>0644</fileMode>
+            </file>
+            
         </files>
 
 
@@ -144,6 +158,15 @@
 	            <include>org.apache.geronimo.specs:geronimo-j2ee-connector_1.5_spec</include>
 	            <include>org.apache.tuscany.das.samples:tuscany-das-sample-dbconfig</include>
 	        </includes>	    
+	    <fileMode>0644</fileMode>
+        </dependencySet>
+
+        <!-- DAS tools - torque dependency-->
+        <dependencySet>
+	    <outputDirectory>tuscany-das-${das.version}/tuscany-das-tools</outputDirectory>
+	        <includes>
+	            <include>torque:torque-gen</include>
+	        </includes>
 	    <fileMode>0644</fileMode>
         </dependencySet>
         

Added: incubator/tuscany/java/das/plugin/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/plugin/pom.xml?rev=602484&view=auto
==============================================================================
--- incubator/tuscany/java/das/plugin/pom.xml (added)
+++ incubator/tuscany/java/das/plugin/pom.xml Sat Dec  8 07:44:04 2007
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<project>
+    <parent>
+        <groupId>org.apache.tuscany.das</groupId>
+        <artifactId>tuscany-das</artifactId>
+        <version>1.0-incubating-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>tuscany-das-plugin</artifactId>
+    <packaging>maven-plugin</packaging>
+    <name>Tuscany DAS Maven Plugin</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-plugin-api</artifactId>
+            <version>2.0.4</version>
+            <scope>compile</scope>
+        </dependency>
+	<dependency>
+	    <groupId>org.apache.maven</groupId>
+	    <artifactId>maven-model</artifactId>
+	    <version>2.0.4</version>
+	</dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-project</artifactId>
+            <version>2.0.4</version>
+            <scope>compile</scope>
+        </dependency>       
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-plugin-descriptor</artifactId>
+            <version>2.0.4</version>
+            <scope>compile</scope>
+        </dependency>                
+
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derby</artifactId>
+            <version>10.2.2.0</version>
+        </dependency>
+
+        <dependency>
+		    <groupId>torque</groupId>
+		    <artifactId>torque-gen</artifactId>
+		    <version>3.3-RC2</version>
+		</dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.das</groupId>
+            <artifactId>tuscany-das-tools</artifactId>
+            <version>${das.version}</version>
+            <scope>compile</scope>
+        </dependency>
+    </dependencies>
+       
+    <profiles>
+        <profile>
+			<id>plugin-test</id>       
+           <build>
+			<plugins>
+			    <plugin>
+				<groupId>org.apache.tuscany.das</groupId>
+				<artifactId>tuscany-das-plugin</artifactId>
+				<version>${das.version}</version>
+				<executions>
+				    <execution>
+					<id>dbToxsd</id>
+				    	<phase>generate-resources</phase>
+					<configuration>
+					    <schemaFile>${basedir}/target/schema.xml</schemaFile>
+					    <modelFile>${basedir}/target/sdoModel.xsd</modelFile>
+					    <driverClass>org.apache.derby.jdbc.EmbeddedDriver</driverClass>
+					    <databaseURL>jdbc:derby:${basedir}/../rdb/target/dastest</databaseURL>
+					    <schemaName>APP</schemaName>
+					</configuration>			
+					<goals>
+					    <goal>generate</goal>
+					</goals>
+				    </execution>
+				  </executions>		    
+			    </plugin>	   
+			</plugins>
+    	</build>
+    </profile>
+   </profiles>
+    	 
+</project>
\ No newline at end of file

Added: incubator/tuscany/java/das/plugin/src/main/java/org/apache/tuscany/das/plugin/GeneratorMojo.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/plugin/src/main/java/org/apache/tuscany/das/plugin/GeneratorMojo.java?rev=602484&view=auto
==============================================================================
--- incubator/tuscany/java/das/plugin/src/main/java/org/apache/tuscany/das/plugin/GeneratorMojo.java (added)
+++ incubator/tuscany/java/das/plugin/src/main/java/org/apache/tuscany/das/plugin/GeneratorMojo.java Sat Dec  8 07:44:04 2007
@@ -0,0 +1,111 @@
+/**
+ *
+ *  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.
+ */
+package org.apache.tuscany.das.plugin;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.tuscany.das.rdb.util.DBToXSDGenerator;
+import org.apache.tuscany.das.rdb.util.ModelXSDGenOption;
+
+/**
+ * @goal generate
+ * @phase generate-resources
+ * @description Generate XSD Model files from DB Schema or db schema XML file
+ */
+public class GeneratorMojo extends AbstractMojo {
+    /**
+     * The file containing db schema in xml
+     *
+     * @parameter property="schemaFile"
+     */
+    private String schemaFile;
+
+    /**
+     * The file that will contain Static SDO Model XSD
+     * @parameter
+     */
+    private String modelFile;
+
+    /**
+     * Specifies the driverClass to use for connecting to database.
+     *
+     * @parameter
+     */
+    private String driverClass;
+
+    /**
+     * Specifies the databaseURL
+     *
+     * @parameter
+     */
+    private String databaseURL;
+
+    /**
+     * DB Schema name.
+     *
+     * @parameter
+     */
+    private String schemaName;
+
+    /**
+     * Optional user name.
+     *
+     * @parameter
+     */
+    private String userName;
+
+    /**
+     * Optional password.
+     *
+     * @parameter
+     */
+    private String password;
+
+    public void execute() throws MojoExecutionException {
+    	//if driverClass, databaseURL and schemaName present, use it to connect to DB ,
+    	//if any from these 3 is absent, and schemaFile is present use it as input
+    	ModelXSDGenOption mo =  new ModelXSDGenOption();
+        if (null != driverClass && null != databaseURL && null != schemaName && null != schemaFile) {
+        	mo.setDriverClass(driverClass);
+        	mo.setDatabaseURL(databaseURL);
+        	mo.setSchemaName(schemaName);
+        	mo.setUserName(userName);
+        	mo.setPassword(password);
+        	mo.setSchemaFile(schemaFile);
+        	mo.setModelFile(modelFile);
+
+        	try {
+        		DBToXSDGenerator.getModelFileFromDB(mo);
+        	} catch(Exception e) {
+        		throw new MojoExecutionException(e.getMessage());
+        	}
+        } else if(null != schemaFile) {
+        	mo.setSchemaFile(schemaFile);
+        	mo.setModelFile(modelFile); //if null, STDOUT
+        	try {
+        		DBToXSDGenerator.getModelFileFromSchemaFile(mo);
+        	} catch(Exception e) {
+        		throw new MojoExecutionException(e.getMessage());
+        	}
+        } else {
+        	throw new MojoExecutionException("Provide DB Connection info or DB Schema XML file!");
+        }
+    }
+}
\ No newline at end of file

Modified: incubator/tuscany/java/das/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/pom.xml?rev=602484&r1=602483&r2=602484&view=diff
==============================================================================
--- incubator/tuscany/java/das/pom.xml (original)
+++ incubator/tuscany/java/das/pom.xml Sat Dec  8 07:44:04 2007
@@ -141,6 +141,7 @@
                 <module>rdb</module>
                 <module>samples</module>
                 <module>tools</module>
+                <module>plugin</module>
             </modules>
         </profile>
         
@@ -150,6 +151,7 @@
                 <module>rdb</module>
                 <module>samples</module>
                 <module>tools</module>
+                <module>plugin</module>
                 <module>distribution/binary</module>
                 <module>distribution/source</module>
             </modules>

Modified: incubator/tuscany/java/das/tools/readme.htm
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/tools/readme.htm?rev=602484&r1=602483&r2=602484&view=diff
==============================================================================
--- incubator/tuscany/java/das/tools/readme.htm (original)
+++ incubator/tuscany/java/das/tools/readme.htm Sat Dec  8 07:44:04 2007
@@ -40,9 +40,12 @@
 
  <br>
  <ul>
-  <li>getModelFileFromDB(dbInfoFile); - connect to database and convert DB Schema to XSD Model XSDs </li>
-  <li>getModelFileFromSchemaFile(schemaFileName, SDOModelFileName); - no DB Connection needed, but need Apache Torque output of DB schema file </li>
-  <li>getSchemaFileFromDB(dbInfoFile); - connect to database and use Apache Torque to get DB Schema xml file </li>
+  <li>getModelFileFromDB(String dbInfoFile) - connect to database and convert DB Schema to XSD Model XSDs </li>
+  <li>getModelFileFromSchemaFile(String schemaFileName, String SDOModelFileName) - no DB Connection needed, but need Apache Torque output of DB schema file </li>
+  <li>getSchemaFileFromDB(String dbInfoFile) - connect to database and use Apache Torque to get DB Schema xml file </li>
+  <li>getModelFileFromDB(ModelXSDGenOption mo) - connect to database and convert DB Schema to XSD Model XSDs </li>
+  <li>getModelFileFromSchemaFile(ModelXSDGenOption mo) - no DB Connection needed, but need Apache Torque output of DB schema file </li>
+  <li>ModelXSDGenOption holds - schemaFile, modelFile, driverClass, databaseURL, schemaName, userName, password</li>
 </ul>
   
 To build the Tuscany DAS DBToXSDGenerator tool, perform the following steps <br>
@@ -52,7 +55,7 @@
 <li> --->To run as a standalone tool, call the above listed methods from DBToXSDGenerator </li>
 </ul>
 
-<b>Assumption</b> Database exists and contains required tables, constraints.<br>
+<b>Assumption</b> Database exists and contains required tables, constraints. Required Driver jar is in classpath<br>
 
 <ul  style="border-right-style: solid; border-left-style: solid; border-top-style: solid; border-bottom-style: solid">
  <b>Example dbInfoFile</b><br>

Modified: incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToSchemaFile.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToSchemaFile.java?rev=602484&r1=602483&r2=602484&view=diff
==============================================================================
--- incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToSchemaFile.java (original)
+++ incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToSchemaFile.java Sat Dec  8 07:44:04 2007
@@ -30,32 +30,25 @@
 
 public class DBToSchemaFile {
 	private static final Logger logger = Logger.getLogger(DBToSchemaFile.class);
-	
-	private static String driverClass = null;
-	private static String url = null;
-	private static String schemaName = null;
-	private static String userName = null;
-	private static String password = null;
-	private static String schemaFileName = null;//should not be null
-	private static String modelFileName = null;//if null STDOUT
+	private static ModelXSDGenOption mo = null;//schemaFileName should not be null. id modelFileName null STDOUT
 	
 	protected static void schemaFileFromDB() throws Exception {
 		Project p = new Project();
 	    p.setBaseDir(new File("."));
 		TorqueJDBCTransformTask tsk = new TorqueJDBCTransformTask();
 		tsk.setProject(p);
-		tsk.setDbDriver(driverClass);
-		tsk.setDbUrl(url);
+		tsk.setDbDriver(mo.getDriverClass());
+		tsk.setDbUrl(mo.getDatabaseURL());
 		tsk.setSameJavaName(true);
-		tsk.setDbSchema(schemaName);
+		tsk.setDbSchema(mo.getSchemaName());
 		tsk.setTaskName("jdbc");
-		tsk.setDbUser(userName);
-		tsk.setDbPassword(password);
-		if(!schemaFileName.equals("")) {
-			File schemaFile = new File( schemaFileName);
+		tsk.setDbUser(mo.getUserName());
+		tsk.setDbPassword(mo.getPassword());
+		if(!mo.getSchemaFile().trim().equals("")) {
+			File schemaFile = new File( mo.getSchemaFile());
 			schemaFile.createNewFile();
 		}
-		tsk.setOutputFile(schemaFileName);
+		tsk.setOutputFile(mo.getSchemaFile());
 		tsk.execute();
 	}
 	
@@ -63,7 +56,7 @@
 		XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
 		
 		XMLStreamReader reader = xmlFactory.createXMLStreamReader(new InputStreamReader(DBToXSDGenerator.getStream(dbInfoFileName)));
-
+		mo = new ModelXSDGenOption();
         while (true) {
             int event = reader.next();
             if(javax.xml.stream.XMLStreamConstants.END_DOCUMENT == event) {
@@ -73,22 +66,22 @@
             switch (event) {            
 	            case javax.xml.stream.XMLStreamConstants.START_ELEMENT: {
 	               if (reader.getName().getLocalPart().equals("ConnectionProperties")) {
-	                	driverClass = reader.getAttributeValue(null, "driverClass");
-	                	url = reader.getAttributeValue(null, "databaseURL");
-	                	schemaName = reader.getAttributeValue(null, "schemaName");
-	                	userName = reader.getAttributeValue(null, "userName");
-	                	if(userName == null)
-	                		userName = "";
-	                	password = reader.getAttributeValue(null, "password");
-	                	if(password == null)
-	                		password = "";
+	            	   mo.setDriverClass(reader.getAttributeValue(null, "driverClass"));
+	                   mo.setDatabaseURL(reader.getAttributeValue(null, "databaseURL"));
+	                   mo.setSchemaName(reader.getAttributeValue(null, "schemaName"));
+	                   mo.setUserName(reader.getAttributeValue(null, "userName"));
+	                	if(mo.getUserName() == null)
+	                		mo.setUserName("");
+	                	mo.setPassword(reader.getAttributeValue(null, "password"));
+	                	if(mo.getPassword() == null)
+	                		mo.setPassword("");
 	                } else if (reader.getName().getLocalPart().equals("ConnectionInfo")) {	                
 	                	//ignore
 	                } else if (reader.getName().getLocalPart().equals("Config")) {
 	                	//ignore
 	                } else if (reader.getName().getLocalPart().equals("OutFiles")) {	                
-	                	schemaFileName = reader.getAttributeValue(null, "schemaFile");
-	                	modelFileName = reader.getAttributeValue(null, "modelFile");
+	                	mo.setSchemaFile(reader.getAttributeValue(null, "schemaFile"));
+	                	mo.setModelFile(reader.getAttributeValue(null, "modelFile"));
 	                } else {
 	                	throw new RuntimeException("not got dbInfo  - tableNames List or connectionInfo:"+reader.getName()+":");
 	                }
@@ -98,36 +91,29 @@
         }
         
         if (logger.isDebugEnabled()) {
-			logger.debug("driverClass:"+driverClass);
-			logger.debug("url:"+url);
-			logger.debug("schemaName:"+schemaName);
-			logger.debug("schemaFileName:"+schemaFileName);
-			logger.debug("modelFileName:"+modelFileName);
-			logger.debug("userName:"+userName);
-			logger.debug("password:"+password);
+			logger.debug("driverClass:"+mo.getDriverClass());
+			logger.debug("url:"+mo.getDatabaseURL());
+			logger.debug("schemaName:"+mo.getSchemaName());
+			logger.debug("schemaFileName:"+mo.getSchemaFile());
+			logger.debug("modelFileName:"+mo.getModelFile());
+			logger.debug("userName:"+mo.getUserName());
+			logger.debug("password:"+mo.getPassword());
 		}            
 
-        if(driverClass == null || url == null || schemaName == null || schemaFileName == null || modelFileName == null) {
+        if(mo.getDriverClass() == null || mo.getDatabaseURL() == null || mo.getSchemaName() == null || mo.getSchemaFile() == null 
+        		|| mo.getModelFile() == null) {
      	   throw new RuntimeException("Required inputs missing - check driverClass, url, schemaName, schemaFile, modelFile!");
         }
 
         return;
     }
 
-	protected static String getSchemaFileName() {
-		return schemaFileName;
-	}
-
-	protected static void setSchemaFileName(String schemaFileName) {
-		DBToSchemaFile.schemaFileName = schemaFileName;
-	}
-
-	protected static String getModelFileName() {
-		return modelFileName;
+	public static ModelXSDGenOption getMo() {
+		return mo;
 	}
 
-	protected static void setModelFileName(String modelFileName) {
-		DBToSchemaFile.modelFileName = modelFileName;
+	public static void setMo(ModelXSDGenOption mo) {
+		DBToSchemaFile.mo = mo;
 	}
 	
 }

Modified: incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToXSDGenerator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToXSDGenerator.java?rev=602484&r1=602483&r2=602484&view=diff
==============================================================================
--- incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToXSDGenerator.java (original)
+++ incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToXSDGenerator.java Sat Dec  8 07:44:04 2007
@@ -34,22 +34,52 @@
 	/**
 	 * If user supplies schemaFileName and modelFileName will use it instead of the one from DBToSchemaFile.
 	 * schemaFile should exist. If modelFileName is null, will use STDOUT.
-	 * @param schemaFileName then one with Torque output
+	 * @param schemaFileName the result of Torque output
 	 * @throws Exception
 	 */
 	public static void getModelFileFromSchemaFile(String schemaFileName, String modelFileName) throws Exception {
+		if(schemaFileName == null || schemaFileName.trim().equals("")) {
+			throw new RuntimeException("Null or empty schemaFileName");
+		}
+		
 		SchemaFileToXSD.convert(schemaFileName, modelFileName);
 	}
 	
 	/**
+	 * If user supplies schemaFileName and modelFileName through ModelXSDGenOption, will use it instead of 
+	 * the one from DBToSchemaFile. schemaFile should exist. If modelFileName is null, will use STDOUT.
+	 * @param ModelXSDGenOption 
+	 * @throws Exception
+	 */
+	public static void getModelFileFromSchemaFile(ModelXSDGenOption mo) throws Exception {
+		getModelFileFromSchemaFile(mo.getSchemaFile(), mo.getModelFile());
+	}
+	
+	/**
 	 * All in one
-	 * @param dbInfoFileName
+	 * @param dbInfoFileName e.g. DBConnectionConfig.xml
 	 * @throws Exception
 	 */
 	public static void getModelFileFromDB(String dbInfoFileName) throws Exception {
 		DBToSchemaFile.read(dbInfoFileName);
 		DBToSchemaFile.schemaFileFromDB();
-		getModelFileFromSchemaFile(DBToSchemaFile.getSchemaFileName(), DBToSchemaFile.getModelFileName());
+		getModelFileFromSchemaFile(DBToSchemaFile.getMo());
+	}
+	
+	/**
+	 * Useful for plugin
+	 */
+	public static void getModelFileFromDB(ModelXSDGenOption mo) throws Exception {
+		if(mo.getSchemaFile() == null || mo.getSchemaFile().trim().equals("") || 
+			mo.getDriverClass() == null || mo.getDriverClass().trim().equals("") || 
+			mo.getDatabaseURL() == null || mo.getDatabaseURL().trim().equals("") ||
+			mo.getSchemaName() == null || mo.getSchemaName().trim().equals("")) {
+			throw new RuntimeException("Required inputs missing - check driverClass, url, schemaName, schemaFile!");
+		}
+		
+		DBToSchemaFile.setMo(mo);	
+		DBToSchemaFile.schemaFileFromDB();
+		getModelFileFromSchemaFile(DBToSchemaFile.getMo().getSchemaFile(), DBToSchemaFile.getMo().getModelFile());
 	}
 	
     protected static InputStream getStream(String fileName) {

Added: incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ModelXSDGenOption.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ModelXSDGenOption.java?rev=602484&view=auto
==============================================================================
--- incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ModelXSDGenOption.java (added)
+++ incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ModelXSDGenOption.java Sat Dec  8 07:44:04 2007
@@ -0,0 +1,134 @@
+/**
+ *
+ *  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.
+ */
+package org.apache.tuscany.das.rdb.util;
+
+import java.io.File;
+
+public class ModelXSDGenOption {
+
+    /**
+     * Name of the schema file
+     *
+     * @parameter
+     */
+    private String schemaFile;
+
+    /**
+     * Name of the model file
+     *
+     * @parameter
+     */
+    private String modelFile;
+
+    /**
+     * Name of the DBDriver class Name
+     *
+     * @parameter
+     */
+    private String driverClass;
+
+    /**
+     * Name of the DB URL
+     *
+     * @parameter
+     */
+    private String databaseURL;
+    
+    /**
+     * Name of the DB Schema Name
+     *
+     * @parameter
+     */    
+    private String schemaName;
+
+    /**
+     * Optional user name.
+     *
+     * @parameter
+     */
+    private String userName;
+
+    /**
+     * Optional password.
+     *
+     * @parameter
+     */
+    private String password;
+
+    public ModelXSDGenOption() {
+    }
+
+	public String getSchemaFile() {
+		return schemaFile;
+	}
+
+	public void setSchemaFile(String schemaFile) {
+		this.schemaFile = schemaFile;
+	}
+
+	public String getModelFile() {
+		return modelFile;
+	}
+
+	public void setModelFile(String modelFile) {
+		this.modelFile = modelFile;
+	}
+
+	public String getDriverClass() {
+		return driverClass;
+	}
+
+	public void setDriverClass(String driverClass) {
+		this.driverClass = driverClass;
+	}
+
+	public String getDatabaseURL() {
+		return databaseURL;
+	}
+
+	public void setDatabaseURL(String databaseURL) {
+		this.databaseURL = databaseURL;
+	}
+
+	public String getSchemaName() {
+		return schemaName;
+	}
+
+	public void setSchemaName(String schemaName) {
+		this.schemaName = schemaName;
+	}
+
+	public String getUserName() {
+		return userName;
+	}
+
+	public void setUserName(String userName) {
+		this.userName = userName;
+	}
+
+	public String getPassword() {
+		return password;
+	}
+
+	public void setPassword(String password) {
+		this.password = password;
+	}
+	
+}

Modified: incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/SchemaFileToXSD.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/SchemaFileToXSD.java?rev=602484&r1=602483&r2=602484&view=diff
==============================================================================
--- incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/SchemaFileToXSD.java (original)
+++ incubator/tuscany/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/SchemaFileToXSD.java Sat Dec  8 07:44:04 2007
@@ -130,7 +130,7 @@
 		String startLine = "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:this=\"http:///org.apache.tuscany.das.rdb.test/schemaModel.xsd\" targetNamespace=\"http:///org.apache.tuscany.das.rdb.test/schemaModel.xsd\">\n";
 		String endLine = "</xsd:schema>"; 
 			
-		if(xsdModelFileName != null) {
+		if(xsdModelFileName != null && !xsdModelFileName.trim().equals("")) {
 			writeFilesToDir = true;
 		}
 		

Modified: incubator/tuscany/java/das/tools/src/test/resources/DBConnectionConfig.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/tools/src/test/resources/DBConnectionConfig.xml?rev=602484&r1=602483&r2=602484&view=diff
==============================================================================
--- incubator/tuscany/java/das/tools/src/test/resources/DBConnectionConfig.xml (original)
+++ incubator/tuscany/java/das/tools/src/test/resources/DBConnectionConfig.xml Sat Dec  8 07:44:04 2007
@@ -1,34 +1,31 @@
 <?xml version="1.0" encoding="ASCII"?>
 <!--
-  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
+	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.
+-->
+<Config xmlns="http:///org.apache.tuscany.das.rdb/config.xsd">
 
-  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.
- -->
- <Config xmlns="http:///org.apache.tuscany.das.rdb/config.xsd"> 
-    
-    <!--Uncomment below for derby test-->
+	<!--Uncomment below for derby test-->
 	<ConnectionInfo>
 		<ConnectionProperties
 			driverClass="org.apache.derby.jdbc.EmbeddedDriver"
-			databaseURL="jdbc:derby:target/dastest;create=true"
-			schemaName = "APP"
-			loginTimeout="600000"/>
-	</ConnectionInfo>
-	<OutFiles
-		schemaFile="target/dbSchema.txt"
-		modelFile="target/schemaModel.xsd"
-	/>
+			databaseURL="jdbc:derby:target/dastest;create=true" schemaName="APP"
+		/>
+	</ConnectionInfo>
+	<OutFiles schemaFile="target/dbSchema.txt"
+		modelFile="target/schemaModel.xsd" />
 </Config>

Modified: incubator/tuscany/java/das/tools/src/test/resources/dbConfig.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/tools/src/test/resources/dbConfig.xml?rev=602484&r1=602483&r2=602484&view=diff
==============================================================================
--- incubator/tuscany/java/das/tools/src/test/resources/dbConfig.xml (original)
+++ incubator/tuscany/java/das/tools/src/test/resources/dbConfig.xml Sat Dec  8 07:44:04 2007
@@ -1,32 +1,34 @@
 <?xml version="1.0" encoding="ASCII"?>
 <!--
-  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.
- -->
+	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.
+-->
 <DBConfig xmlns="http:///org.apache.tuscany.das.rdb/dbconfig.xsd">
 	<ConnectionInfo>
-		<ConnectionProperties 
-			driverClass="org.apache.derby.jdbc.EmbeddedDriver" 
-			databaseURL="jdbc:derby:target/dastest; create = true" 
-			loginTimeout="600000"/>
+		<ConnectionProperties
+			driverClass="org.apache.derby.jdbc.EmbeddedDriver"
+			databaseURL="jdbc:derby:target/dastest; create = true"
+			/>
 	</ConnectionInfo>
-	<Table name="STATES" SQLCreate="CREATE TABLE STATES (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(2))">
+	<Table name="STATES"
+		SQLCreate="CREATE TABLE STATES (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(2))">
 	</Table>
-	<Table name="CITIES" SQLCreate="CREATE TABLE CITIES (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(50), STATES_ID INTEGER,  
-	CONSTRAINT FK1 FOREIGN KEY (STATES_ID) REFERENCES  STATES (ID) ON DELETE NO ACTION ON UPDATE NO ACTION)"	>
+	<Table name="CITIES"
+		SQLCreate="CREATE TABLE CITIES (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(50), STATES_ID INTEGER,  
+	CONSTRAINT FK1 FOREIGN KEY (STATES_ID) REFERENCES  STATES (ID) ON DELETE NO ACTION ON UPDATE NO ACTION)">
 	</Table>
 </DBConfig>



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org