diff --git a/hibernate/src/main/org/apache/maven/hibernate/beans/SchemaBeanBase.java b/hibernate/src/main/org/apache/maven/hibernate/beans/SchemaBeanBase.java
new file mode 100644
index 00000000..1561d2af
--- /dev/null
+++ b/hibernate/src/main/org/apache/maven/hibernate/beans/SchemaBeanBase.java
@@ -0,0 +1,235 @@
+package org.apache.maven.hibernate.beans;
+
+/* ====================================================================
+ * Copyright 2004 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.
+ * ====================================================================
+ */
+
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.cfg.Configuration;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ * Base class for Beans which serve as Proxy To Hibernate API
+ *
+ *
+ * @author Michal Maczka
+ * @author Felipe Leme
+ * @version $Id: SchemaBeanBase.java,v 1.1 2004/11/06 21:50:38 felipeal Exp $
+ */
+public abstract class SchemaBeanBase extends CommonOperationsBean
+{
+
+ private String properties = null;
+ private String config = null;
+ private boolean quiet = false;
+ private boolean text = false;
+
+ protected static final Log LOG = LogFactory.getLog(MappingsAggregatorBean.class);
+
+
+
+ /**
+ * @return
+ */
+ public boolean getQuiet()
+ {
+ return quiet;
+ }
+
+ /**
+ * @return
+ */
+ public boolean getText()
+ {
+ return text;
+ }
+
+ /**
+ * @param b
+ */
+ public void setQuiet(boolean b)
+ {
+ quiet = b;
+ }
+
+ /**
+ * @param b
+ */
+ public void setText(boolean b)
+ {
+ text = b;
+ }
+
+ /**
+ * @return
+ */
+ public String getConfig()
+ {
+ return config;
+ }
+
+ /**
+ * @return
+ */
+ public String getProperties()
+ {
+ return properties;
+ }
+
+ /**
+ * @param string
+ */
+ public void setConfig(String string)
+ {
+ config = string;
+ }
+
+ /**
+ * @param string
+ */
+ public void setProperties(String string)
+ {
+ properties = string;
+ }
+
+ /**
+ *
+ * Hibernate requires that
+ * Java classes (beans) are accesible on the
+ * classpath. As they are not in plugin classpath
+ * we have to take care about.
+ * To assure that we have them visible for plugin
+ * classloader
+ * we will make temporay change to context classloader
+ * which will be restored when method terminates.
+ *
+ */
+ public void execute() throws Exception
+ {
+
+ Thread currentThread = Thread.currentThread();
+ ClassLoader oldClassLoader = currentThread.getContextClassLoader();
+ try
+ {
+ File [] baseDirs = getBaseDirs ();
+ URL [] urls = new URL [baseDirs.length];
+ for (int i = 0; i < urls.length; i++) {
+ urls [i] = baseDirs [i].toURL ();
+ }
+
+ URLClassLoader newClassLoader =
+ new URLClassLoader(urls, getClass().getClassLoader());
+ currentThread.setContextClassLoader(newClassLoader);
+
+ Configuration cfg = getConfiguration();
+ executeSchema( cfg );
+
+ }
+ finally
+ {
+ currentThread.setContextClassLoader(oldClassLoader);
+ }
+ }
+
+ /**
+ * Method that does the real job
+ */
+ protected abstract void executeSchema(Configuration cfg) throws Exception;
+
+ /**
+ *
+ */
+ private Configuration getConfiguration() throws HibernateException
+ {
+ Configuration cfg = new Configuration();
+ if (getConfig() != null)
+ {
+ File f = new File(getConfig());
+ LOG.debug("Hibernate Configuration File: " + f.getAbsolutePath());
+ cfg.configure(f);
+ }
+
+ String[] files = getFileNames ();
+ for (int i = 0; i < files.length; i++)
+ {
+ String filename = files[i];
+ if (filename.endsWith(".jar"))
+ {
+ cfg.addJar(filename);
+ }
+ else
+ {
+ cfg.addFile(filename);
+ }
+ }
+ return cfg;
+ }
+
+ private String schemaOutputFile = null;
+ private String delimiter = null;
+
+
+
+ /**
+ * @return
+ */
+ public String getSchemaOutputFile() {
+ return schemaOutputFile;
+ }
+
+ /**
+ * @return
+ */
+ public String getOutputFile() {
+ return schemaOutputFile;
+ }
+
+ /**
+ * @return
+ */
+ public String getDelimiter() {
+ return delimiter;
+ }
+
+ /**
+ * @param string
+ */
+ public void setSchemaOutputFile(String string) {
+ schemaOutputFile = string;
+ }
+
+ /**
+ * @param string
+ */
+ public void setOutputFile(String string) {
+ schemaOutputFile = string;
+ }
+
+ /**
+ * @param string
+ */
+ public void setDelimiter(String string) {
+ delimiter = string;
+ }
+
+}
diff --git a/hibernate/src/main/org/apache/maven/hibernate/beans/SchemaExportBean.java b/hibernate/src/main/org/apache/maven/hibernate/beans/SchemaExportBean.java
index c39f29de..001a5b31 100644
--- a/hibernate/src/main/org/apache/maven/hibernate/beans/SchemaExportBean.java
+++ b/hibernate/src/main/org/apache/maven/hibernate/beans/SchemaExportBean.java
@@ -17,17 +17,9 @@ package org.apache.maven.hibernate.beans;
* ====================================================================
*/
-import java.io.File;
import java.io.FileInputStream;
-import java.io.IOException;
-import java.net.URL;
-import java.net.URLClassLoader;
import java.util.Properties;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import net.sf.hibernate.HibernateException;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
@@ -35,122 +27,15 @@ import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
*
* The Bean which serves as Proxy To Hibernate API
*
- *
- *
*
* @author Michal Maczka
- * @version $Id: SchemaExportBean.java,v 1.7 2004/07/25 13:49:38 epugh Exp $
+ * @version $Id: SchemaExportBean.java,v 1.8 2004/11/06 21:50:38 felipeal Exp $
*/
-public class SchemaExportBean extends CommonOperationsBean
+public class SchemaExportBean extends SchemaBeanBase
{
- private String properties = null;
- private String config = null;
- private String schemaOutputFile = null;
- private String delimiter = null;
- private boolean quiet = false;
- private boolean text = false;
private boolean drop = false;
- private static final Log LOG = LogFactory.getLog(MappingsAggregatorBean.class);
-
- /**
- * @return
- */
- public String getSchemaOutputFile()
- {
- return schemaOutputFile;
- }
-
- /**
- * @return
- */
- public String getOutputFile()
- {
- return schemaOutputFile;
- }
-
-
- /**
- * @return
- */
- public boolean getQuiet()
- {
- return quiet;
- }
-
- /**
- * @return
- */
- public boolean getText()
- {
- return text;
- }
-
- /**
- * @param string
- */
- public void setSchemaOutputFile(String string)
- {
- schemaOutputFile = string;
- }
-
- /**
- * @param string
- */
- public void setOutputFile(String string)
- {
- schemaOutputFile = string;
- }
-
- /**
- * @param b
- */
- public void setQuiet(boolean b)
- {
- quiet = b;
- }
-
- /**
- * @param b
- */
- public void setText(boolean b)
- {
- text = b;
- }
-
- /**
- * @return
- */
- public String getConfig()
- {
- return config;
- }
-
- /**
- * @return
- */
- public String getProperties()
- {
- return properties;
- }
-
- /**
- * @param string
- */
- public void setConfig(String string)
- {
- config = string;
- }
-
- /**
- * @param string
- */
- public void setProperties(String string)
- {
- properties = string;
- }
-
/**
* @return
*/
@@ -166,102 +51,8 @@ public class SchemaExportBean extends CommonOperationsBean
{
drop = b;
}
-
- /**
- * @return
- */
- public String getDelimiter()
- {
- return delimiter;
- }
-
- /**
- * @param string
- */
- public void setDelimiter(String string)
- {
- delimiter = string;
- }
-
- /**
- *
- * Hibernate requires that
- * Java classes (beans) are accesible on the
- * classpath. As they are not in plugin classpath
- * we have to take care about.
- * To assure that we have them visible for plugin
- * classloader
- * we will make temporay change to context classloader
- * which will be restored when method terminates.
- *
- */
- public void execute() throws Exception
- {
-
- Thread currentThread = Thread.currentThread();
- ClassLoader oldClassLoader = currentThread.getContextClassLoader();
- try
- {
- File [] baseDirs = getBaseDirs ();
- URL [] urls = new URL [baseDirs.length];
- for (int i = 0; i < urls.length; i++) {
- urls [i] = baseDirs [i].toURL ();
- }
-
- URLClassLoader newClassLoader =
- new URLClassLoader(urls, getClass().getClassLoader());
- currentThread.setContextClassLoader(newClassLoader);
-
- Configuration cfg = getConfiguration();
- SchemaExport schemaExport = getSchemaExport(cfg);
-
- if (isDrop())
- {
- schemaExport.drop(!getQuiet(), !getText());
- }
- else
- {
- schemaExport.create(!getQuiet(), !getText());
- }
- }
- finally
- {
- currentThread.setContextClassLoader(oldClassLoader);
- }
- }
-
- /**
- *
- */
- private Configuration getConfiguration() throws HibernateException
- {
- Configuration cfg = new Configuration();
- if (getConfig() != null)
- {
- File f = new File(getConfig());
- LOG.debug("Hibernate Configuration File: " + f.getAbsolutePath());
- cfg.configure(f);
- }
-
- String[] files = getFileNames ();
- for (int i = 0; i < files.length; i++)
- {
- String filename = files[i];
- if (filename.endsWith(".jar"))
- {
- cfg.addJar(filename);
- }
- else
- {
- cfg.addFile(filename);
- }
- }
- return cfg;
- }
-
- private SchemaExport getSchemaExport(Configuration cfg)
- throws HibernateException, IOException
- {
+
+ protected void executeSchema(Configuration cfg) throws Exception {
SchemaExport schemaExport = null;
if (getProperties() == null)
{
@@ -276,7 +67,14 @@ public class SchemaExportBean extends CommonOperationsBean
LOG.debug("Output file:" + getOutputFile());
schemaExport.setOutputFile(getOutputFile());
schemaExport.setDelimiter(getDelimiter());
- return schemaExport;
- }
+ if (isDrop())
+ {
+ schemaExport.drop(!getQuiet(), !getText());
+ }
+ else
+ {
+ schemaExport.create(!getQuiet(), !getText());
+ }
+ }
}
diff --git a/hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaExportTag.java b/hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaExportTag.java
index 2f591a5a..43cf0735 100644
--- a/hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaExportTag.java
+++ b/hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaExportTag.java
@@ -17,219 +17,50 @@ package org.apache.maven.hibernate.jelly;
* ====================================================================
*/
-import org.apache.commons.jelly.JellyTagException;
-import org.apache.commons.jelly.TagSupport;
-import org.apache.commons.jelly.XMLOutput;
import org.apache.maven.hibernate.beans.SchemaExportBean;
/**
*
- * Jelly tag which delagates all calls
- * to {@link SchemaExportBean}
+ * Jelly tag which delagates all calls to {@link SchemaExportBean}
*
* @author Michal Maczka
- * @version $Id: SchemaExportTag.java,v 1.4 2004/07/02 07:32:52 epugh Exp $
+ * @version $Id: SchemaExportTag.java,v 1.5 2004/11/06 21:50:38 felipeal Exp $
*/
-public class SchemaExportTag extends TagSupport
+public class SchemaExportTag extends SchemaTagBase
{
-
- private SchemaExportBean bean = new SchemaExportBean();
-
- /**
- *
- */
- protected void execute() throws JellyTagException
- {
- try
- {
- bean.execute();
- }
- catch (Exception e)
- {
- String msg = " Schema Export failed";
- throw new JellyTagException(msg, e);
- }
-
+
+ public SchemaExportTag() {
+ super( new SchemaExportBean() );
}
-
- /**
- * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
- */
- public void doTag(XMLOutput arg0) throws JellyTagException
- {
- execute();
- }
-
- /**
- * @return
- */
- public boolean getText()
- {
- return bean.getText();
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- public String toString()
- {
- return bean.toString();
- }
-
- /**
- * @return
- */
- public boolean getQuiet()
- {
- return bean.getQuiet();
- }
-
- /**
- * @param string
- */
- public void setExcludes(String string)
- {
- bean.setExcludes(string);
- }
-
- /**
- * @param b
- */
+
public void setDrop(boolean b)
{
- bean.setDrop(b);
+ ((SchemaExportBean) bean).setDrop(b);
}
-
- /**
- * @param string
- */
- public void setIncludes(String string)
- {
- bean.setIncludes(string);
- }
-
- /**
- * @return
- */
- public String getOutputFile()
- {
- return bean.getOutputFile();
- }
-
- /**
- * @return
- */
- public String getExcludes()
- {
- return bean.getExcludes();
- }
-
- /**
- * @param string
- */
+
public void setOutputFile(String string)
{
bean.setOutputFile(string);
}
- /**
- * @return
- */
- public boolean isDrop()
- {
- return bean.isDrop();
- }
-
- /**
- * @param string
- */
- public void setConfig(String string)
- {
- bean.setConfig(string);
- }
-
- /**
- * @return
- */
- public String getIncludes()
- {
- return bean.getIncludes();
- }
-
- /**
- * @return
- */
- public String getBasedir()
- {
- return bean.getBasedir();
- }
-
- /**
- * @return
- */
- public String getProperties()
- {
- return bean.getProperties();
- }
-
- /**
- * @return
- */
- public String getConfig()
- {
- return bean.getConfig();
- }
-
- /**
- * @param b
- */
- public void setText(boolean b)
- {
- bean.setText(b);
- }
-
- /**
- * @param string
- */
- public void setBasedir(String string)
- {
- bean.setBasedir(string);
- }
-
- /**
- * @param b
- */
- public void setQuiet(boolean b)
- {
- bean.setQuiet(b);
- }
-
- /**
- * @param string
- */
- public void setProperties(String string)
- {
- bean.setProperties(string);
- }
-
- public String getDelimiter()
- {
- return bean.getDelimiter();
- }
-
public void setDelimiter(String delimiter)
{
bean.setDelimiter(delimiter);
}
+
+ public boolean isDrop()
+ {
+ return ((SchemaExportBean) bean).isDrop();
+ }
+
+ public String getOutputFile()
+ {
+ return bean.getOutputFile();
+ }
- /**
- */
- public String getSchemaOutputFile() {
- return bean.getSchemaOutputFile();
- }
- /**
- */
- public void setSchemaOutputFile(String string) {
- bean.setSchemaOutputFile(string);
- }
+ public String getDelimiter()
+ {
+ return bean.getDelimiter();
+ }
+
}
diff --git a/hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaTagBase.java b/hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaTagBase.java
new file mode 100644
index 00000000..b5a3dd2b
--- /dev/null
+++ b/hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaTagBase.java
@@ -0,0 +1,199 @@
+package org.apache.maven.hibernate.jelly;
+
+/* ====================================================================
+ * Copyright 2004 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.
+ * ====================================================================
+ */
+
+import org.apache.commons.jelly.JellyTagException;
+import org.apache.commons.jelly.TagSupport;
+import org.apache.commons.jelly.XMLOutput;
+import org.apache.maven.hibernate.beans.SchemaBeanBase;
+
+/**
+ *
+ * Base class for Jelly tags that uses Hibernate's Schema classes
+ *
+ * @author Michal Maczka
+ * @author Felipe Leme
+ * @version $Id: SchemaTagBase.java,v 1.1 2004/11/06 21:50:38 felipeal Exp $
+ */
+public abstract class SchemaTagBase extends TagSupport
+{
+
+ protected final SchemaBeanBase bean;
+
+ protected SchemaTagBase( SchemaBeanBase b ) {
+ bean = b;
+ }
+
+ /**
+ *
+ */
+ protected void execute() throws JellyTagException
+ {
+ try
+ {
+ bean.execute();
+ }
+ catch (Exception e)
+ {
+ String msg = "Schema operation failed";
+ throw new JellyTagException(msg, e);
+ }
+
+ }
+
+ /**
+ * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
+ */
+ public void doTag(XMLOutput arg0) throws JellyTagException
+ {
+ execute();
+ }
+
+ /**
+ * @return
+ */
+ public boolean getText()
+ {
+ return bean.getText();
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ return bean.toString();
+ }
+
+ /**
+ * @return
+ */
+ public boolean getQuiet()
+ {
+ return bean.getQuiet();
+ }
+
+ /**
+ * @param string
+ */
+ public void setExcludes(String string)
+ {
+ bean.setExcludes(string);
+ }
+
+ /**
+ * @param string
+ */
+ public void setIncludes(String string)
+ {
+ bean.setIncludes(string);
+ }
+
+ /**
+ * @return
+ */
+ public String getExcludes()
+ {
+ return bean.getExcludes();
+ }
+
+ /**
+ * @param string
+ */
+ public void setConfig(String string)
+ {
+ bean.setConfig(string);
+ }
+
+ /**
+ * @return
+ */
+ public String getIncludes()
+ {
+ return bean.getIncludes();
+ }
+
+ /**
+ * @return
+ */
+ public String getBasedir()
+ {
+ return bean.getBasedir();
+ }
+
+ /**
+ * @return
+ */
+ public String getProperties()
+ {
+ return bean.getProperties();
+ }
+
+ /**
+ * @return
+ */
+ public String getConfig()
+ {
+ return bean.getConfig();
+ }
+
+ /**
+ * @param b
+ */
+ public void setText(boolean b)
+ {
+ bean.setText(b);
+ }
+
+ /**
+ * @param string
+ */
+ public void setBasedir(String string)
+ {
+ bean.setBasedir(string);
+ }
+
+ /**
+ * @param b
+ */
+ public void setQuiet(boolean b)
+ {
+ bean.setQuiet(b);
+ }
+
+ /**
+ * @param string
+ */
+ public void setProperties(String string)
+ {
+ bean.setProperties(string);
+ }
+
+
+ /**
+ */
+ public String getSchemaOutputFile() {
+ return bean.getSchemaOutputFile();
+ }
+ /**
+ */
+ public void setSchemaOutputFile(String string) {
+ bean.setSchemaOutputFile(string);
+ }
+
+}