[jboss-svn-commits] JBL Code SVN: r5317 - in labs/jbossesb/trunk/product/core/common: src/org/jboss/soa/esb/helpers src/org/jboss/soa/esb/helpers/persist src/org/jboss/soa/esb/util tests/src/org/jboss/soa/esb tests/src/org/jboss/soa/esb/helpers tests/src/org/jboss/soa/esb/util

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jul 27 13:23:48 EDT 2006


Author: tfennelly
Date: 2006-07-27 13:23:34 -0400 (Thu, 27 Jul 2006)
New Revision: 5317

Added:
   labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/AppServerContextUnitTest.java
   labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/
   labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/EsbUtilUnitTest.java
Removed:
   labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/NormalizedDate.java
Modified:
   labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/AppServerContext.java
   labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java
   labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/util/BaseBusinessObject.java
   labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/util/EsbUtil.java
Log:
Added some more unit tests

Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/AppServerContext.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/AppServerContext.java	2006-07-27 17:18:21 UTC (rev 5316)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/AppServerContext.java	2006-07-27 17:23:34 UTC (rev 5317)
@@ -1,110 +1,104 @@
 /*
-* 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;
 
 import java.util.*;
 import javax.naming.*;
 import org.apache.log4j.Logger;
+
+
 /**
- * Obtains JNDI naming context for a predefined list of 'well known' server types
- *
+ * Obtains JNDI naming context for a predefined list of 'well known' server
+ * types
+ * 
  */
+public abstract class AppServerContext {
+	/**
+	 * Logger for this class
+	 */
+	private static final Logger m_oLogger = Logger
+			.getLogger(AppServerContext.class);
 
-public class AppServerContext
-{
-    /**
-     * Logger for this class
-     */
-    private static final Logger m_oLogger = Logger
-            .getLogger(AppServerContext.class);
+	/**
+	 * Indicates that a jboss context is requested
+	 */
+	public static final String CTX_JBOSS = "jboss";
 
-  /**
-   * Indicates that a jboss context is requested
-   */
-  public static final String CTX_JBOSS = "jboss";
+	public static final int MAX_RETRIES = 10;
 
-  public static final int MAX_RETRIES		= 10;
-  public static final int WAIT_FOR_RETRY 	= 30;
+	public static final int WAIT_FOR_RETRY = 30;
 
-  public enum SERVER_TYPE
-  {
-	  jboss
-	  ,weblogic
-	  ,websphere
-	  ,oracle
-  };
+	public enum SERVER_TYPE {
+		jboss, weblogic, websphere, oracle
+	};
 
-  //	No public default constructor
-  private AppServerContext() {}
+	public static Context getServerContext(String pType, String p_sJndiServer) {
+		return getServerContext(SERVER_TYPE.valueOf(pType), p_sJndiServer);
+	}
+	
+	// REVIEW: What is all this about... this class doesn't support anything other than a JBoss Server!!
 
-  /**
-   * Equivalent to calling getServerContext(CTX_JBOSS);
-   */
-  public static Context getServerContext(String p_sJndiServer)
-  { return getServerContext(SERVER_TYPE.jboss,p_sJndiServer); }
+	/**
+	 * Searches a predefined table of 'well known' app server types, and returns
+	 * the corresponding naming context
+	 * 
+	 * @param p_sServer:
+	 *            name or IP of server, and optionally port #
+	 */
+	private static Context getServerContext(SERVER_TYPE pType,
+			String p_sJndiServer) {
+		switch (pType) {
+		case jboss:
+			return jbossContext(p_sJndiServer);
+		}
 
-  public static Context getServerContext(String pType , String p_sJndiServer)
-  	{	return getServerContext(SERVER_TYPE.valueOf(pType),p_sJndiServer); }
+		return null;
+	} // __________________________________
 
-  /**
-   * Searches a predefined table of 'well known' app server types, and returns
-   * the corresponding naming context
-   * @param p_sServer: name or IP of server, and optionally port #
-   */
-  public static Context getServerContext(SERVER_TYPE pType , String p_sJndiServer)
-  {
-    switch (pType)
-    { case jboss :  return jbossContext(p_sJndiServer);
-    }
+	private static Context jbossContext(String p_sJndiServer) {
+		Properties oPr = new Properties();
+		oPr.setProperty(Context.PROVIDER_URL, p_sJndiServer);
+		oPr.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+				"org.jnp.interfaces.NamingContextFactory");
+		oPr.setProperty(Context.URL_PKG_PREFIXES,
+				"jboss.naming:org.jnp.interfaces");
 
-    return null;
-  } //__________________________________
+		boolean bCtxOK = false;
+		Context oCtx = null;
+		for (int i1 = 0; (!bCtxOK) && i1 < MAX_RETRIES; i1++) {
+			// check if context is valid
+			try {
+				oCtx = new InitialContext(oPr);
+				oCtx.list("__dummy2@#$%");
+				bCtxOK = true;
+			} catch (NamingException nex) {
+				bCtxOK = true;
+			}
+		}
+		if (bCtxOK)
+			return oCtx;
+		m_oLogger.error("Can't connect to jndiServer <" + p_sJndiServer + ">");
+		return null;
 
-    private static Context jbossContext(String p_sJndiServer)
-    {
-    	Properties oPr = new Properties();
-        oPr.setProperty(Context.PROVIDER_URL, p_sJndiServer);
-        oPr.setProperty(Context.INITIAL_CONTEXT_FACTORY
-                ,"org.jnp.interfaces.NamingContextFactory");
-        oPr.setProperty(Context.URL_PKG_PREFIXES
-        		,"jboss.naming:org.jnp.interfaces");
+	} // ________________________
 
-        boolean bCtxOK = false;
-        Context oCtx = null;
-        for (int i1=0; (! bCtxOK) && i1<MAX_RETRIES; i1++)
-        {
-        	// check if context is valid
-            try
-            {	oCtx = new InitialContext(oPr);
-            	oCtx.list("__dummy2@#$%");
-            	bCtxOK = true;
-            }
-            catch (NamingException nex)	{bCtxOK = true;	}
-        }
-    	if (bCtxOK)
-    		return oCtx;
-    	m_oLogger.error("Can't connect to jndiServer <" + p_sJndiServer + ">") ;
-    	return null;
-
-    } //________________________
-
-} //____________________________________________________________________________
+} // ____________________________________________________________________________

