geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r219976 [6/12] - in /geronimo/trunk: ./ etc/ sandbox/console-core/ sandbox/console-core/src/ sandbox/console-core/src/java/ sandbox/console-core/src/java/org/ sandbox/console-core/src/java/org/apache/ sandbox/console-core/src/java/org/apach...
Date Thu, 21 Jul 2005 01:38:23 GMT
Added: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerPortlet.java?rev=219976&view=auto
==============================================================================
--- geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerPortlet.java (added)
+++ geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerPortlet.java Wed Jul 20 18:38:12 2005
@@ -0,0 +1,179 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.internaldb;
+
+import java.io.IOException;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+public class DBViewerPortlet extends GenericPortlet {
+
+    private static final int RDBMS_DERBY = 1;
+
+    private static final int RDBMS_MSSQL = 2;
+
+    private static final String MAXIMIZEDVIEW_JSP = "/WEB-INF/view/internaldb/dbViewerMaximized.jsp";
+
+    private static final String HELPVIEW_JSP = "/WEB-INF/view/internaldb/dbViewerHelp.jsp";
+
+    private static final String LISTDATABASES_JSP = "/WEB-INF/view/internaldb/listDatabases.jsp";
+
+    private static final String LISTTABLES_JSP = "/WEB-INF/view/internaldb/listTables.jsp";
+
+    private static final String VIEWTABLECONTENTS_JSP = "/WEB-INF/view/internaldb/viewTableContents.jsp";
+
+    private static final String LISTDB_ACTION = "listDatabases";
+
+    private static final String LISTTBLS_ACTION = "listTables";
+
+    private static final String VIEWTBLCONTENTS_ACTION = "viewTableContents";
+
+    private static final String DERBY_HOME = System
+            .getProperty("derby.system.home");
+
+    private static DBViewerHelper helper = new DBViewerHelper();
+
+    private PortletRequestDispatcher maximizedView;
+
+    private PortletRequestDispatcher helpView;
+
+    private PortletRequestDispatcher listDatabasesView;
+
+    private PortletRequestDispatcher listTablesView;
+
+    private PortletRequestDispatcher viewTableContentsView;
+
+    public void processAction(ActionRequest actionRequest,
+            ActionResponse actionResponse) throws PortletException, IOException {
+        // getting parameters here because it fails on doView()
+        String action = actionRequest.getParameter("action");
+        String db = actionRequest.getParameter("db");
+        String tbl = actionRequest.getParameter("tbl");
+        String viewTables = actionRequest.getParameter("viewTables");
+        String rdbms = actionRequest.getParameter("rdbms");
+        // pass them to the render request
+        if (action != null) {
+            actionResponse.setRenderParameter("action", action);
+        }
+        if (db != null) {
+            actionResponse.setRenderParameter("db", db);
+        }
+        if (tbl != null) {
+            actionResponse.setRenderParameter("tbl", tbl);
+        }
+        if (viewTables != null) {
+            actionResponse.setRenderParameter("viewTables", viewTables);
+        }
+        if (rdbms != null) {
+            actionResponse.setRenderParameter("rdbms", rdbms);
+        }
+    }
+
+    protected void doView(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws IOException, PortletException {
+        if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
+            return;
+        }
+        String action = renderRequest.getParameter("action");
+        String db = renderRequest.getParameter("db");
+        String tbl = renderRequest.getParameter("tbl");
+        String viewTables = renderRequest.getParameter("viewTables");
+        String rdbms = renderRequest.getParameter("rdbms");
+        int rdbmsParam = (rdbms == null ? RDBMS_DERBY : Integer.parseInt(rdbms));
+
+        if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
+            if (rdbmsParam == RDBMS_DERBY) {
+                // Check is database & table is valid
+                if (LISTTBLS_ACTION.equals(action)
+                        || VIEWTBLCONTENTS_ACTION.equals(action)) {
+                    if (!helper.isDBValid(DERBY_HOME, db)) {
+                        // DB not valid
+                        System.out.println("ERROR: db not valid: " + db);
+                        action = "";
+                    }
+                }
+                if (VIEWTBLCONTENTS_ACTION.equals(action)) {
+                    if (!helper.isTblValid(db, tbl)) {
+                        // Table not valid
+                        System.out.println("ERROR: table not valid: " + tbl);
+                        action = "";
+                    }
+                }
+            }
+
+            renderRequest.setAttribute("rdbms", rdbms);
+            if (LISTTBLS_ACTION.equals(action)) {
+                renderRequest.setAttribute("db", db);
+                renderRequest.setAttribute("viewTables", viewTables);
+                renderRequest.setAttribute("ds", DerbyConnectionUtil
+                        .getDataSource(db));
+                listTablesView.include(renderRequest, renderResponse);
+            } else if (VIEWTBLCONTENTS_ACTION.equals(action)) {
+                renderRequest.setAttribute("db", db);
+                renderRequest.setAttribute("tbl", tbl);
+                renderRequest.setAttribute("viewTables", viewTables);
+                renderRequest.setAttribute("ds", DerbyConnectionUtil
+                        .getDataSource(db));
+                viewTableContentsView.include(renderRequest, renderResponse);
+            } else {
+                renderRequest.setAttribute("databases", helper
+                        .getDerbyDatabases(DERBY_HOME));
+                listDatabasesView.include(renderRequest, renderResponse);
+            }
+        } else {
+            maximizedView.include(renderRequest, renderResponse);
+        }
+    }
+
+    protected void doHelp(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws PortletException, IOException {
+        helpView.include(renderRequest, renderResponse);
+    }
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        super.init(portletConfig);
+        maximizedView = portletConfig.getPortletContext().getRequestDispatcher(
+                MAXIMIZEDVIEW_JSP);
+        helpView = portletConfig.getPortletContext().getRequestDispatcher(
+                HELPVIEW_JSP);
+        listDatabasesView = portletConfig.getPortletContext()
+                .getRequestDispatcher(LISTDATABASES_JSP);
+        listTablesView = portletConfig.getPortletContext()
+                .getRequestDispatcher(LISTTABLES_JSP);
+        viewTableContentsView = portletConfig.getPortletContext()
+                .getRequestDispatcher(VIEWTABLECONTENTS_JSP);
+    }
+
+    public void destroy() {
+        maximizedView = null;
+        helpView = null;
+        listDatabasesView = null;
+        listTablesView = null;
+        viewTableContentsView = null;
+        super.destroy();
+    }
+
+}
\ No newline at end of file

