[jboss-svn-commits] JBL Code SVN: r5427 - in labs/jbossesb/trunk/product/core: common/src/org/jboss/soa/esb common/src/org/jboss/soa/esb/common common/src/org/jboss/soa/esb/helpers/persist common/src/org/jboss/soa/esb/parameters common/src/org/jboss/soa/esb/util common/tests/src/org/jboss/soa/esb common/tests/src/org/jboss/soa/esb/helpers common/tests/src/org/jboss/soa/esb/notification common/tests/src/org/jboss/soa/esb/parameters common/tests/src/org/jboss/soa/esb/util listeners/src/org/jboss/soa/esb/listeners services/src/org/jboss/soa/esb/services/msglistener
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Aug 3 05:41:11 EDT 2006
Author: tfennelly
Date: 2006-08-03 05:40:47 -0400 (Thu, 03 Aug 2006)
New Revision: 5427
Added:
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/BaseException.java
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamFileRepository.java
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamName.java
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamRepository.java
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamRepositoryException.java
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamRepositoryFactory.java
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/util/StreamUtils.java
labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/parameters/
labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/parameters/ParamRepositoryFactoryUnitTest.java
labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/parameters/ParamsFileRepositoryUnitTest.java
labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/parameters/TestParamRepo.java
labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/StreamUtilsUnitTest.java
Removed:
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/DefaultReposFactory.java
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamsReposUtil.java
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamsRepository.java
Modified:
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/common/SystemProperties.java
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/SqlDbTable.java
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/SqlField.java
labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/DomElementUnitTest.java
labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/MacroExpanderUnitTest.java
labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/BaseBusinessObjectUnitTest.java
labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/BobjStdDTOUnitTest.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/AbstractPoller.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/JmsQueueListener.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/OldDirListener.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/msglistener/AbstractEsbMsgDrivenBean.java
Log:
Fixed up the Parameter Respository code a bit.
Added unit tests to the Parameter Repository code.
Added: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/BaseException.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/BaseException.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/BaseException.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -0,0 +1,42 @@
+package org.jboss.soa.esb;
+
+/**
+ * Base ESB Exception.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class BaseException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Public Default Constructor.
+ */
+ public BaseException() {
+ super();
+ }
+
+ /**
+ * Public Constructor.
+ * @param message Exception message.
+ */
+ public BaseException(String message) {
+ super(message);
+ }
+
+ /**
+ * Public Constructor.
+ * @param message Exception message.
+ * @param cause Exception cause.
+ */
+ public BaseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Public Constructor.
+ * @param cause Exception cause.
+ */
+ public BaseException(Throwable cause) {
+ super(cause);
+ }
+}
Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/common/SystemProperties.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/common/SystemProperties.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/common/SystemProperties.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -38,7 +38,7 @@
public static final String JNDI_SERVER_URL = "org.jboss.soa.esb.jndi.server.url";
- public static final String PARAMS_REPOS_FACTORY_CLASS = "org.jboss.soa.esb.paramsRepository.factory.class";
+ public static final String PARAMS_REPOS_IMPL_CLASS = "org.jboss.soa.esb.paramsRepository.class";
public static final String OBJECT_STORE_CONFIG_FILE = "org.jboss.soa.esb.objStore.configfile";
@@ -61,8 +61,8 @@
new KeyValuePair(SMTP_PORT, getSmtpPort()),
new KeyValuePair(JNDI_SERVER_TYPE, getJndiServerType()),
new KeyValuePair(JNDI_SERVER_URL, getJndiServerURL()),
- new KeyValuePair(PARAMS_REPOS_FACTORY_CLASS,
- getParamsReposFactoryClass()),
+ new KeyValuePair(PARAMS_REPOS_IMPL_CLASS,
+ getParamRepositoryImplClass()),
new KeyValuePair(OBJECT_STORE_CONFIG_FILE, getObjStoreConfigFile()),
new KeyValuePair(ENCRYPT_FACTORY_CLASS, getEncryptionFactoryClass())
@@ -101,10 +101,8 @@
return System.getProperty(JNDI_SERVER_URL, SystemProperties.DEFAULT_HOST);
}
- public static String getParamsReposFactoryClass() {
- return System.getProperty(PARAMS_REPOS_FACTORY_CLASS,
- org.jboss.soa.esb.parameters.DefaultReposFactory.class
- .getName());
+ public static String getParamRepositoryImplClass() {
+ return System.getProperty(PARAMS_REPOS_IMPL_CLASS);
}
public static String getObjStoreConfigFile() {
Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -1,24 +1,24 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.soa.esb.helpers.persist;
import java.io.*;
@@ -28,80 +28,113 @@
import org.jboss.soa.esb.helpers.DomElement;
/**
- * <p>Obtain a connection that implements the DataSource interface</p>
- * <p>Description: Enable compatible use of JdbcCleanConn from outside a
- * J2EE app container</p>
+ * <p>
+ * Obtain a connection that implements the DataSource interface
+ * </p>
+ * <p>
+ * Description: Enable compatible use of JdbcCleanConn from outside a J2EE app
+ * container
+ * </p>
+ *
* @version 1.0
* @see JdbcCleanConn
* @see DomElement
*/
-public class SimpleDataSource implements DataSource
-{
- private PrintWriter m_oPW = new PrintWriter(System.out);
- private int m_iTO = 10;
- private String m_sUrl , m_sUsr, m_sPwd;
- private Connection m_oConn;
+public class SimpleDataSource implements DataSource {
+ private PrintWriter m_oPW = new PrintWriter(System.out);
- public static final String DRIVER = "driver-class";
- public static final String URL = "connection-url";
- public static final String USER = "user-name";
- public static final String PASSWORD = "password";
+ private int m_iTO = 10;
- private SimpleDataSource() {}
+ private String m_sUrl, m_sUsr, m_sPwd;
- /**
- * Obtain a DataSource by providing connection parameters. DomElement argument
- * must contain the following attributes
- * <p>
- * <li> driver-class</li>
- * <li> connection-url</li>
- * <li> user-name</li>
- * <li> password</li>
- * </p>
- * @param p_oP DomElement - Parameter tree that contains the 4 attributes needed
- * @throws Exception
- * @see DomElement
- * @see SimpleDataSource#SimpleDataSource(String,String,String,String)
- * @see javax.sql.DataSource
- */
- SimpleDataSource(DomElement p_oP)
- throws Exception
- { this (p_oP.getAttr(DRIVER) ,p_oP.getAttr(URL)
- ,p_oP.getAttr(USER) ,p_oP.getAttr(PASSWORD));
- } //________________________________
+ private Connection m_oConn;
- /**
- * Obtain a connection to a DB using the provided arguments to call
- * @param p_sDriver String - Java class of the JDBC driver to use (e.g. org.postgresql.Driver)
- * @param p_sDbURL String - The URL of the database (e.g. jdbc:postgresql://chodedb1:5432/cq3)
- * @param p_sUsr String - Username
- * @param p_sPwd String - Password
- * @throws Exception
- * @see DriverManager#getConnection(String,String,String)
- * @see javax.sql.DataSource
- */
- public SimpleDataSource(String p_sDriver, String p_sDbURL, String p_sUsr, String p_sPwd)
- throws Exception
- { Class.forName(p_sDriver);
- m_sUrl = p_sDbURL;
- getConnection(p_sUsr, p_sPwd);
- } //________________________________
+ public static final String DRIVER = "driver-class";
- public Connection getConnection() { return m_oConn; }
+ public static final String URL = "connection-url";
- public Connection getConnection(String username, String password)
- { m_sUsr = username;
- m_sPwd = password;
- try { m_oConn = DriverManager.getConnection (m_sUrl,m_sUsr,m_sPwd); }
- catch (Exception e) { m_oConn = null; }
- return m_oConn;
- } //________________________________
+ public static final String USER = "user-name";
- public int getLoginTimeout() { return m_iTO; }
+ public static final String PASSWORD = "password";
- public PrintWriter getLogWriter() { return m_oPW; }
+ private SimpleDataSource() {
+ }
- public void setLoginTimeout(int seconds) { m_iTO = seconds; }
+ /**
+ * Obtain a DataSource by providing connection parameters. DomElement
+ * argument must contain the following attributes
+ * <p>
+ * <li> driver-class</li>
+ * <li> connection-url</li>
+ * <li> user-name</li>
+ * <li> password</li>
+ * </p>
+ *
+ * @param p_oP
+ * DomElement - Parameter tree that contains the 4 attributes
+ * needed
+ * @throws Exception
+ * @see DomElement
+ * @see SimpleDataSource#SimpleDataSource(String,String,String,String)
+ * @see javax.sql.DataSource
+ */
+ SimpleDataSource(DomElement p_oP) throws Exception {
+ this(p_oP.getAttr(DRIVER), p_oP.getAttr(URL), p_oP.getAttr(USER), p_oP
+ .getAttr(PASSWORD));
+ } // ________________________________
- public void setLogWriter(PrintWriter out){ m_oPW = out; }
-} //______________________________________________________
+ /**
+ * Obtain a connection to a DB using the provided arguments to call
+ *
+ * @param p_sDriver
+ * String - Java class of the JDBC driver to use (e.g.
+ * org.postgresql.Driver)
+ * @param p_sDbURL
+ * String - The URL of the database (e.g.
+ * jdbc:postgresql://chodedb1:5432/cq3)
+ * @param p_sUsr
+ * String - Username
+ * @param p_sPwd
+ * String - Password
+ * @throws Exception
+ * @see DriverManager#getConnection(String,String,String)
+ * @see javax.sql.DataSource
+ */
+ public SimpleDataSource(String p_sDriver, String p_sDbURL, String p_sUsr,
+ String p_sPwd) throws Exception {
+ Class.forName(p_sDriver);
+ m_sUrl = p_sDbURL;
+ getConnection(p_sUsr, p_sPwd);
+ } // ________________________________
+
+ public Connection getConnection() {
+ return m_oConn;
+ }
+
+ public Connection getConnection(String username, String password) {
+ m_sUsr = username;
+ m_sPwd = password;
+ try {
+ m_oConn = DriverManager.getConnection(m_sUrl, m_sUsr, m_sPwd);
+ } catch (Exception e) {
+ m_oConn = null;
+ }
+ return m_oConn;
+ } // ________________________________
+
+ public int getLoginTimeout() {
+ return m_iTO;
+ }
+
+ public PrintWriter getLogWriter() {
+ return m_oPW;
+ }
+
+ public void setLoginTimeout(int seconds) {
+ m_iTO = seconds;
+ }
+
+ public void setLogWriter(PrintWriter out) {
+ m_oPW = out;
+ }
+} // ______________________________________________________
Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/SqlDbTable.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/SqlDbTable.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/SqlDbTable.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -1,164 +1,177 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.soa.esb.helpers.persist;
import java.sql.*;
+public abstract class SqlDbTable {
+ protected String m_sTableName;
-public abstract class SqlDbTable
-{
- protected String m_sTableName;
- protected SqlField [] m_oaFields;
+ protected SqlField[] m_oaFields;
- protected PreparedStatement[] m_oaPS;
- private JdbcCleanConn m_oConn;
- public JdbcCleanConn getConn() { return m_oConn; }
+ protected PreparedStatement[] m_oaPS;
+ private JdbcCleanConn m_oConn;
- public final String getTableName() { return m_sTableName; }
- public final SqlField[] getAllFields() { return m_oaFields; }
+ public JdbcCleanConn getConn() {
+ return m_oConn;
+ }
- private String m_sInsertSql, m_sUpdateSql, m_sDeleteSql;
- protected String m_sSelectSql;
+ public final String getTableName() {
+ return m_sTableName;
+ }
- public SqlDbTable(JdbcCleanConn p_oC, String p_sTblNm) throws Exception
- { m_oConn = p_oC;
- m_sTableName = p_sTblNm;
- initFields();
- } //________________________________
+ public final SqlField[] getAllFields() {
+ return m_oaFields;
+ }
- public abstract int setInsValues(PreparedStatement p_PS,Object bobj) throws Exception;
- public abstract Object getFromRS(ResultSet p_oRS) throws Exception;
+ private String m_sInsertSql, m_sUpdateSql, m_sDeleteSql;
- protected abstract String getSelectFields();
+ protected String m_sSelectSql;
- public String getFldName(int p_i)
- { return (null ==m_oaFields) ? null
- : (p_i < 0) ? null
- : (p_i >= m_oaFields.length) ? null
- : m_oaFields[p_i].getFieldName();
- } //________________________________
+ public SqlDbTable(JdbcCleanConn p_oC, String p_sTblNm) throws Exception {
+ m_oConn = p_oC;
+ m_sTableName = p_sTblNm;
+ initFields();
+ } // ________________________________
- public String getSelectStatement()
- { if ( m_sSelectSql != null ) return m_sSelectSql;
- StringBuffer sb=new StringBuffer("select ").append(getSelectFields());
- m_sSelectSql = sb.append(" from ").append(getTableName()).toString();
- return m_sSelectSql;
- } //________________________________
+ public abstract int setInsValues(PreparedStatement p_PS, Object bobj)
+ throws Exception;
- public String getInsertStatement()
- {
- if ( m_sInsertSql != null ) return m_sInsertSql;
+ public abstract Object getFromRS(ResultSet p_oRS) throws Exception;
- StringBuffer sb=new StringBuffer(256);
- sb.append("insert into ").append(getTableName());
+ protected abstract String getSelectFields();
- sb.append(" values (");
- for (int i = 0; i <m_oaFields.length; i++) ((i<1)?sb:sb.append(",")).append('?');
- sb.append(')');
+ public String getFldName(int p_i) {
+ return (null == m_oaFields) ? null : (p_i < 0) ? null
+ : (p_i >= m_oaFields.length) ? null : m_oaFields[p_i]
+ .getFieldName();
+ } // ________________________________
- return (m_sInsertSql = sb.toString());
- } //________________________________
+ public String getSelectStatement() {
+ if (m_sSelectSql != null)
+ return m_sSelectSql;
+ StringBuffer sb = new StringBuffer("select ").append(getSelectFields());
+ m_sSelectSql = sb.append(" from ").append(getTableName()).toString();
+ return m_sSelectSql;
+ } // ________________________________
- public String getUpdateStatement()
- {
- if ( m_sUpdateSql != null ) return m_sUpdateSql;
+ public String getInsertStatement() {
+ if (m_sInsertSql != null)
+ return m_sInsertSql;
- StringBuffer sb=new StringBuffer(256);
- sb.append("update ").append(getTableName()).append(" set ");
+ StringBuffer sb = new StringBuffer(256);
+ sb.append("insert into ").append(getTableName());
- StringBuffer sbWhere = new StringBuffer(" where ");
+ sb.append(" values (");
+ for (int i = 0; i < m_oaFields.length; i++)
+ ((i < 1) ? sb : sb.append(",")).append('?');
+ sb.append(')');
- int iVal = 0;
- int iWh = 0;
- for (int i = 0; i <m_oaFields.length; i++)
- { SqlField oCurr = m_oaFields[i];
- if (oCurr.isPrimaryKey())
- ((iWh++<1)?sbWhere:sbWhere.append(" and "))
- .append(oCurr.getFieldName()).append(" = ?");
- else
- ((iVal++<1)?sb:sb.append(","))
- .append(oCurr.getFieldName()).append(" = ?");
- }
- sb.append(sbWhere);
+ return (m_sInsertSql = sb.toString());
+ } // ________________________________
- return (m_sUpdateSql = sb.toString());
- } //________________________________
+ public String getUpdateStatement() {
+ if (m_sUpdateSql != null)
+ return m_sUpdateSql;
- public String getDeleteStatement()
- {
- if ( m_sDeleteSql != null ) return m_sDeleteSql;
+ StringBuffer sb = new StringBuffer(256);
+ sb.append("update ").append(getTableName()).append(" set ");
- StringBuffer sb=new StringBuffer(256);
- sb.append("delete from ").append(getTableName())
- .append(" where ");
+ StringBuffer sbWhere = new StringBuffer(" where ");
- int iWh = 0;
- for (int i = 0; i <m_oaFields.length; i++)
- { SqlField oCurr = m_oaFields[i];
- if (! oCurr.isPrimaryKey()) continue;
- ((iWh++<1)?sb:sb.append(" and "))
- .append(oCurr.getFieldName()).append(" = ?");
- }
+ int iVal = 0;
+ int iWh = 0;
+ for (int i = 0; i < m_oaFields.length; i++) {
+ SqlField oCurr = m_oaFields[i];
+ if (oCurr.isPrimaryKey())
+ ((iWh++ < 1) ? sbWhere : sbWhere.append(" and ")).append(
+ oCurr.getFieldName()).append(" = ?");
+ else
+ ((iVal++ < 1) ? sb : sb.append(",")).append(
+ oCurr.getFieldName()).append(" = ?");
+ }
+ sb.append(sbWhere);
- return (m_sDeleteSql = sb.toString());
- } //________________________________
+ return (m_sUpdateSql = sb.toString());
+ } // ________________________________
- public void setObject(PreparedStatement p_PS, int p_iFld, Object p_sFldVal)
- throws SQLException
- { if (null!=p_sFldVal)
- if (p_sFldVal instanceof String)
- { String sTr = ((String)p_sFldVal).trim();
- p_sFldVal = (sTr.length()>0) ? sTr : null;
- }
- ;
- int iSqlIdx = 1 + p_iFld;
- if (null==p_sFldVal)p_PS.setNull (iSqlIdx, m_oaFields[p_iFld].getSqlType());
- else p_PS.setObject (iSqlIdx, p_sFldVal);
- } //________________________________
+ public String getDeleteStatement() {
+ if (m_sDeleteSql != null)
+ return m_sDeleteSql;
- public void setLong(PreparedStatement p_PS, int p_iFld, long p_lVal)
- throws SQLException
- { p_PS.setLong(1+p_iFld,p_lVal);
- } //________________________________
+ StringBuffer sb = new StringBuffer(256);
+ sb.append("delete from ").append(getTableName()).append(" where ");
- public void setInt(PreparedStatement p_PS, int p_iFld, int p_iVal)
- throws SQLException
- { p_PS.setInt(1+p_iFld,p_iVal);
- } //________________________________
+ int iWh = 0;
+ for (int i = 0; i < m_oaFields.length; i++) {
+ SqlField oCurr = m_oaFields[i];
+ if (!oCurr.isPrimaryKey())
+ continue;
+ ((iWh++ < 1) ? sb : sb.append(" and "))
+ .append(oCurr.getFieldName()).append(" = ?");
+ }
- private void initFields() throws Exception
- { PreparedStatement PS = m_oConn.prepareStatement(getSelectStatement());
+ return (m_sDeleteSql = sb.toString());
+ } // ________________________________
- ResultSetMetaData MD = m_oConn.execQueryWait(PS,3).getMetaData();
- m_oaFields = new SqlField[MD.getColumnCount()];
- for (int i1=0; i1<m_oaFields.length;i1++)
- { int iCol = 1+i1;
- String sFN = MD.getColumnName(iCol);
- Class oCL = Class.forName(MD.getColumnClassName(iCol));
- int iTP = MD.getColumnType(iCol);
- int iSZ = MD.getColumnDisplaySize(iCol);
- m_oaFields[i1] = new SqlField(sFN,oCL,iTP,iSZ,false);
- }
- PS.close();
- } //________________________________
-} //____________________________________________________________________________
+ public void setObject(PreparedStatement p_PS, int p_iFld, Object p_sFldVal)
+ throws SQLException {
+ if (null != p_sFldVal)
+ if (p_sFldVal instanceof String) {
+ String sTr = ((String) p_sFldVal).trim();
+ p_sFldVal = (sTr.length() > 0) ? sTr : null;
+ }
+ ;
+ int iSqlIdx = 1 + p_iFld;
+ if (null == p_sFldVal)
+ p_PS.setNull(iSqlIdx, m_oaFields[p_iFld].getSqlType());
+ else
+ p_PS.setObject(iSqlIdx, p_sFldVal);
+ } // ________________________________
+
+ public void setLong(PreparedStatement p_PS, int p_iFld, long p_lVal)
+ throws SQLException {
+ p_PS.setLong(1 + p_iFld, p_lVal);
+ } // ________________________________
+
+ public void setInt(PreparedStatement p_PS, int p_iFld, int p_iVal)
+ throws SQLException {
+ p_PS.setInt(1 + p_iFld, p_iVal);
+ } // ________________________________
+
+ private void initFields() throws Exception {
+ PreparedStatement PS = m_oConn.prepareStatement(getSelectStatement());
+
+ ResultSetMetaData MD = m_oConn.execQueryWait(PS, 3).getMetaData();
+ m_oaFields = new SqlField[MD.getColumnCount()];
+ for (int i1 = 0; i1 < m_oaFields.length; i1++) {
+ int iCol = 1 + i1;
+ String sFN = MD.getColumnName(iCol);
+ Class oCL = Class.forName(MD.getColumnClassName(iCol));
+ int iTP = MD.getColumnType(iCol);
+ int iSZ = MD.getColumnDisplaySize(iCol);
+ m_oaFields[i1] = new SqlField(sFN, oCL, iTP, iSZ, false);
+ }
+ PS.close();
+ } // ________________________________
+} // ____________________________________________________________________________
Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/SqlField.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/SqlField.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/SqlField.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -1,53 +1,83 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.soa.esb.helpers.persist;
-public class SqlField
-{
- private int m_sqlType;
- private Class m_javaType;
- private int m_sqlLength;
- private String m_fieldName;
- private boolean m_primaryKey;
+public class SqlField {
+ private int m_sqlType;
- public SqlField(String pFldName,Class pJavaType,int pSqlType
- ,int pFieldLength, boolean pk)
- {
- m_fieldName = pFldName;
- m_javaType = pJavaType;
- m_sqlType = pSqlType;
- m_sqlLength = pFieldLength;
- m_primaryKey = pk;
- }
+ private Class m_javaType;
- public int getSqlType() { return m_sqlType; }
- public Class getJavaType() { return m_javaType; }
- public int getSqlLength() { return this.m_sqlLength; }
- public String getFieldName() { return this.m_fieldName; }
- public boolean isPrimaryKey() { return this.m_primaryKey; }
+ private int m_sqlLength;
- public void setSqlType(int pSqlType) { m_sqlType = pSqlType; }
- public void setJavaType(Class pJavaType) { m_javaType = pJavaType; }
- public void setSqlLength(int pSqlLength) { m_sqlLength = pSqlLength; }
- public void setFieldName(String pFieldName) { m_fieldName = pFieldName; }
- public void setPrimaryKey(boolean pPrimaryKey) { m_primaryKey = pPrimaryKey; }
-} //____________________________________________________________________________
+ private String m_fieldName;
+
+ private boolean m_primaryKey;
+
+ public SqlField(String pFldName, Class pJavaType, int pSqlType,
+ int pFieldLength, boolean pk) {
+ m_fieldName = pFldName;
+ m_javaType = pJavaType;
+ m_sqlType = pSqlType;
+ m_sqlLength = pFieldLength;
+ m_primaryKey = pk;
+ }
+
+ public int getSqlType() {
+ return m_sqlType;
+ }
+
+ public Class getJavaType() {
+ return m_javaType;
+ }
+
+ public int getSqlLength() {
+ return this.m_sqlLength;
+ }
+
+ public String getFieldName() {
+ return this.m_fieldName;
+ }
+
+ public boolean isPrimaryKey() {
+ return this.m_primaryKey;
+ }
+
+ public void setSqlType(int pSqlType) {
+ m_sqlType = pSqlType;
+ }
+
+ public void setJavaType(Class pJavaType) {
+ m_javaType = pJavaType;
+ }
+
+ public void setSqlLength(int pSqlLength) {
+ m_sqlLength = pSqlLength;
+ }
+
+ public void setFieldName(String pFieldName) {
+ m_fieldName = pFieldName;
+ }
+
+ public void setPrimaryKey(boolean pPrimaryKey) {
+ m_primaryKey = pPrimaryKey;
+ }
+} // ____________________________________________________________________________
Deleted: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/DefaultReposFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/DefaultReposFactory.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/DefaultReposFactory.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -1,134 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.soa.esb.parameters;
-
-import java.io.*;
-import java.util.Properties;
-
-import javax.naming.CompoundName;
-import javax.naming.InvalidNameException;
-import javax.naming.Name;
-
-import org.jboss.soa.esb.helpers.DomElement;
-
-public class DefaultReposFactory
-{
- public static FileReposit getRepository(Object p_o)
- {
- return new FileReposit();
-
- } //________________________________
-
- /**
- * This is a dummy class to provide basic (extremely basic)
- * storage/retrieval of parameter trees for jboss.esb
- * in a file system
- *
- * @author Esteban
- *
- */
- public static class FileReposit implements ParamsRepository
- {
- // Only this factory can instantiate an object of this class
- private FileReposit() {}
-
- public DomElement getElement(Name pName) throws Exception
- {
- return getFromFile(pName);
- } //____________________________
-
- public DomElement removeElement(Name pName) throws Exception
- {
- File oF = fileFromName(pName);
- if (! oF.exists())
- return null;
- DomElement oRet = getFromFile(oF);
- oF.delete();
- return oRet;
- } //____________________________
-
- public void removeSubree(Name pName) throws Exception
- { purgeSubTree(fileFromName(pName));
- } //____________________________
-
- public DomElement storeElement(Name pName, DomElement p_oNew)
- throws Exception
- {
- if (pName.size() < 1)
- throw new Exception("Name has no elements");
- File oF = fileFromName(pName);
- DomElement oOld = getFromFile(oF);
- if (null==p_oNew)
- { if (oF.exists())
- oF.delete();
- return oOld;
- }
- dirFromName(pName).mkdirs();
- ByteArrayOutputStream oByStr = p_oNew.toXml();
- FileOutputStream oOut = new FileOutputStream(oF);
- oOut.write(oByStr.toByteArray());
- oOut.close();
-
- return oOld;
- } //____________________________
-
- private static DomElement getFromFile(Name pName) throws Exception
- { return getFromFile(fileFromName(pName));
- } //____________________________
-
- private static DomElement getFromFile(File p_oF) throws Exception
- { if (! p_oF.exists()) return null;
- return DomElement.fromInputStream(new FileInputStream(p_oF));
- } //____________________________
-
- public static File dirFromName(Name pName)
- { int iMax = pName.size()-1;
- StringBuilder sb = new StringBuilder();
- for (int i1=0; i1<iMax; i1++)
- ((i1<1) ? sb : sb.append("/")).append(pName.get(i1));
- return new File(sb.toString());
- } //____________________________
-
- public static File fileFromName(Name pName)
- { return new File(dirFromName(pName),pName.get(-1+pName.size()));
- } //____________________________
-
- private void purgeSubTree(File oF)
- { if (! oF.exists()) return;
- if (oF.isDirectory())
- for (File oCurr : oF.listFiles())
- purgeSubTree(oCurr);
- oF.delete();
- } //____________________________
-
- private static final Properties s_oSyntax = new Properties();
- static
- { s_oSyntax.setProperty("jndi.syntax.direction","left_to_right");
- s_oSyntax.setProperty("jndi.syntax.separator","/");
- };
-
- public Name nameFromString(String p_s)
- throws InvalidNameException
- { return new CompoundName(p_s,s_oSyntax);
- } //________________________________
- } //____________________________________________________
-} //____________________________________________________________________________
Added: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamFileRepository.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamFileRepository.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamFileRepository.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -0,0 +1,154 @@
+package org.jboss.soa.esb.parameters;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.naming.Name;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.util.StreamUtils;
+
+
+/**
+ * This class provides basic file-based storage/retrieval of parameter trees for
+ * the JBoss ESB.
+ * <p/>
+ * This class creates a hierarchical parameter file structure on the file system.
+ * E.g. the value for a parameter named "org/jboss/param1" is stored in a file called
+ * "param1" in the folder "<root>/org/jboss", where "root" is either the working
+ * directory (default) or the directory specified in the
+ * "org.jboss.soa.esb.paramsRepository.file.root" System property.
+ *
+ * @author Esteban
+ *
+ */
+public class ParamFileRepository implements ParamRepository {
+
+ /**
+ * System property defining the repository root directory.
+ */
+ public static final String FILE_PARAMS_REPOS_ROOT = "org.jboss.soa.esb.paramsRepository.file.root";
+ /**
+ * The repository root dir.
+ */
+ private File root;
+ /**
+ * Logger.
+ */
+ private Logger logger = Logger.getLogger(ParamFileRepository.class);
+
+ /**
+ * Public default constructor.
+ */
+ public ParamFileRepository() {
+ String rootDir = System.getProperty(FILE_PARAMS_REPOS_ROOT);
+
+ // Set the repository root directory.
+ if(rootDir == null) {
+ // set it to the working dir.
+ root = new File("./");
+ } else {
+ root = new File(rootDir);
+ if(!root.exists()) {
+ throw new IllegalStateException("Nonexistant directory specified in the [" + FILE_PARAMS_REPOS_ROOT + "] System property.");
+ }
+ }
+
+ logger.info("Setting parameter repository root dir to [" + root.getAbsolutePath() + "].");
+ }
+
+ public void add(ParamName name, String value) throws ParamRepositoryException {
+ synchronized (this) {
+ asserNameOK(name);
+ if(value == null) {
+ throw new IllegalArgumentException("null 'value' arg in method call.");
+ }
+
+ File paramFile = toParamFile(name);
+
+ paramFile.getParentFile().mkdirs();
+ FileOutputStream fileStream = null;
+ try {
+ fileStream = new FileOutputStream(paramFile);
+ fileStream.write(value.getBytes("UTF-8"));
+ } catch (IOException e) {
+ throw new ParamRepositoryException("IO Error while storing param [" + name + "].", e);
+ } finally {
+ try {
+ if(fileStream != null) {
+ fileStream.flush();
+ fileStream.close();
+ }
+ } catch (IOException e) {
+ logger.warn("Unable to close param file: " + paramFile.getAbsolutePath(), e);
+ }
+ }
+ }
+ }
+
+ public String get(ParamName name) throws ParamRepositoryException {
+ synchronized (this) {
+ asserNameOK(name);
+
+ File paramFile = toParamFile(name);
+
+ if (!paramFile.exists()) {
+ return null;
+ }
+
+ InputStream fileStream = null;
+ try {
+ fileStream = new FileInputStream(paramFile);
+ byte[] value = StreamUtils.readStream(fileStream);
+ return new String(value, "UTF-8");
+ } catch (Exception e) {
+ throw new ParamRepositoryException("Unable to load Param Value from file: " + paramFile.getAbsolutePath(), e);
+ } finally {
+ try {
+ if(fileStream != null) {
+ fileStream.close();
+ }
+ } catch (IOException e) {
+ logger.warn("Unable to close param file: " + paramFile.getAbsolutePath(), e);
+ }
+ }
+ }
+ }
+
+ public void remove(ParamName name) {
+ synchronized (this) {
+ asserNameOK(name);
+
+ File paramFile = toParamFile(name);
+ if (paramFile.exists()) {
+ paramFile.delete();
+ }
+ }
+ }
+
+ /**
+ * Get the repository root directory.
+ * @return The repository root directory.
+ */
+ protected File getRoot() {
+ return root;
+ }
+
+ /**
+ * Get the param file for the specified param name.
+ * @param paramName The param name.
+ * @return The param file.
+ */
+ protected File toParamFile(Name paramName) {
+ return new File(root, paramName.toString());
+ }
+
+ private void asserNameOK(ParamName name) {
+ if (name == null || name.size() < 1) {
+ throw new IllegalArgumentException("Invalid name arg: " + name);
+ }
+ }
+}
\ No newline at end of file
Added: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamName.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamName.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamName.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.parameters;
+
+import java.util.Properties;
+
+import javax.naming.CompoundName;
+import javax.naming.InvalidNameException;
+
+/**
+ * Parameter Name.
+ * <p/>
+ * Represents a compound parameter name - from a hierarchical namespace.
+ * <h4 id="syntax">Parameter Name Format</h4>
+ * The syntax of the parameter name is expected to be in "directory" format,
+ * read from left to right, where the syntax seperator character is '/'
+ * e.g. "com/acme/ParameterX".
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class ParamName extends CompoundName {
+
+ private static final long serialVersionUID = 1L;
+ private static final Properties nameSyntaxProperties = new Properties();
+ static {
+ nameSyntaxProperties.setProperty("jndi.syntax.direction", "left_to_right");
+ nameSyntaxProperties.setProperty("jndi.syntax.separator", "/");
+ };
+
+ /**
+ * Public Constructor.
+ * @param name The name of the parameter, specified according to the
+ * <a href="#syntax">defined syntax</a>.
+ * @throws InvalidNameException The supplied name violates the
+ * <a href="#syntax">defined syntax</a>.
+ */
+ public ParamName(String name) throws InvalidNameException {
+ super(name, nameSyntaxProperties);
+ }
+}
Copied: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamRepository.java (from rev 5378, labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamsRepository.java)
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamsRepository.java 2006-08-01 14:16:35 UTC (rev 5378)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamRepository.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.parameters;
+
+
+/**
+ * Parameter Repository Definition.
+ * <p/>
+ * A ParamRepository implementation allows persistence, retrieval and removal of
+ * parameter values.
+ * <p/>
+ * Note that it is assumed that implementations are Thread Safe.
+ *
+ * @author <a href="mailto:schifest at gmail.com">Esteban Shifman</a>
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public interface ParamRepository {
+
+ // byte[] versions of the add and get methods might be needed on this.
+ // In fact, if this is done - rename the existing add and get methods
+ // to addString and getString and add the new byte[] methods as add/get.
+
+ /**
+ * Store a parameter value in the repository.
+ * @param name The parameter name. Must not be <code>null</code>.
+ * @param value The parameter value. Must not be <code>null</code>.
+ * @throws ParamRepositoryException Failed to store the specified parameter value.
+ */
+ public void add(ParamName name, String value) throws ParamRepositoryException;
+
+ /**
+ * Get the value associated with the named parameter.
+ * @param name The parameter name. Must not be <code>null</code>.
+ * @return The parameter value, or null if the parameter is not available in
+ * the repository.
+ * @throws ParamRepositoryException The parameter exists, but an error has occured
+ * while readingit.
+ */
+ public String get(ParamName name) throws ParamRepositoryException;
+
+ /**
+ * Remove a parameter, or a hierarchy of parameters.
+ * <p/>
+ * Because the repository is hierarchical in nature, parameters can be addressed
+ * explicitly or as a group using a hierarchical name.
+ * @param name The parameter name. Must not be <code>null</code>.
+ * @throws ParamRepositoryException Failed to remove the parameter, or hierarchy of parameters,
+ * from the repository..
+ */
+ public void remove(ParamName name) throws ParamRepositoryException;
+}
Added: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamRepositoryException.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamRepositoryException.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamRepositoryException.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -0,0 +1,29 @@
+package org.jboss.soa.esb.parameters;
+
+import org.jboss.soa.esb.BaseException;
+
+/**
+ * {@link org.jboss.soa.esb.parameters.ParamRepository} access Exception.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class ParamRepositoryException extends BaseException {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Public Constructor.
+ * @param message Exception message.
+ */
+ public ParamRepositoryException(String message) {
+ super(message);
+ }
+
+ /**
+ * Public Constructor.
+ * @param message Exception message.
+ * @param cause Exception cause.
+ */
+ public ParamRepositoryException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Added: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamRepositoryFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamRepositoryFactory.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamRepositoryFactory.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.parameters;
+
+import org.jboss.soa.esb.common.SystemProperties;
+
+/**
+ * Factory class for Singleton {@link ParamRepository} creation.
+ * <p/>
+ * Uses the "org.jboss.soa.esb.paramsRepository.class"
+ * system property to determine the {@link ParamRepository} implementation
+ * to be created. If not specified, the default implementation is the
+ * {@link org.jboss.soa.esb.parameters.ParamFileRepository}.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public abstract class ParamRepositoryFactory {
+
+ /**
+ * Singleton instance of the repository.
+ */
+ private static ParamRepository instance;
+
+ /**
+ * Factory method for creating the Singleton {@link ParamRepository} instance
+ * for the system.
+ * @return The ParamRepository instance for the system.
+ */
+ public static ParamRepository getInstance() {
+ if(instance == null) {
+ // Hasn't been created yet - lets created it in a synchronized fashion...
+ instance = synchedGetInstance();
+ }
+
+ return instance;
+ }
+
+ /**
+ * Synchronizes creation of the Singleton instance.
+ * @return The Singleton ParamRepository instance.
+ */
+ private static ParamRepository synchedGetInstance() {
+ synchronized (ParamRepositoryFactory.class) {
+ // The following check ensures that multithreads won't create
+ // multiple instances of the singleton. Threads that are blocked waiting
+ // at the start of this synch block will simply fall through and return the
+ // instance created by the thread that got in ahead of them.
+ if(instance == null) {
+ String runtimeClassName = SystemProperties.getParamRepositoryImplClass();
+
+ if(runtimeClassName == null) {
+ // If there's no repository name configured, return the
+ // default file-based repository...
+ instance = new ParamFileRepository();
+ } else {
+ try {
+ Class<?> runtimeClass = Class.forName(runtimeClassName);
+ instance = (ParamRepository) runtimeClass.newInstance();
+ } catch(Exception e) {
+ new IllegalStateException("System Configuration Exception: Unable to create system " + ParamRepository.class.getSimpleName() + " instance from runtime class name [" + runtimeClassName + "]", e);
+ }
+ }
+ }
+ }
+
+ return instance;
+ }
+
+ /**
+ * Resets the factory, allowing creation of a new Singleton
+ * instance.
+ * <p/>
+ * Should only need to be used for testing purposes.
+ */
+ protected static void reset() {
+ synchronized (ParamRepositoryFactory.class) {
+ instance = null;
+ }
+ }
+}
Deleted: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamsReposUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamsReposUtil.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamsReposUtil.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -1,55 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-
-
-package org.jboss.soa.esb.parameters;
-
-import java.lang.reflect.*;
-
-import org.jboss.soa.esb.common.SystemProperties;
-
-public class ParamsReposUtil
-{
- private ParamsReposUtil() {};
-
- public static ParamsRepository reposFromFactory
- (String p_sFactoryName, Object p_oFactoryParam)
- throws Exception
- {
- Class oFactClass = DefaultReposFactory.class;
- if (null!=p_sFactoryName)
- oFactClass = Class.forName(p_sFactoryName);
- Method oMth = oFactClass.getMethod("getRepository"
- ,new Class[] {Object.class});
- return (ParamsRepository) oMth.invoke(null,p_oFactoryParam);
- } //________________________________
-
- public static ParamsRepository reposFromFactory
- (Object p_oFactoryParam)
- throws Exception
- {
- String sFactClass
- = System.getProperty(SystemProperties.PARAMS_REPOS_FACTORY_CLASS);
- return reposFromFactory(sFactClass,p_oFactoryParam);
- } //________________________________
-
-} //____________________________________________________________________________
Deleted: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamsRepository.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamsRepository.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/parameters/ParamsRepository.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -1,37 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-
-
-package org.jboss.soa.esb.parameters;
-
-import javax.naming.Name;
-import org.jboss.soa.esb.helpers.DomElement;
-
-public interface ParamsRepository
-{
- public Name nameFromString (String p_s) throws Exception;
- public DomElement storeElement
- (Name pName, DomElement p_oNew) throws Exception;
- public DomElement getElement (Name pName) throws Exception;
- public DomElement removeElement (Name pName) throws Exception;
- public void removeSubree (Name pName) throws Exception;
-} //____________________________________________________________________________
Added: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/util/StreamUtils.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/util/StreamUtils.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/util/StreamUtils.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Stream handling utilities.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class StreamUtils {
+
+ /**
+ * Read the supplied InputStream and return as an array of bytes.
+ * @param stream The stream to read.
+ * @return The stream contents in an array of bytes.
+ */
+ public static byte[] readStream(InputStream stream) {
+ if(stream == null) {
+ throw new IllegalArgumentException("null 'stream' arg passed in method call.");
+ }
+
+ ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
+ byte[] buffer = new byte[256];
+ int readCount = 0;
+
+ try {
+ while((readCount = stream.read(buffer)) != -1) {
+ outBuffer.write(buffer, 0, readCount);
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Error reading stream.", e);
+ }
+
+ return outBuffer.toByteArray();
+ }
+}
Modified: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/DomElementUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/DomElementUnitTest.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/DomElementUnitTest.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -25,9 +25,9 @@
import java.io.IOException;
import java.util.Arrays;
-import org.jboss.soa.esb.StreamUtils;
import org.jboss.soa.esb.StringUtils;
import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.util.StreamUtils;
import org.xml.sax.SAXException;
/**
Modified: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/MacroExpanderUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/MacroExpanderUnitTest.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/MacroExpanderUnitTest.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -23,8 +23,8 @@
import java.util.HashMap;
-import org.jboss.soa.esb.StreamUtils;
import org.jboss.soa.esb.helpers.DomElement;
+import org.jboss.soa.esb.util.StreamUtils;
import junit.framework.TestCase;
Added: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/parameters/ParamRepositoryFactoryUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/parameters/ParamRepositoryFactoryUnitTest.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/parameters/ParamRepositoryFactoryUnitTest.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.parameters;
+
+import org.jboss.soa.esb.common.SystemProperties;
+
+import junit.framework.TestCase;
+
+/**
+ * ParamRepositoryFactory unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class ParamRepositoryFactoryUnitTest extends TestCase {
+
+ public void test_ParamRepositoryFactory() {
+ ParamRepository repo;
+
+ repo = ParamRepositoryFactory.getInstance();
+ assertTrue(repo instanceof ParamFileRepository);
+
+ ParamRepositoryFactory.reset();
+ System.setProperty(SystemProperties.PARAMS_REPOS_IMPL_CLASS, TestParamRepo.class.getName());
+ repo = ParamRepositoryFactory.getInstance();
+ assertTrue(repo instanceof TestParamRepo);
+ }
+
+ public void test_ParamRepositoryException() {
+ // for the coverage results ;-)
+ new ParamRepositoryException("message");
+ new ParamRepositoryException("message", new Exception());
+ }
+}
Added: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/parameters/ParamsFileRepositoryUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/parameters/ParamsFileRepositoryUnitTest.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/parameters/ParamsFileRepositoryUnitTest.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.parameters;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+/**
+ * ParamFileRepository unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class ParamsFileRepositoryUnitTest extends TestCase {
+
+ public void test_ParamsFileRepository() throws Exception {
+ File root;
+ ParamFileRepository fileRepo;
+
+ // Check it defaults to the working dir...
+ root = new File("./");
+ fileRepo = new ParamFileRepository();
+ assertEquals(root, fileRepo.getRoot());
+
+ // Check it can pick up from the System prop...
+ root = new File("build/tests/");
+ System.setProperty(ParamFileRepository.FILE_PARAMS_REPOS_ROOT, root.getPath());
+ fileRepo = new ParamFileRepository();
+ assertEquals(root, fileRepo.getRoot());
+
+ // Check for error on invalid System prop...
+ System.setProperty(ParamFileRepository.FILE_PARAMS_REPOS_ROOT, "blah/blah");
+ try {
+ new ParamFileRepository();
+ fail("expected IllegalStateException");
+ } catch(IllegalStateException e) {
+ // expected
+ }
+ }
+
+ public void test_add_get_remove_badargs() throws Exception {
+ System.setProperty(ParamFileRepository.FILE_PARAMS_REPOS_ROOT, "build/tests/");
+ ParamFileRepository fileRepo = new ParamFileRepository();
+
+ test_add_badargs(fileRepo, null, "val");
+ test_add_badargs(fileRepo, new ParamName(""), "val");
+ test_add_badargs(fileRepo, new ParamName(""), "val");
+ test_add_badargs(fileRepo, new ParamName("xxx/yyy"), null);
+
+ test_get_badargs(fileRepo, null);
+ test_get_badargs(fileRepo, new ParamName(""));
+
+ test_remove_badargs(fileRepo, null);
+ test_remove_badargs(fileRepo, new ParamName(""));
+ }
+
+ private void test_add_badargs(ParamFileRepository fileRepo, ParamName name, String value) throws ParamRepositoryException {
+ try {
+ fileRepo.add(name, value);
+ fail("expected IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ private void test_get_badargs(ParamFileRepository fileRepo, ParamName name) throws ParamRepositoryException {
+ try {
+ fileRepo.get(name);
+ fail("expected IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ private void test_remove_badargs(ParamFileRepository fileRepo, ParamName name) {
+ try {
+ fileRepo.remove(name);
+ fail("expected IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void test_add_get_remove() throws Exception {
+ System.setProperty(ParamFileRepository.FILE_PARAMS_REPOS_ROOT, "build/tests/");
+ ParamFileRepository fileRepo = new ParamFileRepository();
+ ParamName name = new ParamName("repostests/jboss/testparam");
+ File paramFile = fileRepo.toParamFile(name);
+
+ // Make sure the parameter doesn't already exist...
+ if(paramFile.exists()) {
+ paramFile.delete();
+ }
+
+ // Now the tests...
+ assertEquals(null, fileRepo.get(name));
+ fileRepo.add(name, "tomtestvalue");
+ assertEquals("tomtestvalue", fileRepo.get(name));
+ fileRepo.remove(name);
+ assertEquals(null, fileRepo.get(name));
+ }
+}
Added: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/parameters/TestParamRepo.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/parameters/TestParamRepo.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/parameters/TestParamRepo.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -0,0 +1,26 @@
+package org.jboss.soa.esb.parameters;
+
+public class TestParamRepo implements ParamRepository {
+
+ public TestParamRepo() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ public void add(ParamName name, String value)
+ throws ParamRepositoryException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public String get(ParamName name) throws ParamRepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void remove(ParamName name) throws ParamRepositoryException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Modified: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/BaseBusinessObjectUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/BaseBusinessObjectUnitTest.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/BaseBusinessObjectUnitTest.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -24,7 +24,6 @@
import java.util.ArrayList;
import java.util.List;
-import org.jboss.soa.esb.StreamUtils;
import junit.framework.TestCase;
Modified: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/BobjStdDTOUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/BobjStdDTOUnitTest.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/BobjStdDTOUnitTest.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -24,7 +24,6 @@
import java.util.ArrayList;
import java.util.List;
-import org.jboss.soa.esb.StreamUtils;
import org.jboss.soa.esb.StringUtils;
import org.jboss.soa.esb.W3CDomUtils;
import org.jboss.soa.esb.common.bizclasses.Address;
Added: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/StreamUtilsUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/StreamUtilsUnitTest.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/StreamUtilsUnitTest.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.util;
+
+import java.io.ByteArrayInputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * StreamUtils unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class StreamUtilsUnitTest extends TestCase {
+
+ public void test_readStream_badargs() {
+ try {
+ StreamUtils.readStream(null);
+ fail("expected IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void test_readStream() {
+ StringBuffer testBuf = new StringBuffer(500);
+ byte[] resStream;
+
+ while(testBuf.length() < 500) {
+ testBuf.append("12121212121212121212121212121212121212121212121212");
+ }
+
+ String testString = testBuf.toString();
+ String resString = new String(StreamUtils.readStream(new ByteArrayInputStream(testString.getBytes())));
+
+ assertEquals(testString, resString);
+ }
+}
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/AbstractPoller.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/AbstractPoller.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/AbstractPoller.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -62,8 +62,8 @@
protected Map<String,GroupOfChilds> m_omChildPrc
= new HashMap<String,GroupOfChilds>();
- protected ParamsRepository m_oParmRepos;
- protected Name m_oParmsName;
+ protected ParamRepository m_oParmRepos;
+ protected ParamName m_oParmName;
protected Logger m_oLogger;
protected DomElement m_oParms;
@@ -80,9 +80,8 @@
{
m_oLogger = EsbUtil.getDefaultLogger(this.getClass());
- String sFactoryClass = SystemProperties.getParamsReposFactoryClass();
- m_oParmRepos = ParamsReposUtil.reposFromFactory(sFactoryClass,null);
- m_oParmsName = m_oParmRepos.nameFromString(p_sParamsUid);
+ m_oParmRepos = ParamRepositoryFactory.getInstance();
+ m_oParmName = new ParamName(p_sParamsUid);
} //__________________________________
protected void runUntilEndRequested() throws Exception
@@ -91,12 +90,12 @@
{ String sMsg = (null == m_oParms)
? "Initial Parameter loading" : "Reloading Params";
m_oLogger.info(formatLogMsg(sMsg));
- m_oParms = m_oParmRepos.getElement(m_oParmsName);
+ m_oParms = DomElement.fromXml(m_oParmRepos.get(m_oParmName));
}
catch (Exception e)
{
StringBuilder sb = new StringBuilder ("Problems loading params ")
- .append(m_oParmsName)
+ .append(m_oParmName)
.append((null==m_oParms)? " exiting..." : "continuing to use cached params")
;
m_oLogger.error(formatLogMsg(sb.toString()));
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/JmsQueueListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/JmsQueueListener.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/JmsQueueListener.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -45,8 +45,8 @@
protected Map<String,GroupOfChilds> m_omChildPrc
= new HashMap<String,GroupOfChilds>();
- protected ParamsRepository m_oParmRepos;
- protected Name m_oParmsName;
+ protected ParamRepository m_oParmRepos;
+ protected ParamName m_oParmName;
protected Logger m_oLogger;
protected DomElement m_oParms;
@@ -65,9 +65,8 @@
{
m_oLogger = EsbUtil.getDefaultLogger(this.getClass());
- String sFactoryClass = SystemProperties.getParamsReposFactoryClass();
- m_oParmRepos = ParamsReposUtil.reposFromFactory(sFactoryClass,null);
- m_oParmsName = m_oParmRepos.nameFromString(p_sParamsUid);
+ m_oParmRepos = ParamRepositoryFactory.getInstance();
+ m_oParmName = new ParamName(p_sParamsUid);
runUntilEndRequested();
} //__________________________________
@@ -77,12 +76,12 @@
{ String sMsg = (null == m_oParms)
? "Initial Parameter loading" : "Reloading Params";
m_oLogger.debug(formatLogMsg(sMsg));
- m_oParms = m_oParmRepos.getElement(m_oParmsName);
+ m_oParms = DomElement.fromXml(m_oParmRepos.get(m_oParmName));
}
catch (Exception e)
{
StringBuilder sb = new StringBuilder ("Problems loading params ")
- .append(m_oParmsName)
+ .append(m_oParmName)
.append((null==m_oParms)? " exiting..." : "continuing to use cached params")
;
m_oLogger.error(formatLogMsg(sb.toString()));
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/OldDirListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/OldDirListener.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/OldDirListener.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -63,8 +63,8 @@
private ThreadGroup m_oThrGrp = Thread.currentThread().getThreadGroup();
private Logger m_oLogger;
- private DomElement m_oParms;
- private ParamsRepository m_oParmRepos;
+ private DomElement paramXmlTree;
+ private ParamRepository m_oParmRepos;
private TopicConnection m_oTopicConn = null;
private TopicSession m_oSession = null;
@@ -74,62 +74,35 @@
public OldDirListener(String p_sParamsUid) throws Exception
{
m_oLogger = EsbUtil.getDefaultLogger(this.getClass());
-// setupSubscribe();
- /*
- * Removing Nagios integration
- try
- {
- String sNagServer = System.getProperty("jbossEsb.nagios.server");
- if (sNagServer != null)
- {
- int iNagPort = Integer.parseInt
- (System.getProperty("jbossEsb.nagios.port","5667"));
- String sNagService =
- System.getProperty("jbossEsb.nagios.service");
- new NagiosStandaloneHeartbeat(
- sNagServer, iNagPort, sNagService, "rosetta-listener-service");
- }
- }
- catch (Exception eNagios)
- {
- m_oLogger.info("Problems with Nagios Notification", eNagios);
- }
- */
-
- String sFactoryClass = SystemProperties.getParamsReposFactoryClass();
- m_oParmRepos = ParamsReposUtil.reposFromFactory(sFactoryClass,null);
-
- Name oParms = m_oParmRepos.nameFromString(p_sParamsUid);
- while (loadParmsCycle(oParms))
- {
- }
+ m_oParmRepos = ParamRepositoryFactory.getInstance();
+ while (loadParmsCycle(new ParamName(p_sParamsUid))) {}
} //__________________________________
- protected boolean loadParmsCycle(Name p_oParams) throws Exception
+ protected boolean loadParmsCycle(ParamName paramName) throws Exception
{
- String sMsg = (null == m_oParms)
+ String sMsg = (null == paramXmlTree)
? "Initial Parameter loading" : "Reloading Params";
m_oLogger.info(sMsg);
try
{
- m_oParms = m_oParmRepos.getElement(p_oParams);
+ paramXmlTree = DomElement.fromXml(m_oParmRepos.get(paramName));
}
catch (Exception e)
{
m_oLogger.warn("Failed to load parameters");
- if (null == m_oParms)
+ if (null == paramXmlTree)
{
throw e;
}
}
- String sAtt = m_oParms.getAttr(PARM_RELOAD_LTCY);
+ String sAtt = paramXmlTree.getAttr(PARM_RELOAD_LTCY);
long lNewLoad = System.currentTimeMillis()
+ ( (null != sAtt) ? (1000 * Integer.parseInt(sAtt)) : 180000);
- DomElement[] oaParms = m_oParms.getAllElemChildren();
+ DomElement[] oaParms = paramXmlTree.getAllElemChildren();
- sAtt = m_oParms.getAttr(PARM_POLL_LTCY);
+ sAtt = paramXmlTree.getAttr(PARM_POLL_LTCY);
long lPollLtcy = (null != sAtt) ? (1000 * Integer.parseInt(sAtt)) : 20000;
if (lPollLtcy < 3000)
{
Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/msglistener/AbstractEsbMsgDrivenBean.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/msglistener/AbstractEsbMsgDrivenBean.java 2006-08-03 09:19:45 UTC (rev 5426)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/msglistener/AbstractEsbMsgDrivenBean.java 2006-08-03 09:40:47 UTC (rev 5427)
@@ -30,7 +30,6 @@
import org.apache.log4j.*;
import org.jboss.soa.esb.util.*;
-import org.jboss.soa.esb.common.*;
import org.jboss.soa.esb.helpers.*;
import org.jboss.soa.esb.parameters.*;
@@ -50,7 +49,7 @@
* The service identifier will be used as a left_to_right (separator="/")
* Name to search the corresponding configuration in a ParamsRepository object
* provided by the factory class name in the
- * SystemProperties.PARAMS_REPOS_FACTORY_CLASS system property
+ * SystemProperties.PARAMS_REPOS_IMPL_CLASS system property
*<p>
* Derived classes are typically empty, and are coded just to tie the
* MDB that extends this class with a specific
@@ -240,12 +239,8 @@
protected DomElement getParameters(String p_sKey)
throws Exception
{
- String sFactoryClass
- = SystemProperties.getParamsReposFactoryClass();
- ParamsRepository oRep
- = ParamsReposUtil.reposFromFactory(sFactoryClass,null);
- return oRep.getElement(oRep.nameFromString(p_sKey));
-
+ ParamRepository repo = ParamRepositoryFactory.getInstance();
+ return DomElement.fromXml(repo.get(new ParamName(p_sKey)));
} //__________________________________
More information about the jboss-svn-commits
mailing list