Deleted: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/NormalizedDate.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/NormalizedDate.java	2006-07-27 17:18:21 UTC (rev 5316)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/NormalizedDate.java	2006-07-27 17:23:34 UTC (rev 5317)
@@ -1,99 +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.helpers;
-
-import java.util.*;
-import java.text.*;
-
- at SuppressWarnings("serial")
-public class NormalizedDate extends Date
-{
-  public static final long NULL = -5361913154553L; // "1800 01 01"
-
-  private static SimpleDateFormat s_odf = new SimpleDateFormat("yyyyMMdd");
-
-  public NormalizedDate()           { super(System.currentTimeMillis()); }
-  public NormalizedDate(Date p_oD)  { super(p_oD.getTime()); }
-  public NormalizedDate(String p_s) throws Exception
-  { super (s_odf.parse(p_s).getTime());
-  } //__________________________________
-  public NormalizedDate(String p_s,String p_sFormat) throws Exception
-  { super (new SimpleDateFormat(p_sFormat).parse(p_s).getTime());
-  } //__________________________________
-
-  public String toString()
-  { return (this.isNull()) ? "" : s_odf.format(this);
-  } //__________________________________
-  public boolean isNull()
-  { return this.getTime()<=NULL;
-  } //__________________________________
-
-  public static String toString(Date p_oD) { return s_odf.format(p_oD); }
-  public static String toString(long p_oL) { return s_odf.format(new Date(p_oL)); }
-  public static NormalizedDate getNull()  { return new NormalizedDate(new Date(NULL)); }
-
-  static final Exception s_oInv = new Exception("Invalid Date");
-
-  public String dateToString()
-  {
-    return NormalizedDate.dateToString(this,"dd/MM/yyyy");
-  }
-
-  public static String dateToString(NormalizedDate p_o,String p_sFmt)
-  { return (null == p_o)?"":new SimpleDateFormat(p_sFmt).format(p_o); }
-
-  public static NormalizedDate parseDate (String p_s) throws Exception
-  { Calendar  oCal = Calendar.getInstance();
-    StringTokenizer ST = new StringTokenizer(p_s,"/");
-    if (ST.countTokens() < 2)
-    { StringBuffer sb = new StringBuffer(p_s);
-      if (sb.length()<6)sb.append("         ");
-      sb.insert(2,"/").insert(5,"/");
-      ST = new StringTokenizer(sb.toString(),"/");
-    }
-    try
-    { int iDay = Integer.parseInt(ST.nextToken());
-      int iMonth = Integer.parseInt(ST.nextToken());
-      int iYr = Integer.parseInt(ST.nextToken());
-      iYr = (iYr < 20) ? 2000 + iYr
-	  : (iYr < 100)? 1900 + iYr
-	  : iYr;
-//      if (iYr < 1920 || iYr > 2010) throw s_oInv;
-      if (iMonth < 1 || iMonth > 12) throw s_oInv;
-      if (iDay < 1)                 throw s_oInv;
-      oCal.set(iYr,iMonth-1,1);
-      if (iDay > oCal.getActualMaximum(Calendar.DAY_OF_MONTH)) throw s_oInv;
-      oCal.set(iYr,iMonth-1,iDay);
-      return new NormalizedDate(oCal.getTime());
-    }
-    catch (Exception pe) {  throw s_oInv; }
-  } //_______________________________________________
-
-  public static long todayMillis()
-  { Calendar oCal = Calendar.getInstance();
-    oCal.set(Calendar.HOUR_OF_DAY,0);
-    oCal.set(Calendar.MINUTE,0);
-    oCal.set(Calendar.SECOND,0);
-    oCal.set(Calendar.MILLISECOND,0);
-    return oCal.getTimeInMillis();
-  } //__________________________________
-} //____________________________________________________________________________

Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java	2006-07-27 17:18:21 UTC (rev 5316)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java	2006-07-27 17:23:34 UTC (rev 5317)
@@ -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;
 
@@ -28,107 +28,131 @@
 
 import org.apache.log4j.*;
 
