You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sm...@apache.org on 2011/07/03 17:51:46 UTC

svn commit: r1142453 [6/12] - in /incubator/airavata/ws-messaging/trunk/messagebroker: ./ .settings/ customLibs/ customLibs/activeMQ/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/airavata/ src/main...

Added: incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/storage/WsmgPersistantStorage.java
URL: http://svn.apache.org/viewvc/incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/storage/WsmgPersistantStorage.java?rev=1142453&view=auto
==============================================================================
--- incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/storage/WsmgPersistantStorage.java (added)
+++ incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/storage/WsmgPersistantStorage.java Sun Jul  3 15:51:36 2011
@@ -0,0 +1,728 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.wsmg.commons.storage;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.sql.BatchUpdateException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.airavata.wsmg.broker.subscription.SubscriptionEntry;
+import org.apache.airavata.wsmg.broker.subscription.SubscriptionState;
+import org.apache.airavata.wsmg.commons.CommonRoutines;
+import org.apache.airavata.wsmg.commons.WsmgCommonConstants;
+import org.apache.airavata.wsmg.config.ConfigurationManager;
+import org.apache.airavata.wsmg.config.WSMGParameter;
+import org.apache.airavata.wsmg.util.Counter;
+import org.apache.airavata.wsmg.util.TimerThread;
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
+import org.apache.log4j.Logger;
+
+public class WsmgPersistantStorage implements WsmgStorage {
+    org.apache.log4j.Logger logger = Logger.getLogger(WsmgPersistantStorage.class);
+
+    JdbcStorage db = null;
+
+    Connection conn = null;
+
+    private Counter storeToDBCounter = new Counter();
+
+    /*
+     * this thing is never used in this context
+     */
+    // private final static XmlInfosetBuilder builder = XmlConstants.BUILDER;
+    String dbName = null;
+
+    // private ConnectionPool connectionPool;
+    public WsmgPersistantStorage(String ordinarySubsTblName, String specialSubsTblName, ConfigurationManager config)
+            throws AxisFault {
+        /*
+         * try { conn = db.connect(); } catch (SQLException ex) { ex.printStackTrace(); }
+         */
+        this.dbName = ordinarySubsTblName;
+
+        db = new JdbcStorage(config.getConfig(WsmgCommonConstants.CONFIG_JDBC_URL),
+                config.getConfig(WsmgCommonConstants.CONFIG_JDBC_DRIVER));
+
+        // Lets connect to the database and create tables if they are not
+        // already there.
+
+        initDatabaseTables(db);
+
+        // inject dbname to sql statement.
+
+        SubscriptionConstants.ORDINARY_SUBSCRIPTION_INSERT_QUERY = String.format(
+                SubscriptionConstants.INSERT_SQL_QUERY, ordinarySubsTblName);
+
+        SubscriptionConstants.SPECIAL_SUBSCRIPTION_INSERT_QUERY = String.format(SubscriptionConstants.INSERT_SQL_QUERY,
+                specialSubsTblName);
+
+        if (WSMGParameter.measureMessageRate) {
+            TimerThread timerThread = new TimerThread(storeToDBCounter, " StoreSubScriptionToDBCounter");
+            new Thread(timerThread).start();
+        }
+
+        try {
+            initMessageQueueStorage();
+
+        } catch (SQLException sqlEx) {
+            throw AxisFault.makeFault(sqlEx);
+        }
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.airavata.wsmg.commons.storage.SubscriptionStorage#getAllSubscription()
+     */
+    public List<SubscriptionEntry> getAllSubscription() {
+
+        ArrayList<SubscriptionEntry> ret = new ArrayList<SubscriptionEntry>();
+
+        int totalRecord = 0;
+        String query = "SELECT * FROM " + dbName;
+        ResultSet rs = null;
+        try {
+            rs = db.query(query);
+            if (rs != null) {
+                // Get total number of rows
+
+                // Point to the last row in resultset.
+                rs.last();
+                // Get the row position which is also the number of rows in the
+                // ResultSet.
+                totalRecord = rs.getRow();
+                logger.debug("TotalRecord=" + totalRecord);
+                // Create String array to return
+
+                ret.ensureCapacity(totalRecord);
+
+                // Reposition at the beginning of the ResultSet to take up
+                // rs.next() call.
+                rs.beforeFirst();
+
+                while (rs.next()) {
+                    SubscriptionEntry subscriptionEntry = new SubscriptionEntry();
+                    subscriptionEntry.setSubscriptionId(rs.getString("SubscriptionId"));
+                    subscriptionEntry.setSubscribeXml(rs.getString("xml"));
+
+                    /*
+                     * int policyValue = rs.getInt("wsrm"); subscriptionEntry[i] .setWsrmPolicy(policyValue ==
+                     * WsmgCommonConstants.WSRM_POLICY_TRUE);
+                     */
+
+                    ret.add(subscriptionEntry);
+
+                }
+                rs.close();
+            }
+        } catch (SQLException ex) {
+            logger.fatal("sql exception occured", ex);
+            ret = new ArrayList<SubscriptionEntry>();
+        }
+        return ret;
+    }
+
+    public int insert(SubscriptionState subscription) {
+
+        PreparedStatement stmt = null;
+        String address = subscription.getConsumerReference().getAddress();
+        Map<QName, OMElement> referenceParametersMap = subscription.getConsumerReference().getAllReferenceParameters();
+
+        String consumerReferenceParameters = null;
+        if (referenceParametersMap == null) {
+            consumerReferenceParameters = "";
+        } else {
+
+            StringBuffer buffer = new StringBuffer();
+
+            for (Iterator<OMElement> ite = referenceParametersMap.values().iterator(); ite.hasNext();) {
+                OMElement currentReferenceParameter = ite.next();
+
+                try {
+                    buffer.append(currentReferenceParameter.toStringWithConsume());
+                } catch (XMLStreamException se) {
+                    logger.error("unable to convert reference parameter", se);
+                }
+
+            }
+
+            consumerReferenceParameters = buffer.toString();
+
+        }
+        int policyValue = WsmgCommonConstants.WSRM_POLICY_FALSE;
+        if (subscription.isWsrmPolicy()) {
+            policyValue = WsmgCommonConstants.WSRM_POLICY_TRUE;
+        }
+
+        java.util.Date today = new java.util.Date();
+        java.sql.Timestamp now = new java.sql.Timestamp(today.getTime());
+
+        String sql = subscription.isNeverExpire() ? SubscriptionConstants.SPECIAL_SUBSCRIPTION_INSERT_QUERY
+                : SubscriptionConstants.ORDINARY_SUBSCRIPTION_INSERT_QUERY;
+
+        int result = 0;
+
+        Connection connection = null;
+        try {
+
+            connection = db.connect();
+            stmt = connection.prepareStatement(sql);
+
+            stmt.setString(1, subscription.getId());
+            stmt.setString(2, subscription.getSubscribeXml());
+            stmt.setInt(3, policyValue);
+            stmt.setString(4, subscription.getLocalTopic());
+            stmt.setString(5, subscription.getXpathString());
+            stmt.setString(6, address);
+            stmt.setString(7, consumerReferenceParameters);
+            stmt.setTimestamp(8, now);
+            result = db.executeUpdate(stmt);
+            storeToDBCounter.addCounter();
+        } catch (SQLException ex) {
+            logger.fatal("sql exception occured", ex);
+        } finally {
+
+            if (connection != null) {
+                try {
+                    db.closeConnection(connection);
+                } catch (SQLException e) {
+
+                    e.printStackTrace();
+                }
+            }
+
+        }
+
+        return result;
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.airavata.wsmg.commons.storage.SubscriptionStorage#delete(java.lang.String)
+     */
+    public int delete(String subscriptionId) {
+        String query;
+        query = "DELETE FROM " + dbName + " WHERE SubscriptionId='" + subscriptionId + "'";
+        try {
+            db.update(query);
+        } catch (SQLException ex) {
+            logger.fatal("sql exception occured", ex);
+            // TODO : throw this exception
+        }
+        return 0;
+    }
+
+    /**
+     * If data base tables are defined as SQL queries in file placed at xregistry/tables.sql in the classpath, those SQL
+     * queries are execuated against the data base. On the file, any line start # is igonred as a comment.
+     * 
+     * @throws XregistryException
+     */
+    private void initDatabaseTables(JdbcStorage jdbcStorage) throws AxisFault {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        InputStream sqltablesAsStream = cl.getResourceAsStream("broker-tables.sql");
+
+        if (sqltablesAsStream == null) {
+            return;
+        }
+
+        Connection connection = jdbcStorage.connect();
+        try {
+            Statement statement = connection.createStatement();
+
+            String docAsStr = CommonRoutines.readFromStream(sqltablesAsStream);
+            StringTokenizer t = new StringTokenizer(docAsStr, ";");
+
+            while (t.hasMoreTokens()) {
+                String line = t.nextToken();
+                if (line.trim().length() > 0 && !line.startsWith("#")) {
+                    System.out.println(line.trim());
+                    statement.executeUpdate(line.trim());
+                }
+            }
+        } catch (SQLException e) {
+            throw AxisFault.makeFault(e);
+        } catch (IOException e) {
+            throw AxisFault.makeFault(e);
+        } finally {
+            try {
+                jdbcStorage.closeConnection(connection);
+            } catch (SQLException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
+
+    }
+
+    // QUEUE related
+
+    public Object blockingDequeue() {
+
+        boolean gotValue = false;
+
+        while (!gotValue) {
+            try {
+                KeyValueWrapper wrapper = retrive();
+
+                done(wrapper.getKey());
+                return wrapper.getValue();
+            } catch (SQLException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            } catch (IOException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
+        return null;
+
+    }
+
+    public void cleanup() {
+
+        try {
+            cleanDB();
+            initMessageQueueStorage();
+        } catch (SQLException e) {
+            logger.error(e);
+        }
+
+    }
+
+    public void enqueue(Object object, String trackId) {
+
+        // Get the Max ID cache and update and unlock the table
+        Connection connection = null;
+        try {
+            connection = db.connect();
+
+            PreparedStatement stmt;
+            stmt = connection.prepareStatement("lock tables " + QueueContants.TABLE_NAME_MAXID + " write");
+            stmt.executeQuery();
+            stmt.close();
+            // System.out.println("locked maxId table");
+
+            stmt = connection.prepareStatement(QueueContants.SQL_MAX_ID_SEPERATE_TABLE);
+            ResultSet result = stmt.executeQuery();
+
+            int nextkey;
+
+            if (result.next()) {
+                nextkey = result.getInt(1);
+                result.close();
+                stmt.close();
+                stmt = connection.prepareStatement(QueueContants.SQL_MAX_ID_INCREMENT + (nextkey));
+                stmt.executeUpdate();
+                stmt.close();
+            } else {
+                nextkey = 1;
+                result.close();
+                stmt.close();
+                stmt = connection.prepareStatement(QueueContants.SQL_MAX_ID_INSERT);
+                stmt.executeUpdate();
+                stmt.close();
+            }
+            stmt = connection.prepareStatement("unlock tables");
+            stmt.executeQuery();
+            stmt.close();
+
+            stmt = connection.prepareStatement(QueueContants.SQL_INSERT_STATEMENT);
+
+            stmt.setInt(1, nextkey);
+            stmt.setString(2, trackId);
+            byte[] buffer;
+            ByteArrayOutputStream output = new ByteArrayOutputStream();
+            ObjectOutputStream out = new ObjectOutputStream(output);
+            out.writeObject(object);
+            buffer = output.toByteArray();
+            ByteArrayInputStream in = new ByteArrayInputStream(buffer);
+            stmt.setBinaryStream(3, in, buffer.length);
+            db.executeUpdate(stmt);
+        } catch (SQLException sqlEx) {
+            logger.error("unable to enque the message in persistant storage", sqlEx);
+        } catch (IOException ioEx) {
+            logger.error("unable to enque the message in persistant storage", ioEx);
+
+        } finally {
+
+            if (connection != null) {
+                try {
+                    db.closeConnection(connection);
+                } catch (SQLException e) {
+                    e.printStackTrace();
+                }
+            }
+
+        }
+    }
+
+    public void flush() {
+        // nothing to do.
+    }
+
+    public int size() {
+        throw new UnsupportedOperationException();
+    }
+
+    private void initMessageQueueStorage() throws SQLException {
+        Connection connection = db.connect();
+
+        PreparedStatement stmt;
+        stmt = connection.prepareStatement("lock tables " + QueueContants.TABLE_NAME_MAXID + " write" + ","
+                + QueueContants.TABLE_NAME_MINID + " write");
+        stmt.executeQuery();
+        stmt.close();
+        // System.out.println("locked tables (maxId and minId)4");
+        stmt = connection.prepareStatement(QueueContants.SQL_MAX_ID_SEPERATE_TABLE);
+        ResultSet result = stmt.executeQuery();
+        if (!result.next()) {
+            result.close();
+            stmt.close();
+            stmt = connection.prepareStatement(QueueContants.SQL_MAX_ID_INSERT);
+            stmt.executeUpdate();
+            stmt.close();
+        }
+
+        stmt = connection.prepareStatement(QueueContants.SQL_MIN_ID_SEPERATE_TABLE);
+        result = stmt.executeQuery();
+
+        if (!result.next()) {
+            result.close();
+            stmt.close();
+            stmt = connection.prepareStatement(QueueContants.SQL_MIN_ID_INSERT);
+            stmt.executeUpdate();
+            stmt.close();
+        }
+
+        stmt = connection.prepareStatement("unlock tables");
+        stmt.executeQuery();
+        stmt.close();
+        db.closeConnection(connection);
+        // System.out.println("unlocked tables (maxId and minId)4");
+    }
+
+    public KeyValueWrapper retrive() throws SQLException, IOException {
+        Object obj = null;
+
+        // Get the smallest id
+        Connection connection = db.connect();
+        boolean loop = true;
+
+        int nextkey = -1;
+        int maxid = -2;
+        PreparedStatement stmt = null;
+        ResultSet result = null;
+        boolean connectionClosed = false;
+        long wait = 1000;
+        while (loop) {
+            // System.out.println("Checking Queue DB");
+            stmt = connection.prepareStatement("lock tables " + QueueContants.TABLE_NAME_MAXID + " write" + ","
+                    + QueueContants.TABLE_NAME_MINID + " write");
+            stmt.executeQuery();
+            stmt.close();
+            // System.out.println("locked maxId and minId table");
+            // System.out.println("looping in retrive");
+
+            stmt = connection.prepareStatement(QueueContants.SQL_MIN_ID_SEPERATE_TABLE);
+            result = stmt.executeQuery();
+
+            if (result.next()) {
+                nextkey = result.getInt(1);
+                result.close();
+                stmt.close();
+
+            } else {
+                throw new RuntimeException("Queue init has failed earlier");
+            }
+
+            stmt = connection.prepareStatement(QueueContants.SQL_MAX_ID_SEPERATE_TABLE);
+            result = stmt.executeQuery();
+
+            if (result.next()) {
+                maxid = result.getInt(1);
+                result.close();
+                stmt.close();
+
+            } else {
+                throw new RuntimeException("Queue init has failed earlier");
+            }
+
+            // stmt = connection.prepareStatement(SQL_MAX_ID_SEPERATE_TABLE);
+            // result = stmt.executeQuery();
+            //
+            // if (result.next()) {
+            // nextkey = result.getInt(1);
+            // result.close();
+            // stmt.close();
+            //
+            // } else {
+            // throw new RuntimeException("Queue init has failed earlier");
+            // }
+
+            stmt = connection.prepareStatement("unlock tables");
+            stmt.executeQuery();
+            stmt.close();
+            // System.out.println("unlocked tables (maxId and minId)1");
+            if (maxid > nextkey) {
+                loop = false;
+                stmt = connection.prepareStatement(QueueContants.SQL_MIN_ID_INCREMENT + (nextkey));
+                stmt.executeUpdate();
+                stmt.close();
+                stmt = connection.prepareStatement("unlock tables");
+                stmt.executeQuery();
+                stmt.close();
+                // System.out.println("unlocked tables (maxId and minId) 2");
+
+            } else {
+                try {
+                    stmt = connection.prepareStatement("unlock tables");
+                    // System.out.println("unlocked tables (maxId and minId) 3");
+                    stmt.executeQuery();
+                    stmt.close();
+                    db.closeConnection(connection);
+                    connectionClosed = true;
+                    wait = Math.min((wait + 1000), QueueContants.FINAL_WAIT_IN_MILI);
+                    // System.out.println("Wait="+wait);
+                    Thread.sleep(wait);
+                } catch (InterruptedException e) {
+
+                }
+            }
+            if (connectionClosed) {
+                connection = db.connect();
+                connectionClosed = false;
+            }
+        }
+
+        stmt = connection.prepareStatement(QueueContants.SQL_SELECT_STATEMENT + nextkey);
+        result = stmt.executeQuery();
+        // FIXME: THis loop caused out-of-memory
+        while (!result.next()) {
+            // FIXME Remove this while loop and change the
+            // order of db update if possible in the save.
+            result.close();
+            stmt.close();
+            // System.out.println("Looping in 1");
+            try {
+                Thread.sleep(2000);
+            } catch (InterruptedException e) {
+
+                logger.error("interruped while thread sleep", e);
+            }
+            stmt = connection.prepareStatement(QueueContants.SQL_SELECT_STATEMENT + nextkey);
+            result = stmt.executeQuery();
+
+        }
+        int id = result.getInt(1);
+        InputStream in = result.getAsciiStream(2);
+        ObjectInputStream s = new ObjectInputStream(in);
+        try {
+            obj = s.readObject();
+        } catch (ClassNotFoundException e) {
+
+            e.printStackTrace();
+        }
+        result.close();
+        stmt.close();
+
+        db.closeConnection(connection);
+
+        return new KeyValueWrapper(id, obj);
+
+    }
+
+    public void done(int key) throws SQLException {
+        String query = null;
+        PreparedStatement stmt = null;
+        Connection connection = db.connect();
+        try {
+            query = QueueContants.SQL_DELETE_STATEMENT + key;
+            // System.out.println("Deleting key="+key);
+            stmt = connection.prepareStatement(query);
+            db.executeUpdate(stmt);
+            stmt.close();
+        } finally {
+            db.closeConnection(connection);
+        }
+
+    }
+
+    public void cleanDB() throws SQLException {
+        Connection con = db.connect();
+        Statement stmt = con.createStatement();
+        int[] aiupdateCounts = new int[0];
+        boolean bError = false;
+        try {
+
+            con.setAutoCommit(false);
+            // ...
+            bError = false;
+            stmt.clearBatch();
+            int totalStatement = 0;
+            // add SQL statements
+            stmt.addBatch("lock tables disQ write, MaxIDTable write, MinIDTable write;");
+            // System.out.println("locked tables (maxId and minId) 5");
+            stmt.addBatch("Delete from disQ;");
+            stmt.addBatch("Delete from MaxIDTable;");
+            stmt.addBatch("Delete from MinIDTable;");
+            stmt.addBatch("unlock tables;");
+            // System.out.println("unlocked tables (maxId and minId) 5");
+            totalStatement = 5;
+
+            aiupdateCounts = new int[totalStatement];
+
+            // execute the statements
+            aiupdateCounts = stmt.executeBatch();
+
+        } // end try
+
+        // catch blocks
+        // ...
+        catch (BatchUpdateException bue) {
+            bError = true;
+            aiupdateCounts = bue.getUpdateCounts();
+            logger.error("SQLException: " + bue.getMessage());
+            logger.error("SQLState:  " + bue.getSQLState());
+            logger.error("Message:  " + bue.getMessage());
+            logger.error("Vendor:  " + bue.getErrorCode());
+            logger.info("Update counts:  ");
+            int[] updateCounts = bue.getUpdateCounts();
+
+            for (int i = 0; i < updateCounts.length; i++) {
+                logger.error(updateCounts[i] + "   ");
+            }
+
+            SQLException SQLe = bue;
+            while (SQLe != null) {
+                // do exception stuff
+
+                SQLe = SQLe.getNextException();
+                logger.error(SQLe);
+            }
+        } // end BatchUpdateException catch
+        catch (SQLException SQLe) {
+            // ...
+            logger.error(SQLe);
+        } // end SQLException catch
+        finally {
+            db.closeConnection(con);
+            // determine operation result
+            for (int i = 0; i < aiupdateCounts.length; i++) {
+                int iProcessed = aiupdateCounts[i];
+                // The int values that can be returned in the update counts
+                // array are:
+                // -3--Operation error. A driver has the option to stop at the
+                // first error and throw a BatchUpdateException or to report the
+                // error and continue. This value is only seen in the latter
+                // case.
+                // -2--The operation was successful, but the number of rows
+                // affected is unknown.
+                // Zero--DDL statement or no rows affected by the operation.
+                // Greater than zero--Operation was successful, number of rows
+                // affected by the operation.
+                if (iProcessed > 0 || iProcessed == -2) {
+                    // statement was successful
+                    // ...
+                } else {
+                    // error on statement
+                    logger.info("Batch update successful.");
+                    bError = true;
+                    break;
+                }
+            } // end for
+
+            if (bError) {
+                con.rollback();
+            } else {
+                con.commit();
+            }
+            con.setAutoCommit(true);
+        } // end finally
+        logger.info("Queue is cleaned.");
+    }
+
+    private static class SubscriptionConstants {
+
+        public static String INSERT_SQL_QUERY = "INSERT INTO %s(SubscriptionId, xml, wsrm, Topics, XPath, ConsumerAddress, ReferenceProperties, CreationTime) "
+                + "VALUES( ? , ? , ? , ? , ? , ? , ? , ?)";
+
+        public static String ORDINARY_SUBSCRIPTION_INSERT_QUERY = null;
+
+        public static String SPECIAL_SUBSCRIPTION_INSERT_QUERY = null;
+
+    }
+
+    private static class QueueContants {
+        public static final int FINAL_WAIT_IN_MILI = 5000;
+
+        public static final String TABLE_NAME = "disQ";
+
+        public static final String TABLE_NAME_MAXID = "MaxIDTable";
+
+        public static final String TABLE_NAME_MINID = "MinIDTable";
+
+        public static final int STATUS_OPEN = 0;
+
+        public static final String SQL_INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME
+                + " (id, trackId, message, status) " + "VALUES (?,?,?," + STATUS_OPEN + ")";
+
+        public static String SQL_DELETE_STATEMENT = "DELETE FROM " + TABLE_NAME + " WHERE id=";
+
+        public static String SQL_SELECT_STATEMENT = "SELECT id,message FROM " + TABLE_NAME + " WHERE id=";
+
+        public static String SQL_MAX_ID_SEPERATE_TABLE = "SELECT maxID FROM " + TABLE_NAME_MAXID;
+
+        public static String SQL_MIN_ID_SEPERATE_TABLE = "SELECT minID FROM " + TABLE_NAME_MINID;
+
+        public static String SQL_MAX_ID_INSERT = "INSERT INTO " + TABLE_NAME_MAXID + " (maxID) VALUES (1)";
+
+        public static String SQL_MIN_ID_INSERT = "INSERT INTO " + TABLE_NAME_MINID + " (minID) VALUES (1)";
+
+        public static String SQL_MAX_ID_INCREMENT = "UPDATE " + TABLE_NAME_MAXID + " SET maxID = maxID+1 WHERE maxID =";
+
+        public static String SQL_MIN_ID_INCREMENT = "UPDATE " + TABLE_NAME_MINID + " SET minID = minID+1 WHERE minID =";
+
+    }
+
+}

Added: incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/storage/WsmgStorage.java
URL: http://svn.apache.org/viewvc/incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/storage/WsmgStorage.java?rev=1142453&view=auto
==============================================================================
--- incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/storage/WsmgStorage.java (added)
+++ incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/storage/WsmgStorage.java Sun Jul  3 15:51:36 2011
@@ -0,0 +1,47 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.wsmg.commons.storage;
+
+import java.util.List;
+
+import org.apache.airavata.wsmg.broker.subscription.SubscriptionEntry;
+import org.apache.airavata.wsmg.broker.subscription.SubscriptionState;
+
+public interface WsmgStorage {
+
+    public abstract List<SubscriptionEntry> getAllSubscription();
+
+    public abstract int insert(SubscriptionState subscription);
+
+    public abstract int delete(String subscriptionId);
+
+    public void enqueue(Object object, String trackId);
+
+    public Object blockingDequeue();
+
+    public int size();
+
+    public void flush();
+
+    public void cleanup();
+
+}

Added: incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/util/OMElementComparator.java
URL: http://svn.apache.org/viewvc/incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/util/OMElementComparator.java?rev=1142453&view=auto
==============================================================================
--- incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/util/OMElementComparator.java (added)
+++ incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/util/OMElementComparator.java Sun Jul  3 15:51:36 2011
@@ -0,0 +1,182 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.wsmg.commons.util;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.apache.airavata.wsmg.commons.exceptions.XMLComparisonException;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMNode;
+import org.apache.log4j.Logger;
+
+public class OMElementComparator {
+
+    private static Logger log = Logger.getLogger(OMElementComparator.class);
+
+    private Vector<String> ignorableNamespaceList = new Vector<String>();
+
+    public void addIgnorableNamespace(String nsURI) {
+        ignorableNamespaceList.add(nsURI);
+    }
+
+    public void clearIgnorableNamespaces() {
+        ignorableNamespaceList.clear();
+    }
+
+    public boolean compare(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+
+        // ignore if the elements belong to any of the ignorable namespaces list
+        if (isIgnorable(elementOne) || isIgnorable(elementTwo)) {
+            return true;
+        }
+
+        if (elementOne == null && elementTwo == null) {
+            log.info("Both Elements are null.");
+            return true;
+        }
+        if (elementOne == null && elementTwo != null) {
+            throw new XMLComparisonException("Element One is null and Element Two is not null");
+        }
+        if (elementOne != null && elementTwo == null) {
+            throw new XMLComparisonException("Element Two is null and Element One is not null");
+        }
+
+        compare("Elements names are not equal. ", elementOne.getLocalName(), elementTwo.getLocalName());
+
+        compare("Element namespaces are not equal", elementOne.getNamespace(), elementTwo.getNamespace());
+
+        compareAllAttributes(elementOne, elementTwo);
+
+        /*
+         * Trimming the value of the XMLElement is not correct since this compare method cannot be used to compare
+         * element contents with trailing and leading whitespaces BUT for the practicalltiy of tests and to get the
+         * current tests working we have to trim() the contents
+         */
+        compare("Elements texts are not equal ", elementOne.getText().trim(), elementTwo.getText().trim());
+
+        compareAllChildren(elementOne, elementTwo);
+
+        return true;
+    }
+
+    private void compareAllAttributes(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+        compareAttibutes(elementOne, elementTwo);
+        compareAttibutes(elementTwo, elementOne);
+    }
+
+    private void compareAllChildren(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+        compareChildren(elementOne, elementTwo);
+        compareChildren(elementTwo, elementOne);
+    }
+
+    private boolean isIgnorable(OMElement elt) {
+        if (elt != null) {
+            OMNamespace namespace = elt.getNamespace();
+            if (namespace != null) {
+                return ignorableNamespaceList.contains(namespace.getNamespaceURI());
+            } else {
+                return false;
+            }
+        } else {
+            return false;
+        }
+    }
+
+    private void compareChildren(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+        // ignore if the elements belong to any of the ignorable namespaces list
+        if (isIgnorable(elementOne) || isIgnorable(elementTwo)) {
+            return;
+        }
+        Iterator elementOneChildren = elementOne.getChildren();
+        while (elementOneChildren.hasNext()) {
+            OMNode omNode = (OMNode) elementOneChildren.next();
+            if (omNode instanceof OMElement) {
+                OMElement elementOneChild = (OMElement) omNode;
+                OMElement elementTwoChild = null;
+                // Do the comparison only if the element is not ignorable
+                if (!isIgnorable(elementOneChild)) {
+                    elementTwoChild = elementTwo.getFirstChildWithName(elementOneChild.getQName());
+                    // Do the comparison only if the element is not ignorable
+                    if (!isIgnorable(elementTwoChild)) {
+                        if (elementTwoChild == null) {
+                            throw new XMLComparisonException(" There is no " + elementOneChild.getLocalName()
+                                    + " element under " + elementTwo.getLocalName());
+                        }
+                    }
+                }
+                compare(elementOneChild, elementTwoChild);
+            }
+        }
+    }
+
+    private void compareAttibutes(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+        int elementOneAtribCount = 0;
+        int elementTwoAtribCount = 0;
+        Iterator attributes = elementOne.getAllAttributes();
+        while (attributes.hasNext()) {
+            OMAttribute omAttribute = (OMAttribute) attributes.next();
+            OMAttribute attr = elementTwo.getAttribute(omAttribute.getQName());
+            if (attr == null) {
+                throw new XMLComparisonException("Attributes are not the same in two elements. Attribute "
+                        + omAttribute.getLocalName() + " != ");
+            }
+            elementOneAtribCount++;
+        }
+
+        Iterator elementTwoIter = elementTwo.getAllAttributes();
+        while (elementTwoIter.hasNext()) {
+            elementTwoIter.next();
+            elementTwoAtribCount++;
+
+        }
+
+        if (elementOneAtribCount != elementTwoAtribCount) {
+            throw new XMLComparisonException("Attributes are not the same in two elements.");
+        }
+    }
+
+    private void compare(String failureNotice, String one, String two) throws XMLComparisonException {
+        if (!one.equals(two)) {
+            throw new XMLComparisonException(failureNotice + one + " != " + two);
+        }
+    }
+
+    private void compare(String failureNotice, OMNamespace one, OMNamespace two) throws XMLComparisonException {
+        if (one == null && two == null) {
+            return;
+        } else if (one != null && two == null) {
+            throw new XMLComparisonException("First Namespace is NOT null. But the second is null");
+        } else if (one == null && two != null) {
+            throw new XMLComparisonException("First Namespace is null. But the second is NOT null");
+        }
+
+        if (!one.getNamespaceURI().equals(two.getNamespaceURI())) {
+            throw new XMLComparisonException(failureNotice + one + " != " + two);
+        }
+
+        // Do we need to compare prefixes as well
+    }
+
+}

Added: incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/config/Configuration.java
URL: http://svn.apache.org/viewvc/incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/config/Configuration.java?rev=1142453&view=auto
==============================================================================
--- incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/config/Configuration.java (added)
+++ incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/config/Configuration.java Sun Jul  3 15:51:36 2011
@@ -0,0 +1,504 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.wsmg.config;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.Properties;
+import java.util.Vector;
+
+/**
+ * Configuration interface.
+ * 
+ */
+@Deprecated
+public interface Configuration {
+
+    /**
+     * Create an Configuration object that is a subset of this one. The new Configuration object contains every key from
+     * the current Configuration that starts with prefix. The prefix is removed from the keys in the subset.
+     * 
+     * @param prefix
+     *            The prefix used to select the properties.
+     */
+    Configuration subset(String prefix);
+
+    /**
+     * Check if the configuration is empty.
+     * 
+     * @return true is the configuration contains no key/value pair, false otherwise
+     */
+    boolean isEmpty();
+
+    /**
+     * Check if the configuration contains the key.
+     * 
+     * @return true is the configuration contains a value for this key, false otherwise
+     */
+    boolean containsKey(String key);
+
+    /**
+     * Add a property to the configuration. If it already exists then the value stated here will be added to the
+     * configuration entry. For example, if
+     * 
+     * resource.loader = file
+     * 
+     * is already present in the configuration and you
+     * 
+     * addProperty("resource.loader", "classpath")
+     * 
+     * Then you will end up with a Vector like the following:
+     * 
+     * ["file", "classpath"]
+     * 
+     * @param key
+     *            The Key to add the property to.
+     * @param token
+     *            The Value to add.
+     */
+    void addProperty(String key, Object value);
+
+    /**
+     * Set a property, this will replace any previously set values. Set values is implicitly a call to
+     * clearProperty(key), addProperty(key,value).
+     * 
+     * @param key
+     *            The key of the property to change
+     * @param value
+     *            The new value
+     */
+    void setProperty(String key, Object value);
+
+    /**
+     * Clear a property in the configuration.
+     * 
+     * @param key
+     *            the key to remove along with corresponding value.
+     */
+    void clearProperty(String key);
+
+    /**
+     * Gets a property from the configuration.
+     * 
+     * @param key
+     *            property to retrieve
+     * @return value as object. Will return user value if exists, if not then default value if exists, otherwise null
+     */
+    String getProperty(String key);
+
+    /**
+     * Get the list of the keys contained in the configuration repository that match the specified prefix.
+     * 
+     * @param prefix
+     *            The prefix to test against.
+     * @return An Iterator of keys that match the prefix.
+     */
+    Iterator getKeys(String prefix);
+
+    /**
+     * Get the list of the keys contained in the configuration repository.
+     * 
+     * @return An Iterator.
+     */
+    Iterator getKeys();
+
+    /**
+     * Get a list of properties associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @return The associated properties if key is found.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a String/Vector.
+     * @exception IllegalArgumentException
+     *                if one of the tokens is malformed (does not contain an equals sign).
+     */
+    Properties getProperties(String key);
+
+    /**
+     * Get a boolean associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @return The associated boolean.
+     * @exception NoSuchElementException
+     *                is thrown if the key doesn't map to an existing object.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Boolean.
+     */
+    boolean getBoolean(String key);
+
+    /**
+     * Get a boolean associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated boolean.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Boolean.
+     */
+    boolean getBoolean(String key, boolean defaultValue);
+
+    /**
+     * Get a boolean associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated boolean if key is found and has valid format, default value otherwise.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Boolean.
+     */
+    Boolean getBoolean(String key, Boolean defaultValue);
+
+    /**
+     * Get a byte associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @return The associated byte.
+     * @exception NoSuchElementException
+     *                is thrown if the key doesn't map to an existing object.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Byte.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    byte getByte(String key);
+
+    /**
+     * Get a byte associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated byte.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Byte.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    byte getByte(String key, byte defaultValue);
+
+    /**
+     * Get a byte associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated byte if key is found and has valid format, default value otherwise.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Byte.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    Byte getByte(String key, Byte defaultValue);
+
+    /**
+     * Get a double associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @return The associated double.
+     * @exception NoSuchElementException
+     *                is thrown if the key doesn't map to an existing object.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Double.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    double getDouble(String key);
+
+    /**
+     * Get a double associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated double.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Double.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    double getDouble(String key, double defaultValue);
+
+    /**
+     * Get a double associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated double if key is found and has valid format, default value otherwise.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Double.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    Double getDouble(String key, Double defaultValue);
+
+    /**
+     * Get a float associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @return The associated float.
+     * @exception NoSuchElementException
+     *                is thrown if the key doesn't map to an existing object.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Float.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    float getFloat(String key);
+
+    /**
+     * Get a float associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated float.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Float.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    float getFloat(String key, float defaultValue);
+
+    /**
+     * Get a float associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated float if key is found and has valid format, default value otherwise.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Float.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    Float getFloat(String key, Float defaultValue);
+
+    /**
+     * Get a int associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @return The associated int.
+     * @exception NoSuchElementException
+     *                is thrown if the key doesn't map to an existing object.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Integer.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    int getInt(String key);
+
+    /**
+     * Get a int associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated int.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Integer.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    int getInt(String key, int defaultValue);
+
+    /**
+     * Get a int associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated int if key is found and has valid format, default value otherwise.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Integer.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    Integer getInteger(String key, Integer defaultValue);
+
+    /**
+     * Get a long associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @return The associated long.
+     * @exception NoSuchElementException
+     *                is thrown if the key doesn't map to an existing object.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Long.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    long getLong(String key);
+
+    /**
+     * Get a long associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated long.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Long.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    long getLong(String key, long defaultValue);
+
+    /**
+     * Get a long associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated long if key is found and has valid format, default value otherwise.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Long.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    Long getLong(String key, Long defaultValue);
+
+    /**
+     * Get a short associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @return The associated short.
+     * @exception NoSuchElementException
+     *                is thrown if the key doesn't map to an existing object.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Short.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    short getShort(String key);
+
+    /**
+     * Get a short associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated short.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Short.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    short getShort(String key, short defaultValue);
+
+    /**
+     * Get a short associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated short if key is found and has valid format, default value otherwise.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Short.
+     * @exception NumberFormatException
+     *                is thrown if the value mapped by the key has not a valid number format.
+     */
+    Short getShort(String key, Short defaultValue);
+
+    /**
+     * Get a string associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @return The associated string.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a String.
+     */
+    String getString(String key);
+
+    /**
+     * Get a string associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated string if key is found and has valid format, default value otherwise.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a String.
+     */
+    String getString(String key, String defaultValue);
+
+    /**
+     * Get an array of strings associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @return The associated string array if key is found.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a String/Vector of Strings.
+     */
+    String[] getStringArray(String key);
+
+    /**
+     * Get a Vector of strings associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @return The associated Vector.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Vector.
+     */
+    Vector getVector(String key);
+
+    /**
+     * Get a Vector of strings associated with the given configuration key.
+     * 
+     * @param key
+     *            The configuration key.
+     * @param defaultValue
+     *            The default value.
+     * @return The associated Vector.
+     * @exception ClassCastException
+     *                is thrown if the key maps to an object that is not a Vector.
+     */
+    Vector getVector(String key, Vector defaultValue);
+}

Added: incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/config/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/config/ConfigurationManager.java?rev=1142453&view=auto
==============================================================================
--- incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/config/ConfigurationManager.java (added)
+++ incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/config/ConfigurationManager.java Sun Jul  3 15:51:36 2011
@@ -0,0 +1,90 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.wsmg.config;
+
+import java.io.File;
+import java.util.Properties;
+
+import org.apache.airavata.wsmg.commons.WsmgCommonConstants;
+import org.apache.axis2.Constants;
+import org.apache.log4j.Logger;
+
+public class ConfigurationManager {
+
+    private Logger logger = Logger.getLogger(ConfigurationManager.class);
+
+    protected Properties configurations = new Properties();
+
+    public ConfigurationManager(String configFileName) {
+
+        try {
+
+            configurations.load(this.getClass().getClassLoader().getResourceAsStream(configFileName));
+
+        } catch (Exception e) {
+            throw new RuntimeException("unable to load configurations", e);
+        }
+
+    }
+
+    private void configureSystemProperties(Properties p) {
+        String axis2Repo = getConfig(WsmgCommonConstants.CONFIG_AXIS2_REPO, null);
+
+        if (!dirExists(axis2Repo)) {
+
+            String axis2Home = System.getenv("AXIS2_HOME");
+
+            axis2Repo = axis2Home.endsWith(File.separator) ? axis2Home + axis2Repo : axis2Home + File.separator
+                    + axis2Repo;
+
+        }
+
+        if (axis2Repo != null) {
+
+            logger.info("axis2 repository :" + axis2Repo);
+            System.setProperty(Constants.AXIS2_REPO, axis2Repo);
+        }
+
+    }
+
+    public String getConfig(String configName) {
+
+        return configurations.getProperty(configName);
+    }
+
+    public String getConfig(String configName, String defaultVal) {
+        return configurations.getProperty(configName, defaultVal);
+    }
+
+    public int getConfig(String configName, int defaultVal) {
+
+        return Integer.parseInt(configurations.getProperty(configName, Integer.toString(defaultVal)));
+
+    }
+
+    private boolean dirExists(String path) {
+        File f = new File(path);
+
+        return f.isDirectory();
+    }
+
+}

Added: incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/config/ConfigurationParamsReader.java
URL: http://svn.apache.org/viewvc/incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/config/ConfigurationParamsReader.java?rev=1142453&view=auto
==============================================================================
--- incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/config/ConfigurationParamsReader.java (added)
+++ incubator/airavata/ws-messaging/trunk/messagebroker/src/main/java/org/apache/airavata/wsmg/config/ConfigurationParamsReader.java Sun Jul  3 15:51:36 2011
@@ -0,0 +1,917 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.wsmg.config;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Responsible for loading the configuration parameters specified in a configuration file.
+ */
+
+@Deprecated
+public class ConfigurationParamsReader implements Configuration {
+
+    static final Logger log = Logger.getLogger(ConfigurationParamsReader.class);
+    public final String FILE_SEPARATOR = "/";
+
+    public final String DELIMITER = ",";
+
+    private final int INITIAL_LIST_SIZE = 3;
+
+    private String basePath = null;
+
+    private ArrayList keysList = new ArrayList();
+
+    protected Configuration defaults = null;
+
+    protected Hashtable store = new Hashtable();
+
+    public ConfigurationParamsReader() {
+    }
+
+    public ConfigurationParamsReader(String file) {
+        try {
+            load(file);
+        } catch (IOException ioe) {
+            ioe.printStackTrace();
+            log.info(ioe.getMessage());
+        }
+    }
+
+    public ConfigurationParamsReader(Configuration defaults) {
+        this.defaults = defaults;
+    }
+
+    /**
+     * Load the properties from the given file
+     * 
+     * @param file
+     *            The properties file to load
+     * @throws IOException
+     */
+    public void load(String file) throws IOException {
+        load(this.getClass().getClassLoader().getResourceAsStream(file));
+    }
+
+    /**
+     * Load the properties from the given input stream.
+     * 
+     * @param input
+     *            An InputStream on the properties file
+     * @throws IOException
+     */
+    public void load(InputStream input) throws IOException {
+        load(input, null);
+    }
+
+    /**
+     * Load the properties from the given input stream and using the specified encoding.
+     * 
+     * @param input
+     *            An InputStream.
+     * @param enc
+     *            An encoding.
+     * @exception IOException
+     */
+    public synchronized void load(InputStream input, String enc) throws IOException {
+
+        LineNumberReader reader = null;
+
+        if (enc != null) {
+            try {
+                reader = new LineNumberReader(new InputStreamReader(input, enc));
+            } catch (UnsupportedEncodingException e) {
+                // Get one with the default encoding...
+            }
+        }
+        if (reader == null) {
+            reader = new LineNumberReader(new InputStreamReader(input));
+        }
+
+        StringBuffer sb = new StringBuffer();
+        while (true) {
+
+            String line = reader.readLine();
+            if (line == null) {
+                break; // EOF
+            }
+
+            line = line.trim();
+            if (line.startsWith("#")) {
+                continue;
+
+            } else if (line.equals("")) {
+                continue;
+
+            } else if (line.endsWith("\\")) {
+                sb.append(line.substring(0, line.length() - 1));
+                continue;
+
+            } else {
+                line = sb.append(line).toString();
+                sb = new StringBuffer();
+
+                int equalIndex = line.indexOf('=');
+                /**
+                 * fix commons.configuration bug
+                 * 
+                 * @see BasePropertiesConfiguration#load we not only make sure there is an equal sign, but also there is
+                 *      something after the equal sign
+                 */
+                if (equalIndex > 0 && (equalIndex + 1) < line.length()) {
+                    String key = line.substring(0, equalIndex).trim();
+                    String value = line.substring(equalIndex + 1).trim();
+
+                    addProperty(key, value);
+
+                }
+            }
+        }
+    }
+
+    /**
+     * @param The
+     *            file name with which to get InputStream
+     * @return An InputStream
+     * @throws IOException
+     */
+    public InputStream getPropertyStream(String resourceName) throws IOException {
+
+        InputStream resource = null;
+        File file = null;
+
+        if (resourceName.startsWith(FILE_SEPARATOR)) {
+            // an absolute path
+            file = new File(resourceName);
+            log.info("configuration: load " + resourceName);
+        } else if (basePath == null || basePath.equals("")) {
+
+            file = new File(resourceName);
+            String canonName = file.getCanonicalPath();
+            file = new File(canonName);
+            log.info("configuration: load " + canonName);
+        } else {
+            StringBuffer fileName = new StringBuffer();
+
+            if (!basePath.endsWith(FILE_SEPARATOR)) {
+                basePath = basePath + FILE_SEPARATOR;
+            }
+            fileName.append(basePath).append(resourceName);
+            file = new File(fileName.toString());
+            String canonName = file.getCanonicalPath();
+            file = new File(canonName);
+            log.info("configuration: load " + canonName);
+        }
+
+        if (file == null || !file.exists()) {
+            throw new FileNotFoundException("File not exists " + resourceName);
+
+        } else if (!file.canRead()) {
+            throw new IOException("File " + resourceName + " exists but could not be read.");
+
+        } else {
+            resource = new FileInputStream(file);
+        }
+
+        return resource;
+    }
+
+    /**
+     * @see Configuration
+     */
+    public void addProperty(String key, Object token) {
+
+        List tokenAdd = null;
+
+        if (token instanceof String) {
+            tokenAdd = processString((String) token);
+
+        } else if (token instanceof Collection) {
+
+            for (Iterator it = ((Collection) token).iterator(); it.hasNext();) {
+                addProperty(key, it.next());
+            }
+            return;
+
+        } else {
+            tokenAdd = new Vector(1);
+            tokenAdd.add(token);
+        }
+
+        Object o = store.get(key);
+        if (o instanceof Vector) {
+            for (Iterator it = tokenAdd.iterator(); it.hasNext();) {
+                ((Vector) o).add(it.next());
+            }
+
+        } else {
+            Vector v = new Vector();
+            if (o != null) {
+                v.add(o);
+            }
+            for (Iterator it = tokenAdd.iterator(); it.hasNext();) {
+                v.add(it.next());
+            }
+
+            if (o == null && v.size() == 1) {
+                addPropertyDirect(key, v.get(0));
+
+            } else {
+                addPropertyDirect(key, v);
+            }
+        }
+    }
+
+    /**
+     * @param token
+     *            A String token
+     * @return A List of Strings
+     */
+    protected List processString(String token) {
+        List l = new ArrayList(INITIAL_LIST_SIZE);
+
+        if (token.indexOf(DELIMITER) > 0) {
+            StringTokenizer tokenizer = new StringTokenizer(token, DELIMITER);
+
+            while (tokenizer.hasMoreTokens()) {
+                String value = tokenizer.nextToken();
+                /**
+                 * fix commons.configuration bug
+                 * 
+                 * @see PropertiesConfiguration#processString() more trim() call allows both comma "," AND whitespace
+                 *      between values
+                 */
+                l.add(value.trim());
+            }
+        } else {
+            l.add(token);
+        }
+
+        return l;
+    }
+
+    /**
+     * @param key
+     *            key to use for mapping
+     * @param obj
+     *            object to store
+     */
+    protected void addPropertyDirect(String key, Object obj) {
+
+        if (!store.containsKey(key)) {
+            keysList.add(key);
+        }
+
+        store.put(key, obj);
+    }
+
+    /**
+     * Map <code> true </code>, <code> on </code>, <code> yes </code> to true; <code> false </code>, <code> off </code>,
+     * <code> no </code> to false.
+     * 
+     * @param value
+     *            The value to test for boolean state.
+     * @return String of true, false or null
+     */
+    public String testBoolean(String value) {
+
+        String val = value.toLowerCase();
+
+        if (val.equals("true") || val.equals("on") || val.equals("yes")) {
+            return "true";
+
+        } else if (val.equals("false") || val.equals("off") || val.equals("no")) {
+            return "false";
+
+        } else {
+            return null;
+        }
+
+    }
+
+    /**
+     * 
+     * @see Configuration
+     */
+    public Configuration subset(String prefix) {
+
+        Configuration pc = new ConfigurationParamsReader();
+        Iterator keys = this.getKeys();
+        boolean valid = false;
+
+        while (keys.hasNext()) {
+            Object key = keys.next();
+
+            if (key instanceof String && ((String) key).startsWith(prefix)) {
+                if (!valid) {
+                    valid = true;
+                }
+
+                String newKey = null;
+                if (((String) key).length() == prefix.length()) {
+                    newKey = prefix;
+
+                } else {
+                    newKey = ((String) key).substring(prefix.length() + 1);
+                }
+
+                Object value = store.get(key);
+                ((ConfigurationParamsReader) pc).addPropertyDirect(newKey, value);
+
+            }
+        }
+
+        if (valid) {
+            return pc;
+        } else {
+            return null;
+        }
+
+    }
+
+    /**
+     * @see Configuration#isEmpty
+     */
+    public boolean isEmpty() {
+        return store.isEmpty();
+    }
+
+    /**
+     * @see Configuration
+     */
+    public boolean containsKey(String key) {
+        return store.containsKey(key);
+    }
+
+    /**
+     * @see Configuration
+     */
+    public void setProperty(String key, Object value) {
+        clearProperty(key);
+        addProperty(key, value);
+    }
+
+    /**
+     * @see Configuration
+     */
+    public void clearProperty(String key) {
+
+        if (containsKey(key)) {
+            for (int i = 0; i < keysList.size(); i++) {
+                if (((String) keysList.get(i)).equals(key)) {
+                    keysList.remove(i);
+                    break;
+                }
+            }
+            store.remove(key);
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public Iterator getKeys() {
+        return keysList.iterator();
+    }
+
+    /**
+     * @see Configuration
+     */
+    public Iterator getKeys(String prefix) {
+        Iterator keys = getKeys();
+        ArrayList matchingKeys = new ArrayList();
+
+        while (keys.hasNext()) {
+            Object key = keys.next();
+
+            if (key instanceof String && ((String) key).startsWith(prefix)) {
+                matchingKeys.add(key);
+            }
+        }
+        return matchingKeys.iterator();
+    }
+
+    /**
+     * Returns all the properties that have been read from the specified configuration file
+     */
+    public Properties getProperties(Properties _defaults) {
+        Properties props = new Properties(_defaults);
+
+        Enumeration e = store.keys();
+        while (e.hasMoreElements()) {
+            String _key = (String) e.nextElement();
+            String _value = store.get(_key).toString();
+            props.setProperty(_key, _value);
+        }
+        return props;
+
+    }
+
+    /**
+     * @see Configuration
+     * @see #getProperties(String, Properties)
+     */
+    public Properties getProperties(String key) {
+        return getProperties(key, null);
+    }
+
+    /**
+     * @see Configuration
+     */
+    public Properties getProperties(String key, Properties defaults) {
+
+        String[] tokens = getStringArray(key);
+
+        /*
+         * Each token is of the form 'key=value'.
+         */
+        Properties props = (defaults == null ? new Properties() : new Properties(defaults));
+
+        for (int i = 0; i < tokens.length; i++) {
+            String token = tokens[i];
+            int equalIndex = token.indexOf('=');
+            if (equalIndex > 0) {
+                String pkey = token.substring(0, equalIndex).trim();
+                String pvalue = token.substring(equalIndex + 1).trim();
+                props.put(pkey, pvalue);
+            } else if (tokens.length == 1 && token.equals("")) {
+                // Semantically equivalent to an empty Properties
+                // object.
+                break;
+            } else {
+                throw new IllegalArgumentException('\'' + token + "' does not contain an equals sign");
+            }
+        }
+        return props;
+    }
+
+    /**
+     * @see Configuration
+     */
+    public String getProperty(String key) {
+
+        Object o = store.get(key);
+
+        if (o == null) {
+            if (defaults != null) {
+                o = defaults.getProperty(key);
+            }
+        }
+        return o.toString();
+    }
+
+    /**
+     * @see Configuration
+     */
+    public boolean getBoolean(String key) {
+        Boolean b = getBoolean(key, (Boolean) null);
+        if (b != null) {
+            return b.booleanValue();
+
+        } else {
+            throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public boolean getBoolean(String key, boolean defaultValue) {
+        return getBoolean(key, new Boolean(defaultValue)).booleanValue();
+    }
+
+    /**
+     * @see Configuration
+     */
+    public Boolean getBoolean(String key, Boolean defaultValue) {
+        Object value = resolveVectorStore(key);
+
+        if (value instanceof Boolean) {
+            return (Boolean) value;
+        } else if (value instanceof String) {
+            String s = testBoolean((String) value);
+            Boolean b = new Boolean(s);
+            return b;
+        } else if (value == null) {
+            if (defaults != null) {
+                return defaults.getBoolean(key, defaultValue);
+            } else {
+                return defaultValue;
+            }
+        } else {
+            throw new ClassCastException('\'' + key + "' doesn't map to a Boolean object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public byte getByte(String key) {
+        Byte b = getByte(key, null);
+        if (b != null) {
+            return b.byteValue();
+        } else {
+            throw new NoSuchElementException('\'' + key + " doesn't map to an existing object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public byte getByte(String key, byte defaultValue) {
+        return getByte(key, new Byte(defaultValue)).byteValue();
+    }
+
+    /**
+     * @see Configuration
+     */
+    public Byte getByte(String key, Byte defaultValue) {
+        Object value = resolveVectorStore(key);
+
+        if (value instanceof Byte) {
+            return (Byte) value;
+        } else if (value instanceof String) {
+            Byte b = new Byte((String) value);
+            return b;
+        } else if (value == null) {
+            if (defaults != null) {
+                return defaults.getByte(key, defaultValue);
+            } else {
+                return defaultValue;
+            }
+        } else {
+            throw new ClassCastException('\'' + key + "' doesn't map to a Byte object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public double getDouble(String key) {
+        Double d = getDouble(key, null);
+        if (d != null) {
+            return d.doubleValue();
+        } else {
+            throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public double getDouble(String key, double defaultValue) {
+        return getDouble(key, new Double(defaultValue)).doubleValue();
+    }
+
+    /**
+     * @see Configuration
+     */
+    public Double getDouble(String key, Double defaultValue) {
+        Object value = resolveVectorStore(key);
+
+        if (value instanceof Double) {
+            return (Double) value;
+        } else if (value instanceof String) {
+            Double d = new Double((String) value);
+            return d;
+        } else if (value == null) {
+            if (defaults != null) {
+                return defaults.getDouble(key, defaultValue);
+            } else {
+                return defaultValue;
+            }
+        } else {
+            throw new ClassCastException('\'' + key + "' doesn't map to a Double object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public float getFloat(String key) {
+        Float f = getFloat(key, null);
+        if (f != null) {
+            return f.floatValue();
+        } else {
+            throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public float getFloat(String key, float defaultValue) {
+        return getFloat(key, new Float(defaultValue)).floatValue();
+    }
+
+    /**
+     * @see Configuration
+     */
+    public Float getFloat(String key, Float defaultValue) {
+        Object value = resolveVectorStore(key);
+
+        if (value instanceof Float) {
+            return (Float) value;
+        } else if (value instanceof String) {
+            Float f = new Float((String) value);
+            return f;
+        } else if (value == null) {
+            if (defaults != null) {
+                return defaults.getFloat(key, defaultValue);
+            } else {
+                return defaultValue;
+            }
+        } else {
+            throw new ClassCastException('\'' + key + "' doesn't map to a Float object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public int getInt(String key) {
+        Integer i = getInteger(key, null);
+        if (i != null) {
+            return i.intValue();
+        } else {
+            throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public int getInt(String key, int defaultValue) {
+        Integer i = getInteger(key, null);
+
+        if (i == null) {
+            return defaultValue;
+        }
+
+        return i.intValue();
+    }
+
+    /**
+     * @see Configuration
+     */
+    public Integer getInteger(String key, Integer defaultValue) {
+        Object value = resolveVectorStore(key);
+
+        if (value instanceof Integer) {
+            return (Integer) value;
+        } else if (value instanceof String) {
+            Integer i = new Integer((String) value);
+            return i;
+        } else if (value == null) {
+            if (defaults != null) {
+                return defaults.getInteger(key, defaultValue);
+            } else {
+                return defaultValue;
+            }
+        } else {
+            throw new ClassCastException('\'' + key + "' doesn't map to a Integer object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public long getLong(String key) {
+        Long l = getLong(key, null);
+        if (l != null) {
+            return l.longValue();
+        } else {
+            throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public long getLong(String key, long defaultValue) {
+        return getLong(key, new Long(defaultValue)).longValue();
+    }
+
+    /**
+     * @see Configuration
+     */
+    public Long getLong(String key, Long defaultValue) {
+        Object value = resolveVectorStore(key);
+
+        if (value instanceof Long) {
+            return (Long) value;
+        } else if (value instanceof String) {
+            Long l = new Long((String) value);
+            return l;
+        } else if (value == null) {
+            if (defaults != null) {
+                return defaults.getLong(key, defaultValue);
+            } else {
+                return defaultValue;
+            }
+        } else {
+            throw new ClassCastException('\'' + key + "' doesn't map to a Long object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public short getShort(String key) {
+        Short s = getShort(key, null);
+        if (s != null) {
+            return s.shortValue();
+        } else {
+            throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public short getShort(String key, short defaultValue) {
+        return getShort(key, new Short(defaultValue)).shortValue();
+    }
+
+    /**
+     * @see Configuration
+     */
+    public Short getShort(String key, Short defaultValue) {
+        Object value = resolveVectorStore(key);
+
+        if (value instanceof Short) {
+            return (Short) value;
+        } else if (value instanceof String) {
+            Short s = new Short((String) value);
+            return s;
+        } else if (value == null) {
+            if (defaults != null) {
+                return defaults.getShort(key, defaultValue);
+            } else {
+                return defaultValue;
+            }
+        } else {
+            throw new ClassCastException('\'' + key + "' doesn't map to a Short object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public String getString(String key) {
+        return getString(key, null);
+    }
+
+    /**
+     * @see Configuration
+     */
+    public String getString(String key, String defaultValue) {
+        Object value = resolveVectorStore(key);
+
+        if (value instanceof String) {
+            return (String) value;
+
+        } else if (value == null) {
+            if (defaults != null) {
+                return defaults.getString(key, defaultValue);
+            } else {
+                return defaultValue;
+            }
+        } else {
+            throw new ClassCastException('\'' + key + "' doesn't map to a String object");
+        }
+    }
+
+    /**
+     * @see Configuration
+     */
+    public String[] getStringArray(String key) {
+        Object value = store.get(key);
+
+        String[] tokens;
+
+        if (value instanceof String) {
+            tokens = new String[1];
+            tokens[0] = (String) value;
+
+        } else if (value instanceof Vector) {
+            tokens = new String[((Vector) value).size()];
+
+            for (int i = 0; i < tokens.length; i++) {
+
+                tokens[i] = (String) ((Vector) value).get(i);
+            }
+
+        } else if (value == null) {
+            if (defaults != null) {
+                tokens = defaults.getStringArray(key);
+            } else {
+                tokens = new String[0];
+            }
+        } else {
+            throw new ClassCastException('\'' + key + "' doesn't map to a String/Vector object");
+        }
+        return tokens;
+    }
+
+    /**
+     * @see Configuration
+     */
+    public Vector getVector(String key) {
+        return getVector(key, null);
+    }
+
+    /**
+     * @see Configuration
+     */
+    public Vector getVector(String key, Vector defaultValue) {
+        Object value = store.get(key);
+        Vector v = null;
+
+        if (value instanceof String) {
+            v = new Vector(1);
+            v.addElement((String) value);
+
+        } else if (value == null) {
+            if (defaults != null) {
+                v = defaults.getVector(key, defaultValue);
+            } else {
+                v = ((defaultValue == null) ? new Vector() : defaultValue);
+            }
+        } else {
+            throw new ClassCastException('\'' + key + "' doesn't map to a Vector object: " + value + ", a "
+                    + value.getClass().getName());
+        }
+        return v;
+    }
+
+    /**
+	 * 
+	 */
+    public String getBasePath() {
+        return this.basePath;
+    }
+
+    /**
+	 * 
+	 */
+    public void setBasePath(String path) {
+        this.basePath = path;
+    }
+
+    /**
+     * Returns an object from the store described by the key. If the value is a Vector object, replace it with the first
+     * object in the container
+     * 
+     * @param key
+     *            The property key.
+     * 
+     * @return value Value, transparently resolving a possible Vector dependency.
+     */
+    private Object resolveVectorStore(String key) {
+        Object value = store.get(key);
+        if (value != null && value instanceof Vector) {
+            value = ((Vector) value).get(0);
+        }
+        return value;
+    }
+
+}