felipeal 2004/11/06 13:50:38 Modified: hibernate/src/main/org/apache/maven/hibernate/jelly SchemaExportTag.java hibernate/src/main/org/apache/maven/hibernate/beans SchemaExportBean.java Added: hibernate/src/main/org/apache/maven/hibernate/jelly SchemaTagBase.java hibernate/src/main/org/apache/maven/hibernate/beans SchemaBeanBase.java Log: MPHIBERNATE-13: refactored current classes in order to create new ones Revision Changes Path 1.5 +17 -186 maven-plugins/hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaExportTag.java Index: SchemaExportTag.java =================================================================== RCS file: /home/cvs/maven-plugins/hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaExportTag.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SchemaExportTag.java 2 Jul 2004 07:32:52 -0000 1.4 +++ SchemaExportTag.java 6 Nov 2004 21:50:38 -0000 1.5 @@ -17,219 +17,50 @@ * ==================================================================== */ -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 [EMAIL PROTECTED] SchemaExportBean} + * Jelly tag which delagates all calls to [EMAIL PROTECTED] SchemaExportBean} * * @author <a href="[EMAIL PROTECTED]">Michal Maczka</a> * @version $Id$ */ -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); - } - - } - - /** - * @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); + + public SchemaExportTag() { + super( new SchemaExportBean() ); } - - /** - * @param b - */ + public void setDrop(boolean b) { - bean.setDrop(b); - } - - /** - * @param string - */ - public void setIncludes(String string) - { - bean.setIncludes(string); + ((SchemaExportBean) bean).setDrop(b); } - - /** - * @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) + public void setDelimiter(String delimiter) { - bean.setBasedir(string); + bean.setDelimiter(delimiter); } - /** - * @param b - */ - public void setQuiet(boolean b) + public boolean isDrop() { - bean.setQuiet(b); + return ((SchemaExportBean) bean).isDrop(); } - /** - * @param string - */ - public void setProperties(String string) + public String getOutputFile() { - bean.setProperties(string); + return bean.getOutputFile(); } - + public String getDelimiter() { return bean.getDelimiter(); } - - public void setDelimiter(String delimiter) - { - bean.setDelimiter(delimiter); - } - - /** - */ - public String getSchemaOutputFile() { - return bean.getSchemaOutputFile(); - } - /** - */ - public void setSchemaOutputFile(String string) { - bean.setSchemaOutputFile(string); - } + } 1.1 maven-plugins/hibernate/src/main/org/apache/maven/hibernate/jelly/SchemaTagBase.java Index: SchemaTagBase.java =================================================================== 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 <a href="[EMAIL PROTECTED]">Michal Maczka</a> * @author <a href="[EMAIL PROTECTED]">Felipe Leme</a> * @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); } } 1.8 +13 -215 maven-plugins/hibernate/src/main/org/apache/maven/hibernate/beans/SchemaExportBean.java Index: SchemaExportBean.java =================================================================== RCS file: /home/cvs/maven-plugins/hibernate/src/main/org/apache/maven/hibernate/beans/SchemaExportBean.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SchemaExportBean.java 25 Jul 2004 13:49:38 -0000 1.7 +++ SchemaExportBean.java 6 Nov 2004 21:50:38 -0000 1.8 @@ -17,17 +17,9 @@ * ==================================================================== */ -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 @@ * * The Bean which serves as Proxy To Hibernate API * <br/> - * - * * * @author <a href="[EMAIL PROTECTED]">Michal Maczka</a> * @version $Id$ */ -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 @@ { 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 @@ LOG.debug("Output file:" + getOutputFile()); schemaExport.setOutputFile(getOutputFile()); schemaExport.setDelimiter(getDelimiter()); - return schemaExport; - } + if (isDrop()) + { + schemaExport.drop(!getQuiet(), !getText()); + } + else + { + schemaExport.create(!getQuiet(), !getText()); + } + } } 1.1 maven-plugins/hibernate/src/main/org/apache/maven/hibernate/beans/SchemaBeanBase.java Index: SchemaBeanBase.java =================================================================== 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 * <br/> * * @author <a href="[EMAIL PROTECTED]">Michal Maczka</a> * @author <a href="[EMAIL PROTECTED]">Felipe Leme</a> * @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; } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]