001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Sam
028: */
029:
030: package com.caucho.netbeans;
031:
032: import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
033:
034: import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
035: import javax.enterprise.deploy.spi.DeploymentManager;
036: import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
037: import javax.enterprise.deploy.spi.factories.DeploymentFactory;
038: import java.util.WeakHashMap;
039: import java.util.logging.*;
040:
041: public class ResinDeploymentFactory implements DeploymentFactory {
042: private static final Logger log = Logger
043: .getLogger(ResinDeploymentFactory.class.getName());
044: private static final PluginL10N L = new PluginL10N(
045: ResinDeploymentFactory.class);
046:
047: private static final String RESIN_PREFIX = "resin:"; // NOI18N
048: private static final String DISCONNECTED_URI = "resin:virtual";
049:
050: private static DeploymentFactory _instance;
051:
052: private static final WeakHashMap<InstanceProperties, ResinDeploymentManager> _managerCache = new WeakHashMap<InstanceProperties, ResinDeploymentManager>();
053:
054: public static synchronized DeploymentFactory create() {
055: if (_instance == null) {
056: //log.fine("Create Resin Deployment Factory");
057:
058: _instance = new ResinDeploymentFactory();
059:
060: DeploymentFactoryManager.getInstance()
061: .registerDeploymentFactory(_instance);
062: }
063:
064: return _instance;
065: }
066:
067: public boolean handlesURI(String uri) {
068: return (uri != null) && uri.startsWith(RESIN_PREFIX);
069: }
070:
071: public DeploymentManager getDeploymentManager(String uri,
072: String username, String password)
073: throws DeploymentManagerCreationException {
074: if (!handlesURI(uri))
075: throw new DeploymentManagerCreationException(L.l(
076: "'{0}' is not a Resin URI", uri));
077:
078: InstanceProperties ip = InstanceProperties
079: .getInstanceProperties(uri);
080:
081: if (ip == null) {
082: if (!DISCONNECTED_URI.equals(uri))
083: throw new DeploymentManagerCreationException(L.l(
084: "Resin instance '{0}' is not registered.", uri));
085: }
086:
087: ResinDeploymentManager manager = _managerCache.get(ip);
088:
089: if (manager == null) {
090: try {
091: manager = new ResinDeploymentManager(uri, ip);
092: _managerCache.put(ip, manager);
093: } catch (IllegalArgumentException e) {
094: Exception t = new DeploymentManagerCreationException(
095: L
096: .l(
097: "Cannot create deployment manager for Resin instance: {0}",
098: uri));
099:
100: throw (DeploymentManagerCreationException) t
101: .initCause(e);
102: }
103: }
104:
105: return manager;
106: }
107:
108: public DeploymentManager getDisconnectedDeploymentManager(String uri)
109: throws DeploymentManagerCreationException {
110: // called on initialization and configuration
111: return getDeploymentManager(uri, null, null);
112: }
113:
114: public String getDisplayName() {
115: return "Resin 3.1";
116: }
117:
118: public String getProductVersion() {
119: return "3.1";
120: }
121: }
|