Propchange: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java?rev=219976&view=auto
==============================================================================
--- geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java (added)
+++ geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java Wed Jul 20 18:38:12 2005
@@ -0,0 +1,136 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.internaldb;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import javax.management.ObjectName;
+import javax.sql.DataSource;
+
+import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.kernel.jmx.JMXUtil;
+
+/**
+ * A static class to handle retreiving connections. This class is built to
+ * handle lookups to the SystemDatabase as a special case. If a connection is
+ * requested for the SystemDatabase this class gets a DataSource from an admin
+ * object registered in the geronimo kernel otherwise the DataSource is looked
+ * up via JNDI.
+ */
+public class DerbyConnectionUtil {
+
+    public static final String CREATE_DB_PROP = ";create=true";
+
+    public static final String SHUTDOWN_DB_PROP = ";shutdown=true";
+
+    private static final int RDBMS_DERBY = 1;
+
+    private static final int RDBMS_MSSQL = 2;
+
+    private static final String SYSTEM_DB = "SYSTEMDATABASE";
+
+    private static final String DERBY_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
+
+    private static final String PROTOCOL = "jdbc:derby:";
+
+    private static final String EMPTY_PROPS = "";
+
+    private static final ObjectName SYSTEM_DATASOURCE_NAME = JMXUtil
+            .getObjectName("geronimo.server:J2EEApplication=null,J2EEServer=geronimo,JCAResource=org/apache/geronimo/SystemDatabase,j2eeType=JCAManagedConnectionFactory,name=SystemDatasource");
+
+    /**
+     * Get database connection.
+     *
+     * @param dbName
+     * @return
+     * @throws SQLException
+     */
+    private static Connection getConnection(String dbName, String properties,
+            String protocol, String driver) throws SQLException {
+        try {
+            Class.forName(driver).newInstance();
+        } catch (Exception e) {
+            // Problem loading driver class
+            return null;
+        }
+        // If we are looking for the SystemDatabase get it from the kernel
+        // because it is not binded to our JNDI Context.
+        if (SYSTEM_DB.equalsIgnoreCase(dbName)) {
+            return getSystemDBConnection();
+        } else {
+            return DriverManager.getConnection(protocol + dbName + properties);
+        }
+    }
+
+    /**
+     * Get a connection to derby.
+     *
+     * @param dbName
+     *            the name of the database to connect to.
+     * @param properties
+     *            the properties to pass to the connection string.
+     * @return
+     */
+    public static Connection getDerbyConnection(String dbName, String properties)
+            throws SQLException {
+        return getConnection(dbName, properties, PROTOCOL, DERBY_DRIVER);
+    }
+
+    public static Connection getDerbyConnection(String dbName)
+            throws SQLException {
+        return getDerbyConnection(dbName, EMPTY_PROPS);
+    }
+
+    /**
+     * Get a connection to the SystemDatabase.
+     *
+     * @return
+     * @throws SQLException
+     */
+    public static Connection getSystemDBConnection() throws SQLException {
+        DataSource ds = null;
+        try {
+            ds = getDataSource(SYSTEM_DB);
+            return ds.getConnection();
+        } catch (Exception e) {
+            throw new SQLException(e.getMessage());
+        }
+    }
+
+    /**
+     * Get the datasource if dbName is == SYSTEM_DB, otherwise returns null.
+     *
+     * @param dbName
+     * @return
+     */
+    public static DataSource getDataSource(String dbName) {
+        try {
+            if (SYSTEM_DB.equalsIgnoreCase(dbName)) {
+                return (DataSource) KernelRegistry.getSingleKernel().invoke(
+                        SYSTEM_DATASOURCE_NAME, "$getResource");
+            } else {
+                return null;
+            }
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+}

Propchange: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBHelper.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBHelper.java?rev=219976&view=auto
==============================================================================
--- geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBHelper.java (added)
+++ geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBHelper.java Wed Jul 20 18:38:12 2005
@@ -0,0 +1,228 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.internaldb;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.Hashtable;
+import java.util.Map;
+
+public class InternalDBHelper {
+
+    private static final int RDBMS_DERBY = 1;
+
+    private static final int RDBMS_MSSQL = 2;
+
+    private static final String JNDI_DERBY = "java:comp/env/SystemDatasource";
+
+    private static final Map derbyDBInfo = new Hashtable();
+
+    /**
+     * Returns the database metadata as a map.
+     *
+     * @return
+     */
+    public Map getDBInfo() {
+        derbyDBInfo.clear();
+        Connection conn = null;
+        try {
+            conn = DerbyConnectionUtil.getSystemDBConnection();
+            DatabaseMetaData dbMD = (DatabaseMetaData) conn.getMetaData();
+
+            // DB
+            derbyDBInfo.put("URL", removeNull(dbMD.getURL()));
+            derbyDBInfo.put("Username", removeNull(dbMD.getUserName()));
+            derbyDBInfo.put("Read Only", removeNull(String.valueOf(dbMD
+                    .isReadOnly())));
+            derbyDBInfo.put("DB Product Name", removeNull(dbMD
+                    .getDatabaseProductName()));
+            derbyDBInfo.put("DB Product Version", removeNull(dbMD
+                    .getDatabaseProductVersion()));
+            derbyDBInfo.put("DB Major Version", removeNull(String.valueOf(dbMD
+                    .getDatabaseMajorVersion())));
+            derbyDBInfo.put("DB Minor Version", removeNull(String.valueOf(dbMD
+                    .getDatabaseMinorVersion())));
+
+            // Driver
+            derbyDBInfo.put("Driver Name", removeNull(dbMD.getDriverName()));
+            derbyDBInfo.put("Driver Version", removeNull(dbMD
+                    .getDriverVersion()));
+            derbyDBInfo.put("Driver Major Version", removeNull(String
+                    .valueOf(dbMD.getDriverMajorVersion())));
+            derbyDBInfo.put("Driver Minor Version", removeNull(String
+                    .valueOf(dbMD.getDriverMinorVersion())));
+
+            // JDBC
+            derbyDBInfo.put("JDBC Major Version", removeNull(String
+                    .valueOf(dbMD.getJDBCMajorVersion())));
+            derbyDBInfo.put("JDBC Minor Version", removeNull(String
+                    .valueOf(dbMD.getJDBCMinorVersion())));
+
+            // Functions
+            derbyDBInfo.put("Numeric Functions", removeNull(dbMD
+                    .getNumericFunctions()));
+            derbyDBInfo.put("String Functions", removeNull(dbMD
+                    .getStringFunctions()));
+            derbyDBInfo.put("System Functions", removeNull(dbMD
+                    .getSystemFunctions()));
+            derbyDBInfo.put("Time Date Functions", removeNull(dbMD
+                    .getTimeDateFunctions()));
+
+            // Etc
+            derbyDBInfo.put("Supported SQL Keywords", removeNull(dbMD
+                    .getSQLKeywords().replace(',', ' ')));
+            derbyDBInfo.put("Supported Types", removeNull(getColumnData(dbMD
+                    .getTypeInfo(), "TYPE_NAME")));
+            derbyDBInfo.put("Table Types", removeNull(getColumnData(dbMD
+                    .getTableTypes(), "TABLE_TYPE")));
+            derbyDBInfo.put("Schemas", removeNull(getColumnData(dbMD
+                    .getSchemas(), "TABLE_SCHEM")));
+            String tx = null;
+
+            switch (dbMD.getDefaultTransactionIsolation()) {
+            case Connection.TRANSACTION_NONE:
+                tx = "not supported";
+                break;
+            case Connection.TRANSACTION_READ_COMMITTED:
+                tx = "dirty reads are prevented; non-repeatable reads and phantom reads can occur";
+                break;
+            case Connection.TRANSACTION_READ_UNCOMMITTED:
+                tx = "dirty reads, non-repeatable reads and phantom reads can occur";
+                break;
+            case Connection.TRANSACTION_REPEATABLE_READ:
+                tx = "dirty reads and non-repeatable reads are prevented; phantom reads can occur";
+                break;
+            case Connection.TRANSACTION_SERIALIZABLE:
+                tx = "dirty reads, non-repeatable reads and phantom reads are prevented";
+                break;
+            default:
+                tx = "";
+                break;
+            }
+
+            derbyDBInfo.put("Default Transaction Isolation", removeNull(tx));
+            String holdability = null;
+
+            switch (dbMD.getResultSetHoldability()) {
+            case ResultSet.HOLD_CURSORS_OVER_COMMIT:
+                holdability = "hold cursors over commit";
+                break;
+            case ResultSet.CLOSE_CURSORS_AT_COMMIT:
+                holdability = "close cursors at commit";
+                break;
+            default:
+                holdability = "";
+                break;
+            }
+            derbyDBInfo.put("Result Set Holdability", removeNull(holdability));
+            String sqlStateType = null;
+
+            switch (dbMD.getSQLStateType()) {
+            case DatabaseMetaData.sqlStateXOpen:
+                sqlStateType = "X/Open SQL CLI";
+                break;
+            case DatabaseMetaData.sqlStateSQL99:
+                sqlStateType = "SQL99";
+                break;
+            default:
+                sqlStateType = "";
+                break;
+            }
+            derbyDBInfo.put("SQL State Type", removeNull(sqlStateType));
+        } catch (SQLException e) {
+            printSQLError((SQLException) e);
+        } finally {
+            // close DB connection
+            try {
+                if (conn != null) {
+                    conn.close();
+                }
+            } catch (SQLException e) {
+                // problem closing DB connection
+            }
+        }
+
+        return derbyDBInfo;
+    }
+
+    private String removeNull(String s) {
+        return ((s == null) ? "" : s);
+    }
+
+    /**
+     * Get a specific column data as a string separated by ','.
+     *
+     * @param rs
+     * @param colName
+     * @return
+     */
+    private String getColumnData(ResultSet rs, String colName) {
+        StringBuffer result = new StringBuffer();
+        try {
+            ResultSetMetaData rsmd = rs.getMetaData();
+
+            // 1) Get column number
+            int selectedCol = -1;
+            int numberOfColumns = rsmd.getColumnCount();
+            for (int i = 1; i <= numberOfColumns; i++) {
+                String columnName = rsmd.getColumnName(i);
+                if (columnName.equals(colName)) {
+                    selectedCol = i;
+                    break;
+                }
+            }
+
+            // 2) Get data
+            boolean firstData = true;
+            while (rs.next()) {
+                for (int i = 1; i <= numberOfColumns; i++) {
+                    if (i == selectedCol) {
+                        if (firstData) {
+                            firstData = false;
+                        } else {
+                            result.append(',');
+                        }
+                        String columnValue = rs.getString(i);
+                        result.append(columnValue);
+                    }
+                }
+            }
+        } catch (SQLException e) {
+            printSQLError((SQLException) e);
+        }
+
+        return result.toString();
+    }
+
+    /**
+     * Print the SQL exception including chained exceptions
+     * if there is one.
+     *
+     * @param e
+     */
+    private void printSQLError(SQLException e) {
+        while (e != null) {
+            System.out.println(e.toString());
+            e = e.getNextException();
+        }
+    }
+
+}
\ No newline at end of file

Propchange: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBPortlet.java?rev=219976&view=auto
==============================================================================
--- geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBPortlet.java (added)
+++ geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBPortlet.java Wed Jul 20 18:38:12 2005
@@ -0,0 +1,104 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.internaldb;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+public class InternalDBPortlet extends GenericPortlet {
+
+    private static final String NORMALVIEW_JSP = "/WEB-INF/view/internaldb/internalDBNormal.jsp";
+
+    private static final String MAXIMIZEDVIEW_JSP = "/WEB-INF/view/internaldb/internalDBMaximized.jsp";
+
+    private static final String HELPVIEW_JSP = "/WEB-INF/view/internaldb/internalDBHelp.jsp";
+
+    private static InternalDBHelper helper = new InternalDBHelper();
+
+    private static Map javaSysInfo = new HashMap();
+
+    private PortletRequestDispatcher normalView;
+
+    private PortletRequestDispatcher maximizedView;
+
+    private PortletRequestDispatcher helpView;
+
+    public void processAction(ActionRequest actionRequest,
+            ActionResponse actionResponse) throws PortletException, IOException {
+        // Getting parameters here because it fails on doView()
+        String rdbms = actionRequest.getParameter("rdbms");
+        if (rdbms != null) {
+            actionResponse.setRenderParameter("rdbms", rdbms);
+        }
+    }
+
+    protected void doView(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws IOException, PortletException {
+        if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
+            return;
+        }
+
+        String rdbmsParam = renderRequest.getParameter("rdbms");
+        int rdbms = 1;
+        if ((rdbmsParam != null) && (rdbmsParam.length() > 0)) {
+            rdbms = Integer.parseInt(rdbmsParam);
+        }
+        Map internalDB = helper.getDBInfo();
+        renderRequest.setAttribute("internalDB", internalDB);
+
+        if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
+            normalView.include(renderRequest, renderResponse);
+        } else {
+            maximizedView.include(renderRequest, renderResponse);
+        }
+    }
+
+    protected void doHelp(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws PortletException, IOException {
+        helpView.include(renderRequest, renderResponse);
+    }
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        super.init(portletConfig);
+        normalView = portletConfig.getPortletContext().getRequestDispatcher(
+                NORMALVIEW_JSP);
+        maximizedView = portletConfig.getPortletContext().getRequestDispatcher(
+                MAXIMIZEDVIEW_JSP);
+        helpView = portletConfig.getPortletContext().getRequestDispatcher(
+                HELPVIEW_JSP);
+    }
+
+    public void destroy() {
+        normalView = null;
+        maximizedView = null;
+        helpView = null;
+        super.destroy();
+    }
+
+}
\ No newline at end of file

Propchange: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java?rev=219976&view=auto
==============================================================================
--- geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java (added)
+++ geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java Wed Jul 20 18:38:12 2005
@@ -0,0 +1,218 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.internaldb;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class RunSQLHelper {
+
+    public static final String SQL_SUCCESS_MSG = "SQL command/s successful";
+
+    public static final String SQL_EMPTY_MSG = "SQL Command/s can't be empty";
+
+    private static final String DB_CREATED_MSG = "Database created";
+
+    private static final String DB_DELETED_MSG = "Database deleted";
+
+    private static final String DERBY_BACKUP_FOLDER = "derby.backup";
+
+    private static final String PARENT_FOLDER = "..";
+
+    private static final String BAK_EXTENSION = ".bak";
+
+    private static final String BAK_PREFIX = "BAK_";
+
+    public String createDB(String dbName) {
+        String result = DB_CREATED_MSG + ": " + dbName;
+
+        Connection conn = null;
+        try {
+            conn = DerbyConnectionUtil.getDerbyConnection(dbName,
+                    DerbyConnectionUtil.CREATE_DB_PROP);
+        } catch (Throwable e) {
+            if (e instanceof SQLException) {
+                result = getSQLError((SQLException) e);
+            } else {
+                result = e.getMessage();
+            }
+        } finally {
+            // close DB connection
+            try {
+                if (conn != null) {
+                    conn.close();
+                }
+            } catch (SQLException e) {
+                result = "Problem closing DB connection";
+            }
+        }
+
+        return result;
+    }
+
+    public String backupDB(String derbyHome, String dbName) {
+        return "";
+    }
+
+    public String restoreDB(String derbyHome, String dbName) {
+        return "";
+    }
+
+    public String deleteDB(String derbyHome, String dbName) {
+        String result = DB_DELETED_MSG + ": " + dbName;
+
+        // shutdown database before deleting it
+        if (!shutdownDB(dbName)) {
+            result = "Database not deleted: " + dbName
+                    + " Couldn't shutdown db: " + dbName;
+            return result;
+        }
+
+        try {
+            // create backup folder if not created
+            File derbyBackupFolder = new File(derbyHome + File.separatorChar
+                    + PARENT_FOLDER + File.separatorChar + DERBY_BACKUP_FOLDER);
+            if (!derbyBackupFolder.exists()) {
+                if (!derbyBackupFolder.mkdirs()) {
+                    result = "Database not deleted: " + dbName
+                            + " Derby backup folder not created: "
+                            + derbyBackupFolder;
+                    return result;
+                }
+            }
+
+            File oldDBFolder = new File(derbyHome + File.separatorChar + dbName);
+            if (oldDBFolder.exists()) {
+                // Need to add a prefix because File.createTempFile's first
+                // argument must be a String at least three characters long.
+                File tmpFile = File.createTempFile(BAK_PREFIX + dbName,
+                        BAK_EXTENSION, derbyBackupFolder);
+                File newDBFolder = new File(tmpFile.getAbsolutePath());
+                /*
+                 * Delete temp file and create a temp folder using the temp
+                 * filename
+                 */
+                if (tmpFile.delete()) {
+                    if (newDBFolder.mkdirs()) {
+                        if (!oldDBFolder.renameTo(new File(newDBFolder,
+                                oldDBFolder.getName()))) {
+                            result = "Database not deleted: " + dbName
+                                    + " DB folder not renamed";
+                            return result;
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return result;
+    }
+
+    public String runSQL(String dbName, String sql) {
+        String result = SQL_SUCCESS_MSG;
+
+        if ((sql == null) || (sql.trim().length() == 0)) {
+            result = SQL_EMPTY_MSG;
+            return result;
+        }
+
+        Connection conn = null;
+        Statement s = null;
+        try {
+
+            conn = DerbyConnectionUtil.getDerbyConnection(dbName);
+            conn.setAutoCommit(false);
+
+            s = conn.createStatement();
+            String[] sqlCmds = sql.split(";");
+            for (int i = 0; i < sqlCmds.length; i++) {
+                if (sqlCmds[i].trim().length() > 0) {
+                    // debug printout (remove later)
+                    System.out.println("SQL" + i + ": <" + sqlCmds[i].trim()
+                            + ">");
+                    s.execute(sqlCmds[i]);
+                }
+            }
+            conn.commit();
+        } catch (Throwable e) {
+            if (e instanceof SQLException) {
+                result = getSQLError((SQLException) e);
+            } else {
+                result = e.getMessage();
+            }
+        } finally {
+            // close DB connection
+            try {
+                if (s != null) {
+                    s.close();
+                }
+                if (conn != null) {
+                    conn.close();
+                }
+            } catch (SQLException e) {
+                if (SQL_SUCCESS_MSG.equals(result)) {
+                    result = "Problem closing DB connection: " + e.getMessage();
+                }
+            }
+        }
+
+        return result;
+    }
+
+    private boolean shutdownDB(String dbName) {
+        boolean ok = true;
+
+        boolean gotSQLExc = false;
+        try {
+            DerbyConnectionUtil.getDerbyConnection(dbName,
+                    DerbyConnectionUtil.SHUTDOWN_DB_PROP);
+        } catch (SQLException se) {
+            gotSQLExc = true;
+        }
+
+        if (!gotSQLExc) {
+            ok = false;
+        }
+
+        return ok;
+    }
+
+    private String getSQLError(SQLException e) {
+        StringBuffer errorMsg = new StringBuffer();
+        while (e != null) {
+            //errorMsg.append(e.toString());
+            errorMsg.append(e.getMessage());
+            errorMsg.append(" * ");
+            e = e.getNextException();
+        }
+
+        return errorMsg.toString();
+    }
+
+    public static void main(String[] args) {
+        new RunSQLHelper().runSQL("derbyDB4",
+                "create table derbyTbl1(num int, addr varchar(40));"
+                        + "create table derbyTbl2(num int, addr varchar(40));"
+                        + "create table derbyTbl3(num int, addr varchar(40));"
+                        + "insert into derb");
+    }
+}

Propchange: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLPortlet.java?rev=219976&view=auto
==============================================================================
--- geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLPortlet.java (added)
+++ geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLPortlet.java Wed Jul 20 18:38:12 2005
@@ -0,0 +1,168 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.internaldb;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+public class RunSQLPortlet extends GenericPortlet {
+
+    private static final String NORMALVIEW_JSP = "/WEB-INF/view/internaldb/runSQLNormal.jsp";
+
+    private static final String MAXIMIZEDVIEW_JSP = "/WEB-INF/view/internaldb/runSQLMaximized.jsp";
+
+    private static final String HELPVIEW_JSP = "/WEB-INF/view/internaldb/runSQLHelp.jsp";
+
+    private static final String CREATEDB_ACTION = "Create";
+
+    private static final String DELETEDB_ACTION = "Delete";
+
+    private static final String RUNSQL_ACTION = "Run SQL";
+
+    private static final String BACKUPDB_ACTION = "Backup";
+
+    private static final String RESTOREDB_ACTION = "Restore";
+
+    private static RunSQLHelper sqlHelper = new RunSQLHelper();
+
+    private static DBViewerHelper dbHelper = new DBViewerHelper();
+
+    private static String derbyHome = System.getProperty("derby.system.home");
+
+    private PortletRequestDispatcher normalView;
+
+    private PortletRequestDispatcher maximizedView;
+
+    private PortletRequestDispatcher helpView;
+
+    private Collection databases;
+
+    private String action;
+
+    private String createDB;
+
+    private String deleteDB;
+
+    private String useDB;
+
+    private String backupDB;
+
+    private String restoreDB;
+
+    private String sqlStmts;
+
+    private String actionResult;
+
+    public void processAction(ActionRequest actionRequest,
+            ActionResponse actionResponse) throws PortletException, IOException {
+        // Getting parameters here because it fails on doView()
+        action = actionRequest.getParameter("action");
+        createDB = actionRequest.getParameter("createDB");
+        deleteDB = actionRequest.getParameter("deleteDB");
+        useDB = actionRequest.getParameter("useDB");
+        backupDB = actionRequest.getParameter("backupDB");
+        restoreDB = actionRequest.getParameter("restoreDB");
+        sqlStmts = actionRequest.getParameter("sqlStmts");
+        actionResult = "";
+        if (CREATEDB_ACTION.equals(action)) {
+            actionResult = sqlHelper.createDB(createDB);
+        } else if (DELETEDB_ACTION.equals(action)) {
+            actionResult = sqlHelper.deleteDB(derbyHome, deleteDB);
+        } else if (RUNSQL_ACTION.equals(action)) {
+            actionResult = sqlHelper.runSQL(useDB, sqlStmts);
+        } else if (BACKUPDB_ACTION.equals(action)) {
+            actionResult = sqlHelper.backupDB(derbyHome, backupDB);
+        } else if (RESTOREDB_ACTION.equals(action)) {
+            actionResult = sqlHelper.restoreDB(derbyHome, restoreDB);
+        }
+    }
+
+    protected void doView(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws IOException, PortletException {
+        if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
+            return;
+        }
+
+        String singleSelectStmt;
+        if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
+            databases = dbHelper.getDerbyDatabases(derbyHome);
+            renderRequest.setAttribute("databases", databases);
+            if (RUNSQL_ACTION.equals(action)) {
+                // check if it's a single Select statement
+                if ((sqlStmts != null) && (sqlStmts.trim().indexOf(';') == -1)
+                        && sqlStmts.trim().toUpperCase().startsWith("SELECT")
+                        && RunSQLHelper.SQL_SUCCESS_MSG.equals(actionResult)) {
+                    singleSelectStmt = sqlStmts.trim();
+                    // set action result to blank so it won't display
+                    actionResult = "";
+                } else {
+                    singleSelectStmt = "";
+                }
+                renderRequest.setAttribute("useDB", useDB);
+                renderRequest
+                        .setAttribute("singleSelectStmt", singleSelectStmt);
+                renderRequest.setAttribute("ds", DerbyConnectionUtil
+                        .getDataSource(useDB));
+            }
+            if ((action != null) && (action.trim().length() > 0)) {
+                renderRequest.setAttribute("actionResult", actionResult);
+                //set action to null so that subsequent renders of portlet
+                // won't display
+                //action result if there is no action to process
+                action = null;
+            }
+            normalView.include(renderRequest, renderResponse);
+        } else {
+            maximizedView.include(renderRequest, renderResponse);
+        }
+    }
+
+    protected void doHelp(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws PortletException, IOException {
+        helpView.include(renderRequest, renderResponse);
+    }
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        super.init(portletConfig);
+        normalView = portletConfig.getPortletContext().getRequestDispatcher(
+                NORMALVIEW_JSP);
+        maximizedView = portletConfig.getPortletContext().getRequestDispatcher(
+                MAXIMIZEDVIEW_JSP);
+        helpView = portletConfig.getPortletContext().getRequestDispatcher(
+                HELPVIEW_JSP);
+        databases = dbHelper.getDerbyDatabases(derbyHome);
+    }
+
+    public void destroy() {
+        normalView = null;
+        maximizedView = null;
+        helpView = null;
+        super.destroy();
+    }
+
+}

Propchange: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/AbstractJMSManager.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/AbstractJMSManager.java?rev=219976&view=auto
==============================================================================
--- geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/AbstractJMSManager.java (added)
+++ geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/AbstractJMSManager.java Wed Jul 20 18:38:12 2005
@@ -0,0 +1,122 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.jmsmanager;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
+import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContextImpl;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.KernelRegistry;
+
+public abstract class AbstractJMSManager {
+
+    protected static final String JMS_SERVER_MBEAN_NAME = "geronimo.server:J2EEApplication=null,J2EEModule=org/apache/geronimo/ActiveMQServer,J2EEServer=geronimo,j2eeType=JMSServer,name=ActiveMQl";
+
+    protected static final String GET_BROKER_ADMIN_FUNCTION = "getBrokerAdmin";
+
+    public static final String TOPIC_TYPE = "Topic";
+
+    public static final String QUEUE_TYPE = "Queue";
+
+    //ViewDestinations attribute names
+    protected static final String DESTINATION_LIST = "destinations";
+
+    protected static final String DESTINATION_MSG = "destinationsMsg";
+
+    //CreateDestinations attribute names
+    protected static final String DESTINATION_NAME = "destinationMessageDestinationName";
+
+    protected static final String DESTINATION_PHYSICAL_NAME = "destinationPhysicalName";
+
+    protected static final String DESTINATION_TYPE = "destinationType";
+
+    protected static final String DESTINATION_APPLICATION_NAME = "destinationApplicationName";
+
+    protected static final String DESTINATION_MODULE_NAME = "destinationModuleName";
+
+    protected static final String DESTINATION_CONFIG_URI = "destinationConfigURI";
+
+    protected static final String CONNECTION_FACTORY_NAME = "geronimo.server:J2EEApplication=null,J2EEServer=geronimo,JCAResource=org/apache/geronimo/SystemJMS,j2eeType=JCAManagedConnectionFactory,name=DefaultActiveMQConnectionFactory";
+
+    protected static Object[] no_args = new Object[0];
+
+    protected static String[] no_params = new String[0];
+
+    protected static Kernel kernel = KernelRegistry.getSingleKernel();
+
+    protected static final String BASE_CONFIG_URI = "runtimedestination/";
+
+    protected ObjectName mBeanName;
+
+    public static final ObjectName DESTINATION_QUERY;
+
+    public static final ObjectName ACTIVEMQJCA_RESOURCE_QUERY;
+
+    public static final String ACTIVEMQJCA_RESOURCE;
+
+    static {
+        try {
+
+            DESTINATION_QUERY = ObjectName
+                    .getInstance("geronimo.server:j2eeType="
+                            + NameFactory.JCA_ADMIN_OBJECT + ",*");
+            ACTIVEMQJCA_RESOURCE_QUERY = ObjectName
+                    .getInstance("*:j2eeType=JCAManagedConnectionFactory,name=DefaultActiveMQConnectionFactory,*");
+            ACTIVEMQJCA_RESOURCE = getActiveMQJCA_RESOURCE(ACTIVEMQJCA_RESOURCE_QUERY);
+
+            if (null == ACTIVEMQJCA_RESOURCE) {
+                throw new RuntimeException(
+                        "No JCA resource was found for DefaultActiveMQConnectionFactory");
+            }
+
+        } catch (MalformedObjectNameException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static final J2eeContext baseContext = new J2eeContextImpl(
+            "geronimo.server", "geronimo", "null", ACTIVEMQJCA_RESOURCE, null,
+            null, NameFactory.JCA_ADMIN_OBJECT);
+
+    /**
+     * Get the JCA resource name of the activemq bean.
+     *
+     * @return JCA resource name
+     */
+    public static String getActiveMQJCA_RESOURCE(ObjectName obj) {
+
+        Set modules = kernel.listGBeans(obj);
+
+        String JCA_Resource = null;
+
+        for (Iterator iterator = modules.iterator(); iterator.hasNext();) {
+            ObjectName activemqObject = (ObjectName) iterator.next();
+            JCA_Resource = activemqObject
+                    .getKeyProperty(NameFactory.JCA_RESOURCE);
+        }
+
+        return JCA_Resource;
+    }
+
+}

Propchange: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/AbstractJMSManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/DestinationInfo.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/DestinationInfo.java?rev=219976&view=auto
==============================================================================
--- geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/DestinationInfo.java (added)
+++ geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/DestinationInfo.java Wed Jul 20 18:38:12 2005
@@ -0,0 +1,132 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.jmsmanager;
+
+import javax.jms.Queue;
+
+public class DestinationInfo implements Comparable {
+
+    private final String name;
+
+    private final String physicalName;
+
+    private final Class type;
+
+    private final String applicationName;
+
+    private final String moduleName;
+
+    private final String configURI;
+
+    public DestinationInfo(String name, String physicalName, Class type,
+            String applicationName, String moduleName, String configURI) {
+        this.name = name;
+        this.physicalName = physicalName;
+        this.type = type;
+        this.applicationName = applicationName;
+        this.moduleName = moduleName;
+        this.configURI = configURI;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getPhysicalName() {
+        return physicalName;
+    }
+
+    public Class getType() {
+        return type;
+    }
+
+    public String getApplicationName() {
+        return applicationName;
+    }
+
+    public String getModuleName() {
+        return moduleName;
+    }
+
+    public String getConfigURI() {
+        return configURI;
+    }
+
+    /**
+     * Determines if the destination that this objects represents is viewable
+     * from the console this means that either the destination that this object
+     * represents was added via the Geronimo JMS Console or it is a Queue.
+     *
+     * @return true if the console knows how to display this Destination
+     *         otherwise returns false.
+     */
+    public boolean isViewable() {
+        return Queue.class.isAssignableFrom(type) || isConsoleManaged();
+    }
+
+    /**
+     * Determines if the destination that this objects represents is removable
+     * from the console this means that the destination that this object
+     * represents was added via the Geronimo JMS Console.
+     *
+     * @return true if the console knows how to remove this Destination
+     *         otherwise returns false.
+     */
+    public boolean isRemovable() {
+        return isConsoleManaged();
+    }
+
+    /**
+     * Determines if the destination that this objects represents was added via
+     * the console.
+     *
+     * @return true if the destination that this objects represents was added
+     *         via the console otherwise returns false.
+     */
+    private boolean isConsoleManaged() {
+        return configURI.indexOf(AbstractJMSManager.BASE_CONFIG_URI + name) > -1;
+    }
+
+    public int compareTo(Object o) {
+        if (o instanceof DestinationInfo) {
+            DestinationInfo rhs = (DestinationInfo) o;
+            // If one of the objects is removable and the other is not, the
+            // removable one is less (comes first in a descending sort).
+            if (rhs.isRemovable() != this.isRemovable()) {
+                if (this.isRemovable()) {
+                    return -1;
+                } else {
+                    return 1;
+                }
+                // If one of the objects is viewable and the other is not the
+                // viewable one is less (comes first in a descending sort).
+            } else if (rhs.isViewable() != this.isViewable()) {
+                if (this.isViewable()) {
+                    return -1;
+                } else {
+                    return 1;
+                }
+                // Sort by name if all else fails.
+            } else {
+                return this.name.compareTo(rhs.getName());
+            }
+        }
+        return 1;
+    }
+
+}

Propchange: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/DestinationInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/JMSConnectionFactoryManagerPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/JMSConnectionFactoryManagerPortlet.java?rev=219976&view=auto
==============================================================================
--- geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/JMSConnectionFactoryManagerPortlet.java (added)
+++ geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/JMSConnectionFactoryManagerPortlet.java Wed Jul 20 18:38:12 2005
@@ -0,0 +1,306 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.jmsmanager;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+import org.apache.geronimo.console.databasemanager.DataSourceInfo;
+import org.apache.geronimo.console.jmsmanager.activemqCF.ActiveMQConnectorHelper;
+import org.apache.geronimo.gbean.GAttributeInfo;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.kernel.jmx.JMXUtil;
+
+public class JMSConnectionFactoryManagerPortlet extends GenericPortlet {
+
+    private final static ActiveMQConnectorHelper helper = new ActiveMQConnectorHelper();
+
+    private final static String PARENT_ID = "org/apache/geronimo/SystemJMS";
+
+    private final static String ADD_MODE = "addACF";
+
+    private final static String SUBMIT_CREATE = "Create";
+
+    private final ObjectName DATABASE_QUERY = JMXUtil
+            .getObjectName("*:j2eeType=JCAManagedConnectionFactory,*");
+
+    protected final String NORMAL_VIEW = "/WEB-INF/view/jmsmanager/activemq/normal.jsp";;
+
+    protected final String DETAIL_VIEW = "/WEB-INF/view/jmsmanager/activemq/detail.jsp";
+
+    protected final String HELP_VIEW = "/WEB-INF/view/jmsmanager/activemq/help.jsp";;
+
+    protected final String ADD_VIEW = "/WEB-INF/view/jmsmanager/activemq/addACF.jsp";
+
+    protected Kernel kernel;
+
+    private PortletRequestDispatcher normalView;
+
+    private PortletRequestDispatcher detailView;
+
+    private PortletRequestDispatcher helpView;
+
+    private PortletRequestDispatcher addView;
+
+    private static final Set HIDDEN_ATTRIBUTES;
+
+    static {
+        HIDDEN_ATTRIBUTES = new HashSet();
+        HIDDEN_ATTRIBUTES.add("kernel");
+        HIDDEN_ATTRIBUTES.add("connectionImplClass");
+        HIDDEN_ATTRIBUTES.add("connectionInterface");
+        HIDDEN_ATTRIBUTES.add("connectionFactoryInterface");
+        HIDDEN_ATTRIBUTES.add("connectionFactoryImplClass");
+        HIDDEN_ATTRIBUTES.add("implementedInterfaces");
+        HIDDEN_ATTRIBUTES.add("managedConnectionFactoryClass");
+        HIDDEN_ATTRIBUTES.add("recoveryXAResources");
+    }
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        super.init(portletConfig);
+        kernel = KernelRegistry.getSingleKernel();
+        PortletContext context = portletConfig.getPortletContext();
+        normalView = context.getRequestDispatcher(NORMAL_VIEW);
+        detailView = context.getRequestDispatcher(DETAIL_VIEW);
+        helpView = context.getRequestDispatcher(HELP_VIEW);
+        addView = context.getRequestDispatcher(ADD_VIEW);
+    }
+
+    public void processAction(ActionRequest actionRequest,
+            ActionResponse actionResponse) throws PortletException, IOException {
+        String mode = actionRequest.getParameter("mode");
+        String submit = actionRequest.getParameter("submit");
+
+        if (mode == null) {
+            return;
+        } else if (ADD_MODE.equals(mode)) {
+            actionResponse.setRenderParameter("mode", mode);
+            if (SUBMIT_CREATE.equals(submit)) {
+                String acfName = actionRequest.getParameter("acfName");
+                String jndiName = actionRequest.getParameter("jndiName");
+                String serverURL = actionRequest.getParameter("serverURL");
+                String userName = actionRequest.getParameter("userName");
+                String pword = actionRequest.getParameter("pword");
+                String poolMaxSize = actionRequest.getParameter("poolMaxSize");
+                String blocking = actionRequest.getParameter("blocking");
+
+                String[] args = { trimStr(acfName), trimStr(PARENT_ID),
+                        trimStr(acfName), trimStr(serverURL),
+                        trimStr(userName), pword, trimStr(acfName),
+                        trimStr(poolMaxSize), trimStr(blocking),
+                        trimStr(jndiName) };
+                helper.deployPlan(args);
+                // Set mode to list after creating the new ConnectionFactories
+                actionResponse.setRenderParameter("mode", "list");
+            }
+            return;
+        }
+
+        String name = actionRequest.getParameter("name");
+        if (name != null) {
+            actionResponse.setRenderParameter("mode", "list");
+            return;
+        }
+    }
+
+    protected void doView(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws IOException, PortletException {
+        if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
+            return;
+        }
+
+        List dependencies = helper.getDependencies();
+        // pass them to the render request
+        renderRequest.setAttribute("dependencies", (String[]) dependencies
+                .toArray(new String[dependencies.size()]));
+
+        String name = renderRequest.getParameter("name");
+        String mode = renderRequest.getParameter("mode");
+        String check = renderRequest.getParameter("check");
+
+        if (ADD_MODE.equals(mode)) {
+            addView.include(renderRequest, renderResponse);
+            return;
+        }
+
+        boolean test = false;
+        if (name == null || mode == null) {
+            mode = "list";
+        }
+        if ("true".equals(check)) {
+            test = true;
+        }
+        if ("detail".equals(mode) || "config".equals(mode)) {
+            renderDetail(renderRequest, renderResponse, name);
+        } else {
+            renderList(renderRequest, renderResponse, name, test);
+        }
+    }
+
+    private void renderList(RenderRequest renderRequest,
+            RenderResponse renderResponse, String name, boolean check)
+            throws PortletException, IOException {
+
+        Set gbeanNames = kernel.listGBeans(DATABASE_QUERY);
+        List connectionFactories = new ArrayList(gbeanNames.size());
+        for (Iterator i = gbeanNames.iterator(); i.hasNext();) {
+            ObjectName gbeanName = (ObjectName) i.next();
+
+            // check that this connector is a DataSource
+            try {
+                Class cfInterface = Class.forName((String) kernel.getAttribute(
+                        gbeanName, "connectionFactoryInterface"));
+                if (!(ConnectionFactory.class).isAssignableFrom(cfInterface)) {
+                    continue;
+                }
+            } catch (Exception e) {
+                throw new PortletException(e);
+            }
+
+            DataSourceInfo info = new DataSourceInfo();
+            info.setObjectName(gbeanName);
+            info.setName(gbeanName.getKeyProperty("name"));
+            try {
+                info.setJndiName((String) kernel.getAttribute(gbeanName,
+                        "globalJNDIName"));
+                info
+                        .setState((Integer) kernel.getAttribute(gbeanName,
+                                "state"));
+                //check if user asked this connection to be tested
+                if ((gbeanName.toString().equals(name)) && (check)) {
+                    info.setWorking(true);
+                    try {
+                        Object cf = kernel.invoke(gbeanName, "$getResource");
+                        testConnection(cf);
+                        info.setMessage("Connected");
+                    } catch (Exception e) {
+                        Throwable t = e;
+                        String message = "Failed: ";
+                        if (t.getMessage() != null) {
+                            message = message + t.getMessage();
+                        } else {
+                            while (t.getMessage() == null) {
+                                t = t.getCause();
+                                if (t != null) {
+                                    message = message + t.getMessage();
+                                } else {
+                                    message = message + "Unknown reason";
+                                }
+                            }
+                        }
+                        info.setMessage(message);
+                    }
+                } else {
+                    info.setWorking(false);
+                }
+
+            } catch (Exception e) {
+                throw new PortletException(e);
+            }
+            connectionFactories.add(info);
+        }
+        Collections.sort(connectionFactories);
+        renderRequest.setAttribute("cFactories", connectionFactories);
+
+        normalView.include(renderRequest, renderResponse);
+    }
+
+    private void renderDetail(RenderRequest renderRequest,
+            RenderResponse renderResponse, String name)
+            throws PortletException, IOException {
+        ObjectName gbeanName;
+
+        try {
+            gbeanName = new ObjectName(name);
+        } catch (MalformedObjectNameException e) {
+            throw new PortletException("Malformed parameter name: "
+                    + renderRequest.getParameter("name"));
+        }
+
+        try {
+            GBeanInfo gbeanInfo = kernel.getGBeanInfo(gbeanName);
+            Set attributes = gbeanInfo.getAttributes();
+            Map values = new HashMap(attributes.size());
+            for (Iterator i = attributes.iterator(); i.hasNext();) {
+                GAttributeInfo attribute = (GAttributeInfo) i.next();
+                String gname = attribute.getName();
+                if (HIDDEN_ATTRIBUTES.contains(gname)) {
+                    continue;
+                }
+                Object value = kernel.getAttribute(gbeanName, gname);
+                values.put(gname, value);
+            }
+            renderRequest.setAttribute("attributeMap", values);
+        } catch (Exception e) {
+            throw new PortletException(e);
+        }
+
+        detailView.include(renderRequest, renderResponse);
+    }
+
+    protected void doHelp(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws PortletException, IOException {
+        helpView.include(renderRequest, renderResponse);
+    }
+
+    public void destroy() {
+        normalView = null;
+        helpView = null;
+        addView = null;
+        kernel = null;
+        super.destroy();
+    }
+
+    private String trimStr(String str) {
+        if (str != null) {
+            return str.trim();
+        }
+        return "";
+    }
+
+    protected void testConnection(Object cf) throws Exception {
+        ConnectionFactory jmscf = (ConnectionFactory) cf;
+        Connection c = jmscf.createConnection();
+        c.close();
+    }
+
+}

Propchange: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/JMSConnectionFactoryManagerPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/JMSManagerPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/JMSManagerPortlet.java?rev=219976&view=auto
==============================================================================
--- geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/JMSManagerPortlet.java (added)
+++ geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/JMSManagerPortlet.java Wed Jul 20 18:38:12 2005
@@ -0,0 +1,141 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.jmsmanager;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jms.ConnectionFactory;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+import org.apache.geronimo.console.jmsmanager.handlers.CreateDestinationHandler;
+import org.apache.geronimo.console.jmsmanager.handlers.PortletResponseHandler;
+import org.apache.geronimo.console.jmsmanager.handlers.RemoveDestinationHandler;
+import org.apache.geronimo.console.jmsmanager.handlers.StatisticsHandler;
+import org.apache.geronimo.console.jmsmanager.renderers.CreateDestinationRenderer;
+import org.apache.geronimo.console.jmsmanager.renderers.PortletRenderer;
+import org.apache.geronimo.console.jmsmanager.renderers.StatisticsRenderer;
+import org.apache.geronimo.console.jmsmanager.renderers.ViewDLQRenderer;
+import org.apache.geronimo.console.jmsmanager.renderers.ViewDestinationsRenderer;
+import org.apache.geronimo.console.jmsmanager.renderers.ViewMessagesRenderer;
+
+public class JMSManagerPortlet extends GenericPortlet {
+
+    private PortletRequestDispatcher edit;
+
+    private PortletRequestDispatcher help;
+
+    private ConnectionFactory cf;
+
+    private Map handlers;
+
+    private Map renderers;
+
+    private PortletContext context;
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        super.init(portletConfig);
+
+        context = portletConfig.getPortletContext();
+
+        help = context
+                .getRequestDispatcher("/WEB-INF/view/jmsmanager/help.jsp");
+        edit = context
+                .getRequestDispatcher("/WEB-INF/view/jmsmanager/edit.jsp");
+
+        renderers = new HashMap();
+        renderers.put("createDestination", new CreateDestinationRenderer());
+        renderers.put("viewDestinations", new ViewDestinationsRenderer());
+        renderers.put("statistics", new StatisticsRenderer());
+        renderers.put("viewMessages", new ViewMessagesRenderer());
+        renderers.put("viewDLQ", new ViewDLQRenderer());
+
+        handlers = new HashMap();
+        handlers.put("createDestination", new CreateDestinationHandler());
+        handlers.put("removeDestination", new RemoveDestinationHandler());
+        handlers.put("statistics", new StatisticsHandler());
+
+    }
+
+    public void doHelp(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws PortletException, IOException {
+        help.include(renderRequest, renderResponse);
+    }
+
+    public void doView(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws IOException, PortletException {
+
+        if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
+            return;
+        }
+
+        String view = renderRequest.getParameter("processAction");
+        if (view == null) {
+            // no specific content requested - show the destinations list
+            view = "viewDestinations";
+        }
+
+        PortletRenderer renderer = (PortletRenderer) renderers.get(view);
+        if (renderer == null) {
+            throw new PortletException("Invalid view parameter specified: "
+                    + view);
+        }
+
+        String include = renderer.render(renderRequest, renderResponse);
+        if (include != null) {
+            PortletRequestDispatcher requestDispatcher = context
+                    .getRequestDispatcher(include);
+            requestDispatcher.include(renderRequest, renderResponse);
+        }
+
+    }
+
+    public void processAction(ActionRequest actionRequest,
+            ActionResponse actionResponse) throws PortletException, IOException {
+        String processAction = actionRequest.getParameter("processaction");
+
+        PortletResponseHandler handler = (PortletResponseHandler) handlers
+                .get(processAction);
+
+        if (handler == null) {
+            // throw new RuntimeException( "no handlers for processAction = " +
+            // processAction );
+            handler = (PortletResponseHandler) handlers.get("viewDestinations");
+        }
+
+        handler.processAction(actionRequest, actionResponse);
+    }
+
+    public void destroy() {
+
+        help = null;
+        edit = null;
+        super.destroy();
+    }
+
+}

Propchange: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/JMSManagerPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/activemqCF/ActiveMQConnectorHelper.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/activemqCF/ActiveMQConnectorHelper.java?rev=219976&view=auto
==============================================================================
--- geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/activemqCF/ActiveMQConnectorHelper.java (added)
+++ geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/activemqCF/ActiveMQConnectorHelper.java Wed Jul 20 18:38:12 2005
@@ -0,0 +1,270 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.console.jmsmanager.activemqCF;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.management.ObjectName;
+
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.console.util.ObjectNameConstants;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.kernel.config.ConfigurationManager;
+import org.apache.geronimo.kernel.config.ConfigurationUtil;
+import org.apache.geronimo.kernel.jmx.JMXUtil;
+
+public class ActiveMQConnectorHelper {
+
+    private final static File REPO_FOLDER;
+
+    private final static String PLAN_FILE;
+
+    private final static String MODULE_FILE;
+
+    private final static String ACTIVEMQ_RA = "/activemq/rars/activemq-ra-3.1-SNAPSHOT.rar";
+
+    private final static String PLAN_XML = "/activemq/rars/amqconnectorPlan.xml";
+
+    private static final String LINE_SEP = System.getProperty("line.separator");
+
+    private static final String PLAN_TEMPLATE = getPlanTemplate();
+
+    // Deployer
+    private static final ObjectName DEPLOYER_NAME = JMXUtil
+            .getObjectName(ObjectNameConstants.DEPLOYER_OBJECT_NAME);
+
+    private static final String[] DEPLOYER_ARGS = { File.class.getName(),
+            File.class.getName() };
+
+    private static final String DEPLOY_METHOD = "deploy";
+
+    // Repository
+    private static final ObjectName REPO_NAME = JMXUtil
+            .getObjectName(ObjectNameConstants.REPO_OBJECT_NAME);
+
+    private static final String[] REPO_ARGS = { URI.class.getName() };
+
+    private static final String GETURL_METHOD = "getURL";
+
+    private List dependencies;
+
+    static {
+        // Initialize static vars
+        REPO_FOLDER = getRepositoryFile();
+        MODULE_FILE = REPO_FOLDER.getAbsolutePath() + ACTIVEMQ_RA;
+        PLAN_FILE = REPO_FOLDER.getAbsolutePath() + PLAN_XML;
+    }
+
+    private static File getRepositoryFile() {
+        File repoFile = null;
+
+        try {
+            Kernel kernel = KernelRegistry.getSingleKernel();
+            URI uri = new URI(".");
+            URL rootURL = (URL) kernel.invoke(REPO_NAME, GETURL_METHOD,
+                    new Object[] {uri}, REPO_ARGS);
+            uri = new URI(rootURL.toString());
+            repoFile = new File(uri);
+        } catch (URISyntaxException e) {
+            System.out.println("ERROR: Invalid repository URL");
+            e.printStackTrace();
+        } catch (Exception e) {
+            System.out.println("ERROR: Problem getting repository location");
+            e.printStackTrace();
+        }
+
+        return repoFile;
+    }
+
+    private static String getPlanTemplate() {
+        StringBuffer sb = new StringBuffer();
+        sb.append("<?xml version=\"1.0\"?>\n");
+        sb
+                .append("<connector xmlns=\"http://geronimo.apache.org/xml/ns/j2ee/connector\"\n");
+        sb.append("    version=\"1.5\" configId=\"{0}\" parentId=\"{1}\">\n");
+        sb.append("  <resourceadapter>\n");
+        sb.append("    <resourceadapter-instance>\n");
+        sb.append("      <resourceadapter-name>{2}</resourceadapter-name>\n");
+        sb
+                .append("      <config-property-setting name=\"ServerUrl\">{3}</config-property-setting>\n");
+        sb
+                .append("      <config-property-setting name=\"UserName\">{4}</config-property-setting>\n");
+        sb
+                .append("      <config-property-setting name=\"Password\">{5}</config-property-setting>\n");
+        sb
+                .append("      <workmanager><gbean-link>DefaultWorkManager</gbean-link></workmanager>\n");
+        sb.append("    </resourceadapter-instance>\n");
+        sb.append("    <outbound-resourceadapter>\n");
+        sb.append("      <connection-definition>\n");
+        sb
+                .append("        <connectionfactory-interface>javax.jms.ConnectionFactory</connectionfactory-interface>\n");
+        sb.append("        <connectiondefinition-instance>\n");
+        sb.append("          <name>{6}</name>\n");
+        sb
+                .append("          <implemented-interface>javax.jms.QueueConnectionFactory</implemented-interface>\n");
+        sb
+                .append("          <implemented-interface>javax.jms.TopicConnectionFactory</implemented-interface>\n");
+        sb.append("          <connectionmanager>\n");
+        sb.append("            <xa-transaction>\n");
+        sb.append("              <transaction-caching/>\n");
+        sb.append("            </xa-transaction>\n");
+        sb.append("            <single-pool>\n");
+        sb.append("              <max-size>{7}</max-size>\n");
+        sb
+                .append("              <blocking-timeout-milliseconds>{8}</blocking-timeout-milliseconds>\n");
+        sb.append("              <match-one/>\n");
+        sb.append("            </single-pool>\n");
+        sb.append("          </connectionmanager>\n");
+        sb.append("          <global-jndi-name>{9}</global-jndi-name>\n");
+        sb
+                .append("          <credential-interface>javax.resource.spi.security.PasswordCredential</credential-interface>\n");
+        sb.append("        </connectiondefinition-instance>\n");
+        sb.append("      </connection-definition>\n");
+        sb.append("    </outbound-resourceadapter>\n");
+        sb.append("  </resourceadapter>\n");
+        sb.append("</connector>\n");
+
+        return sb.toString();
+    }
+
+    private void savePlan(String filename, Object[] args) {
+        MessageFormat mf = new MessageFormat(PLAN_TEMPLATE);
+        String plan = mf.format(args);
+
+        try {
+            File f = new File(filename);
+            f.createNewFile();
+            FileOutputStream fos = new FileOutputStream(f);
+            OutputStreamWriter osw = new OutputStreamWriter(fos);
+            Writer out = new BufferedWriter(osw);
+            out.write(plan);
+            out.flush();
+            out.close();
+            osw.close();
+            fos.close();
+        } catch (Exception e) {
+            System.out.println("ERROR: Problem creating the plan file");
+            e.printStackTrace();
+        }
+    }
+
+    public void deployPlan(Object[] args) {
+        savePlan(PLAN_FILE, args);
+        deployPlan(new File(MODULE_FILE), new File(PLAN_FILE));
+    }
+
+    public void deployPlan(File moduleFile, File planFile) {
+        try {
+            Kernel kernel = KernelRegistry.getSingleKernel();
+            List list = (List) kernel.invoke(DEPLOYER_NAME, DEPLOY_METHOD,
+                    new Object[] {moduleFile, planFile}, DEPLOYER_ARGS);
+            System.out.println("Deployed: " + moduleFile + " : " + planFile);
+            // start installed app/s
+            int size = list.size();
+            for (int i = 0; i < size; i++) {
+                String config = (String) list.get(i);
+                //URI configID = new URI(config);
+                //kernel.startConfiguration(configID);
+                ConfigurationManager configurationManager = ConfigurationUtil
+                        .getConfigurationManager(kernel);
+                ObjectName configName = configurationManager.load(URI
+                        .create(config));
+
+                kernel.startRecursiveGBean(configName);
+            }
+        } catch (DeploymentException e) {
+            StringBuffer buf = new StringBuffer(256);
+            Throwable cause = e;
+            while (cause != null) {
+                buf.append(cause.getMessage());
+                buf.append(LINE_SEP);
+                cause = cause.getCause();
+            }
+            System.out
+                    .println("ERROR: Problem deploying the ActiveMQ connector: "
+                            + buf.toString());
+            e.printStackTrace();
+        } catch (URISyntaxException e) {
+            System.out
+                    .println("ERROR: Newly installed app has invalid config ID");
+            e.printStackTrace();
+        } catch (Exception e) {
+            System.out.println("ERROR: Problem creating the datasource");
+            e.printStackTrace();
+        }
+    }
+
+    public List getDependencies() {
+        List dependencies = null;
+
+        try {
+            dependencies = getListing(REPO_FOLDER, REPO_FOLDER
+                    .getCanonicalPath());
+            Collections.sort(dependencies);
+        } catch (Exception e) {
+            System.out.println("ERROR: Problem getting dependencies");
+            e.printStackTrace();
+        }
+
+        return dependencies;
+    }
+
+    private List getListing(File dir, String basepath)
+            throws java.io.IOException {
+        if (dir == null) {
+            throw new IllegalArgumentException("directory argument is null");
+        }
+
+        if (!dir.isDirectory()) {
+            throw new IllegalArgumentException("directory argument expected");
+        }
+
+        List listing = new ArrayList();
+
+        List ls = Arrays.asList(dir.listFiles());
+        Iterator iter = ls.iterator();
+
+        while (iter.hasNext()) {
+            File f = (File) iter.next();
+
+            if (f.isDirectory()) {
+                List listing1 = getListing(f, basepath);
+                listing.addAll(listing1);
+            } else {
+                listing.add(f.getCanonicalPath().substring(
+                        basepath.length() + 1).replace('\\', '/'));
+            }
+        }
+        return listing;
+    }
+
+}
\ No newline at end of file

Propchange: geronimo/trunk/sandbox/console-standard/src/java/org/apache/geronimo/console/jmsmanager/activemqCF/ActiveMQConnectorHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message