1 19 20 package org.netbeans.modules.tomcat5; 21 22 import java.util.WeakHashMap ; 23 import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager ; 24 import javax.enterprise.deploy.spi.DeploymentManager ; 25 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException ; 26 import javax.enterprise.deploy.spi.factories.DeploymentFactory ; 27 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 28 import org.netbeans.modules.tomcat5.TomcatManager.TomcatVersion; 29 import org.openide.ErrorManager; 30 import org.openide.util.NbBundle; 31 32 43 public final class TomcatFactory implements DeploymentFactory { 44 45 public static final String SERVER_ID_50 = "Tomcat"; public static final String SERVER_ID_55 = "Tomcat55"; public static final String SERVER_ID_60 = "Tomcat60"; 49 public static final String TOMCAT_URI_PREFIX_50 = "tomcat:"; public static final String TOMCAT_URI_PREFIX_55 = "tomcat55:"; public static final String TOMCAT_URI_PREFIX_60 = "tomcat60:"; 53 private static final String DISCONNECTED_URI_50 = "tomcat:jakarta-tomcat-5.0.x"; private static final String DISCONNECTED_URI_55 = "tomcat55:jakarta-tomcat-5.5.x"; private static final String DISCONNECTED_URI_60 = "tomcat60:apache-tomcat-6.0.x"; 57 private static TomcatFactory instance; 58 private static TomcatFactory instance55; 59 private static TomcatFactory instance60; 60 61 private static final WeakHashMap managerCache = new WeakHashMap (); 62 63 private static ErrorManager err = ErrorManager.getDefault ().getInstance ("org.netbeans.modules.tomcat5"); 65 private final String tomcatUriPrefix; 66 private final String disconnectedUri; 67 private final TomcatVersion version; 68 69 private TomcatFactory(TomcatVersion version) { 70 this.version = version; 71 switch (version) { 72 case TOMCAT_50 : 73 tomcatUriPrefix = TOMCAT_URI_PREFIX_50; 74 disconnectedUri = DISCONNECTED_URI_50; 75 break; 76 case TOMCAT_55 : 77 tomcatUriPrefix = TOMCAT_URI_PREFIX_55; 78 disconnectedUri = DISCONNECTED_URI_55; 79 break; 80 case TOMCAT_60 : 81 default: 82 tomcatUriPrefix = TOMCAT_URI_PREFIX_60; 83 disconnectedUri = DISCONNECTED_URI_60; 84 break; 85 } 86 } 87 88 91 public static synchronized TomcatFactory create50() { 92 if (instance == null) { 93 if (err.isLoggable (ErrorManager.INFORMATIONAL)) err.log ("Creating TomcatFactory"); instance = new TomcatFactory(TomcatVersion.TOMCAT_50); 95 DeploymentFactoryManager.getInstance().registerDeploymentFactory(instance); 96 } 97 return instance; 98 } 99 100 103 public static synchronized TomcatFactory create55() { 104 if (instance55 == null) { 105 if (err.isLoggable (ErrorManager.INFORMATIONAL)) err.log ("Creating TomcatFactory"); instance55 = new TomcatFactory(TomcatVersion.TOMCAT_55); 107 DeploymentFactoryManager.getInstance().registerDeploymentFactory(instance55); 108 } 109 return instance55; 110 } 111 112 115 public static synchronized TomcatFactory create60() { 116 if (instance60 == null) { 117 if (err.isLoggable (ErrorManager.INFORMATIONAL)) err.log ("Creating TomcatFactory"); instance60 = new TomcatFactory(TomcatVersion.TOMCAT_60); 119 DeploymentFactoryManager.getInstance().registerDeploymentFactory(instance60); 120 } 121 return instance60; 122 } 123 124 127 public static ErrorManager getEM () { 128 return err; 129 } 130 131 138 public synchronized DeploymentManager getDeploymentManager(String uri, String uname, String passwd) 139 throws DeploymentManagerCreationException { 140 if (!handlesURI (uri)) { 141 throw new DeploymentManagerCreationException ("Invalid URI:" + uri); } 143 InstanceProperties ip = InstanceProperties.getInstanceProperties(uri); 147 if (ip == null) { 148 if (!disconnectedUri.equals(uri)) { 150 throw new DeploymentManagerCreationException ("Tomcat instance: " + uri + " is not registered in the IDE."); } 152 } 153 TomcatManager tm = (TomcatManager)managerCache.get(ip); 154 if (tm == null) { 155 try { 156 tm = new TomcatManager(true, uri.substring(tomcatUriPrefix.length()), version); 157 managerCache.put(ip, tm); 158 } catch (IllegalArgumentException iae) { 159 Throwable t = new DeploymentManagerCreationException ("Cannot create deployment manager for Tomcat instance: " + uri + "."); throw (DeploymentManagerCreationException )(t.initCause(iae)); 161 } 162 } 163 return tm; 164 } 165 166 public DeploymentManager getDisconnectedDeploymentManager(String uri) 167 throws DeploymentManagerCreationException { 168 return getDeploymentManager(uri, null, null); 170 } 171 172 public String getDisplayName() { 173 switch (version) { 174 case TOMCAT_50 : 175 return NbBundle.getMessage(TomcatFactory.class, "LBL_TomcatFactory"); 176 case TOMCAT_55 : 177 return NbBundle.getMessage(TomcatFactory.class, "LBL_TomcatFactory55"); 178 case TOMCAT_60 : 179 default: 180 return NbBundle.getMessage(TomcatFactory.class, "LBL_TomcatFactory60"); 181 } 182 } 183 184 public String getProductVersion() { 185 return NbBundle.getMessage(TomcatFactory.class, "LBL_TomcatFactoryVersion"); 186 } 187 188 192 public boolean handlesURI(String str) { 193 return str != null && str.startsWith (tomcatUriPrefix); 194 } 195 196 } 197 | Popular Tags |