-public class JdbcCleanConn
-{
-  private DataSource  m_oDS=null;
-  private Connection  m_conn=null;
-  protected List<PreparedStatement> m_olPrepSt
-  	= new ArrayList<PreparedStatement>();
-  protected Logger    m_oLogger;
+public class JdbcCleanConn {
+	private DataSource m_oDS = null;
 
-  public JdbcCleanConn(DataSource p_oDS) throws Exception
-    { m_oDS = p_oDS;
-      m_oLogger = Logger.getLogger(this.getClass());
-    }
+	private Connection m_conn = null;
 
-  public void commit ()    throws Exception { if (null != m_conn)m_conn.commit(); }
-  public void rollback ()  throws Exception { if (null != m_conn)m_conn.rollback(); }
+	protected List<PreparedStatement> m_olPrepSt = new ArrayList<PreparedStatement>();
 
-  public void release()
-  { if (null != m_conn)
-    { try { m_conn.rollback(); }
-      catch (Exception eRoll) {}
+	protected Logger m_oLogger;
 
-      for (PreparedStatement PS : m_olPrepSt)
-        try { PS.close(); } catch (Exception e) {}
-      try { m_conn.close(); }
-      catch (Exception e1) {}
-    }
-    m_olPrepSt.clear();
-    m_conn  = null;
-  } //__________________________________
+	public JdbcCleanConn(DataSource p_oDS) throws Exception {
+		m_oDS = p_oDS;
+		m_oLogger = Logger.getLogger(this.getClass());
+	}
 
-  public PreparedStatement prepareStatement (String p_sSt, int p_i1, int p_i2)
-      throws Exception
-  {
-    if (null == m_conn) connect();
-    PreparedStatement PS = m_conn.prepareStatement(p_sSt, p_i1, p_i2);
-    m_olPrepSt.add(PS);
-    return PS;
-  } //__________________________________
+	public void commit() throws Exception {
+		if (null != m_conn)
+			m_conn.commit();
+	}
 
-  public PreparedStatement prepareStatement (String p_sSt) throws Exception
-  {
-    if (null == m_conn) connect();
-    PreparedStatement PS = m_conn.prepareStatement(p_sSt);
-    m_olPrepSt.add(PS);
-    return PS;
-  } //__________________________________
+	public void rollback() throws Exception {
+		if (null != m_conn)
+			m_conn.rollback();
+	}
 
-  public ResultSet execQueryWait(PreparedStatement p_PS, int p_iQtry)
-      throws Exception
-  {
-    Exception eRet=null;
-    int iQtry = (p_iQtry<1) ? 1 : (p_iQtry < 50) ? p_iQtry : 50;
-    for (int i1=0; i1<iQtry; i1++)
-    { try { return p_PS.executeQuery(); }
-      catch (Exception e)
-      { if (null==eRet) eRet = new Exception(e.getMessage());
-//	System.out.println("Retrying "+i1);
-        Thread.sleep(100+(new Double(100*Math.random())).longValue());
-      }
-    }
-    m_oLogger.error("execQueryWait() FAILED",eRet);
-    throw eRet;
-  } //__________________________________
+	public void release() {
+		if (null != m_conn) {
+			try {
+				m_conn.rollback();
+			} catch (Exception eRoll) {
+			}
 
-  public void execUpdWait(PreparedStatement p_PS, int p_iQtry)
-      throws Exception
-  {
-    Exception eRet=null;
-    int iQtry = (p_iQtry<1) ? 1 : (p_iQtry < 50) ? p_iQtry : 50;
-    for (int i1=0; i1<iQtry; i1++)
-    { try { p_PS.executeUpdate(); return; }
-      catch (Exception e)
-      { if (null==eRet) eRet = new Exception(e.getMessage());
-//        System.out.println("Retrying "+i1);
-        Thread.sleep(100+(new Double(100*Math.random())).longValue());
-      }
-    }
-    m_oLogger.error("execUpdWait() FAILED",eRet);
-    throw eRet;
-  } //__________________________________
+			for (PreparedStatement PS : m_olPrepSt)
+				try {
+					PS.close();
+				} catch (Exception e) {
+				}
+			try {
+				m_conn.close();
+			} catch (Exception e1) {
+			}
+		}
+		m_olPrepSt.clear();
+		m_conn = null;
+	} // __________________________________
 
-  private void connect() throws Exception
-  {
-    Exception eRet = null;
-    for (int i1=0; i1<5; i1++)
-    { try { m_conn = m_oDS.getConnection(); eRet = null; break; }
-      catch (Exception e)
-      { if (null==eRet) eRet = new Exception(e.getMessage());
-        System.out.println("Connecting "+i1);
-        Thread.sleep(2000+(new Double(100*Math.random())).longValue());
-      }
-    }
-    if (null != eRet)
-    { m_oLogger.error("connect() FAILED",eRet);
-      throw eRet;
-    }
-    m_conn.setAutoCommit(false);
-    m_conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+	public PreparedStatement prepareStatement(String p_sSt, int p_i1, int p_i2)
+			throws Exception {
+		if (null == m_conn)
+			connect();
+		PreparedStatement PS = m_conn.prepareStatement(p_sSt, p_i1, p_i2);
+		m_olPrepSt.add(PS);
+		return PS;
+	} // __________________________________
 
-    m_olPrepSt.clear();
+	public PreparedStatement prepareStatement(String p_sSt) throws Exception {
+		if (null == m_conn)
+			connect();
+		PreparedStatement PS = m_conn.prepareStatement(p_sSt);
+		m_olPrepSt.add(PS);
+		return PS;
+	} // __________________________________
 
-  } //__________________________________
+	public ResultSet execQueryWait(PreparedStatement p_PS, int p_iQtry)
+			throws Exception {
+		Exception eRet = null;
+		int iQtry = (p_iQtry < 1) ? 1 : (p_iQtry < 50) ? p_iQtry : 50;
+		for (int i1 = 0; i1 < iQtry; i1++) {
+			try {
+				return p_PS.executeQuery();
+			} catch (Exception e) {
+				if (null == eRet)
+					eRet = new Exception(e.getMessage());
+				// System.out.println("Retrying "+i1);
+				Thread.sleep(100 + (new Double(100 * Math.random()))
+						.longValue());
+			}
+		}
+		m_oLogger.error("execQueryWait() FAILED", eRet);
+		throw eRet;
+	} // __________________________________
 
-} //____________________________________________________________________________
+	public void execUpdWait(PreparedStatement p_PS, int p_iQtry)
+			throws Exception {
+		Exception eRet = null;
+		int iQtry = (p_iQtry < 1) ? 1 : (p_iQtry < 50) ? p_iQtry : 50;
+		for (int i1 = 0; i1 < iQtry; i1++) {
+			try {
+				p_PS.executeUpdate();
+				return;
+			} catch (Exception e) {
+				if (null == eRet)
+					eRet = new Exception(e.getMessage());
+				// System.out.println("Retrying "+i1);
+				Thread.sleep(100 + (new Double(100 * Math.random()))
+						.longValue());
+			}
+		}
+		m_oLogger.error("execUpdWait() FAILED", eRet);
+		throw eRet;
+	} // __________________________________
+
+	private void connect() throws Exception {
+		Exception eRet = null;
+		for (int i1 = 0; i1 < 5; i1++) {
+			try {
+				m_conn = m_oDS.getConnection();
+				eRet = null;
+				break;
+			} catch (Exception e) {
+				if (null == eRet)
+					eRet = new Exception(e.getMessage());
+				System.out.println("Connecting " + i1);
+				Thread.sleep(2000 + (new Double(100 * Math.random()))
+						.longValue());
+			}
+		}
+		if (null != eRet) {
+			m_oLogger.error("connect() FAILED", eRet);
+			throw eRet;
+		}
+		m_conn.setAutoCommit(false);
+		m_conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+
+		m_olPrepSt.clear();
+
+	} // __________________________________
+
+} // ____________________________________________________________________________

Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/util/BaseBusinessObject.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/util/BaseBusinessObject.java	2006-07-27 17:18:21 UTC (rev 5316)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/util/BaseBusinessObject.java	2006-07-27 17:23:34 UTC (rev 5317)
@@ -1,257 +1,362 @@
 /*
-* 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.util;
 
 import java.util.*;
 import java.lang.reflect.*;
 
-public class BaseBusinessObject
-{
-  public BobjStdDTO      toDTO() throws Exception { return getBaseDTO(); }
-  public String classNm() { return this.getClass().getSimpleName(); }
-  public boolean isNull () { return false; }
-  public String toString ()
-  { try { return this.toDTO().toXml(); }
-    catch (Exception e) {return null; }
-  } //__________________________________
+public class BaseBusinessObject {
+	public BobjStdDTO toDTO() throws Exception {
+		return getBaseDTO();
+	}
 
-  public          String []   locator()      	{ return new String [] {}; }
-  public          String []   locator(int p_i)
-  { return (0==p_i) ? locator() : new String [] {};
-  }
-  /**
-   * Get all locators for a given BaseBusinessObject
-   * <p /> Override this method in your class if you have more than 1 locator array
-   * @return An array of String arrays containing all locators
-   */
-  public String[][]	allLocators()		{ return new String[][]  {locator()}; }
+	public String classNm() {
+		return this.getClass().getSimpleName();
+	}
 
