0001: /**
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */package org.apache.geronimo.console.databasemanager.wizard;
0017:
0018: import java.io.BufferedOutputStream;
0019: import java.io.ByteArrayOutputStream;
0020: import java.io.File;
0021: import java.io.FileOutputStream;
0022: import java.io.FileReader;
0023: import java.io.IOException;
0024: import java.io.PrintWriter;
0025: import java.io.Serializable;
0026: import java.io.StringReader;
0027: import java.io.StringWriter;
0028: import java.io.UnsupportedEncodingException;
0029: import java.net.MalformedURLException;
0030: import java.net.URI;
0031: import java.net.URL;
0032: import java.net.URLClassLoader;
0033: import java.net.URLDecoder;
0034: import java.net.URLEncoder;
0035: import java.sql.Connection;
0036: import java.sql.DatabaseMetaData;
0037: import java.sql.Driver;
0038: import java.sql.SQLException;
0039: import java.util.ArrayList;
0040: import java.util.Arrays;
0041: import java.util.Collections;
0042: import java.util.Comparator;
0043: import java.util.HashMap;
0044: import java.util.HashSet;
0045: import java.util.List;
0046: import java.util.Map;
0047: import java.util.Properties;
0048: import java.util.Set;
0049: import java.util.SortedSet;
0050:
0051: import javax.enterprise.deploy.model.DDBean;
0052: import javax.enterprise.deploy.model.DDBeanRoot;
0053: import javax.enterprise.deploy.shared.ModuleType;
0054: import javax.enterprise.deploy.spi.DeploymentConfiguration;
0055: import javax.enterprise.deploy.spi.DeploymentManager;
0056: import javax.enterprise.deploy.spi.Target;
0057: import javax.enterprise.deploy.spi.TargetModuleID;
0058: import javax.enterprise.deploy.spi.status.ProgressObject;
0059: import javax.portlet.ActionRequest;
0060: import javax.portlet.ActionResponse;
0061: import javax.portlet.PortletConfig;
0062: import javax.portlet.PortletException;
0063: import javax.portlet.PortletRequest;
0064: import javax.portlet.PortletRequestDispatcher;
0065: import javax.portlet.PortletSession;
0066: import javax.portlet.RenderRequest;
0067: import javax.portlet.RenderResponse;
0068: import javax.portlet.WindowState;
0069: import javax.xml.parsers.DocumentBuilder;
0070: import javax.xml.parsers.DocumentBuilderFactory;
0071:
0072: import org.apache.commons.fileupload.FileItem;
0073: import org.apache.commons.fileupload.disk.DiskFileItemFactory;
0074: import org.apache.commons.fileupload.portlet.PortletFileUpload;
0075: import org.apache.commons.logging.Log;
0076: import org.apache.commons.logging.LogFactory;
0077: import org.apache.geronimo.connector.deployment.jsr88.ConfigPropertySetting;
0078: import org.apache.geronimo.connector.deployment.jsr88.ConnectionDefinition;
0079: import org.apache.geronimo.connector.deployment.jsr88.ConnectionDefinitionInstance;
0080: import org.apache.geronimo.connector.deployment.jsr88.ConnectionManager;
0081: import org.apache.geronimo.connector.deployment.jsr88.Connector15DCBRoot;
0082: import org.apache.geronimo.connector.deployment.jsr88.ConnectorDCB;
0083: import org.apache.geronimo.connector.deployment.jsr88.ResourceAdapter;
0084: import org.apache.geronimo.connector.deployment.jsr88.SinglePool;
0085: import org.apache.geronimo.connector.outbound.PoolingAttributes;
0086: import org.apache.geronimo.console.BasePortlet;
0087: import org.apache.geronimo.console.databasemanager.ManagementHelper;
0088: import org.apache.geronimo.console.ajax.ProgressInfo;
0089: import org.apache.geronimo.console.util.PortletManager;
0090: import org.apache.geronimo.converter.DatabaseConversionStatus;
0091: import org.apache.geronimo.converter.JDBCPool;
0092: import org.apache.geronimo.converter.bea.WebLogic81DatabaseConverter;
0093: import org.apache.geronimo.converter.jboss.JBoss4DatabaseConverter;
0094: import org.apache.geronimo.deployment.service.jsr88.EnvironmentData;
0095: import org.apache.geronimo.deployment.tools.loader.ConnectorDeployable;
0096: import org.apache.geronimo.gbean.AbstractName;
0097: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
0098: import org.apache.geronimo.kernel.management.State;
0099: import org.apache.geronimo.kernel.proxy.GeronimoManagedBean;
0100: import org.apache.geronimo.kernel.repository.Artifact;
0101: import org.apache.geronimo.kernel.repository.FileWriteMonitor;
0102: import org.apache.geronimo.kernel.repository.ListableRepository;
0103: import org.apache.geronimo.kernel.repository.WriteableRepository;
0104: import org.apache.geronimo.kernel.util.XmlUtil;
0105: import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory;
0106: import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
0107: import org.w3c.dom.Document;
0108: import org.w3c.dom.Element;
0109: import org.w3c.dom.Node;
0110: import org.w3c.dom.NodeList;
0111: import org.xml.sax.InputSource;
0112:
0113: /**
0114: * A portlet that lets you configure and deploy JDBC connection pools.
0115: *
0116: * @version $Rev: 611338 $ $Date: 2008-01-11 16:42:22 -0800 (Fri, 11 Jan 2008) $
0117: */
0118: public class DatabasePoolPortlet extends BasePortlet {
0119: private final static Log log = LogFactory
0120: .getLog(DatabasePoolPortlet.class);
0121: private final static Set<String> INCLUDE_ARTIFACTIDS = new HashSet<String>(
0122: Arrays.asList("system-database"));
0123:
0124: private final static Set<String> EXCLUDE_GROUPIDS = new HashSet<String>(
0125: Arrays.asList("org.apache.geronimo.modules",
0126: "org.apache.geronimo.configs",
0127: "org.apache.geronimo.applications",
0128: "org.apache.geronimo.assemblies", "org.apache.cxf",
0129: "org.apache.tomcat", "org.tranql", "commons-cli",
0130: "commons-io", "commons-logging", "commons-lang",
0131: "axis", "org.apache.axis2", "org.apache.directory",
0132: "org.apache.activemq", "org.apache.openejb",
0133: "org.apache.myfaces", "org.mortbay.jetty"));
0134: private final static String DRIVER_SESSION_KEY = "org.apache.geronimo.console.dbpool.Drivers";
0135: private final static String CONFIG_SESSION_KEY = "org.apache.geronimo.console.dbpool.ConfigParam";
0136: private final static String DRIVER_INFO_URL = "http://geronimo.apache.org/driver-downloads.properties";
0137: private static final String LIST_VIEW = "/WEB-INF/view/dbwizard/list.jsp";
0138: private static final String EDIT_VIEW = "/WEB-INF/view/dbwizard/edit.jsp";
0139: private static final String SELECT_RDBMS_VIEW = "/WEB-INF/view/dbwizard/selectDatabase.jsp";
0140: private static final String BASIC_PARAMS_VIEW = "/WEB-INF/view/dbwizard/basicParams.jsp";
0141: private static final String CONFIRM_URL_VIEW = "/WEB-INF/view/dbwizard/confirmURL.jsp";
0142: private static final String TEST_CONNECTION_VIEW = "/WEB-INF/view/dbwizard/testConnection.jsp";
0143: private static final String DOWNLOAD_VIEW = "/WEB-INF/view/dbwizard/selectDownload.jsp";
0144: private static final String DOWNLOAD_STATUS_VIEW = "/WEB-INF/view/dbwizard/downloadStatus.jsp";
0145: private static final String SHOW_PLAN_VIEW = "/WEB-INF/view/dbwizard/showPlan.jsp";
0146: private static final String IMPORT_UPLOAD_VIEW = "/WEB-INF/view/dbwizard/importUpload.jsp";
0147: private static final String IMPORT_STATUS_VIEW = "/WEB-INF/view/dbwizard/importStatus.jsp";
0148: private static final String USAGE_VIEW = "/WEB-INF/view/dbwizard/usage.jsp";
0149: private static final String LIST_MODE = "list";
0150: private static final String EDIT_MODE = "edit";
0151: private static final String SELECT_RDBMS_MODE = "rdbms";
0152: private static final String BASIC_PARAMS_MODE = "params";
0153: private static final String CONFIRM_URL_MODE = "url";
0154: private static final String TEST_CONNECTION_MODE = "test";
0155: private static final String SHOW_PLAN_MODE = "plan";
0156: private static final String DOWNLOAD_MODE = "download";
0157: private static final String DOWNLOAD_STATUS_MODE = "downloadStatus";
0158: private static final String EDIT_EXISTING_MODE = "editExisting";
0159: private static final String DELETE_MODE = "delete";
0160: private static final String SAVE_MODE = "save";
0161: private static final String IMPORT_START_MODE = "startImport";
0162: private static final String IMPORT_UPLOAD_MODE = "importUpload";
0163: private static final String IMPORT_STATUS_MODE = "importStatus";
0164: private static final String IMPORT_COMPLETE_MODE = "importComplete";
0165: private static final String WEBLOGIC_IMPORT_MODE = "weblogicImport";
0166: private static final String USAGE_MODE = "usage";
0167: private static final String IMPORT_EDIT_MODE = "importEdit";
0168: private static final String MODE_KEY = "mode";
0169:
0170: private PortletRequestDispatcher listView;
0171: private PortletRequestDispatcher editView;
0172: private PortletRequestDispatcher selectRDBMSView;
0173: private PortletRequestDispatcher basicParamsView;
0174: private PortletRequestDispatcher confirmURLView;
0175: private PortletRequestDispatcher testConnectionView;
0176: private PortletRequestDispatcher downloadView;
0177: private PortletRequestDispatcher downloadStatusView;
0178: private PortletRequestDispatcher planView;
0179: private PortletRequestDispatcher importUploadView;
0180: private PortletRequestDispatcher importStatusView;
0181: private PortletRequestDispatcher usageView;
0182:
0183: public void init(PortletConfig portletConfig)
0184: throws PortletException {
0185: super .init(portletConfig);
0186: listView = portletConfig.getPortletContext()
0187: .getRequestDispatcher(LIST_VIEW);
0188: editView = portletConfig.getPortletContext()
0189: .getRequestDispatcher(EDIT_VIEW);
0190: selectRDBMSView = portletConfig.getPortletContext()
0191: .getRequestDispatcher(SELECT_RDBMS_VIEW);
0192: basicParamsView = portletConfig.getPortletContext()
0193: .getRequestDispatcher(BASIC_PARAMS_VIEW);
0194: confirmURLView = portletConfig.getPortletContext()
0195: .getRequestDispatcher(CONFIRM_URL_VIEW);
0196: testConnectionView = portletConfig.getPortletContext()
0197: .getRequestDispatcher(TEST_CONNECTION_VIEW);
0198: downloadView = portletConfig.getPortletContext()
0199: .getRequestDispatcher(DOWNLOAD_VIEW);
0200: downloadStatusView = portletConfig.getPortletContext()
0201: .getRequestDispatcher(DOWNLOAD_STATUS_VIEW);
0202: planView = portletConfig.getPortletContext()
0203: .getRequestDispatcher(SHOW_PLAN_VIEW);
0204: importUploadView = portletConfig.getPortletContext()
0205: .getRequestDispatcher(IMPORT_UPLOAD_VIEW);
0206: importStatusView = portletConfig.getPortletContext()
0207: .getRequestDispatcher(IMPORT_STATUS_VIEW);
0208: usageView = portletConfig.getPortletContext()
0209: .getRequestDispatcher(USAGE_VIEW);
0210: }
0211:
0212: public void destroy() {
0213: listView = null;
0214: editView = null;
0215: selectRDBMSView = null;
0216: basicParamsView = null;
0217: confirmURLView = null;
0218: testConnectionView = null;
0219: downloadView = null;
0220: downloadStatusView = null;
0221: planView = null;
0222: importUploadView = null;
0223: importStatusView = null;
0224: usageView = null;
0225: super .destroy();
0226: }
0227:
0228: public DriverDownloader.DriverInfo[] getDriverInfo(
0229: PortletRequest request) {
0230: PortletSession session = request.getPortletSession(true);
0231: DriverDownloader.DriverInfo[] results = (DriverDownloader.DriverInfo[]) session
0232: .getAttribute(DRIVER_SESSION_KEY,
0233: PortletSession.APPLICATION_SCOPE);
0234: if (results == null) {
0235: DriverDownloader downloader = new DriverDownloader();
0236: try {
0237: results = downloader.loadDriverInfo(new URL(
0238: DRIVER_INFO_URL));
0239: session.setAttribute(DRIVER_SESSION_KEY, results,
0240: PortletSession.APPLICATION_SCOPE);
0241: } catch (MalformedURLException e) {
0242: log.error("Unable to download driver data", e);
0243: results = new DriverDownloader.DriverInfo[0];
0244: }
0245: }
0246: return results;
0247: }
0248:
0249: /**
0250: * Loads data about a resource adapter. Depending on what we already have, may load
0251: * the name and description, but always loads the config property descriptions.
0252: *
0253: * @param request Pass it or die
0254: * @param rarPath If we're creating a new RA, the path to identify it
0255: * @param displayName If we're editing an existing RA, its name
0256: * @param adapterAbstractName If we're editing an existing RA, its AbstractName
0257: * @return resource adapter parameter data object
0258: */
0259: public ResourceAdapterParams getRARConfiguration(
0260: PortletRequest request, String rarPath, String displayName,
0261: String adapterAbstractName) {
0262: PortletSession session = request.getPortletSession(true);
0263: if (rarPath != null && !rarPath.equals("")) {
0264: ResourceAdapterParams results = (ResourceAdapterParams) session
0265: .getAttribute(CONFIG_SESSION_KEY + "-" + rarPath,
0266: PortletSession.APPLICATION_SCOPE);
0267: if (results == null) {
0268: results = loadConfigPropertiesByPath(request, rarPath);
0269: session.setAttribute(
0270: CONFIG_SESSION_KEY + "-" + rarPath, results,
0271: PortletSession.APPLICATION_SCOPE);
0272: session.setAttribute(CONFIG_SESSION_KEY + "-"
0273: + results.displayName, results,
0274: PortletSession.APPLICATION_SCOPE);
0275: }
0276: return results;
0277: } else if (displayName != null && !displayName.equals("")
0278: && adapterAbstractName != null
0279: && !adapterAbstractName.equals("")) {
0280: ResourceAdapterParams results = (ResourceAdapterParams) session
0281: .getAttribute(CONFIG_SESSION_KEY + "-"
0282: + displayName,
0283: PortletSession.APPLICATION_SCOPE);
0284: if (results == null) {
0285: results = loadConfigPropertiesByAbstractName(request,
0286: adapterAbstractName);
0287: session.setAttribute(CONFIG_SESSION_KEY + "-"
0288: + displayName, results,
0289: PortletSession.APPLICATION_SCOPE);
0290: }
0291: return results;
0292: } else {
0293: throw new IllegalArgumentException();
0294: }
0295: }
0296:
0297: public void processAction(ActionRequest actionRequest,
0298: ActionResponse actionResponse) throws PortletException,
0299: IOException {
0300: String mode = actionRequest.getParameter(MODE_KEY);
0301: if (mode.equals(IMPORT_UPLOAD_MODE)) {
0302: processImportUpload(actionRequest, actionResponse);
0303: actionResponse.setRenderParameter(MODE_KEY,
0304: IMPORT_STATUS_MODE);
0305: return;
0306: }
0307: PoolData data = new PoolData();
0308: data.load(actionRequest);
0309: if (mode.equals("process-" + SELECT_RDBMS_MODE)) {
0310: DatabaseDriver info = getDatabaseInfo(actionRequest, data);
0311: if (info != null) {
0312: data.rarPath = info.getRAR().toString();
0313: if (info.isSpecific()) {
0314: data.adapterDisplayName = "Unknown"; // will pick these up when we process the RA type in the render request
0315: data.adapterDescription = "Unknown";
0316: actionResponse.setRenderParameter(MODE_KEY,
0317: EDIT_MODE);
0318: } else {
0319: data.driverClass = info.getDriverClassName();
0320: data.urlPrototype = info.getURLPrototype();
0321: actionResponse.setRenderParameter(MODE_KEY,
0322: BASIC_PARAMS_MODE);
0323: }
0324: } else {
0325: actionResponse.setRenderParameter(MODE_KEY,
0326: SELECT_RDBMS_MODE);
0327: }
0328: } else if (mode.equals("process-" + DOWNLOAD_MODE)) {
0329: String name = actionRequest.getParameter("driverName");
0330: DriverDownloader.DriverInfo[] drivers = getDriverInfo(actionRequest);
0331: DriverDownloader.DriverInfo found = null;
0332: for (DriverDownloader.DriverInfo driver : drivers) {
0333: if (driver.getName().equals(name)) {
0334: found = driver;
0335: break;
0336: }
0337: }
0338: if (found != null) {
0339: data.jars = new String[] { found.getRepositoryURI() };
0340: WriteableRepository repo = PortletManager
0341: .getCurrentServer(actionRequest)
0342: .getWritableRepositories()[0];
0343: final PortletSession session = actionRequest
0344: .getPortletSession();
0345: ProgressInfo progressInfo = new ProgressInfo();
0346: progressInfo.setMainMessage("Downloading "
0347: + found.getName());
0348: session.setAttribute(ProgressInfo.PROGRESS_INFO_KEY,
0349: progressInfo, PortletSession.APPLICATION_SCOPE);
0350: // Start the download monitoring
0351: new Thread(new Downloader(found, progressInfo, repo))
0352: .start();
0353: actionResponse.setRenderParameter(MODE_KEY,
0354: DOWNLOAD_STATUS_MODE);
0355: } else {
0356: actionResponse.setRenderParameter(MODE_KEY,
0357: DOWNLOAD_MODE);
0358: }
0359: } else if (mode.equals("process-" + DOWNLOAD_STATUS_MODE)) {
0360: if (data.getDbtype() == null
0361: || data.getDbtype().equals("Other")) {
0362: actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE);
0363: } else {
0364: actionResponse.setRenderParameter(MODE_KEY,
0365: BASIC_PARAMS_MODE);
0366: }
0367: } else if (mode.equals("process-" + BASIC_PARAMS_MODE)) {
0368: DatabaseDriver info;
0369: info = getDatabaseInfo(actionRequest, data);
0370: if (info != null) {
0371: data.url = populateURL(info.getURLPrototype(), info
0372: .getURLParameters(), data.getUrlProperties());
0373: }
0374: if (attemptDriverLoad(actionRequest, data) != null) {
0375: actionResponse.setRenderParameter(MODE_KEY,
0376: CONFIRM_URL_MODE);
0377: } else {
0378: actionResponse.setRenderParameter("driverError",
0379: "Unable to load driver " + data.driverClass);
0380: actionResponse.setRenderParameter(MODE_KEY,
0381: BASIC_PARAMS_MODE);
0382: }
0383: } else if (mode.equals("process-" + CONFIRM_URL_MODE)) {
0384: String test = actionRequest.getParameter("test");
0385: if (test == null || test.equals("true")) {
0386: String result = null;
0387: String stack = null;
0388: try {
0389: result = attemptConnect(actionRequest, data);
0390: } catch (Exception e) {
0391: StringWriter writer = new StringWriter();
0392: PrintWriter temp = new PrintWriter(writer);
0393: e.printStackTrace(temp);
0394: temp.flush();
0395: temp.close();
0396: stack = writer.getBuffer().toString();
0397: }
0398: if (result != null)
0399: actionResponse.setRenderParameter("connectResult",
0400: result);
0401: actionRequest.getPortletSession(true).setAttribute(
0402: "connectError", stack);
0403: actionResponse.setRenderParameter(MODE_KEY,
0404: TEST_CONNECTION_MODE);
0405: } else {
0406: save(actionRequest, actionResponse, data, false);
0407: }
0408: } else if (mode.equals(SAVE_MODE)) {
0409: save(actionRequest, actionResponse, data, false);
0410: } else if (mode.equals(SHOW_PLAN_MODE)) {
0411: String plan = save(actionRequest, actionResponse, data,
0412: true);
0413: actionRequest.getPortletSession(true).setAttribute(
0414: "deploymentPlan", plan);
0415: actionResponse.setRenderParameter(MODE_KEY, SHOW_PLAN_MODE);
0416: } else if (mode.equals(EDIT_EXISTING_MODE)) {
0417: final String name = actionRequest
0418: .getParameter("adapterAbstractName");
0419: loadConnectionFactory(actionRequest, name, data
0420: .getAbstractName(), data);
0421: actionResponse.setRenderParameter("adapterAbstractName",
0422: name);
0423: actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE);
0424: } else if (mode.equals(SELECT_RDBMS_MODE)) {
0425: if (data.getAdapterDisplayName() == null) { // Set a default for a new pool
0426: data.adapterDisplayName = "TranQL Generic JDBC Resource Adapter";
0427: }
0428: actionResponse.setRenderParameter(MODE_KEY, mode);
0429: } else if (mode.equals(WEBLOGIC_IMPORT_MODE)) {
0430: String domainDir = actionRequest
0431: .getParameter("weblogicDomainDir");
0432: String libDir = actionRequest
0433: .getParameter("weblogicLibDir");
0434: try {
0435: DatabaseConversionStatus status = WebLogic81DatabaseConverter
0436: .convert(libDir, domainDir);
0437: actionRequest.getPortletSession(true).setAttribute(
0438: "ImportStatus", new ImportStatus(status));
0439: actionResponse.setRenderParameter(MODE_KEY,
0440: IMPORT_STATUS_MODE);
0441: } catch (Exception e) {
0442: log.error("Unable to import", e);
0443: actionResponse.setRenderParameter("from", actionRequest
0444: .getParameter("from"));
0445: actionResponse.setRenderParameter(MODE_KEY,
0446: IMPORT_START_MODE);
0447: }
0448: } else if (mode.equals(IMPORT_START_MODE)) {
0449: actionResponse.setRenderParameter("from", actionRequest
0450: .getParameter("from"));
0451: actionResponse.setRenderParameter(MODE_KEY, mode);
0452: } else if (mode.equals(IMPORT_EDIT_MODE)) {
0453: ImportStatus status = getImportStatus(actionRequest);
0454: int index = Integer.parseInt(actionRequest
0455: .getParameter("importIndex"));
0456: status.setCurrentPoolIndex(index);
0457: loadImportedData(actionRequest, data, status
0458: .getCurrentPool());
0459: actionResponse.setRenderParameter(MODE_KEY, EDIT_MODE);
0460: } else if (mode.equals(IMPORT_COMPLETE_MODE)) {
0461: ImportStatus status = getImportStatus(actionRequest);
0462: log.warn("Import Results:"); //todo: create a screen for this
0463: log.warn(" " + status.getSkippedCount() + " ignored");
0464: log.warn(" " + status.getStartedCount()
0465: + " reviewed but not deployed");
0466: log.warn(" " + status.getPendingCount() + " not reviewed");
0467: log.warn(" " + status.getFinishedCount() + " deployed");
0468: actionRequest.getPortletSession().removeAttribute(
0469: "ImportStatus");
0470: } else if (mode.equals(DELETE_MODE)) {
0471: String name = actionRequest
0472: .getParameter("adapterAbstractName");
0473: loadConnectionFactory(actionRequest, name, data
0474: .getAbstractName(), data);
0475: delete(actionRequest, actionResponse, data);
0476: } else {
0477: actionResponse.setRenderParameter(MODE_KEY, mode);
0478: }
0479: data.store(actionResponse);
0480: }
0481:
0482: private static class Downloader implements Runnable {
0483: private WriteableRepository repo;
0484: private DriverDownloader.DriverInfo driver;
0485: private ProgressInfo progressInfo;
0486:
0487: public Downloader(DriverDownloader.DriverInfo driver,
0488: ProgressInfo progressInfo, WriteableRepository repo) {
0489: this .driver = driver;
0490: this .progressInfo = progressInfo;
0491: this .repo = repo;
0492: }
0493:
0494: public void run() {
0495: DriverDownloader downloader = new DriverDownloader();
0496: try {
0497: downloader.loadDriver(repo, driver,
0498: new FileWriteMonitor() {
0499: private int fileSize;
0500:
0501: public void writeStarted(
0502: String fileDescription, int fileSize) {
0503: this .fileSize = fileSize;
0504: log.info("Downloading "
0505: + fileDescription);
0506: }
0507:
0508: public void writeProgress(int bytes) {
0509: int kbDownloaded = (int) Math
0510: .floor(bytes / 1024);
0511: if (fileSize > 0) {
0512: int percent = (bytes * 100)
0513: / fileSize;
0514: progressInfo
0515: .setProgressPercent(percent);
0516: progressInfo
0517: .setSubMessage(kbDownloaded
0518: + " / " + fileSize
0519: / 1024
0520: + " Kb downloaded");
0521: } else {
0522: progressInfo
0523: .setSubMessage(kbDownloaded
0524: + " Kb downloaded");
0525: }
0526: }
0527:
0528: public void writeComplete(int bytes) {
0529: log.info("Finished downloading "
0530: + bytes + " b");
0531: }
0532: });
0533: } catch (IOException e) {
0534: log.error("Unable to download database driver", e);
0535: } finally {
0536: progressInfo.setFinished(true);
0537: }
0538: }
0539: }
0540:
0541: private void loadImportedData(PortletRequest request,
0542: PoolData data, ImportStatus.PoolProgress progress)
0543: throws PortletException {
0544: if (!progress.getType().equals(
0545: ImportStatus.PoolProgress.TYPE_XA)) {
0546: JDBCPool pool = (JDBCPool) progress.getPool();
0547: data.dbtype = "Other";
0548: data.adapterDisplayName = "TranQL Generic JDBC Resource Adapter";
0549: data.blockingTimeout = getImportString(pool
0550: .getBlockingTimeoutMillis());
0551: data.driverClass = pool.getDriverClass();
0552: data.idleTimeout = pool.getIdleTimeoutMillis() != null ? Integer
0553: .toString(pool.getIdleTimeoutMillis().intValue()
0554: / (60 * 1000))
0555: : null;
0556: data.maxSize = getImportString(pool.getMaxSize());
0557: data.minSize = getImportString(pool.getMinSize());
0558: data.name = pool.getName();
0559: data.password = pool.getPassword();
0560: data.url = pool.getJdbcURL();
0561: data.user = pool.getUsername();
0562: if (pool.getDriverClass() != null) {
0563: DatabaseDriver info = getDatabaseInfoFromDriver(
0564: request, data);
0565: if (info != null) {
0566: data.rarPath = info.getRAR().toString();
0567: data.urlPrototype = info.getURLPrototype();
0568: } else {
0569: throw new PortletException(
0570: "Don't recognize database driver "
0571: + data.driverClass + "!");
0572: }
0573: }
0574: } else {
0575: //todo: handle XA
0576: }
0577: }
0578:
0579: private static String getImportString(Integer value) {
0580: return value == null ? null : value.toString();
0581: }
0582:
0583: private boolean processImportUpload(ActionRequest request,
0584: ActionResponse response) throws PortletException {
0585: String type = request.getParameter("importSource");
0586: response.setRenderParameter("importSource", type);
0587: if (!PortletFileUpload.isMultipartContent(request)) {
0588: throw new PortletException("Expected file upload");
0589: }
0590:
0591: PortletFileUpload uploader = new PortletFileUpload(
0592: new DiskFileItemFactory());
0593: try {
0594: List<FileItem> items = uploader.parseRequest(request);
0595: for (FileItem item : items) {
0596: if (!item.isFormField()) {
0597: File file = File.createTempFile("geronimo-import",
0598: "");
0599: file.deleteOnExit();
0600: log.debug("Writing database pool import file to "
0601: + file.getAbsolutePath());
0602: item.write(file);
0603: DatabaseConversionStatus status = processImport(
0604: file, type);
0605: request.getPortletSession(true).setAttribute(
0606: "ImportStatus", new ImportStatus(status));
0607: return true;
0608: } else {
0609: throw new PortletException(
0610: "Not expecting any form fields");
0611: }
0612: }
0613: } catch (PortletException e) {
0614: throw e;
0615: } catch (Exception e) {
0616: throw new PortletException(e);
0617: }
0618: return false;
0619: }
0620:
0621: private DatabaseConversionStatus processImport(File importFile,
0622: String type) throws PortletException, IOException {
0623: if (type.equals("JBoss 4")) {
0624: return JBoss4DatabaseConverter.convert(new FileReader(
0625: importFile));
0626: } else if (type.equals("WebLogic 8.1")) {
0627: return WebLogic81DatabaseConverter.convert(new FileReader(
0628: importFile));
0629: } else {
0630: throw new PortletException("Unknown import type '" + type
0631: + "'");
0632: }
0633: }
0634:
0635: private ResourceAdapterParams loadConfigPropertiesByPath(
0636: PortletRequest request, String rarPath) {
0637: DeploymentManager mgr = ManagementHelper.getManagementHelper(
0638: request).getDeploymentManager();
0639: try {
0640: URL url = getRAR(request, rarPath).toURL();
0641: ConnectorDeployable deployable = new ConnectorDeployable(
0642: url);
0643: final DDBeanRoot ddBeanRoot = deployable.getDDBeanRoot();
0644: String adapterName = null, adapterDesc = null;
0645: String[] test = ddBeanRoot
0646: .getText("connector/display-name");
0647: if (test != null && test.length > 0) {
0648: adapterName = test[0];
0649: }
0650: test = ddBeanRoot.getText("connector/description");
0651: if (test != null && test.length > 0) {
0652: adapterDesc = test[0];
0653: }
0654: DDBean[] definitions = ddBeanRoot
0655: .getChildBean("connector/resourceadapter/outbound-resourceadapter/connection-definition");
0656: List<ConfigParam> configs = new ArrayList<ConfigParam>();
0657: if (definitions != null) {
0658: for (DDBean definition : definitions) {
0659: String iface = definition
0660: .getText("connectionfactory-interface")[0];
0661: if (iface.equals("javax.sql.DataSource")) {
0662: DDBean[] beans = definition
0663: .getChildBean("config-property");
0664: for (DDBean bean : beans) {
0665: String name = bean
0666: .getText("config-property-name")[0]
0667: .trim();
0668: String type = bean
0669: .getText("config-property-type")[0]
0670: .trim();
0671: test = bean
0672: .getText("config-property-value");
0673: String value = test == null
0674: || test.length == 0 ? null
0675: : test[0].trim();
0676: test = bean.getText("description");
0677: String desc = test == null
0678: || test.length == 0 ? null
0679: : test[0].trim();
0680: configs.add(new ConfigParam(name, type,
0681: desc, value));
0682: }
0683: }
0684: }
0685: }
0686: return new ResourceAdapterParams(adapterName, adapterDesc,
0687: configs.toArray(new ConfigParam[configs.size()]));
0688: } catch (Exception e) {
0689: log.error("Unable to read configuration properties", e);
0690: return null;
0691: } finally {
0692: if (mgr != null)
0693: mgr.release();
0694: }
0695: }
0696:
0697: private ResourceAdapterParams loadConfigPropertiesByAbstractName(
0698: PortletRequest request, String abstractName) {
0699: ResourceAdapterModule module = (ResourceAdapterModule) PortletManager
0700: .getManagedBean(request, new AbstractName(URI
0701: .create(abstractName)));
0702: String dd = module.getDeploymentDescriptor();
0703: DocumentBuilderFactory factory = XmlUtil
0704: .newDocumentBuilderFactory();
0705: factory.setValidating(false);
0706: factory.setNamespaceAware(true);
0707: try {
0708: DocumentBuilder builder = factory.newDocumentBuilder();
0709: final StringReader reader = new StringReader(dd);
0710: Document doc = builder.parse(new InputSource(reader));
0711: reader.close();
0712: Element elem = doc.getDocumentElement(); // connector
0713: String displayName = getFirstText(elem
0714: .getElementsByTagName("display-name"));
0715: String description = getFirstText(elem
0716: .getElementsByTagName("description"));
0717: elem = (Element) elem.getElementsByTagName(
0718: "resourceadapter").item(0);
0719: elem = (Element) elem.getElementsByTagName(
0720: "outbound-resourceadapter").item(0);
0721: NodeList defs = elem
0722: .getElementsByTagName("connection-definition");
0723: List<ConfigParam> all = new ArrayList<ConfigParam>();
0724: for (int i = 0; i < defs.getLength(); i++) {
0725: final Element def = (Element) defs.item(i);
0726: String iface = getFirstText(
0727: def
0728: .getElementsByTagName("connectionfactory-interface"))
0729: .trim();
0730: if (iface.equals("javax.sql.DataSource")) {
0731: NodeList configs = def
0732: .getElementsByTagName("config-property");
0733: for (int j = 0; j < configs.getLength(); j++) {
0734: Element config = (Element) configs.item(j);
0735: String name = getFirstText(
0736: config
0737: .getElementsByTagName("config-property-name"))
0738: .trim();
0739: String type = getFirstText(
0740: config
0741: .getElementsByTagName("config-property-type"))
0742: .trim();
0743: String test = getFirstText(config
0744: .getElementsByTagName("config-property-value"));
0745: String value = test == null ? null : test
0746: .trim();
0747: test = getFirstText(config
0748: .getElementsByTagName("description"));
0749: String desc = test == null ? null : test.trim();
0750: all
0751: .add(new ConfigParam(name, type, desc,
0752: value));
0753: }
0754: }
0755: }
0756: return new ResourceAdapterParams(displayName, description,
0757: all.toArray(new ConfigParam[all.size()]));
0758: } catch (Exception e) {
0759: log.error("Unable to read resource adapter DD", e);
0760: return null;
0761: }
0762: }
0763:
0764: private String getFirstText(NodeList list) {
0765: if (list.getLength() == 0) {
0766: return null;
0767: }
0768: Element first = (Element) list.item(0);
0769: StringBuffer buf = new StringBuffer();
0770: NodeList all = first.getChildNodes();
0771: for (int i = 0; i < all.getLength(); i++) {
0772: Node node = all.item(i);
0773: if (node.getNodeType() == Node.TEXT_NODE) {
0774: buf.append(node.getNodeValue());
0775: }
0776: }
0777: return buf.toString();
0778: }
0779:
0780: private void loadConnectionFactory(ActionRequest actionRequest,
0781: String adapterName, String factoryName, PoolData data) {
0782: AbstractName abstractAdapterName = new AbstractName(URI
0783: .create(adapterName));
0784: AbstractName abstractFactoryName = new AbstractName(URI
0785: .create(factoryName));
0786:
0787: ResourceAdapterModule adapter = (ResourceAdapterModule) PortletManager
0788: .getManagedBean(actionRequest, abstractAdapterName);
0789: JCAManagedConnectionFactory factory = (JCAManagedConnectionFactory) PortletManager
0790: .getManagedBean(actionRequest, abstractFactoryName);
0791: data.adapterDisplayName = adapter.getDisplayName();
0792: data.adapterDescription = adapter.getDescription();
0793: try {
0794: data.name = (String) abstractFactoryName.getName().get(
0795: "name");
0796: if (data.isGeneric()) {
0797: data.url = (String) factory
0798: .getConfigProperty("ConnectionURL");
0799: data.driverClass = (String) factory
0800: .getConfigProperty("Driver");
0801: data.user = (String) factory
0802: .getConfigProperty("UserName");
0803: data.password = (String) factory
0804: .getConfigProperty("Password");
0805: } else {
0806: ResourceAdapterParams params = getRARConfiguration(
0807: actionRequest, data.getRarPath(), data
0808: .getAdapterDisplayName(), adapterName);
0809: for (int i = 0; i < params.getConfigParams().length; i++) {
0810: ConfigParam cp = params.getConfigParams()[i];
0811: Object value = factory.getConfigProperty(cp
0812: .getName());
0813: data.properties.put("property-" + cp.getName(),
0814: value == null ? null : value.toString());
0815: }
0816: }
0817: } catch (Exception e) {
0818: log.error("Unable to look up connection property", e);
0819: }
0820: //todo: push the lookup into ManagementHelper
0821: PoolingAttributes pool = (PoolingAttributes) factory
0822: .getConnectionManagerContainer();
0823: data.minSize = Integer.toString(pool.getPartitionMinSize());
0824: data.maxSize = Integer.toString(pool.getPartitionMaxSize());
0825: data.blockingTimeout = Integer.toString(pool
0826: .getBlockingTimeoutMilliseconds());
0827: data.idleTimeout = Integer.toString(pool
0828: .getIdleTimeoutMinutes());
0829:
0830: }
0831:
0832: protected void doView(RenderRequest renderRequest,
0833: RenderResponse renderResponse) throws IOException,
0834: PortletException {
0835: if (WindowState.MINIMIZED
0836: .equals(renderRequest.getWindowState())) {
0837: return;
0838: }
0839: try {
0840: String mode = renderRequest.getParameter(MODE_KEY);
0841: PoolData data = new PoolData();
0842: data.load(renderRequest);
0843: renderRequest.setAttribute("pool", data);
0844: // If not headed anywhere in particular, send to list
0845: if (mode == null || mode.equals("")) {
0846: mode = LIST_MODE;
0847: }
0848: // If headed to list but there's an import in progress, redirect to import status
0849: if (mode.equals(LIST_MODE)
0850: && getImportStatus(renderRequest) != null) {
0851: mode = IMPORT_STATUS_MODE;
0852: }
0853:
0854: if (mode.equals(LIST_MODE)) {
0855: renderList(renderRequest, renderResponse);
0856: } else if (mode.equals(EDIT_MODE)) {
0857: renderEdit(renderRequest, renderResponse, data);
0858: } else if (mode.equals(SELECT_RDBMS_MODE)) {
0859: renderSelectRDBMS(renderRequest, renderResponse);
0860: } else if (mode.equals(DOWNLOAD_MODE)) {
0861: renderDownload(renderRequest, renderResponse);
0862: } else if (mode.equals(DOWNLOAD_STATUS_MODE)) {
0863: renderDownloadStatus(renderRequest, renderResponse);
0864: } else if (mode.equals(BASIC_PARAMS_MODE)) {
0865: renderBasicParams(renderRequest, renderResponse, data);
0866: } else if (mode.equals(CONFIRM_URL_MODE)) {
0867: renderConfirmURL(renderRequest, renderResponse);
0868: } else if (mode.equals(TEST_CONNECTION_MODE)) {
0869: renderTestConnection(renderRequest, renderResponse);
0870: } else if (mode.equals(SHOW_PLAN_MODE)) {
0871: renderPlan(renderRequest, renderResponse, data);
0872: } else if (mode.equals(IMPORT_START_MODE)) {
0873: renderImportUploadForm(renderRequest, renderResponse);
0874: } else if (mode.equals(IMPORT_STATUS_MODE)) {
0875: renderImportStatus(renderRequest, renderResponse);
0876: } else if (mode.equals(USAGE_MODE)) {
0877: renderUsage(renderRequest, renderResponse);
0878: }
0879: } catch (Throwable e) {
0880: log.error("Unable to render portlet", e);
0881: }
0882: }
0883:
0884: private void renderUsage(RenderRequest request,
0885: RenderResponse response) throws IOException,
0886: PortletException {
0887: usageView.include(request, response);
0888: }
0889:
0890: private void renderImportStatus(RenderRequest request,
0891: RenderResponse response) throws IOException,
0892: PortletException {
0893: request.setAttribute("status", getImportStatus(request));
0894: populatePoolList(request);
0895: importStatusView.include(request, response);
0896: }
0897:
0898: private void renderImportUploadForm(RenderRequest request,
0899: RenderResponse response) throws IOException,
0900: PortletException {
0901: request.setAttribute("from", request.getParameter("from"));
0902: importUploadView.include(request, response);
0903: }
0904:
0905: private void renderList(RenderRequest renderRequest,
0906: RenderResponse renderResponse) throws IOException,
0907: PortletException {
0908: populatePoolList(renderRequest);
0909: listView.include(renderRequest, renderResponse);
0910: }
0911:
0912: private void populatePoolList(PortletRequest renderRequest) {
0913: ResourceAdapterModule[] modules = PortletManager
0914: .getOutboundRAModules(renderRequest,
0915: "javax.sql.DataSource");
0916: List<ConnectionPool> list = new ArrayList<ConnectionPool>();
0917: for (ResourceAdapterModule module : modules) {
0918: AbstractName moduleName = PortletManager
0919: .getManagementHelper(renderRequest).getNameFor(
0920: module);
0921:
0922: JCAManagedConnectionFactory[] databases = PortletManager
0923: .getOutboundFactoriesForRA(renderRequest, module,
0924: "javax.sql.DataSource");
0925: for (JCAManagedConnectionFactory db : databases) {
0926: AbstractName dbName = PortletManager
0927: .getManagementHelper(renderRequest).getNameFor(
0928: db);
0929: list.add(new ConnectionPool(moduleName, dbName,
0930: (String) dbName.getName().get(
0931: NameFactory.J2EE_NAME),
0932: ((GeronimoManagedBean) db).getState()));
0933: }
0934: }
0935: Collections.sort(list);
0936: renderRequest.setAttribute("pools", list);
0937: }
0938:
0939: private void renderEdit(RenderRequest renderRequest,
0940: RenderResponse renderResponse, PoolData data)
0941: throws IOException, PortletException {
0942: if (data.abstractName == null || data.abstractName.equals("")) {
0943: DatabaseDriver info = getDatabaseInfo(renderRequest, data);
0944: loadDriverJARList(renderRequest, info);
0945: }
0946: if (!data.isGeneric()) {
0947: ResourceAdapterParams params = getRARConfiguration(
0948: renderRequest, data.getRarPath(), data
0949: .getAdapterDisplayName(), renderRequest
0950: .getParameter("adapterAbstractName"));
0951: data.adapterDisplayName = params.getDisplayName();
0952: data.adapterDescription = params.getDescription();
0953: Map<String, ConfigParam> map = new HashMap<String, ConfigParam>();
0954: boolean more = false;
0955: for (int i = 0; i < params.getConfigParams().length; i++) {
0956: ConfigParam param = params.getConfigParams()[i];
0957: if (!data.properties.containsKey("property-"
0958: + param.getName())) {
0959: data.properties.put("property-" + param.getName(),
0960: param.getDefaultValue());
0961: more = true;
0962: }
0963: map.put("property-" + param.getName(), param);
0964: }
0965: if (more) {
0966: data.loadPropertyNames();
0967: }
0968: renderRequest.setAttribute("ConfigParams", map);
0969: }
0970: editView.include(renderRequest, renderResponse);
0971: }
0972:
0973: private void renderSelectRDBMS(RenderRequest renderRequest,
0974: RenderResponse renderResponse) throws IOException,
0975: PortletException {
0976: renderRequest.setAttribute("databases",
0977: getAllDrivers(renderRequest));
0978: selectRDBMSView.include(renderRequest, renderResponse);
0979: }
0980:
0981: private void renderDownload(RenderRequest renderRequest,
0982: RenderResponse renderResponse) throws IOException,
0983: PortletException {
0984: renderRequest.setAttribute("drivers",
0985: getDriverInfo(renderRequest));
0986: downloadView.include(renderRequest, renderResponse);
0987: }
0988:
0989: private void renderDownloadStatus(RenderRequest renderRequest,
0990: RenderResponse renderResponse) throws IOException,
0991: PortletException {
0992: downloadStatusView.include(renderRequest, renderResponse);
0993: }
0994:
0995: private void renderBasicParams(RenderRequest renderRequest,
0996: RenderResponse renderResponse, PoolData data)
0997: throws IOException, PortletException {
0998: DatabaseDriver info = getDatabaseInfo(renderRequest, data);
0999: loadDriverJARList(renderRequest, info);
1000: // Make sure all properties available for the DB are listed
1001: if (info != null) {
1002: for (String param : info.getURLParameters()) {
1003: final String key = "urlproperty-" + param;
1004: if (!data.getUrlProperties().containsKey(key)) {
1005: data.getUrlProperties().put(
1006: key,
1007: param.equalsIgnoreCase("port")
1008: && info.getDefaultPort() > 0 ? info
1009: .getDefaultPort() : null);
1010: }
1011: }
1012: }
1013: // Pass on errors
1014: renderRequest.setAttribute("driverError", renderRequest
1015: .getParameter("driverError"));
1016:
1017: basicParamsView.include(renderRequest, renderResponse);
1018: }
1019:
1020: private void loadDriverJARList(RenderRequest renderRequest,
1021: DatabaseDriver info) {
1022: // List the available JARs
1023: List<String> list = new ArrayList<String>();
1024: ListableRepository[] repos = PortletManager.getCurrentServer(
1025: renderRequest).getRepositories();
1026: Set<Artifact> dependencyFilters = info == null ? null : info
1027: .getDependencyFilters();
1028: for (ListableRepository repo : repos) {
1029: SortedSet<Artifact> artifacts = repo.list();
1030: for (Artifact artifact : artifacts) {
1031: if (dependencyFilters != null) {
1032: for (Artifact filter : dependencyFilters) {
1033: if (filter.matches(artifact)) {
1034: list.add(artifact.toString());
1035: }
1036: }
1037:
1038: } else if (INCLUDE_ARTIFACTIDS.contains(artifact
1039: .getArtifactId())
1040: || !EXCLUDE_GROUPIDS.contains(artifact
1041: .getGroupId())) {
1042: list.add(artifact.toString());
1043: }
1044: }
1045: }
1046: Collections.sort(list);
1047: renderRequest.setAttribute("availableJars", list);
1048: }
1049:
1050: private void renderConfirmURL(RenderRequest renderRequest,
1051: RenderResponse renderResponse) throws IOException,
1052: PortletException {
1053: confirmURLView.include(renderRequest, renderResponse);
1054: }
1055:
1056: private void renderTestConnection(RenderRequest renderRequest,
1057: RenderResponse renderResponse) throws IOException,
1058: PortletException {
1059: // Pass on results
1060: renderRequest.setAttribute("connectResult", renderRequest
1061: .getParameter("connectResult"));
1062: renderRequest.setAttribute("connectError", renderRequest
1063: .getPortletSession().getAttribute("connectError"));
1064: testConnectionView.include(renderRequest, renderResponse);
1065: }
1066:
1067: private void renderPlan(RenderRequest renderRequest,
1068: RenderResponse renderResponse, PoolData data)
1069: throws IOException, PortletException {
1070: // Pass on results
1071: renderRequest.setAttribute("deploymentPlan", renderRequest
1072: .getPortletSession().getAttribute("deploymentPlan"));
1073: // Digest the RAR URI
1074: String path = PortletManager.getRepositoryEntry(renderRequest,
1075: data.getRarPath()).getPath();
1076: String base = PortletManager.getCurrentServer(renderRequest)
1077: .getServerInfo().getCurrentBaseDirectory();
1078: if (base != null && path.startsWith(base)) {
1079: path = path.substring(base.length());
1080: if (path.startsWith("/")) {
1081: path = path.substring(1);
1082: }
1083: } else {
1084: int pos = path.lastIndexOf('/');
1085: path = path.substring(pos + 1);
1086: }
1087: renderRequest.setAttribute("rarRelativePath", path);
1088:
1089: planView.include(renderRequest, renderResponse);
1090: }
1091:
1092: private static String attemptConnect(PortletRequest request,
1093: PoolData data) throws SQLException, IllegalAccessException,
1094: InstantiationException {
1095: Class driverClass = attemptDriverLoad(request, data);
1096: Driver driver = (Driver) driverClass.newInstance();
1097: if (driver.acceptsURL(data.url)) {
1098: Properties props = new Properties();
1099: if (data.user != null) {
1100: props.put("user", data.user);
1101: }
1102: if (data.password != null) {
1103: props.put("password", data.password);
1104: }
1105: Connection con = null;
1106: try {
1107: con = driver.connect(data.url, props);
1108: final DatabaseMetaData metaData = con.getMetaData();
1109: return metaData.getDatabaseProductName() + " "
1110: + metaData.getDatabaseProductVersion();
1111: } finally {
1112: if (con != null) {
1113: try {
1114: con.close();
1115: } catch (SQLException e) {
1116: //ignore
1117: }
1118: }
1119: }
1120: } else
1121: throw new SQLException("Driver " + data.getDriverClass()
1122: + " does not accept URL " + data.url);
1123: }
1124:
1125: private void delete(PortletRequest request,
1126: ActionResponse response, PoolData data) {
1127: // check to make sure the abstract name does not begin with 'org.apache.geronimo.configs'
1128: // if it does not - then delete it -- otherwise it is a system database
1129: if (data.getAbstractName() != null) {
1130: boolean isSystemDatabasePool = (data.getAbstractName()
1131: .indexOf("org.apache.geronimo.configs") == 0);
1132:
1133: if (!isSystemDatabasePool) {
1134: DeploymentManager mgr = ManagementHelper
1135: .getManagementHelper(request)
1136: .getDeploymentManager();
1137: try {
1138: // retrieve all running modules
1139: TargetModuleID[] runningIds = mgr
1140: .getRunningModules(ModuleType.RAR, mgr
1141: .getTargets());
1142:
1143: // index of module to keep
1144: int index = -1;
1145:
1146: // only keep module id that is associated with selected DB pool
1147: for (int i = 0; i < runningIds.length; i++) {
1148: if (data.getAbstractName().contains(
1149: runningIds[i].getModuleID())) {
1150: index = i;
1151: break;
1152: }
1153: }
1154: TargetModuleID[] ids = { runningIds[index] };
1155:
1156: // undeploy the db pool
1157: ProgressObject po = mgr.undeploy(ids);
1158: waitForProgress(po);
1159:
1160: if (po.getDeploymentStatus().isCompleted()) {
1161: log
1162: .info("Undeployment completed successfully!");
1163: }
1164: } catch (Exception e) {
1165: log.error("Undeployment unsuccessful!");
1166: } finally {
1167: if (mgr != null)
1168: mgr.release();
1169: }
1170: }
1171: }
1172: }
1173:
1174: private static String save(PortletRequest request,
1175: ActionResponse response, PoolData data, boolean planOnly) {
1176: ImportStatus status = getImportStatus(request);
1177: if (data.abstractName == null || data.abstractName.equals("")) { // we're creating a new pool
1178: data.name = data.name.replaceAll("\\s", "");
1179: DeploymentManager mgr = ManagementHelper
1180: .getManagementHelper(request)
1181: .getDeploymentManager();
1182: try {
1183: File rarFile = getRAR(request, data.getRarPath());
1184: ConnectorDeployable deployable = new ConnectorDeployable(
1185: rarFile.toURL());
1186: DeploymentConfiguration config = mgr
1187: .createConfiguration(deployable);
1188: final DDBeanRoot ddBeanRoot = deployable
1189: .getDDBeanRoot();
1190: Connector15DCBRoot root = (Connector15DCBRoot) config
1191: .getDConfigBeanRoot(ddBeanRoot);
1192: ConnectorDCB connector = (ConnectorDCB) root
1193: .getDConfigBean(ddBeanRoot.getChildBean(root
1194: .getXpaths()[0])[0]);
1195:
1196: EnvironmentData environment = new EnvironmentData();
1197: connector.setEnvironment(environment);
1198: org.apache.geronimo.deployment.service.jsr88.Artifact configId = new org.apache.geronimo.deployment.service.jsr88.Artifact();
1199: environment.setConfigId(configId);
1200: configId.setGroupId("console.dbpool");
1201: String artifactId = data.name;
1202: if (artifactId.indexOf('/') != -1) {
1203: // slash in artifact-id results in invalid configuration-id and leads to deployment errors
1204: artifactId = artifactId.replaceAll("/", "%2F");
1205: }
1206: configId.setArtifactId(artifactId);
1207: configId.setVersion("1.0");
1208: configId.setType("rar");
1209:
1210: String[] jars = data.getJars();
1211: int length = jars[jars.length - 1].length() == 0 ? jars.length - 1
1212: : jars.length;
1213: org.apache.geronimo.deployment.service.jsr88.Artifact[] dependencies = new org.apache.geronimo.deployment.service.jsr88.Artifact[length];
1214: for (int i = 0; i < dependencies.length; i++) {
1215: dependencies[i] = new org.apache.geronimo.deployment.service.jsr88.Artifact();
1216: }
1217: environment.setDependencies(dependencies);
1218: for (int i = 0; i < dependencies.length; i++) {
1219: Artifact tmp = Artifact.create(jars[i]);
1220: dependencies[i].setGroupId(tmp.getGroupId());
1221: dependencies[i].setArtifactId(tmp.getArtifactId());
1222: dependencies[i].setVersion(tmp.getVersion()
1223: .toString());
1224: dependencies[i].setType(tmp.getType());
1225: }
1226:
1227: ResourceAdapter adapter = connector
1228: .getResourceAdapter()[0];
1229: ConnectionDefinition definition = new ConnectionDefinition();
1230: adapter
1231: .setConnectionDefinition(new ConnectionDefinition[] { definition });
1232: definition
1233: .setConnectionFactoryInterface("javax.sql.DataSource");
1234: ConnectionDefinitionInstance instance = new ConnectionDefinitionInstance();
1235: definition
1236: .setConnectionInstance(new ConnectionDefinitionInstance[] { instance });
1237: instance.setName(data.getName());
1238: ConfigPropertySetting[] settings = instance
1239: .getConfigPropertySetting();
1240: if (data.isGeneric()) { // it's a generic TranQL JDBC pool
1241: for (ConfigPropertySetting setting : settings) {
1242: if (setting.getName().equals("UserName")) {
1243: setting.setValue(data.user);
1244: } else if (setting.getName().equals("Password")) {
1245: setting.setValue(data.password);
1246: } else if (setting.getName().equals(
1247: "ConnectionURL")) {
1248: setting.setValue(data.url);
1249: } else if (setting.getName().equals("Driver")) {
1250: setting.setValue(data.driverClass);
1251: }
1252: }
1253: } else { // it's an XA driver or non-TranQL RA
1254: for (ConfigPropertySetting setting : settings) {
1255: String value = data.properties.get("property-"
1256: + setting.getName());
1257: setting.setValue(value == null ? "" : value);
1258: }
1259: }
1260: ConnectionManager manager = instance
1261: .getConnectionManager();
1262: manager.setTransactionLocal(true);
1263: SinglePool pool = new SinglePool();
1264: manager.setPoolSingle(pool);
1265: pool.setMatchOne(true);
1266: // Max Size needs to be set before the minimum. This is because
1267: // the connection manager will constrain the minimum based on the
1268: // current maximum value in the pool. We might consider adding a
1269: // setPoolConstraints method to allow specifying both at the same time.
1270: if (data.maxSize != null && !data.maxSize.equals("")) {
1271: pool.setMaxSize(new Integer(data.maxSize));
1272: }
1273: if (data.minSize != null && !data.minSize.equals("")) {
1274: pool.setMinSize(new Integer(data.minSize));
1275: }
1276: if (data.blockingTimeout != null
1277: && !data.blockingTimeout.equals("")) {
1278: pool.setBlockingTimeoutMillis(new Integer(
1279: data.blockingTimeout));
1280: }
1281: if (data.idleTimeout != null
1282: && !data.idleTimeout.equals("")) {
1283: pool.setIdleTimeoutMinutes(new Integer(
1284: data.idleTimeout));
1285: }
1286:
1287: if (planOnly) {
1288: ByteArrayOutputStream out = new ByteArrayOutputStream();
1289: config.save(out);
1290: out.close();
1291: return new String(out.toByteArray(), "US-ASCII");
1292: } else {
1293: File tempFile = File.createTempFile(
1294: "console-deployment", ".xml");
1295: tempFile.deleteOnExit();
1296: log
1297: .debug("Writing database pool deployment plan to "
1298: + tempFile.getAbsolutePath());
1299: BufferedOutputStream out = new BufferedOutputStream(
1300: new FileOutputStream(tempFile));
1301: config.save(out);
1302: out.flush();
1303: out.close();
1304: Target[] targets = mgr.getTargets();
1305: if (null == targets) {
1306: throw new IllegalStateException(
1307: "No target to distribute to");
1308: }
1309: targets = new Target[] { targets[0] };
1310:
1311: ProgressObject po = mgr.distribute(targets,
1312: rarFile, tempFile);
1313: waitForProgress(po);
1314: if (po.getDeploymentStatus().isCompleted()) {
1315: TargetModuleID[] ids = po
1316: .getResultTargetModuleIDs();
1317: po = mgr.start(ids);
1318: waitForProgress(po);
1319: if (po.getDeploymentStatus().isCompleted()) {
1320: ids = po.getResultTargetModuleIDs();
1321: if (status != null) {
1322: status.getCurrentPool().setName(
1323: data.getName());
1324: status.getCurrentPool()
1325: .setConfigurationName(
1326: ids[0].getModuleID());
1327: status.getCurrentPool().setFinished(
1328: true);
1329: response.setRenderParameter(MODE_KEY,
1330: IMPORT_STATUS_MODE);
1331: }
1332:
1333: log
1334: .info("Deployment completed successfully!");
1335: }
1336: } else if (po.getDeploymentStatus().isFailed()) {
1337: data.deployError = "Unable to deploy: "
1338: + data.name;
1339: response
1340: .setRenderParameter(MODE_KEY, EDIT_MODE);
1341: log.info("Deployment Failed!");
1342: }
1343: }
1344: } catch (Exception e) {
1345: log.error("Unable to save connection pool", e);
1346: } finally {
1347: if (mgr != null)
1348: mgr.release();
1349: }
1350: } else { // We're saving updates to an existing pool
1351: if (planOnly) {
1352: throw new UnsupportedOperationException(
1353: "Can't update a plan for an existing deployment");
1354: }
1355: try {
1356: JCAManagedConnectionFactory factory = (JCAManagedConnectionFactory) PortletManager
1357: .getManagedBean(request, new AbstractName(URI
1358: .create(data.getAbstractName())));
1359: if (data.isGeneric()) {
1360: factory.setConfigProperty("ConnectionURL", data
1361: .getUrl());
1362: factory.setConfigProperty("UserName", data
1363: .getUser());
1364: factory.setConfigProperty("Password", data
1365: .getPassword());
1366: } else {
1367: for (Map.Entry<String, String> entry : data
1368: .getProperties().entrySet()) {
1369: factory.setConfigProperty(entry.getKey()
1370: .substring("property-".length()), entry
1371: .getValue());
1372: }
1373: }
1374: //todo: push the lookup into ManagementHelper
1375: PoolingAttributes pool = (PoolingAttributes) factory
1376: .getConnectionManagerContainer();
1377: pool.setPartitionMinSize(data.minSize == null
1378: || data.minSize.equals("") ? 0 : Integer
1379: .parseInt(data.minSize));
1380: pool.setPartitionMaxSize(data.maxSize == null
1381: || data.maxSize.equals("") ? 10 : Integer
1382: .parseInt(data.maxSize));
1383: pool
1384: .setBlockingTimeoutMilliseconds(data.blockingTimeout == null
1385: || data.blockingTimeout.equals("") ? 5000
1386: : Integer
1387: .parseInt(data.blockingTimeout));
1388: pool.setIdleTimeoutMinutes(data.idleTimeout == null
1389: || data.idleTimeout.equals("") ? 15 : Integer
1390: .parseInt(data.idleTimeout));
1391: } catch (Exception e) {
1392: log.error("Unable to save connection pool", e);
1393: }
1394: }
1395: return null;
1396: }
1397:
1398: private static void waitForProgress(ProgressObject po) {
1399: while (po.getDeploymentStatus().isRunning()) {
1400: try {
1401: Thread.sleep(100);
1402: } catch (InterruptedException e) {
1403: e.printStackTrace();
1404: }
1405: }
1406: }
1407:
1408: private static ImportStatus getImportStatus(PortletRequest request) {
1409: return (ImportStatus) request.getPortletSession(true)
1410: .getAttribute("ImportStatus");
1411: }
1412:
1413: private static File getRAR(PortletRequest request, String rarPath) {
1414: org.apache.geronimo.kernel.repository.Artifact artifact = org.apache.geronimo.kernel.repository.Artifact
1415: .create(rarPath);
1416: ListableRepository[] repos = PortletManager.getCurrentServer(
1417: request).getRepositories();
1418: for (ListableRepository repo : repos) {
1419: // if the artifact is not fully resolved then try to resolve it
1420: if (!artifact.isResolved()) {
1421: SortedSet results = repo.list(artifact);
1422: if (!results.isEmpty()) {
1423: artifact = (Artifact) results.first();
1424: } else {
1425: continue;
1426: }
1427: }
1428: File url = repo.getLocation(artifact);
1429: if (url != null) {
1430: if (url.exists() && url.canRead() && !url.isDirectory()) {
1431: return url;
1432: }
1433: }
1434: }
1435: return null;
1436: }
1437:
1438: /**
1439: * WARNING: This method relies on having access to the same repository
1440: * URLs as the server uses.
1441: *
1442: * @param request portlet request
1443: * @param data info about jars to include
1444: * @return driver class
1445: */
1446: private static Class attemptDriverLoad(PortletRequest request,
1447: PoolData data) {
1448: List<URL> list = new ArrayList<URL>();
1449: try {
1450: String[] jars = data.getJars();
1451: if (jars == null) {
1452: log
1453: .error("Driver load failed since no jar files were selected.");
1454: return null;
1455: }
1456: ListableRepository[] repos = PortletManager
1457: .getCurrentServer(request).getRepositories();
1458:
1459: for (String jar : jars) {
1460: Artifact artifact = Artifact.create(jar);
1461: for (ListableRepository repo : repos) {
1462: File url = repo.getLocation(artifact);
1463: if (url != null) {
1464: list.add(url.toURL());
1465: }
1466: }
1467: }
1468: URLClassLoader loader = new URLClassLoader(list
1469: .toArray(new URL[list.size()]),
1470: DatabasePoolPortlet.class.getClassLoader());
1471: try {
1472: return loader.loadClass(data.driverClass);
1473: } catch (ClassNotFoundException e) {
1474: return null;
1475: }
1476: } catch (Exception e) {
1477: e.printStackTrace();
1478: return null;
1479: }
1480: }
1481:
1482: private static String populateURL(String url, List<String> keys,
1483: Map properties) {
1484: for (String key : keys) {
1485: String value = (String) properties
1486: .get("urlproperty-" + key);
1487: if (value == null || value.equals("")) {
1488: int begin = url.indexOf("{" + key + "}");
1489: int end = begin + key.length() + 2;
1490: for (int j = begin - 1; j >= 0; j--) {
1491: char c = url.charAt(j);
1492: if (c == ';' || c == ':') {
1493: begin = j;
1494: break;
1495: } else if (c == '/') {
1496: if (url.length() > end
1497: && url.charAt(end) == '/') {
1498: begin = j; // Don't leave // if foo is null for /<foo>/
1499: }
1500: break;
1501: }
1502: }
1503: url = url.substring(0, begin) + url.substring(end);
1504: } else {
1505: if (value.indexOf('\\') != -1
1506: || value.indexOf('$') != -1) {
1507: // value contains backslash or dollar sign and needs preprocessing for replaceAll to work properly
1508: StringBuffer temp = new StringBuffer();
1509: char[] valueChars = value.toCharArray();
1510: for (char valueChar : valueChars) {
1511: if (valueChar == '\\' || valueChar == '$') {
1512: temp.append('\\');
1513: }
1514: temp.append(valueChar);
1515: }
1516: value = temp.toString();
1517: }
1518: url = url.replaceAll("\\{" + key + "\\}", value);
1519: }
1520: }
1521: return url;
1522: }
1523:
1524: private static DatabaseDriver[] getAllDrivers(PortletRequest request) {
1525: DatabaseDriver[] result = (DatabaseDriver[]) PortletManager
1526: .getGBeansImplementing(request, DatabaseDriver.class);
1527: Arrays.sort(result, new Comparator<DatabaseDriver>() {
1528: public int compare(DatabaseDriver o1, DatabaseDriver o2) {
1529: String name1 = o1.getName();
1530: String name2 = o2.getName();
1531: if (name1.equals("Other"))
1532: name1 = "zzzOther";
1533: if (name2.equals("Other"))
1534: name2 = "zzzOther";
1535: return name1.compareTo(name2);
1536: }
1537: });
1538: return result;
1539: }
1540:
1541: private static DatabaseDriver getDatabaseInfo(
1542: PortletRequest request, PoolData data) {
1543: DatabaseDriver info = null;
1544: DatabaseDriver[] all = getAllDrivers(request);
1545: for (DatabaseDriver next : all) {
1546: if (next.getName().equals(data.getDbtype())) {
1547: info = next;
1548: break;
1549: }
1550: }
1551: return info;
1552: }
1553:
1554: private static DatabaseDriver getDatabaseInfoFromDriver(
1555: PortletRequest request, PoolData data) {
1556: DatabaseDriver info = null;
1557: DatabaseDriver[] all = getAllDrivers(request);
1558: for (DatabaseDriver next : all) {
1559: if (next.getDriverClassName() != null
1560: && next.getDriverClassName().equals(
1561: data.getDriverClass())) {
1562: info = next;
1563: break;
1564: }
1565: }
1566: return info;
1567: }
1568:
1569: public static class PoolData implements Serializable {
1570: private static final long serialVersionUID = 1L;
1571: private String name;
1572: private String dbtype;
1573: private String user;
1574: private String password;
1575: private Map<String, String> properties = new HashMap<String, String>(); // Configuration for non-Generic drivers
1576: private Map<String, Object> urlProperties = new HashMap<String, Object>(); // URL substitution for Generic drivers
1577: private Map<String, String> propertyNames; //todo: store these in the ConfigParam instead
1578: private String driverClass;
1579: private String url;
1580: private String urlPrototype;
1581: private String[] jars;
1582: private String minSize;
1583: private String maxSize;
1584: private String blockingTimeout;
1585: private String idleTimeout;
1586: private String abstractName;
1587: private String adapterDisplayName;
1588: private String adapterDescription;
1589: private String rarPath;
1590: private String importSource;
1591: private Map<String, String> abstractNameMap; // generated as needed, don't need to read/write it
1592: private String deployError;
1593:
1594: public void load(PortletRequest request) {
1595: name = request.getParameter("name");
1596: if (name != null && name.equals(""))
1597: name = null;
1598: driverClass = request.getParameter("driverClass");
1599: if (driverClass != null && driverClass.equals(""))
1600: driverClass = null;
1601: dbtype = request.getParameter("dbtype");
1602: if (dbtype != null && dbtype.equals(""))
1603: dbtype = null;
1604: user = request.getParameter("user");
1605: if (user != null && user.equals(""))
1606: user = null;
1607: password = request.getParameter("password");
1608: if (password != null && password.equals(""))
1609: password = null;
1610: url = request.getParameter("url");
1611: if (url != null && url.equals("")) {
1612: url = null;
1613: } else if (url != null && url.startsWith("URLENCODED")) {
1614: try {
1615: url = URLDecoder.decode(url.substring(10), "UTF-8");
1616: } catch (UnsupportedEncodingException e) {
1617: throw new RuntimeException("Unable to decode URL",
1618: e);
1619: } catch (IllegalArgumentException e) { // not encoded after all??
1620: url = url.substring(10);
1621: }
1622: }
1623: urlPrototype = request.getParameter("urlPrototype");
1624: if (urlPrototype != null && urlPrototype.equals(""))
1625: urlPrototype = null;
1626: jars = request.getParameterValues("jars");
1627: minSize = request.getParameter("minSize");
1628: if (minSize != null && minSize.equals(""))
1629: minSize = null;
1630: maxSize = request.getParameter("maxSize");
1631: if (maxSize != null && maxSize.equals(""))
1632: maxSize = null;
1633: blockingTimeout = request.getParameter("blockingTimeout");
1634: if (blockingTimeout != null && blockingTimeout.equals(""))
1635: blockingTimeout = null;
1636: idleTimeout = request.getParameter("idleTimeout");
1637: if (idleTimeout != null && idleTimeout.equals(""))
1638: idleTimeout = null;
1639: abstractName = request.getParameter("abstractName");
1640: if (abstractName != null && abstractName.equals(""))
1641: abstractName = null;
1642: adapterDisplayName = request
1643: .getParameter("adapterDisplayName");
1644: if (adapterDisplayName != null
1645: && adapterDisplayName.equals(""))
1646: adapterDisplayName = null;
1647: adapterDescription = request
1648: .getParameter("adapterDescription");
1649: if (adapterDescription != null
1650: && adapterDescription.equals(""))
1651: adapterDescription = null;
1652: rarPath = request.getParameter("rarPath");
1653: if (rarPath != null && rarPath.equals(""))
1654: rarPath = null;
1655: importSource = request.getParameter("importSource");
1656: if (importSource != null && importSource.equals(""))
1657: importSource = null;
1658: Map map = request.getParameterMap();
1659: propertyNames = new HashMap<String, String>();
1660: for (Object o : map.keySet()) {
1661: String key = (String) o;
1662: if (key.startsWith("urlproperty-")) {
1663: urlProperties.put(key, request.getParameter(key));
1664: } else if (key.startsWith("property-")) {
1665: properties.put(key, request.getParameter(key));
1666: propertyNames.put(key, getPropertyName(key));
1667: }
1668: }
1669: deployError = request.getParameter("deployError");
1670: if (deployError != null && deployError.equals(""))
1671: deployError = null;
1672: }
1673:
1674: public void loadPropertyNames() {
1675: propertyNames = new HashMap<String, String>();
1676: for (String key : properties.keySet()) {
1677: propertyNames.put(key, getPropertyName(key));
1678: }
1679: }
1680:
1681: private static String getPropertyName(String key) {
1682: int pos = key.indexOf('-');
1683: key = Character.toUpperCase(key.charAt(pos + 1))
1684: + key.substring(pos + 2);
1685: StringBuffer buf = new StringBuffer();
1686: pos = 0;
1687: for (int i = 1; i < key.length(); i++) {
1688: if (Character.isUpperCase(key.charAt(i))) {
1689: if (Character.isUpperCase(key.charAt(i - 1))) { // ongoing capitalized word
1690:
1691: } else { // start of a new word
1692: buf.append(key.substring(pos, i)).append(" ");
1693: pos = i;
1694: }
1695: } else {
1696: if (Character.isUpperCase(key.charAt(i - 1))
1697: && i - pos > 1) { // first lower-case after a series of caps
1698: buf.append(key.substring(pos, i - 1)).append(
1699: " ");
1700: pos = i - 1;
1701: }
1702: }
1703: }
1704: buf.append(key.substring(pos));
1705: return buf.toString();
1706: }
1707:
1708: public void store(ActionResponse response) {
1709: if (name != null)
1710: response.setRenderParameter("name", name);
1711: if (dbtype != null)
1712: response.setRenderParameter("dbtype", dbtype);
1713: if (driverClass != null)
1714: response.setRenderParameter("driverClass", driverClass);
1715: if (user != null)
1716: response.setRenderParameter("user", user);
1717: if (password != null)
1718: response.setRenderParameter("password", password);
1719: if (url != null) { // attempt to work around Pluto/Tomcat error with ; in a stored value
1720: try {
1721: response.setRenderParameter("url", "URLENCODED"
1722: + URLEncoder.encode(url, "UTF-8"));
1723: } catch (UnsupportedEncodingException e) {
1724: throw new RuntimeException("Unable to encode URL",
1725: e);
1726: }
1727: }
1728: if (urlPrototype != null)
1729: response.setRenderParameter("urlPrototype",
1730: urlPrototype);
1731: if (jars != null)
1732: response.setRenderParameter("jars", jars);
1733: if (minSize != null)
1734: response.setRenderParameter("minSize", minSize);
1735: if (maxSize != null)
1736: response.setRenderParameter("maxSize", maxSize);
1737: if (blockingTimeout != null)
1738: response.setRenderParameter("blockingTimeout",
1739: blockingTimeout);
1740: if (idleTimeout != null)
1741: response.setRenderParameter("idleTimeout", idleTimeout);
1742: if (abstractName != null)
1743: response.setRenderParameter("abstractName",
1744: abstractName);
1745: if (adapterDisplayName != null)
1746: response.setRenderParameter("adapterDisplayName",
1747: adapterDisplayName);
1748: if (adapterDescription != null)
1749: response.setRenderParameter("adapterDescription",
1750: adapterDescription);
1751: if (importSource != null)
1752: response.setRenderParameter("importSource",
1753: importSource);
1754: if (rarPath != null)
1755: response.setRenderParameter("rarPath", rarPath);
1756: for (Map.Entry<String, Object> entry : urlProperties
1757: .entrySet()) {
1758: if (entry.getValue() != null) {
1759: response.setRenderParameter(entry.getKey(), entry
1760: .getValue().toString());
1761: }
1762: }
1763: for (Map.Entry<String, String> entry : properties
1764: .entrySet()) {
1765: if (entry.getValue() != null) {
1766: response.setRenderParameter(entry.getKey(), entry
1767: .getValue());
1768: }
1769: }
1770: if (deployError != null)
1771: response.setRenderParameter("deployError", deployError);
1772: }
1773:
1774: public String getName() {
1775: return name;
1776: }
1777:
1778: public String getDbtype() {
1779: return dbtype;
1780: }
1781:
1782: public String getUser() {
1783: return user;
1784: }
1785:
1786: public String getPassword() {
1787: return password;
1788: }
1789:
1790: public Map<String, String> getProperties() {
1791: return properties;
1792: }
1793:
1794: public Map<String, String> getPropertyNames() {
1795: return propertyNames;
1796: }
1797:
1798: public Map<String, Object> getUrlProperties() {
1799: return urlProperties;
1800: }
1801:
1802: public String getUrl() {
1803: return url;
1804: }
1805:
1806: public String[] getJars() {
1807: return jars;
1808: }
1809:
1810: public String getMinSize() {
1811: return minSize;
1812: }
1813:
1814: public String getMaxSize() {
1815: return maxSize;
1816: }
1817:
1818: public String getBlockingTimeout() {
1819: return blockingTimeout;
1820: }
1821:
1822: public String getIdleTimeout() {
1823: return idleTimeout;
1824: }
1825:
1826: public String getDriverClass() {
1827: return driverClass;
1828: }
1829:
1830: public String getUrlPrototype() {
1831: return urlPrototype;
1832: }
1833:
1834: public String getAbstractName() {
1835: return abstractName;
1836: }
1837:
1838: public String getAdapterDisplayName() {
1839: return adapterDisplayName;
1840: }
1841:
1842: public String getAdapterDescription() {
1843: return adapterDescription;
1844: }
1845:
1846: public String getRarPath() {
1847: return rarPath;
1848: }
1849:
1850: public boolean isGeneric() {
1851: //todo: is there any better way to tell?
1852: return adapterDisplayName == null
1853: || adapterDisplayName
1854: .equals("TranQL Generic JDBC Resource Adapter");
1855: }
1856:
1857: public String getImportSource() {
1858: return importSource;
1859: }
1860:
1861: public Map<String, String> getAbstractNameMap() {
1862: if (abstractName == null)
1863: return Collections.emptyMap();
1864: if (abstractNameMap != null)
1865: return abstractNameMap;
1866: AbstractName name = new AbstractName(URI
1867: .create(abstractName));
1868: abstractNameMap = new HashMap<String, String>(name
1869: .getName());
1870: abstractNameMap.put("domain", name.getObjectName()
1871: .getDomain());
1872: abstractNameMap.put("groupId", name.getArtifact()
1873: .getGroupId());
1874: abstractNameMap.put("artifactId", name.getArtifact()
1875: .getArtifactId());
1876: abstractNameMap.put("type", name.getArtifact().getType());
1877: abstractNameMap.put("version", name.getArtifact()
1878: .getVersion().toString());
1879: return abstractNameMap;
1880: }
1881:
1882: public String getDeployError() {
1883: return deployError;
1884: }
1885: }
1886:
1887: public static class ConnectionPool implements Serializable,
1888: Comparable {
1889: private static final long serialVersionUID = 1L;
1890: private final String adapterAbstractName;
1891: private final String factoryAbstractName;
1892: private final String name;
1893: private final String parentName;
1894: private final int state;
1895:
1896: public ConnectionPool(AbstractName adapterAbstractName,
1897: AbstractName factoryAbstractName, String name, int state) {
1898: this .adapterAbstractName = adapterAbstractName.toURI()
1899: .toString();
1900: String parent = (String) adapterAbstractName.getName().get(
1901: NameFactory.J2EE_APPLICATION);
1902: if (parent != null && parent.equals("null")) {
1903: parent = null;
1904: }
1905: parentName = parent;
1906: this .factoryAbstractName = factoryAbstractName.toURI()
1907: .toString();
1908: this .name = name;
1909: this .state = state;
1910: }
1911:
1912: public String getAdapterAbstractName() {
1913: return adapterAbstractName;
1914: }
1915:
1916: public String getFactoryAbstractName() {
1917: return factoryAbstractName;
1918: }
1919:
1920: public String getName() {
1921: return name;
1922: }
1923:
1924: public String getParentName() {
1925: return parentName;
1926: }
1927:
1928: public int getState() {
1929: return state;
1930: }
1931:
1932: public String getStateName() {
1933: return State.toString(state);
1934: }
1935:
1936: public int compareTo(Object o) {
1937: final ConnectionPool pool = (ConnectionPool) o;
1938: int names = name.compareTo(pool.name);
1939: if (parentName == null) {
1940: if (pool.parentName == null) {
1941: return names;
1942: } else {
1943: return -1;
1944: }
1945: } else {
1946: if (pool.parentName == null) {
1947: return 1;
1948: } else {
1949: int test = parentName.compareTo(pool.parentName);
1950: if (test != 0) {
1951: return test;
1952: } else {
1953: return names;
1954: }
1955: }
1956: }
1957: }
1958: }
1959:
1960: public static class ResourceAdapterParams {
1961: private String displayName;
1962: private String description;
1963: private ConfigParam[] configParams;
1964:
1965: public ResourceAdapterParams(String displayName,
1966: String description, ConfigParam[] configParams) {
1967: this .displayName = displayName;
1968: this .description = description;
1969: this .configParams = configParams;
1970: }
1971:
1972: public String getDisplayName() {
1973: return displayName;
1974: }
1975:
1976: public String getDescription() {
1977: return description;
1978: }
1979:
1980: public ConfigParam[] getConfigParams() {
1981: return configParams;
1982: }
1983: }
1984:
1985: public static class ConfigParam {
1986: private String name;
1987: private String type;
1988: private String description;
1989: private String defaultValue;
1990:
1991: public ConfigParam(String name, String type,
1992: String description, String defaultValue) {
1993: this .name = name;
1994: this .type = type;
1995: this .description = description;
1996: this .defaultValue = defaultValue;
1997: }
1998:
1999: public String getName() {
2000: return name;
2001: }
2002:
2003: public String getType() {
2004: return type;
2005: }
2006:
2007: public String getDescription() {
2008: return description;
2009: }
2010:
2011: public String getDefaultValue() {
2012: return defaultValue;
2013: }
2014: }
2015: }
|