Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 12370 invoked from network); 17 Aug 2007 00:33:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 Aug 2007 00:33:45 -0000 Received: (qmail 77279 invoked by uid 500); 17 Aug 2007 00:33:42 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 77249 invoked by uid 500); 17 Aug 2007 00:33:42 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 77238 invoked by uid 99); 17 Aug 2007 00:33:42 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Aug 2007 17:33:42 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Aug 2007 00:33:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 32F7F1A981D; Thu, 16 Aug 2007 17:33:15 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r566889 [2/3] - in /geronimo/server/trunk: applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/databasemanager/wizard/ configs/webconsole-jetty6/src/plan/ configs/webconsole-tomcat/src/plan/ Date: Fri, 17 Aug 2007 00:33:01 -0000 To: scm@geronimo.apache.org From: djencks@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070817003315.32F7F1A981D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java?view=diff&rev=566889&r1=566888&r2=566889 ============================================================================== --- geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java (original) +++ geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java Thu Aug 16 17:33:00 2007 @@ -42,11 +42,13 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.Iterator; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; import java.util.SortedSet; + import javax.enterprise.deploy.model.DDBean; import javax.enterprise.deploy.model.DDBeanRoot; import javax.enterprise.deploy.shared.ModuleType; @@ -67,6 +69,7 @@ import javax.portlet.WindowState; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; + import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.portlet.PortletFileUpload; @@ -114,41 +117,60 @@ */ public class DatabasePoolPortlet extends BasePortlet { private final static Log log = LogFactory.getLog(DatabasePoolPortlet.class); - private final static String[] SKIP_ENTRIES_WITH = new String[]{"geronimo", "tomcat", "tranql", "commons", "directory", "activemq"}; + private final static Set INCLUDE_ARTIFACTIDS = new HashSet(Arrays.asList("system-database")); + + private final static Set EXCLUDE_GROUPIDS = new HashSet(Arrays.asList("org.apache.geronimo.modules", + "org.apache.geronimo.configs", + "org.apache.geronimo.applications", + "org.apache.geronimo.assemblies", + "org.apache.cxf", + "org.apache.tomcat", + "org.tranql", + "commons-cli", + "commons-io", + "commons-logging", + "commons-lang", + "axis", + "org.apache.axis2", + "org.apache.directory", + "org.apache.activemq", + "org.apache.openejb", + "org.apache.myfaces", + "org.mortbay.jetty")); private final static String DRIVER_SESSION_KEY = "org.apache.geronimo.console.dbpool.Drivers"; private final static String CONFIG_SESSION_KEY = "org.apache.geronimo.console.dbpool.ConfigParam"; - private final static String DRIVER_INFO_URL = "http://geronimo.apache.org/driver-downloads.properties"; - private static final String LIST_VIEW = "/WEB-INF/view/dbwizard/list.jsp"; - private static final String EDIT_VIEW = "/WEB-INF/view/dbwizard/edit.jsp"; - private static final String SELECT_RDBMS_VIEW = "/WEB-INF/view/dbwizard/selectDatabase.jsp"; - private static final String BASIC_PARAMS_VIEW = "/WEB-INF/view/dbwizard/basicParams.jsp"; - private static final String CONFIRM_URL_VIEW = "/WEB-INF/view/dbwizard/confirmURL.jsp"; + private final static String DRIVER_INFO_URL = "http://geronimo.apache.org/driver-downloads.properties"; + private static final String LIST_VIEW = "/WEB-INF/view/dbwizard/list.jsp"; + private static final String EDIT_VIEW = "/WEB-INF/view/dbwizard/edit.jsp"; + private static final String SELECT_RDBMS_VIEW = "/WEB-INF/view/dbwizard/selectDatabase.jsp"; + private static final String BASIC_PARAMS_VIEW = "/WEB-INF/view/dbwizard/basicParams.jsp"; + private static final String CONFIRM_URL_VIEW = "/WEB-INF/view/dbwizard/confirmURL.jsp"; private static final String TEST_CONNECTION_VIEW = "/WEB-INF/view/dbwizard/testConnection.jsp"; - private static final String DOWNLOAD_VIEW = "/WEB-INF/view/dbwizard/selectDownload.jsp"; + private static final String DOWNLOAD_VIEW = "/WEB-INF/view/dbwizard/selectDownload.jsp"; private static final String DOWNLOAD_STATUS_VIEW = "/WEB-INF/view/dbwizard/downloadStatus.jsp"; - private static final String SHOW_PLAN_VIEW = "/WEB-INF/view/dbwizard/showPlan.jsp"; - private static final String IMPORT_UPLOAD_VIEW = "/WEB-INF/view/dbwizard/importUpload.jsp"; - private static final String IMPORT_STATUS_VIEW = "/WEB-INF/view/dbwizard/importStatus.jsp"; - private static final String USAGE_VIEW = "/WEB-INF/view/dbwizard/usage.jsp"; - private static final String LIST_MODE = "list"; - private static final String EDIT_MODE = "edit"; - private static final String SELECT_RDBMS_MODE = "rdbms"; - private static final String BASIC_PARAMS_MODE = "params"; - private static final String CONFIRM_URL_MODE = "url"; + private static final String SHOW_PLAN_VIEW = "/WEB-INF/view/dbwizard/showPlan.jsp"; + private static final String IMPORT_UPLOAD_VIEW = "/WEB-INF/view/dbwizard/importUpload.jsp"; + private static final String IMPORT_STATUS_VIEW = "/WEB-INF/view/dbwizard/importStatus.jsp"; + private static final String USAGE_VIEW = "/WEB-INF/view/dbwizard/usage.jsp"; + private static final String LIST_MODE = "list"; + private static final String EDIT_MODE = "edit"; + private static final String SELECT_RDBMS_MODE = "rdbms"; + private static final String BASIC_PARAMS_MODE = "params"; + private static final String CONFIRM_URL_MODE = "url"; private static final String TEST_CONNECTION_MODE = "test"; - private static final String SHOW_PLAN_MODE = "plan"; - private static final String DOWNLOAD_MODE = "download"; + private static final String SHOW_PLAN_MODE = "plan"; + private static final String DOWNLOAD_MODE = "download"; private static final String DOWNLOAD_STATUS_MODE = "downloadStatus"; - private static final String EDIT_EXISTING_MODE = "editExisting"; - private static final String DELETE_MODE = "delete"; - private static final String SAVE_MODE = "save"; - private static final String IMPORT_START_MODE = "startImport"; - private static final String IMPORT_UPLOAD_MODE = "importUpload"; - private static final String IMPORT_STATUS_MODE = "importStatus"; + private static final String EDIT_EXISTING_MODE = "editExisting"; + private static final String DELETE_MODE = "delete"; + private static final String SAVE_MODE = "save"; + private static final String IMPORT_START_MODE = "startImport"; + private static final String IMPORT_UPLOAD_MODE = "importUpload"; + private static final String IMPORT_STATUS_MODE = "importStatus"; private static final String IMPORT_COMPLETE_MODE = "importComplete"; private static final String WEBLOGIC_IMPORT_MODE = "weblogicImport"; - private static final String USAGE_MODE = "usage"; - private static final String IMPORT_EDIT_MODE = "importEdit"; + private static final String USAGE_MODE = "usage"; + private static final String IMPORT_EDIT_MODE = "importEdit"; private static final String MODE_KEY = "mode"; private PortletRequestDispatcher listView; @@ -198,8 +220,9 @@ public DriverDownloader.DriverInfo[] getDriverInfo(PortletRequest request) { PortletSession session = request.getPortletSession(true); - DriverDownloader.DriverInfo[] results = (DriverDownloader.DriverInfo[]) session.getAttribute(DRIVER_SESSION_KEY, PortletSession.APPLICATION_SCOPE); - if(results == null) { + DriverDownloader.DriverInfo[] results = (DriverDownloader.DriverInfo[]) session.getAttribute(DRIVER_SESSION_KEY, + PortletSession.APPLICATION_SCOPE); + if (results == null) { DriverDownloader downloader = new DriverDownloader(); try { results = downloader.loadDriverInfo(new URL(DRIVER_INFO_URL)); @@ -215,26 +238,32 @@ /** * Loads data about a resource adapter. Depending on what we already have, may load * the name and description, but always loads the config property descriptions. - * @param request Pass it or die - * @param rarPath If we're creating a new RA, the path to identify it - * @param displayName If we're editing an existing RA, its name - * @param adapterAbstractName If we're editing an existing RA, its AbstractName + * + * @param request Pass it or die + * @param rarPath If we're creating a new RA, the path to identify it + * @param displayName If we're editing an existing RA, its name + * @param adapterAbstractName If we're editing an existing RA, its AbstractName + * @return resource adapter parameter data object */ public ResourceAdapterParams getRARConfiguration(PortletRequest request, String rarPath, String displayName, String adapterAbstractName) { PortletSession session = request.getPortletSession(true); - if(rarPath != null && !rarPath.equals("")) { - ResourceAdapterParams results = (ResourceAdapterParams) session.getAttribute(CONFIG_SESSION_KEY+"-"+rarPath, PortletSession.APPLICATION_SCOPE); - if(results == null) { + if (rarPath != null && !rarPath.equals("")) { + ResourceAdapterParams results = (ResourceAdapterParams) session.getAttribute( + CONFIG_SESSION_KEY + "-" + rarPath, PortletSession.APPLICATION_SCOPE); + if (results == null) { results = loadConfigPropertiesByPath(request, rarPath); - session.setAttribute(CONFIG_SESSION_KEY+"-"+rarPath, results, PortletSession.APPLICATION_SCOPE); - session.setAttribute(CONFIG_SESSION_KEY+"-"+results.displayName, results, PortletSession.APPLICATION_SCOPE); + session.setAttribute(CONFIG_SESSION_KEY + "-" + rarPath, results, PortletSession.APPLICATION_SCOPE); + session.setAttribute(CONFIG_SESSION_KEY + "-" + results.displayName, results, + PortletSession.APPLICATION_SCOPE); } return results; - } else if(displayName != null && !displayName.equals("") && adapterAbstractName != null && !adapterAbstractName.equals("")) { - ResourceAdapterParams results = (ResourceAdapterParams) session.getAttribute(CONFIG_SESSION_KEY+"-"+displayName, PortletSession.APPLICATION_SCOPE); - if(results == null) { + } else if (displayName != null && !displayName.equals( + "") && adapterAbstractName != null && !adapterAbstractName.equals("")) { + ResourceAdapterParams results = (ResourceAdapterParams) session.getAttribute( + CONFIG_SESSION_KEY + "-" + displayName, PortletSession.APPLICATION_SCOPE); + if (results == null) { results = loadConfigPropertiesByAbstractName(request, adapterAbstractName); - session.setAttribute(CONFIG_SESSION_KEY+"-"+displayName, results, PortletSession.APPLICATION_SCOPE); + session.setAttribute(CONFIG_SESSION_KEY + "-" + displayName, results, PortletSession.APPLICATION_SCOPE); } return results; } else { @@ -243,49 +272,43 @@ } public void processAction(ActionRequest actionRequest, - ActionResponse actionResponse) throws PortletException, IOException { + ActionResponse actionResponse) throws PortletException, IOException { String mode = actionRequest.getParameter(MODE_KEY); - if(mode.equals(IMPORT_UPLOAD_MODE)) { + if (mode.equals(IMPORT_UPLOAD_MODE)) { processImportUpload(actionRequest, actionResponse); actionResponse.setRenderParameter(MODE_KEY, IMPORT_STATUS_MODE); return; } PoolData data = new PoolData(); data.load(actionRequest); - if(mode.equals("process-"+SELECT_RDBMS_MODE)) { - DatabaseDriver info = null; - info = getDatabaseInfo(actionRequest, data); - if(info != null) { + if (mode.equals("process-" + SELECT_RDBMS_MODE)) { + DatabaseDriver info = getDatabaseInfo(actionRequest, data); + if (info != null) { data.rarPath = info.getRAR().toString(); - if(info.isXA()) { - data.adapterDisplayName="Unknown"; // will pick these up when we process the RA type in the render request - data.adapterDescription="Unknown"; + if (info.isSpecific()) { + data.adapterDisplayName = "Unknown"; // will pick these up when we process the RA type in the render request + data.adapterDescription = "Unknown"; actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE); } else { - if(data.getDbtype().equals("Other")) { - actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE); - } else { - data.driverClass = info.getDriverClassName(); - data.urlPrototype = info.getURLPrototype(); - actionResponse.setRenderParameter(MODE_KEY, BASIC_PARAMS_MODE); - } + data.driverClass = info.getDriverClassName(); + data.urlPrototype = info.getURLPrototype(); + actionResponse.setRenderParameter(MODE_KEY, BASIC_PARAMS_MODE); } } else { actionResponse.setRenderParameter(MODE_KEY, SELECT_RDBMS_MODE); } - } else if(mode.equals("process-"+DOWNLOAD_MODE)) { + } else if (mode.equals("process-" + DOWNLOAD_MODE)) { String name = actionRequest.getParameter("driverName"); DriverDownloader.DriverInfo[] drivers = getDriverInfo(actionRequest); DriverDownloader.DriverInfo found = null; - for (int i = 0; i < drivers.length; i++) { - DriverDownloader.DriverInfo driver = drivers[i]; - if(driver.getName().equals(name)) { + for (DriverDownloader.DriverInfo driver : drivers) { + if (driver.getName().equals(name)) { found = driver; break; } } - if(found != null) { - data.jars = new String[] {found.getRepositoryURI()}; + if (found != null) { + data.jars = new String[]{found.getRepositoryURI()}; WriteableRepository repo = PortletManager.getCurrentServer(actionRequest).getWritableRepositories()[0]; final PortletSession session = actionRequest.getPortletSession(); ProgressInfo progressInfo = new ProgressInfo(); @@ -297,27 +320,27 @@ } else { actionResponse.setRenderParameter(MODE_KEY, DOWNLOAD_MODE); } - } else if(mode.equals("process-"+DOWNLOAD_STATUS_MODE)) { - if(data.getDbtype() == null || data.getDbtype().equals("Other")) { + } else if (mode.equals("process-" + DOWNLOAD_STATUS_MODE)) { + if (data.getDbtype() == null || data.getDbtype().equals("Other")) { actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE); } else { actionResponse.setRenderParameter(MODE_KEY, BASIC_PARAMS_MODE); } - } else if(mode.equals("process-"+BASIC_PARAMS_MODE)) { - DatabaseDriver info = null; + } else if (mode.equals("process-" + BASIC_PARAMS_MODE)) { + DatabaseDriver info; info = getDatabaseInfo(actionRequest, data); - if(info != null) { + if (info != null) { data.url = populateURL(info.getURLPrototype(), info.getURLParameters(), data.getUrlProperties()); } - if(attemptDriverLoad(actionRequest, data) != null) { + if (attemptDriverLoad(actionRequest, data) != null) { actionResponse.setRenderParameter(MODE_KEY, CONFIRM_URL_MODE); } else { - actionResponse.setRenderParameter("driverError", "Unable to load driver "+data.driverClass); + actionResponse.setRenderParameter("driverError", "Unable to load driver " + data.driverClass); actionResponse.setRenderParameter(MODE_KEY, BASIC_PARAMS_MODE); } - } else if(mode.equals("process-"+CONFIRM_URL_MODE)) { + } else if (mode.equals("process-" + CONFIRM_URL_MODE)) { String test = actionRequest.getParameter("test"); - if(test == null || test.equals("true")) { + if (test == null || test.equals("true")) { String result = null; String stack = null; try { @@ -330,29 +353,29 @@ temp.close(); stack = writer.getBuffer().toString(); } - if(result != null) actionResponse.setRenderParameter("connectResult", result); + if (result != null) actionResponse.setRenderParameter("connectResult", result); actionRequest.getPortletSession(true).setAttribute("connectError", stack); actionResponse.setRenderParameter(MODE_KEY, TEST_CONNECTION_MODE); } else { save(actionRequest, actionResponse, data, false); } - } else if(mode.equals(SAVE_MODE)) { + } else if (mode.equals(SAVE_MODE)) { save(actionRequest, actionResponse, data, false); - } else if(mode.equals(SHOW_PLAN_MODE)) { + } else if (mode.equals(SHOW_PLAN_MODE)) { String plan = save(actionRequest, actionResponse, data, true); actionRequest.getPortletSession(true).setAttribute("deploymentPlan", plan); actionResponse.setRenderParameter(MODE_KEY, SHOW_PLAN_MODE); - } else if(mode.equals(EDIT_EXISTING_MODE)) { + } else if (mode.equals(EDIT_EXISTING_MODE)) { final String name = actionRequest.getParameter("adapterAbstractName"); loadConnectionFactory(actionRequest, name, data.getAbstractName(), data); actionResponse.setRenderParameter("adapterAbstractName", name); actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE); - } else if(mode.equals(SELECT_RDBMS_MODE)) { - if(data.getAdapterDisplayName() == null) { // Set a default for a new pool + } else if (mode.equals(SELECT_RDBMS_MODE)) { + if (data.getAdapterDisplayName() == null) { // Set a default for a new pool data.adapterDisplayName = "TranQL Generic JDBC Resource Adapter"; } actionResponse.setRenderParameter(MODE_KEY, mode); - } else if(mode.equals(WEBLOGIC_IMPORT_MODE)) { + } else if (mode.equals(WEBLOGIC_IMPORT_MODE)) { String domainDir = actionRequest.getParameter("weblogicDomainDir"); String libDir = actionRequest.getParameter("weblogicLibDir"); try { @@ -364,24 +387,24 @@ actionResponse.setRenderParameter("from", actionRequest.getParameter("from")); actionResponse.setRenderParameter(MODE_KEY, IMPORT_START_MODE); } - } else if(mode.equals(IMPORT_START_MODE)) { + } else if (mode.equals(IMPORT_START_MODE)) { actionResponse.setRenderParameter("from", actionRequest.getParameter("from")); actionResponse.setRenderParameter(MODE_KEY, mode); - } else if(mode.equals(IMPORT_EDIT_MODE)) { + } else if (mode.equals(IMPORT_EDIT_MODE)) { ImportStatus status = getImportStatus(actionRequest); int index = Integer.parseInt(actionRequest.getParameter("importIndex")); status.setCurrentPoolIndex(index); loadImportedData(actionRequest, data, status.getCurrentPool()); actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE); - } else if(mode.equals(IMPORT_COMPLETE_MODE)) { + } else if (mode.equals(IMPORT_COMPLETE_MODE)) { ImportStatus status = getImportStatus(actionRequest); log.warn("Import Results:"); //todo: create a screen for this - log.warn(" "+status.getSkippedCount()+" ignored"); - log.warn(" "+status.getStartedCount()+" reviewed but not deployed"); - log.warn(" "+status.getPendingCount()+" not reviewed"); - log.warn(" "+status.getFinishedCount()+" deployed"); + log.warn(" " + status.getSkippedCount() + " ignored"); + log.warn(" " + status.getStartedCount() + " reviewed but not deployed"); + log.warn(" " + status.getPendingCount() + " not reviewed"); + log.warn(" " + status.getFinishedCount() + " deployed"); actionRequest.getPortletSession().removeAttribute("ImportStatus"); - } else if(mode.equals(DELETE_MODE)) { + } else if (mode.equals(DELETE_MODE)) { String name = actionRequest.getParameter("adapterAbstractName"); loadConnectionFactory(actionRequest, name, data.getAbstractName(), data); delete(actionRequest, actionResponse, data); @@ -410,22 +433,22 @@ public void writeStarted(String fileDescription, int fileSize) { this.fileSize = fileSize; - log.info("Downloading "+fileDescription); + log.info("Downloading " + fileDescription); } public void writeProgress(int bytes) { - int kbDownloaded = (int)Math.floor(bytes/1024); + int kbDownloaded = (int) Math.floor(bytes / 1024); if (fileSize > 0) { - int percent = (bytes*100)/fileSize; + int percent = (bytes * 100) / fileSize; progressInfo.setProgressPercent(percent); - progressInfo.setSubMessage(kbDownloaded + " / " + fileSize/1024 + " Kb downloaded"); + progressInfo.setSubMessage(kbDownloaded + " / " + fileSize / 1024 + " Kb downloaded"); } else { progressInfo.setSubMessage(kbDownloaded + " Kb downloaded"); } } public void writeComplete(int bytes) { - log.info("Finished downloading "+bytes+" b"); + log.info("Finished downloading " + bytes + " b"); } }); } catch (IOException e) { @@ -436,26 +459,28 @@ } } - private void loadImportedData(PortletRequest request, PoolData data, ImportStatus.PoolProgress progress) throws PortletException { if(!progress.getType().equals(ImportStatus.PoolProgress.TYPE_XA)) { + private void loadImportedData(PortletRequest request, PoolData data, ImportStatus.PoolProgress progress) throws PortletException { + if (!progress.getType().equals(ImportStatus.PoolProgress.TYPE_XA)) { JDBCPool pool = (JDBCPool) progress.getPool(); data.dbtype = "Other"; data.adapterDisplayName = "TranQL Generic JDBC Resource Adapter"; data.blockingTimeout = getImportString(pool.getBlockingTimeoutMillis()); data.driverClass = pool.getDriverClass(); - data.idleTimeout = pool.getIdleTimeoutMillis() == null ? null : Integer.toString(pool.getIdleTimeoutMillis().intValue() / (60 * 1000)); + data.idleTimeout = pool.getIdleTimeoutMillis() != null ? Integer.toString( + pool.getIdleTimeoutMillis().intValue() / (60 * 1000)) : null; data.maxSize = getImportString(pool.getMaxSize()); data.minSize = getImportString(pool.getMinSize()); data.name = pool.getName(); data.password = pool.getPassword(); data.url = pool.getJdbcURL(); data.user = pool.getUsername(); - if(pool.getDriverClass() != null) { + if (pool.getDriverClass() != null) { DatabaseDriver info = getDatabaseInfoFromDriver(request, data); - if(info != null) { + if (info != null) { data.rarPath = info.getRAR().toString(); data.urlPrototype = info.getURLPrototype(); } else { - throw new PortletException("Don't recognize database driver "+data.driverClass+"!"); + throw new PortletException("Don't recognize database driver " + data.driverClass + "!"); } } } else { @@ -476,13 +501,12 @@ PortletFileUpload uploader = new PortletFileUpload(new DiskFileItemFactory()); try { - List items = uploader.parseRequest(request); - for (Iterator i = items.iterator(); i.hasNext();) { - FileItem item = (FileItem) i.next(); + List items = uploader.parseRequest(request); + for (FileItem item : items) { if (!item.isFormField()) { File file = File.createTempFile("geronimo-import", ""); file.deleteOnExit(); - log.debug("Writing database pool import file to "+file.getAbsolutePath()); + log.debug("Writing database pool import file to " + file.getAbsolutePath()); item.write(file); DatabaseConversionStatus status = processImport(file, type); request.getPortletSession(true).setAttribute("ImportStatus", new ImportStatus(status)); @@ -491,21 +515,21 @@ throw new PortletException("Not expecting any form fields"); } } - } catch(PortletException e) { + } catch (PortletException e) { throw e; - } catch(Exception e) { + } catch (Exception e) { throw new PortletException(e); } return false; } private DatabaseConversionStatus processImport(File importFile, String type) throws PortletException, IOException { - if(type.equals("JBoss 4")) { + if (type.equals("JBoss 4")) { return JBoss4DatabaseConverter.convert(new FileReader(importFile)); - } else if(type.equals("WebLogic 8.1")) { + } else if (type.equals("WebLogic 8.1")) { return WebLogic81DatabaseConverter.convert(new FileReader(importFile)); } else { - throw new PortletException("Unknown import type '"+type+"'"); + throw new PortletException("Unknown import type '" + type + "'"); } } @@ -517,23 +541,22 @@ final DDBeanRoot ddBeanRoot = deployable.getDDBeanRoot(); String adapterName = null, adapterDesc = null; String[] test = ddBeanRoot.getText("connector/display-name"); - if(test != null && test.length > 0) { + if (test != null && test.length > 0) { adapterName = test[0]; } test = ddBeanRoot.getText("connector/description"); - if(test != null && test.length > 0) { + if (test != null && test.length > 0) { adapterDesc = test[0]; } - DDBean[] definitions = ddBeanRoot.getChildBean("connector/resourceadapter/outbound-resourceadapter/connection-definition"); - List configs = new ArrayList(); - if(definitions != null) { - for (int i = 0; i < definitions.length; i++) { - DDBean definition = definitions[i]; + DDBean[] definitions = ddBeanRoot.getChildBean( + "connector/resourceadapter/outbound-resourceadapter/connection-definition"); + List configs = new ArrayList(); + if (definitions != null) { + for (DDBean definition : definitions) { String iface = definition.getText("connectionfactory-interface")[0]; - if(iface.equals("javax.sql.DataSource")) { + if (iface.equals("javax.sql.DataSource")) { DDBean[] beans = definition.getChildBean("config-property"); - for (int j = 0; j < beans.length; j++) { - DDBean bean = beans[j]; + for (DDBean bean : beans) { String name = bean.getText("config-property-name")[0].trim(); String type = bean.getText("config-property-type")[0].trim(); test = bean.getText("config-property-value"); @@ -545,17 +568,19 @@ } } } - return new ResourceAdapterParams(adapterName, adapterDesc, (ConfigParam[]) configs.toArray(new ConfigParam[configs.size()])); + return new ResourceAdapterParams(adapterName, adapterDesc, + configs.toArray(new ConfigParam[configs.size()])); } catch (Exception e) { log.error("Unable to read configuration properties", e); return null; } finally { - if(mgr != null) mgr.release(); + if (mgr != null) mgr.release(); } } private ResourceAdapterParams loadConfigPropertiesByAbstractName(PortletRequest request, String abstractName) { - ResourceAdapterModule module = (ResourceAdapterModule) PortletManager.getManagedBean(request, new AbstractName(URI.create(abstractName))); + ResourceAdapterModule module = (ResourceAdapterModule) PortletManager.getManagedBean(request, + new AbstractName(URI.create(abstractName))); String dd = module.getDeploymentDescriptor(); DocumentBuilderFactory factory = XmlUtil.newDocumentBuilderFactory(); factory.setValidating(false); @@ -571,13 +596,13 @@ elem = (Element) elem.getElementsByTagName("resourceadapter").item(0); elem = (Element) elem.getElementsByTagName("outbound-resourceadapter").item(0); NodeList defs = elem.getElementsByTagName("connection-definition"); - List all = new ArrayList(); - for(int i=0; i all = new ArrayList(); + for (int i = 0; i < defs.getLength(); i++) { + final Element def = (Element) defs.item(i); String iface = getFirstText(def.getElementsByTagName("connectionfactory-interface")).trim(); - if(iface.equals("javax.sql.DataSource")) { + if (iface.equals("javax.sql.DataSource")) { NodeList configs = def.getElementsByTagName("config-property"); - for(int j=0; j list = new ArrayList(); + for (ResourceAdapterModule module : modules) { AbstractName moduleName = PortletManager.getManagementHelper(renderRequest).getNameFor(module); - JCAManagedConnectionFactory[] databases = PortletManager.getOutboundFactoriesForRA(renderRequest, module, "javax.sql.DataSource"); - for (int j = 0; j < databases.length; j++) { - JCAManagedConnectionFactory db = databases[j]; - AbstractName dbName = PortletManager.getManagementHelper(renderRequest).getNameFor(db); - list.add(new ConnectionPool(moduleName, dbName, (String)dbName.getName().get(NameFactory.J2EE_NAME), ((GeronimoManagedBean)db).getState())); + JCAManagedConnectionFactory[] databases = PortletManager.getOutboundFactoriesForRA(renderRequest, module, + "javax.sql.DataSource"); + for (JCAManagedConnectionFactory db : databases) { + AbstractName dbName = PortletManager.getManagementHelper(renderRequest).getNameFor(db); + list.add(new ConnectionPool(moduleName, dbName, (String) dbName.getName().get(NameFactory.J2EE_NAME), + ((GeronimoManagedBean) db).getState())); } } Collections.sort(list); @@ -734,24 +762,25 @@ } private void renderEdit(RenderRequest renderRequest, RenderResponse renderResponse, PoolData data) throws IOException, PortletException { - if(data.abstractName == null || data.abstractName.equals("")) { + if (data.abstractName == null || data.abstractName.equals("")) { loadDriverJARList(renderRequest); } - if(!data.isGeneric()) { - ResourceAdapterParams params = getRARConfiguration(renderRequest, data.getRarPath(), data.getAdapterDisplayName(), renderRequest.getParameter("adapterAbstractName")); + if (!data.isGeneric()) { + ResourceAdapterParams params = getRARConfiguration(renderRequest, data.getRarPath(), + data.getAdapterDisplayName(), renderRequest.getParameter("adapterAbstractName")); data.adapterDisplayName = params.getDisplayName(); data.adapterDescription = params.getDescription(); - Map map = new HashMap(); + Map map = new HashMap(); boolean more = false; for (int i = 0; i < params.getConfigParams().length; i++) { ConfigParam param = params.getConfigParams()[i]; - if(!data.properties.containsKey("property-"+param.getName())) { - data.properties.put("property-"+param.getName(), param.getDefaultValue()); + if (!data.properties.containsKey("property-" + param.getName())) { + data.properties.put("property-" + param.getName(), param.getDefaultValue()); more = true; } - map.put("property-"+param.getName(), param); + map.put("property-" + param.getName(), param); } - if(more) { + if (more) { data.loadPropertyNames(); } renderRequest.setAttribute("ConfigParams", map); @@ -777,13 +806,13 @@ loadDriverJARList(renderRequest); // Make sure all properties available for the DB are listed DatabaseDriver info = getDatabaseInfo(renderRequest, data); - if(info != null) { + if (info != null) { String[] params = info.getURLParameters(); - for (int i = 0; i < params.length; i++) { - String param = params[i]; - final String key = "urlproperty-"+param; - if(!data.getUrlProperties().containsKey(key)) { - data.getUrlProperties().put(key, param.equalsIgnoreCase("port") && info.getDefaultPort() > 0 ? new Integer(info.getDefaultPort()) : null); + for (String param : params) { + final String key = "urlproperty-" + param; + if (!data.getUrlProperties().containsKey(key)) { + data.getUrlProperties().put(key, + param.equalsIgnoreCase("port") && info.getDefaultPort() > 0 ? info.getDefaultPort() : null); } } } @@ -795,24 +824,15 @@ private void loadDriverJARList(RenderRequest renderRequest) { // List the available JARs - List list = new ArrayList(); + List list = new ArrayList(); ListableRepository[] repos = PortletManager.getCurrentServer(renderRequest).getRepositories(); - for (int i = 0; i < repos.length; i++) { - ListableRepository repo = repos[i]; - - SortedSet artifacts = repo.list(); - outer: - for (Iterator iterator = artifacts.iterator(); iterator.hasNext();) { - Artifact artifact = (Artifact) iterator.next(); - String test = artifact.toString(); - // todo should only test groupId and should check for long (org.apache.geronimo) and short form - for (int k = 0; k < SKIP_ENTRIES_WITH.length; k++) { - String skip = SKIP_ENTRIES_WITH[k]; - if(test.indexOf(skip) > -1) { - continue outer; - } + for (ListableRepository repo : repos) { + SortedSet artifacts = repo.list(); + for (Artifact artifact : artifacts) { + if (INCLUDE_ARTIFACTIDS.contains(artifact.getArtifactId()) + || !EXCLUDE_GROUPIDS.contains(artifact.getGroupId())) { + list.add(artifact.toString()); } - list.add(test); } } Collections.sort(list); @@ -836,14 +856,14 @@ // Digest the RAR URI String path = PortletManager.getRepositoryEntry(renderRequest, data.getRarPath()).getPath(); String base = PortletManager.getCurrentServer(renderRequest).getServerInfo().getCurrentBaseDirectory(); - if(base != null && path.startsWith(base)) { + if (base != null && path.startsWith(base)) { path = path.substring(base.length()); - if(path.startsWith("/")) { + if (path.startsWith("/")) { path = path.substring(1); } } else { int pos = path.lastIndexOf('/'); - path = path.substring(pos+1); + path = path.substring(pos + 1); } renderRequest.setAttribute("rarRelativePath", path); @@ -853,32 +873,38 @@ private static String attemptConnect(PortletRequest request, PoolData data) throws SQLException, IllegalAccessException, InstantiationException { Class driverClass = attemptDriverLoad(request, data); Driver driver = (Driver) driverClass.newInstance(); - if(driver.acceptsURL(data.url)) { + if (driver.acceptsURL(data.url)) { Properties props = new Properties(); - if(data.user != null) { + if (data.user != null) { props.put("user", data.user); } - if(data.password != null) { + if (data.password != null) { props.put("password", data.password); } Connection con = null; try { con = driver.connect(data.url, props); final DatabaseMetaData metaData = con.getMetaData(); - return metaData.getDatabaseProductName()+" "+metaData.getDatabaseProductVersion(); + return metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion(); } finally { - if(con != null) try{con.close();}catch(SQLException e) {} + if (con != null) { + try { + con.close(); + } catch (SQLException e) { + //ignore + } + } } - } else throw new SQLException("Driver "+data.getDriverClass()+" does not accept URL "+data.url); + } else throw new SQLException("Driver " + data.getDriverClass() + " does not accept URL " + data.url); } private void delete(PortletRequest request, ActionResponse response, PoolData data) { // check to make sure the abstract name does not begin with 'org.apache.geronimo.configs' // if it does not - then delete it -- otherwise it is a system database - if(data.getAbstractName() != null) { + if (data.getAbstractName() != null) { boolean isSystemDatabasePool = (data.getAbstractName().indexOf("org.apache.geronimo.configs") == 0); - if(! isSystemDatabasePool) { + if (!isSystemDatabasePool) { DeploymentManager mgr = PortletManager.getDeploymentManager(request); try { // retrieve all running modules @@ -888,25 +914,25 @@ int index = -1; // only keep module id that is associated with selected DB pool - for(int i = 0; i < runningIds.length; i++) { - if(data.getAbstractName().contains(runningIds[i].getModuleID())) { + for (int i = 0; i < runningIds.length; i++) { + if (data.getAbstractName().contains(runningIds[i].getModuleID())) { index = i; break; } } - TargetModuleID[] ids = { runningIds[index] }; + TargetModuleID[] ids = {runningIds[index]}; // undeploy the db pool ProgressObject po = mgr.undeploy(ids); waitForProgress(po); - if(po.getDeploymentStatus().isCompleted()) { + if (po.getDeploymentStatus().isCompleted()) { log.info("Undeployment completed successfully!"); } - } catch(Exception e) { + } catch (Exception e) { log.error("Undeployment unsuccessful!"); } finally { - if(mgr != null) mgr.release(); + if (mgr != null) mgr.release(); } } } @@ -914,7 +940,7 @@ private static String save(PortletRequest request, ActionResponse response, PoolData data, boolean planOnly) { ImportStatus status = getImportStatus(request); - if(data.abstractName == null || data.abstractName.equals("")) { // we're creating a new pool + if (data.abstractName == null || data.abstractName.equals("")) { // we're creating a new pool data.name = data.name.replaceAll("\\s", ""); DeploymentManager mgr = PortletManager.getDeploymentManager(request); try { @@ -923,7 +949,8 @@ DeploymentConfiguration config = mgr.createConfiguration(deployable); final DDBeanRoot ddBeanRoot = deployable.getDDBeanRoot(); Connector15DCBRoot root = (Connector15DCBRoot) config.getDConfigBeanRoot(ddBeanRoot); - ConnectorDCB connector = (ConnectorDCB) root.getDConfigBean(ddBeanRoot.getChildBean(root.getXpaths()[0])[0]); + ConnectorDCB connector = (ConnectorDCB) root.getDConfigBean( + ddBeanRoot.getChildBean(root.getXpaths()[0])[0]); EnvironmentData environment = new EnvironmentData(); connector.setEnvironment(environment); @@ -931,7 +958,7 @@ environment.setConfigId(configId); configId.setGroupId("console.dbpool"); String artifactId = data.name; - if(artifactId.indexOf('/') != -1) { + if (artifactId.indexOf('/') != -1) { // slash in artifact-id results in invalid configuration-id and leads to deployment errors artifactId = artifactId.replaceAll("/", "%2F"); } @@ -940,18 +967,18 @@ configId.setType("rar"); String[] jars = data.getJars(); - int length = jars[jars.length - 1].length() ==0? jars.length -1: jars.length; + int length = jars[jars.length - 1].length() == 0 ? jars.length - 1 : jars.length; org.apache.geronimo.deployment.service.jsr88.Artifact[] dependencies = new org.apache.geronimo.deployment.service.jsr88.Artifact[length]; - for (int i=0; i entry : data.getProperties().entrySet()) { + factory.setConfigProperty(entry.getKey().substring("property-".length()), + entry.getValue()); } } //todo: push the lookup into ManagementHelper PoolingAttributes pool = (PoolingAttributes) factory.getConnectionManagerContainer(); - pool.setPartitionMinSize(data.minSize == null || data.minSize.equals("") ? 0 : Integer.parseInt(data.minSize)); - pool.setPartitionMaxSize(data.maxSize == null || data.maxSize.equals("") ? 10 : Integer.parseInt(data.maxSize)); - pool.setBlockingTimeoutMilliseconds(data.blockingTimeout == null || data.blockingTimeout.equals("") ? 5000 : Integer.parseInt(data.blockingTimeout)); - pool.setIdleTimeoutMinutes(data.idleTimeout == null || data.idleTimeout.equals("") ? 15 : Integer.parseInt(data.idleTimeout)); + pool.setPartitionMinSize( + data.minSize == null || data.minSize.equals("") ? 0 : Integer.parseInt(data.minSize)); + pool.setPartitionMaxSize( + data.maxSize == null || data.maxSize.equals("") ? 10 : Integer.parseInt(data.maxSize)); + pool.setBlockingTimeoutMilliseconds( + data.blockingTimeout == null || data.blockingTimeout.equals("") ? 5000 : Integer.parseInt( + data.blockingTimeout)); + pool.setIdleTimeoutMinutes( + data.idleTimeout == null || data.idleTimeout.equals("") ? 15 : Integer.parseInt( + data.idleTimeout)); } catch (Exception e) { log.error("Unable to save connection pool", e); } @@ -1076,7 +1108,7 @@ } private static void waitForProgress(ProgressObject po) { - while(po.getDeploymentStatus().isRunning()) { + while (po.getDeploymentStatus().isRunning()) { try { Thread.sleep(100); } catch (InterruptedException e) { @@ -1090,15 +1122,15 @@ } private static File getRAR(PortletRequest request, String rarPath) { - org.apache.geronimo.kernel.repository.Artifact artifact = org.apache.geronimo.kernel.repository.Artifact.create(rarPath); + org.apache.geronimo.kernel.repository.Artifact artifact = org.apache.geronimo.kernel.repository.Artifact.create( + rarPath); ListableRepository[] repos = PortletManager.getCurrentServer(request).getRepositories(); - for (int i = 0; i < repos.length; i++) { - ListableRepository repo = repos[i]; + for (ListableRepository repo : repos) { // if the artifact is not fully resolved then try to resolve it if (!artifact.isResolved()) { SortedSet results = repo.list(artifact); if (!results.isEmpty()) { - artifact = (org.apache.geronimo.kernel.repository.Artifact) results.first(); + artifact = (Artifact) results.first(); } } File url = repo.getLocation(artifact); @@ -1114,28 +1146,33 @@ /** * WARNING: This method relies on having access to the same repository * URLs as the server uses. + * + * @param request portlet request + * @param data info about jars to include + * @return driver class */ private static Class attemptDriverLoad(PortletRequest request, PoolData data) { - List list = new ArrayList(); + List list = new ArrayList(); try { String[] jars = data.getJars(); - if(jars == null) { + if (jars == null) { log.error("Driver load failed since no jar files were selected."); return null; } ListableRepository[] repos = PortletManager.getCurrentServer(request).getRepositories(); - for (int i = 0; i < jars.length; i++) { - org.apache.geronimo.kernel.repository.Artifact artifact = org.apache.geronimo.kernel.repository.Artifact.create(jars[i]); - for (int j = 0; j < repos.length; j++) { - ListableRepository repo = repos[j]; + for (String jar : jars) { + Artifact artifact = Artifact.create( + jar); + for (ListableRepository repo : repos) { File url = repo.getLocation(artifact); if (url != null) { list.add(url.toURL()); } } } - URLClassLoader loader = new URLClassLoader((URL[]) list.toArray(new URL[list.size()]), DatabasePoolPortlet.class.getClassLoader()); + URLClassLoader loader = new URLClassLoader(list.toArray(new URL[list.size()]), + DatabasePoolPortlet.class.getClassLoader()); try { return loader.loadClass(data.driverClass); } catch (ClassNotFoundException e) { @@ -1148,50 +1185,50 @@ } private static String populateURL(String url, String[] keys, Map properties) { - for (int i = 0; i < keys.length; i++) { - String key = keys[i]; - String value = (String) properties.get("urlproperty-"+key); - if(value == null || value.equals("")) { - int begin = url.indexOf("{"+key+"}"); + for (String key : keys) { + String value = (String) properties.get("urlproperty-" + key); + if (value == null || value.equals("")) { + int begin = url.indexOf("{" + key + "}"); int end = begin + key.length() + 2; - for(int j=begin-1; j>=0; j--) { + for (int j = begin - 1; j >= 0; j--) { char c = url.charAt(j); - if(c == ';' || c == ':') { + if (c == ';' || c == ':') { begin = j; break; - } else if(c == '/') { - if(url.length() > end && url.charAt(end) == '/') { + } else if (c == '/') { + if (url.length() > end && url.charAt(end) == '/') { begin = j; // Don't leave // if foo is null for // } break; } } - url = url.substring(0, begin)+url.substring(end); + url = url.substring(0, begin) + url.substring(end); } else { - if(value.indexOf('\\') != -1 || value.indexOf('$') != -1) { + if (value.indexOf('\\') != -1 || value.indexOf('$') != -1) { // value contains backslash or dollar sign and needs preprocessing for replaceAll to work properly StringBuffer temp = new StringBuffer(); char[] valueChars = value.toCharArray(); - for(int j = 0; j < valueChars.length; ++j) { - if(valueChars[j] == '\\' || valueChars[j] == '$') { + for (int j = 0; j < valueChars.length; ++j) { + if (valueChars[j] == '\\' || valueChars[j] == '$') { temp.append('\\'); } temp.append(valueChars[j]); } value = temp.toString(); } - url = url.replaceAll("\\{"+key+"\\}", value); + url = url.replaceAll("\\{" + key + "\\}", value); } } return url; } private static DatabaseDriver[] getAllDrivers(PortletRequest request) { - DatabaseDriver[] result = (DatabaseDriver[]) PortletManager.getGBeansImplementing(request, DatabaseDriver.class); - Arrays.sort(result, new Comparator() { - public int compare(Object o1, Object o2) { - String name1 = ((DatabaseDriver) o1).getName(); - String name2 = ((DatabaseDriver) o2).getName(); + DatabaseDriver[] result = (DatabaseDriver[]) PortletManager.getGBeansImplementing(request, + DatabaseDriver.class); + Arrays.sort(result, new Comparator() { + public int compare(DatabaseDriver o1, DatabaseDriver o2) { + String name1 = o1.getName(); + String name2 = o2.getName(); if (name1.equals("Other")) name1 = "zzzOther"; if (name2.equals("Other")) name2 = "zzzOther"; return name1.compareTo(name2); @@ -1203,8 +1240,7 @@ private static DatabaseDriver getDatabaseInfo(PortletRequest request, PoolData data) { DatabaseDriver info = null; DatabaseDriver[] all = getAllDrivers(request); - for (int i = 0; i < all.length; i++) { - DatabaseDriver next = all[i]; + for (DatabaseDriver next : all) { if (next.getName().equals(data.getDbtype())) { info = next; break; @@ -1216,9 +1252,8 @@ private static DatabaseDriver getDatabaseInfoFromDriver(PortletRequest request, PoolData data) { DatabaseDriver info = null; DatabaseDriver[] all = getAllDrivers(request); - for (int i = 0; i < all.length; i++) { - DatabaseDriver next = all[i]; - if (next.getDriverClassName()!=null && next.getDriverClassName().equals(data.getDriverClass())) { + for (DatabaseDriver next : all) { + if (next.getDriverClassName() != null && next.getDriverClassName().equals(data.getDriverClass())) { info = next; break; } @@ -1232,9 +1267,9 @@ private String dbtype; private String user; private String password; - private Map properties = new HashMap(); // Configuration for non-Generic drivers - private Map urlProperties = new HashMap(); // URL substitution for Generic drivers - private Map propertyNames; //todo: store these in the ConfigParam instead + private Map properties = new HashMap(); // Configuration for non-Generic drivers + private Map urlProperties = new HashMap(); // URL substitution for Generic drivers + private Map propertyNames; //todo: store these in the ConfigParam instead private String driverClass; private String url; private String urlPrototype; @@ -1248,93 +1283,93 @@ private String adapterDescription; private String rarPath; private String importSource; - private Map abstractNameMap; // generated as needed, don't need to read/write it + private Map abstractNameMap; // generated as needed, don't need to read/write it private String deployError; public void load(PortletRequest request) { name = request.getParameter("name"); - if(name != null && name.equals("")) name = null; + if (name != null && name.equals("")) name = null; driverClass = request.getParameter("driverClass"); - if(driverClass != null && driverClass.equals("")) driverClass = null; + if (driverClass != null && driverClass.equals("")) driverClass = null; dbtype = request.getParameter("dbtype"); - if(dbtype != null && dbtype.equals("")) dbtype = null; + if (dbtype != null && dbtype.equals("")) dbtype = null; user = request.getParameter("user"); - if(user != null && user.equals("")) user = null; + if (user != null && user.equals("")) user = null; password = request.getParameter("password"); - if(password != null && password.equals("")) password = null; + if (password != null && password.equals("")) password = null; url = request.getParameter("url"); - if(url != null && url.equals("")) { + if (url != null && url.equals("")) { url = null; - } else if(url != null && url.startsWith("URLENCODED")) { + } else if (url != null && url.startsWith("URLENCODED")) { try { url = URLDecoder.decode(url.substring(10), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unable to decode URL", e); - } catch(IllegalArgumentException e) { // not encoded after all?? + } catch (IllegalArgumentException e) { // not encoded after all?? url = url.substring(10); } } urlPrototype = request.getParameter("urlPrototype"); - if(urlPrototype != null && urlPrototype.equals("")) urlPrototype = null; + if (urlPrototype != null && urlPrototype.equals("")) urlPrototype = null; jars = request.getParameterValues("jars"); minSize = request.getParameter("minSize"); - if(minSize != null && minSize.equals("")) minSize = null; + if (minSize != null && minSize.equals("")) minSize = null; maxSize = request.getParameter("maxSize"); - if(maxSize != null && maxSize.equals("")) maxSize = null; + if (maxSize != null && maxSize.equals("")) maxSize = null; blockingTimeout = request.getParameter("blockingTimeout"); - if(blockingTimeout != null && blockingTimeout.equals("")) blockingTimeout = null; + if (blockingTimeout != null && blockingTimeout.equals("")) blockingTimeout = null; idleTimeout = request.getParameter("idleTimeout"); - if(idleTimeout != null && idleTimeout.equals("")) idleTimeout = null; + if (idleTimeout != null && idleTimeout.equals("")) idleTimeout = null; abstractName = request.getParameter("abstractName"); - if(abstractName != null && abstractName.equals("")) abstractName = null; + if (abstractName != null && abstractName.equals("")) abstractName = null; adapterDisplayName = request.getParameter("adapterDisplayName"); - if(adapterDisplayName != null && adapterDisplayName.equals("")) adapterDisplayName = null; + if (adapterDisplayName != null && adapterDisplayName.equals("")) adapterDisplayName = null; adapterDescription = request.getParameter("adapterDescription"); - if(adapterDescription != null && adapterDescription.equals("")) adapterDescription = null; + if (adapterDescription != null && adapterDescription.equals("")) adapterDescription = null; rarPath = request.getParameter("rarPath"); - if(rarPath != null && rarPath.equals("")) rarPath = null; + if (rarPath != null && rarPath.equals("")) rarPath = null; importSource = request.getParameter("importSource"); - if(importSource != null && importSource.equals("")) importSource = null; + if (importSource != null && importSource.equals("")) importSource = null; Map map = request.getParameterMap(); - propertyNames = new HashMap(); - for (Iterator it = map.keySet().iterator(); it.hasNext();) { - String key = (String) it.next(); - if(key.startsWith("urlproperty-")) { + propertyNames = new HashMap(); + for (Object o : map.keySet()) { + String key = (String) o; + if (key.startsWith("urlproperty-")) { urlProperties.put(key, request.getParameter(key)); - } else if(key.startsWith("property-")) { + } else if (key.startsWith("property-")) { properties.put(key, request.getParameter(key)); propertyNames.put(key, getPropertyName(key)); } } deployError = request.getParameter("deployError"); - if(deployError != null && deployError.equals("")) deployError = null; + if (deployError != null && deployError.equals("")) deployError = null; } public void loadPropertyNames() { - propertyNames = new HashMap(); - for (Iterator it = properties.keySet().iterator(); it.hasNext();) { - String key = (String) it.next(); + propertyNames = new HashMap(); + for (String key : properties.keySet()) { propertyNames.put(key, getPropertyName(key)); } } private static String getPropertyName(String key) { int pos = key.indexOf('-'); - key = Character.toUpperCase(key.charAt(pos+1))+key.substring(pos+2); + key = Character.toUpperCase(key.charAt(pos + 1)) + key.substring(pos + 2); StringBuffer buf = new StringBuffer(); pos = 0; - for(int i=1; i 1) { // first lower-case after a series of caps - buf.append(key.substring(pos, i-1)).append(" "); - pos = i-1; + if (Character.isUpperCase( + key.charAt(i - 1)) && i - pos > 1) { // first lower-case after a series of caps + buf.append(key.substring(pos, i - 1)).append(" "); + pos = i - 1; } } } @@ -1343,42 +1378,40 @@ } public void store(ActionResponse response) { - if(name != null) response.setRenderParameter("name", name); - if(dbtype != null) response.setRenderParameter("dbtype", dbtype); - if(driverClass != null) response.setRenderParameter("driverClass", driverClass); - if(user != null) response.setRenderParameter("user", user); - if(password != null) response.setRenderParameter("password", password); - if(url != null) { // attempt to work around Pluto/Tomcat error with ; in a stored value + if (name != null) response.setRenderParameter("name", name); + if (dbtype != null) response.setRenderParameter("dbtype", dbtype); + if (driverClass != null) response.setRenderParameter("driverClass", driverClass); + if (user != null) response.setRenderParameter("user", user); + if (password != null) response.setRenderParameter("password", password); + if (url != null) { // attempt to work around Pluto/Tomcat error with ; in a stored value try { - response.setRenderParameter("url", "URLENCODED"+URLEncoder.encode(url, "UTF-8")); + response.setRenderParameter("url", "URLENCODED" + URLEncoder.encode(url, "UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unable to encode URL", e); } } - if(urlPrototype != null) response.setRenderParameter("urlPrototype", urlPrototype); - if(jars != null) response.setRenderParameter("jars", jars); - if(minSize != null) response.setRenderParameter("minSize", minSize); - if(maxSize != null) response.setRenderParameter("maxSize", maxSize); - if(blockingTimeout != null) response.setRenderParameter("blockingTimeout", blockingTimeout); - if(idleTimeout != null) response.setRenderParameter("idleTimeout", idleTimeout); - if(abstractName != null) response.setRenderParameter("abstractName", abstractName); - if(adapterDisplayName != null) response.setRenderParameter("adapterDisplayName", adapterDisplayName); - if(adapterDescription != null) response.setRenderParameter("adapterDescription", adapterDescription); - if(importSource != null) response.setRenderParameter("importSource", importSource); - if(rarPath != null) response.setRenderParameter("rarPath", rarPath); - for (Iterator it = urlProperties.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Map.Entry) it.next(); - if(entry.getValue() != null) { - response.setRenderParameter((String)entry.getKey(), (String)entry.getValue()); - } - } - for (Iterator it = properties.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Map.Entry) it.next(); - if(entry.getValue() != null) { - response.setRenderParameter((String)entry.getKey(), (String)entry.getValue()); + if (urlPrototype != null) response.setRenderParameter("urlPrototype", urlPrototype); + if (jars != null) response.setRenderParameter("jars", jars); + if (minSize != null) response.setRenderParameter("minSize", minSize); + if (maxSize != null) response.setRenderParameter("maxSize", maxSize); + if (blockingTimeout != null) response.setRenderParameter("blockingTimeout", blockingTimeout); + if (idleTimeout != null) response.setRenderParameter("idleTimeout", idleTimeout); + if (abstractName != null) response.setRenderParameter("abstractName", abstractName); + if (adapterDisplayName != null) response.setRenderParameter("adapterDisplayName", adapterDisplayName); + if (adapterDescription != null) response.setRenderParameter("adapterDescription", adapterDescription); + if (importSource != null) response.setRenderParameter("importSource", importSource); + if (rarPath != null) response.setRenderParameter("rarPath", rarPath); + for (Map.Entry entry : urlProperties.entrySet()) { + if (entry.getValue() != null) { + response.setRenderParameter((String) entry.getKey(), (String) entry.getValue()); + } + } + for (Map.Entry entry : properties.entrySet()) { + if (entry.getValue() != null) { + response.setRenderParameter((String) entry.getKey(), (String) entry.getValue()); } } - if(deployError != null) response.setRenderParameter("deployError", deployError); + if (deployError != null) response.setRenderParameter("deployError", deployError); } public String getName() { @@ -1397,15 +1430,15 @@ return password; } - public Map getProperties() { + public Map getProperties() { return properties; } - public Map getPropertyNames() { + public Map getPropertyNames() { return propertyNames; } - public Map getUrlProperties() { + public Map getUrlProperties() { return urlProperties; } @@ -1414,7 +1447,7 @@ } public String[] getJars() { - return jars; + return jars; } public String getMinSize() { @@ -1466,11 +1499,11 @@ return importSource; } - public Map getAbstractNameMap() { - if(abstractName == null) return Collections.EMPTY_MAP; - if(abstractNameMap != null) return abstractNameMap; + public Map getAbstractNameMap() { + if (abstractName == null) return Collections.emptyMap(); + if (abstractNameMap != null) return abstractNameMap; AbstractName name = new AbstractName(URI.create(abstractName)); - abstractNameMap = new HashMap(name.getName()); + abstractNameMap = new HashMap(name.getName()); abstractNameMap.put("domain", name.getObjectName().getDomain()); abstractNameMap.put("groupId", name.getArtifact().getGroupId()); abstractNameMap.put("artifactId", name.getArtifact().getArtifactId()); @@ -1494,8 +1527,8 @@ public ConnectionPool(AbstractName adapterAbstractName, AbstractName factoryAbstractName, String name, int state) { this.adapterAbstractName = adapterAbstractName.toURI().toString(); - String parent = (String)adapterAbstractName.getName().get(NameFactory.J2EE_APPLICATION); - if(parent != null && parent.equals("null")) { + String parent = (String) adapterAbstractName.getName().get(NameFactory.J2EE_APPLICATION); + if (parent != null && parent.equals("null")) { parent = null; } parentName = parent; @@ -1529,20 +1562,20 @@ } public int compareTo(Object o) { - final ConnectionPool pool = (ConnectionPool)o; + final ConnectionPool pool = (ConnectionPool) o; int names = name.compareTo(pool.name); - if(parentName == null) { - if(pool.parentName == null) { + if (parentName == null) { + if (pool.parentName == null) { return names; } else { return -1; } } else { - if(pool.parentName == null) { + if (pool.parentName == null) { return 1; } else { int test = parentName.compareTo(pool.parentName); - if(test != 0) { + if (test != 0) { return test; } else { return names;