-  public final    ObjLocator  getObjLocator() { return getObjLocator(0); }
-  public final    ObjLocator  getObjLocator(int p_i)
-  	{ return new ObjLocator(m_lUid,locator(p_i)); }
+	public boolean isNull() {
+		return false;
+	}
 
-  private enum ATTRIB
-  {elem
-  ,rol
-  };
-  enum HIDDEN
-  {uid
-  ,stamp
-  ,type
-  ,snap
-  ,dtSnap
-  ,batch
-  };
-  private EnumMap<ATTRIB,String>m_oData;
-  public String setField(ATTRIB pKey, String pVal)
-  {	if (null==pKey)	return null;
-	String sRet	= (null==m_oData)? null : m_oData.remove(pKey);
-	if (! EsbUtil.isNullString(pVal))
-	{	if (null==m_oData)
-			m_oData = new EnumMap<ATTRIB,String>(ATTRIB.class);
-		m_oData.put(pKey,pVal);
+	public String toString() {
+		try {
+			return this.toDTO().toXml();
+		} catch (Exception e) {
+			return null;
+		}
+	} // __________________________________
+
+	public String[] locator() {
+		return new String[] {};
 	}
-	return sRet;
-  } //__________________________________
 
-  public String getField(ATTRIB pKey)
-  {	if (null==pKey)		return null;
-	if (null==m_oData)	return null;
-  	return m_oData.get(pKey);
-  } //__________________________________
+	public String[] locator(int p_i) {
+		return (0 == p_i) ? locator() : new String[] {};
+	}
 
-  private   long    m_lStamp 	= -1;
-  private   long    m_lUid 		= -1;
-  private   long    m_lLastSnap	=0;
-  private   long    m_lBatch	=0;
-  private   String	m_sDtSnap	= null;
-  private   String	m_sPkg		= null;
+	/**
+	 * Get all locators for a given BaseBusinessObject
+	 * <p />
+	 * Override this method in your class if you have more than 1 locator array
+	 * 
+	 * @return An array of String arrays containing all locators
+	 */
+	public String[][] allLocators() {
+		return new String[][] { locator() };
+	}
 
-  public boolean hasUid () { return m_lUid > 0; }
+	public final ObjLocator getObjLocator() {
+		return getObjLocator(0);
+	}
 
-  public void	setElemNm(String p_s){ setField(ATTRIB.elem,p_s); }
-  public void	setRole(String p_s)  { setField(ATTRIB.rol,p_s); }
-  public void   setStamp  (long p_l) { m_lStamp = p_l; }
-  public void   setUid    (long p_l) { m_lUid = p_l; }
-  public void   setSnap   (long p_l) { m_lLastSnap = p_l; }
-  public void   setBatchNum(long p_l) { m_lBatch = p_l; }
-  public void	setSnapDate(String p_s) { m_sDtSnap = p_s; }
-  public void	setPackage()
-  	{ m_sPkg = this.getClass().getPackage().getName(); }
+	public final ObjLocator getObjLocator(int p_i) {
+		return new ObjLocator(m_lUid, locator(p_i));
+	}
 
-  public String getElemNm()       { return getField(ATTRIB.elem); }
-  public String getRole()         { return getField(ATTRIB.rol); }
-  public long   getStamp()        { return m_lStamp; }
-  public long   getUid ()         { return m_lUid; }
-  public long   getSnap ()        { return m_lLastSnap; }
-  public long   getBatchNum() 	  { return m_lBatch; }
-  public String getSnapDate()	  { return m_sDtSnap; }
+	private enum ATTRIB {
+		elem, rol
+	};
 
-  public BaseBusinessObject() {this((String)null); }
-  protected BaseBusinessObject(String p_sElem) { this(p_sElem,-1); }
-  protected BaseBusinessObject(String p_sElem, long p_lUid)
-  { setField(ATTRIB.elem,p_sElem);
-    m_lUid    = p_lUid;
-    if (null != getElemNm())    return;
-    String sClass   = getClass().getSimpleName();
-    if (null == p_sElem)
-    	setField(ATTRIB.elem,sClass);
-  } //________________________________
+	enum HIDDEN {
+		uid, stamp, type, snap, dtSnap, batch
+	};
 
-  protected BaseBusinessObject(BobjStdDTO p_oDto) throws Exception
-  { this (p_oDto.elementNm());
-    if (p_oDto.isList())        return;
-    commonFieldsFromDTO(this,p_oDto);
-  } //________________________________
+	private EnumMap<ATTRIB, String> m_oData;
 
-  private static final void commonFieldsFromDTO(BaseBusinessObject p_obj,BobjStdDTO p_oDto)
-    throws Exception
-  { for(ATTRIB oCurr : ATTRIB.values())
-	  p_obj.setField(oCurr,p_oDto.getAttr(oCurr.toString()));
+	public String setField(ATTRIB pKey, String pVal) {
+		if (null == pKey)
+			return null;
+		String sRet = (null == m_oData) ? null : m_oData.remove(pKey);
+		if (!EsbUtil.isNullString(pVal)) {
+			if (null == m_oData)
+				m_oData = new EnumMap<ATTRIB, String>(ATTRIB.class);
+			m_oData.put(pKey, pVal);
+		}
+		return sRet;
+	} // __________________________________
 
-    String sAux = p_oDto.getAttr(HIDDEN.uid.toString());
-    if (null != sAux) p_obj.m_lUid  = Long.parseLong(sAux);
+	public String getField(ATTRIB pKey) {
+		if (null == pKey)
+			return null;
+		if (null == m_oData)
+			return null;
+		return m_oData.get(pKey);
+	} // __________________________________
 
-    sAux = p_oDto.getAttr(HIDDEN.stamp.toString());
-    if (null != sAux)  p_obj.m_lStamp  = Long.parseLong(sAux);
+	private long m_lStamp = -1;
 
-    sAux = p_oDto.getAttr(HIDDEN.snap.toString());
-    if (null != sAux)  p_obj.m_lLastSnap = Long.parseLong(sAux);
+	private long m_lUid = -1;
 
-    sAux = p_oDto.getAttr(HIDDEN.batch.toString());
-    p_obj.setBatchNum((null != sAux)? Long.parseLong(sAux) : 0);
+	private long m_lLastSnap = 0;
 
-    // Special treatment for package - only needed for root BaseBusinessObj
-    // this is so only to make XML more compact
-    p_obj.m_sPkg = p_oDto.getAttr(BobjStdDTO.BOBJ_PACKAGE);
-  } //________________________________
+	private long m_lBatch = 0;
 
-  public static final BaseBusinessObject getFromDTO(BobjStdDTO p_oDto)
-    throws Exception
-  {	return new BaseBusinessObject().fromDTO(p_oDto);
-  } //________________________________
+	private String m_sDtSnap = null;
 
-  private BaseBusinessObject fromDTO(BobjStdDTO p_oDto)
-    throws Exception
-  { if (null == p_oDto)   return null;
+	private String m_sPkg = null;
 
-    Class oClass  = Class.forName(p_oDto.fullClassName());
-    Constructor CC=oClass.getConstructor (new Class[]{BobjStdDTO.class});
-    BaseBusinessObject oRet = (BaseBusinessObject)CC.newInstance(new Object []{p_oDto});
+	public boolean hasUid() {
+		return m_lUid > 0;
+	}
 
-    commonFieldsFromDTO(oRet,p_oDto);
-    return oRet;
-  } //________________________________
+	public void setElemNm(String p_s) {
+		setField(ATTRIB.elem, p_s);
+	}
 
-  protected BobjStdDTO getBaseDTO()
-  { String sClass = getClass().getSimpleName();
-    BobjStdDTO oRet = new BobjStdDTO(sClass,getElemNm(),null);
-    if (hasUid())
-      try { oRet.addAttr(HIDDEN.uid.toString(),Long.toString(m_lUid)); }
-      catch (Exception e) {}
-    putStdAtts(oRet);
-    return oRet;
-  } //________________________________
+	public void setRole(String p_s) {
+		setField(ATTRIB.rol, p_s);
+	}
 
-  protected void putStdAtts(BobjStdDTO p_oRet)
-  { try
-    { p_oRet.addAttr(ATTRIB.rol.toString(),getRole());
-//      if (this instanceof XtfStorable)
-//        p_oRet.addAttr(HIDDEN.type.toString(),((XtfStorable)this).getSnapType());
-      if (m_lStamp    > 0) p_oRet.addAttr(HIDDEN.stamp.toString()
-    		  ,Long.toString(m_lStamp));
-      if (m_lLastSnap > 0) p_oRet.addAttr(HIDDEN.snap.toString()
-    		  ,Long.toString(m_lLastSnap));
-      if (! EsbUtil.isNullString(m_sDtSnap))
-    	  p_oRet.addAttr(HIDDEN.dtSnap.toString(),m_sDtSnap);
-      if (getBatchNum()  > 0)
-    	  p_oRet.addAttr(HIDDEN.batch.toString() ,Long.toString(getBatchNum()));
-      if (! EsbUtil.isNullString(m_sPkg))
-    	  p_oRet.addAttr(BobjStdDTO.BOBJ_PACKAGE,m_sPkg);
-    }
-    catch (Exception e1) { }
-  } //________________________________
+	public void setStamp(long p_l) {
+		m_lStamp = p_l;
+	}
 
-  public static final BobjStdDTO getDtoList (Class p_Class
-		  , List<? extends BaseBusinessObject> p_oList)
-  throws Exception
-  { if (null == p_oList)          return null;
-    List<BobjStdDTO> LL = new ArrayList<BobjStdDTO>();
-    for (BaseBusinessObject oCurr : p_oList)
-      LL.add( oCurr.toDTO());
-    String sElem = p_Class.getSimpleName();
-    return (LL.size()<1) ? null : new BobjStdDTO(sElem,null,LL);
-  } //__________________________________
+	public void setUid(long p_l) {
+		m_lUid = p_l;
+	}
 
-  public static BaseBusinessObject getRoleFromList(String p_sRole
-		  , List<? extends BaseBusinessObject> p_oL)
-  { if  (null == p_sRole)   return null;
-    if  (null == p_oL)      return null;
-    for (BaseBusinessObject oCurr : p_oL)
-    	if (p_sRole.equals(oCurr.getRole()))
-    	    	  return oCurr;
-    return null;
-  } //__________________________________
+	public void setSnap(long p_l) {
+		m_lLastSnap = p_l;
+	}
 
-  public static BaseBusinessObject getElemFromList
-  	(String p_sElemNm, List<? extends BaseBusinessObject> p_oL)
-  { if  (null == p_sElemNm) return null;
-    if  (null == p_oL)      return null;
-    for (BaseBusinessObject oCurr  : p_oL)
-    	if (p_sElemNm.equals(oCurr.getElemNm()))
-        		return oCurr;
-    return null;
-  } //__________________________________
+	public void setBatchNum(long p_l) {
+		m_lBatch = p_l;
+	}
 
-  public static BaseBusinessObject rmvElemFromList(String p_sElemNm, List<BaseBusinessObject> p_oL)
-  { if  (null == p_sElemNm) return null;
-    if  (null == p_oL)      return null;
-    for (ListIterator<BaseBusinessObject> II=p_oL.listIterator(); II.hasNext();)
-    { BaseBusinessObject oCurr = II.next();
-      if (p_sElemNm.equals(oCurr.getElemNm()))
-      {	II.remove();
-      	return oCurr;
-      }
-    }
-    return null;
-  } //__________________________________
+	public void setSnapDate(String p_s) {
+		m_sDtSnap = p_s;
+	}
 
-  public static boolean anyFieldNull(String [] p_sa)
-  { if (null == p_sa)     return false;
-    for (int i1=0; i1<p_sa.length;i1++)
-      if (null == p_sa[i1])   return true;
-    return false;
-  } //__________________________________
+	public void setPackage() {
+		m_sPkg = this.getClass().getPackage().getName();
+	}
 
-  public static boolean allFieldsNull(String [] p_sa)
-  { if (null == p_sa)     return false;
-    if (p_sa.length<1)    return false;
-    for (int i1=0; i1<p_sa.length;i1++)
-    { String sCurr = p_sa[i1];
-      if (null == sCurr)    continue;
-      if (sCurr.trim().length()>0) return false;
-    }
-    return true;
-  } //__________________________________
+	public String getElemNm() {
+		return getField(ATTRIB.elem);
+	}
 
-} //____________________________________________________________________________
+	public String getRole() {
+		return getField(ATTRIB.rol);
+	}
+
+	public long getStamp() {
+		return m_lStamp;
+	}
+
+	public long getUid() {
+		return m_lUid;
+	}
+
+	public long getSnap() {
+		return m_lLastSnap;
+	}
+
+	public long getBatchNum() {
+		return m_lBatch;
+	}
+
+	public String getSnapDate() {
+		return m_sDtSnap;
+	}
+
+	public BaseBusinessObject() {
+		this((String) null);
+	}
+
+	protected BaseBusinessObject(String p_sElem) {
+		this(p_sElem, -1);
+	}
+
+	protected BaseBusinessObject(String p_sElem, long p_lUid) {
+		setField(ATTRIB.elem, p_sElem);
+		m_lUid = p_lUid;
+		if (null != getElemNm())
+			return;
+		String sClass = getClass().getSimpleName();
+		if (null == p_sElem)
+			setField(ATTRIB.elem, sClass);
+	} // ________________________________
+
+	protected BaseBusinessObject(BobjStdDTO p_oDto) throws Exception {
+		this(p_oDto.elementNm());
+		if (p_oDto.isList())
+			return;
+		commonFieldsFromDTO(this, p_oDto);
+	} // ________________________________
+
+	private static final void commonFieldsFromDTO(BaseBusinessObject p_obj,
+			BobjStdDTO p_oDto) throws Exception {
+		for (ATTRIB oCurr : ATTRIB.values())
+			p_obj.setField(oCurr, p_oDto.getAttr(oCurr.toString()));
+
+		String sAux = p_oDto.getAttr(HIDDEN.uid.toString());
+		if (null != sAux)
+			p_obj.m_lUid = Long.parseLong(sAux);
+
+		sAux = p_oDto.getAttr(HIDDEN.stamp.toString());
+		if (null != sAux)
+			p_obj.m_lStamp = Long.parseLong(sAux);
+
+		sAux = p_oDto.getAttr(HIDDEN.snap.toString());
+		if (null != sAux)
+			p_obj.m_lLastSnap = Long.parseLong(sAux);
+
+		sAux = p_oDto.getAttr(HIDDEN.batch.toString());
+		p_obj.setBatchNum((null != sAux) ? Long.parseLong(sAux) : 0);
+
+		// Special treatment for package - only needed for root BaseBusinessObj
+		// this is so only to make XML more compact
+		p_obj.m_sPkg = p_oDto.getAttr(BobjStdDTO.BOBJ_PACKAGE);
+	} // ________________________________
+
+	public static final BaseBusinessObject getFromDTO(BobjStdDTO p_oDto)
+			throws Exception {
+		return new BaseBusinessObject().fromDTO(p_oDto);
+	} // ________________________________
+
+	private BaseBusinessObject fromDTO(BobjStdDTO p_oDto) throws Exception {
+		if (null == p_oDto)
+			return null;
+
+		Class oClass = Class.forName(p_oDto.fullClassName());
+		Constructor CC = oClass
+				.getConstructor(new Class[] { BobjStdDTO.class });
+		BaseBusinessObject oRet = (BaseBusinessObject) CC
+				.newInstance(new Object[] { p_oDto });
+
+		commonFieldsFromDTO(oRet, p_oDto);
+		return oRet;
+	} // ________________________________
+
+	protected BobjStdDTO getBaseDTO() {
+		String sClass = getClass().getSimpleName();
+		BobjStdDTO oRet = new BobjStdDTO(sClass, getElemNm(), null);
+		if (hasUid())
+			try {
+				oRet.addAttr(HIDDEN.uid.toString(), Long.toString(m_lUid));
+			} catch (Exception e) {
+			}
+		putStdAtts(oRet);
+		return oRet;
+	} // ________________________________
+
+	protected void putStdAtts(BobjStdDTO p_oRet) {
+		try {
+			p_oRet.addAttr(ATTRIB.rol.toString(), getRole());
+			// if (this instanceof XtfStorable)
+			// p_oRet.addAttr(HIDDEN.type.toString(),((XtfStorable)this).getSnapType());
+			if (m_lStamp > 0)
+				p_oRet
+						.addAttr(HIDDEN.stamp.toString(), Long
+								.toString(m_lStamp));
+			if (m_lLastSnap > 0)
+				p_oRet.addAttr(HIDDEN.snap.toString(), Long
+						.toString(m_lLastSnap));
+			if (!EsbUtil.isNullString(m_sDtSnap))
+				p_oRet.addAttr(HIDDEN.dtSnap.toString(), m_sDtSnap);
+			if (getBatchNum() > 0)
+				p_oRet.addAttr(HIDDEN.batch.toString(), Long
+						.toString(getBatchNum()));
+			if (!EsbUtil.isNullString(m_sPkg))
+				p_oRet.addAttr(BobjStdDTO.BOBJ_PACKAGE, m_sPkg);
+		} catch (Exception e1) {
+		}
+	} // ________________________________
+
+	public static final BobjStdDTO getDtoList(Class p_Class,
+			List<? extends BaseBusinessObject> p_oList) throws Exception {
+		if (null == p_oList)
+			return null;
+		List<BobjStdDTO> LL = new ArrayList<BobjStdDTO>();
+		for (BaseBusinessObject oCurr : p_oList)
+			LL.add(oCurr.toDTO());
+		String sElem = p_Class.getSimpleName();
+		return (LL.size() < 1) ? null : new BobjStdDTO(sElem, null, LL);
+	} // __________________________________
+
+	public static BaseBusinessObject getRoleFromList(String p_sRole,
+			List<? extends BaseBusinessObject> p_oL) {
+		if (null == p_sRole)
+			return null;
+		if (null == p_oL)
+			return null;
+		for (BaseBusinessObject oCurr : p_oL)
+			if (p_sRole.equals(oCurr.getRole()))
+				return oCurr;
+		return null;
+	} // __________________________________
+
+	public static BaseBusinessObject getElemFromList(String p_sElemNm,
+			List<? extends BaseBusinessObject> p_oL) {
+		if (null == p_sElemNm)
+			return null;
+		if (null == p_oL)
+			return null;
+		for (BaseBusinessObject oCurr : p_oL)
+			if (p_sElemNm.equals(oCurr.getElemNm()))
+				return oCurr;
+		return null;
+	} // __________________________________
+
+	public static BaseBusinessObject rmvElemFromList(String p_sElemNm,
+			List<BaseBusinessObject> p_oL) {
+		if (null == p_sElemNm)
+			return null;
+		if (null == p_oL)
+			return null;
+		for (ListIterator<BaseBusinessObject> II = p_oL.listIterator(); II
+				.hasNext();) {
+			BaseBusinessObject oCurr = II.next();
+			if (p_sElemNm.equals(oCurr.getElemNm())) {
+				II.remove();
+				return oCurr;
+			}
+		}
+		return null;
+	} // __________________________________
+
+	public static boolean anyFieldNull(String[] p_sa) {
+		if (null == p_sa)
+			return false;
+		for (int i1 = 0; i1 < p_sa.length; i1++)
+			if (null == p_sa[i1])
+				return true;
+		return false;
+	} // __________________________________
+
+	public static boolean allFieldsNull(String[] p_sa) {
+		if (null == p_sa)
+			return false;
+		if (p_sa.length < 1)
+			return false;
+		for (int i1 = 0; i1 < p_sa.length; i1++) {
+			String sCurr = p_sa[i1];
+			if (null == sCurr)
+				continue;
+			if (sCurr.trim().length() > 0)
+				return false;
+		}
+		return true;
+	} // __________________________________
+
+} // ____________________________________________________________________________

Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/util/EsbUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/util/EsbUtil.java	2006-07-27 17:18:21 UTC (rev 5316)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/util/EsbUtil.java	2006-07-27 17:23:34 UTC (rev 5317)
@@ -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.util;
 
@@ -27,93 +27,107 @@
 import javax.naming.*;
 import org.apache.log4j.*;
 
-public class EsbUtil
-{
-  private EsbUtil() {}
+public class EsbUtil {
+	private EsbUtil() {
+	}
 
-  public static void       dumpSysProps(PrintStream p_OS)
-  { String[] sa = new String[System.getProperties().size()];
-    System.getProperties().keySet().toArray(sa);
-    Arrays.sort(sa);
-    for (String sCurr : sa)
-      p_OS.println(sCurr+"<"+System.getProperty(sCurr)+">");
-  } //__________________________________
+	public static void dumpSysProps(PrintStream p_OS) {
+		String[] sa = new String[System.getProperties().size()];
+		System.getProperties().keySet().toArray(sa);
+		Arrays.sort(sa);
+		for (String sCurr : sa)
+			p_OS.println(sCurr + "=" + System.getProperty(sCurr));
+	} // __________________________________
 
-  public static boolean    isNullString(String p_s)
-  { return (null==p_s) ? true : p_s.trim().length()<1;
-  } //__________________________________
+	public static boolean isNullString(String p_s) {
+		return (null == p_s) ? true : p_s.trim().length() < 1;
+	} // __________________________________
 
-  public static boolean    isLong(String p_s)
-  { if (isNullString(p_s))    return false;
-    try
-    { Long.parseLong(p_s);
-      return true;
-    }
-    catch (Exception e) { return false; }
-  } //__________________________________
+	public static boolean isLong(String p_s) {
+		if (isNullString(p_s))
+			return false;
+		try {
+			Long.parseLong(p_s);
+			return true;
+		} catch (Exception e) {
+			return false;
+		}
+	} // __________________________________
 
-  public static boolean    isPositiveLong(String p_s)
-  { if (isNullString(p_s))    return false;
-    try
-    { long lBk  = Long.parseLong(p_s);
-      return lBk > 0;
-    }
-    catch (Exception e) { return false; }
-  } //__________________________________
+	public static boolean isPositiveLong(String p_s) {
+		if (isNullString(p_s))
+			return false;
+		try {
+			long lBk = Long.parseLong(p_s);
+			return lBk > 0;
+		} catch (Exception e) {
+			return false;
+		}
+	} // __________________________________
 
-  public static int parseInt(String s)
-  {
-    if ( s == null)		return 0;
-    String sVal = s.trim();
-    if (sVal.length() < 1)
-    		return 0;
-    else
-	    try { return Integer.parseInt(s); }
-	    catch (NumberFormatException ex) { return 0; }
-  } //__________________________________
+	public static int parseInt(String s) {
+		if (s == null)
+			return 0;
+		String sVal = s.trim();
+		if (sVal.length() < 1)
+			return 0;
+		else
+			try {
+				return Integer.parseInt(s);
+			} catch (NumberFormatException ex) {
+				return 0;
+			}
+	} // __________________________________
 
-  public static long parseLong(String s)
-  {
-    if ( s == null)		return 0;
-    String sVal = s.trim();
-    if (sVal.length() < 1)
-    		return 0;
-    else
-	    try { return Long.parseLong(s); }
-	    catch (NumberFormatException ex) { return 0; }
-  } //__________________________________
+	public static long parseLong(String s) {
+		if (s == null)
+			return 0;
+		String sVal = s.trim();
+		if (sVal.length() < 1)
+			return 0;
+		else
+			try {
+				return Long.parseLong(s);
+			} catch (NumberFormatException ex) {
+				return 0;
+			}
+	} // __________________________________
 
+	public static Context getJndiContext() {
+		return jndiContextFromSysProp(null);
+	} // __________________________________
 
-  public static Context getJndiContext()
-  { return jndiContextFromSysProp(null);
-  } //__________________________________
+	public static Context jndiContextFromSysProp(String p_sSysProp) {
+		String sProp = (null == p_sSysProp) ? "appServer" : p_sSysProp;
+		return getJbossJndiContext(System.getProperty(sProp));
+	} // __________________________________
 
-  public static Context jndiContextFromSysProp(String p_sSysProp)
-  { String sProp = (null==p_sSysProp) ? "appServer" : p_sSysProp;
-    return getJbossJndiContext(System.getProperty(sProp));
-  } //__________________________________
+	public static Context getJbossJndiContext(String p_sServer) {
+		if (null == p_sServer)
+			return null;
+		Properties oPr = new Properties();
+		oPr.setProperty(Context.PROVIDER_URL, p_sServer);
+		oPr.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+				"org.jnp.interfaces.NamingContextFactory");
+		oPr.setProperty(Context.URL_PKG_PREFIXES,
+				"jboss.naming:org.jnp.interfaces");
+		try {
+			return new InitialContext(oPr);
+		} catch (Exception e) {
+			e.printStackTrace();
+			return null;
+		}
+	} // __________________________________
 
-  public static Context getJbossJndiContext(String p_sServer)
-  { if (null==p_sServer)    return null;
-    Properties oPr = new Properties();
-    oPr.setProperty(Context.PROVIDER_URL,p_sServer);
-    oPr.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
-    oPr.setProperty(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
-    try { return new InitialContext(oPr); }
-    catch (Exception e) { e.printStackTrace(); return null; }
-  } //__________________________________
+	public static String classSuffix(Class pCls) {
+		return pCls.getSimpleName();
+	} // __________________________________
 
-  public static String classSuffix(Class pCls)
-  {	return pCls.getSimpleName();
-  } //__________________________________
-  
-  public static Logger getDefaultLogger(Class p_oCls)
-  {	Logger oRet = Logger.getLogger(p_oCls.getName());
-  	Appender oApp = new ConsoleAppender(new TTCCLayout("ISO8601"));
-  	oRet.addAppender(oApp);
-  	return oRet;
-} //__________________________________
+	public static Logger getDefaultLogger(Class p_oCls) {
+		Logger oRet = Logger.getLogger(p_oCls.getName());
+		Appender oApp = new ConsoleAppender(new TTCCLayout("ISO8601"));
+		oRet.addAppender(oApp);
+		return oRet;
+	} // __________________________________
 
-  
-
-} //____________________________________________________________________________
+} // ____________________________________________________________________________

Added: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/AppServerContextUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/AppServerContextUnitTest.java	2006-07-27 17:18:21 UTC (rev 5316)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/AppServerContextUnitTest.java	2006-07-27 17:23:34 UTC (rev 5317)
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+
+/**
+ * AppServerContex unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class AppServerContextUnitTest extends TestCase {
+
+	public void test_AppServerContext() throws NamingException {
+		Context ctx = AppServerContext.getServerContext("jboss", "http://localhost:1234");
+		
+		Hashtable props = ctx.getEnvironment();
+		System.out.println(props);
+		assertEquals("org.jnp.interfaces.NamingContextFactory", props.get(Context.INITIAL_CONTEXT_FACTORY));
+		assertEquals("http://localhost:1234", props.get(Context.PROVIDER_URL));
+		assertEquals("jboss.naming:org.jnp.interfaces", props.get("java.naming.factory.url.pkgs"));
+	}
+}

Added: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/EsbUtilUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/EsbUtilUnitTest.java	2006-07-27 17:18:21 UTC (rev 5316)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/util/EsbUtilUnitTest.java	2006-07-27 17:23:34 UTC (rev 5317)
@@ -0,0 +1,119 @@
+/*
+ * 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 java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+/**
+ * EsbUtil unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class EsbUtilUnitTest extends TestCase {
+
+	public void testDumpSysProps() throws IOException {
+		ByteArrayOutputStream buf = new ByteArrayOutputStream();
+		
+		EsbUtil.dumpSysProps(new PrintStream(buf));
+		
+		Properties props = new Properties();
+		props.load(new ByteArrayInputStream(buf.toByteArray()));
+		
+		// Just make sure that something was dumped to the printstream...
+		assertTrue(props.containsKey("file.separator"));
+	}
+
+	public void testIsNullString() {
+		assertTrue(EsbUtil.isNullString(null));
+		assertTrue(EsbUtil.isNullString(""));
+		assertTrue(EsbUtil.isNullString(" "));
+		assertTrue(!EsbUtil.isNullString("a"));
+	}
+
+	public void testIsLong() {
+		assertTrue(!EsbUtil.isLong(null));
+		assertTrue(!EsbUtil.isLong(""));
+		assertTrue(!EsbUtil.isLong(" "));
+		assertTrue(!EsbUtil.isLong("a"));
+		assertTrue(!EsbUtil.isLong(" 1"));
+		assertTrue(!EsbUtil.isLong("1 "));
+		assertTrue(!EsbUtil.isLong("1.1"));
+		assertTrue(EsbUtil.isLong("1"));
+		assertTrue(EsbUtil.isLong("-1"));
+	}
+
+	public void testIsPositiveLong() {
+		assertTrue(!EsbUtil.isPositiveLong(null));
+		assertTrue(!EsbUtil.isPositiveLong(""));
+		assertTrue(!EsbUtil.isPositiveLong(" "));
+		assertTrue(!EsbUtil.isPositiveLong("a"));
+		assertTrue(!EsbUtil.isPositiveLong(" 1"));
+		assertTrue(!EsbUtil.isPositiveLong("1 "));
+		assertTrue(!EsbUtil.isPositiveLong("1.1"));
+		assertTrue(EsbUtil.isPositiveLong("1"));
+		assertTrue(!EsbUtil.isPositiveLong("0"));
+		assertTrue(!EsbUtil.isPositiveLong("-1"));
+	}
+
+	public void testParseInt() {
+		assertEquals(0, EsbUtil.parseInt("a"));
+		assertEquals(0, EsbUtil.parseInt(""));
+		assertEquals(0, EsbUtil.parseInt(" "));
+		assertEquals(0, EsbUtil.parseInt(" 1"));
+		assertEquals(0, EsbUtil.parseInt("1 "));
+		assertEquals(0, EsbUtil.parseInt("0"));
+		assertEquals(1, EsbUtil.parseInt("1"));
+		assertEquals(-1, EsbUtil.parseInt("-1"));
+	}
+
+	public void testParseLong() {
+		assertEquals(0L, EsbUtil.parseLong("a"));
+		assertEquals(0L, EsbUtil.parseLong(""));
+		assertEquals(0L, EsbUtil.parseLong(" "));
+		assertEquals(0L, EsbUtil.parseLong(" 1"));
+		assertEquals(0L, EsbUtil.parseLong("1 "));
+		assertEquals(0L, EsbUtil.parseLong("0"));
+		assertEquals(1L, EsbUtil.parseLong("1"));
+		assertEquals(-1L, EsbUtil.parseLong("-1"));
+	}
+
+	public void testGetJndiContext() {
+	}
+
+	public void testJndiContextFromSysProp() {
+	}
+
+	public void testGetJbossJndiContext() {
+	}
+
+	public void testClassSuffix() {
+	}
+
+	public void testGetDefaultLogger() {
+	}
+
+}




More information about the jboss-svn-commits mailing list