1 23 24 package com.sun.enterprise.deployapi; 25 26 import com.sun.enterprise.deployment.client.ServerConnectionIdentifier; 27 import com.sun.enterprise.deployment.util.DOLUtils; 28 import com.sun.enterprise.util.LocalStringManagerImpl; 29 import java.util.Hashtable ; 30 import java.util.logging.Level ; 31 import javax.enterprise.deploy.spi.DeploymentManager ; 32 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException ; 33 import javax.enterprise.deploy.spi.factories.DeploymentFactory ; 34 35 40 public class SunDeploymentFactory implements DeploymentFactory { 41 42 private static LocalStringManagerImpl xlocalStrings = 43 new LocalStringManagerImpl(SunDeploymentFactory.class); 44 45 private static String DMGR_NOT_CONNECTED = xlocalStrings.getLocalString( 46 "enterprise.deployapi.spi.DMgrnotconnected", "Deployment Manager is not connected to J2EE Resources"); 49 51 private final static String PE_BETA_URISTRING = "deployer:Sun:S1AS::"; 55 private final static String DEFAULT_URISTRING = "deployer:Sun:AppServer::"; private final static String HTTPS = "https"; 58 private final static String URI_SEPARATOR = ":"; private final static String LOCAL_HOST = "localhost"; private final static int HOST_PORT = 4848; 62 private final static String [] supportedURIs = { PE_BETA_URISTRING, 63 DEFAULT_URISTRING }; 64 65 private static Hashtable connectedDeploymentManagers; 67 private static Hashtable disconnectedDeploymentManagers; 68 69 private final static String HTTPS_PROTOCOL = "s1ashttps"; 70 private final static String HTTP_PROTOCOL = "s1ashttp"; 71 72 73 public SunDeploymentFactory() { 74 } 75 76 77 89 public DeploymentManager getDeploymentManager(String uri, String username, String password) throws DeploymentManagerCreationException { 90 91 if (handlesURI(uri)) { 92 ServerConnectionIdentifier hostInfo = null; 93 try { 94 hostInfo = parseURIForHostInfo(uri); 95 } catch(Exception ex) { 96 DeploymentManagerCreationException e = new DeploymentManagerCreationException ( 97 xlocalStrings.getLocalString( 98 "enterprise.deployapi.spi.wronghostidentifier", 99 "Wrong host identifier in uri {0} ", new Object [] { uri })); 100 e.initCause(ex); 101 throw e; 102 } 103 try { 104 hostInfo.setUserName(username); 105 hostInfo.setPassword(password); 106 DeploymentManager answer = null; 107 108 answer = new SunDeploymentManager(hostInfo); 109 return answer; 110 } catch(Throwable t) { 111 DeploymentManagerCreationException e = new DeploymentManagerCreationException (xlocalStrings.getLocalString( 112 "enterprise.deployapi.spi.exceptionwhileconnecting", "Exception while connecting to {0} : {1}", new Object [] { uri, t.getMessage() })); e.initCause(t); 115 throw e; 116 } 117 } else { 118 return null; 119 } 120 } 121 122 129 public DeploymentManager getDisconnectedDeploymentManager(String uri) throws DeploymentManagerCreationException { 130 if (handlesURI(uri)) { 131 return new SunDeploymentManager(); 132 } else { 133 return null; 134 } 135 } 136 137 140 public String getDisplayName() { 141 return xlocalStrings.getLocalString( 142 "enterprise.deployapi.spi.DisplayName", 143 "Sun Java System Application Server"); 144 } 145 146 150 public String getProductVersion() { 151 return xlocalStrings.getLocalString( 152 "enterprise.deployapi.spi.ProductVersion", "9.0"); 153 } 154 155 162 public boolean handlesURI(String uri) { 163 if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) { 164 DOLUtils.getDefaultLogger().fine("handlesURI: URI ["+uri+"]"); } 166 167 if (uri != null) { 168 try { 169 return (parseURIForHostInfo(uri)!=null); 170 } catch (Exception ex) { 171 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.deplyomentManagerLoadFailure", new Object [] {uri}); 173 } 174 } 175 return false; 176 } 177 178 179 182 183 public ServerConnectionIdentifier parseURIForHostInfo(String uri) throws Exception { 184 185 String targetURI = null; 186 for (int i=0;i<supportedURIs.length;i++) { 187 if (uri.indexOf(supportedURIs[i])==0) { 188 targetURI = supportedURIs[i]; 189 } 190 } 191 192 if (targetURI == null) { 195 throw new Exception (xlocalStrings.getLocalString( 196 "enterprise.deployapi.spi.invaliduri", "Invalid URI")); } 199 200 ServerConnectionIdentifier sci = new ServerConnectionIdentifier(); 201 202 if(uri.length() == targetURI.length()) { 203 sci.setHostName(LOCAL_HOST); 204 sci.setHostPort(HOST_PORT); 205 } else { 206 String reminder = uri.substring(targetURI.length()); 207 String [] splitted = reminder.split(URI_SEPARATOR); 208 if (splitted.length<2) { 209 throw new Exception (xlocalStrings.getLocalString( 210 "enterprise.deployapi.spi.invaliduri", "Invalid URI")); } 213 if ("".equals(splitted[0])) { 214 sci.setHostName(LOCAL_HOST); 215 } else { 216 sci.setHostName(splitted[0]); 217 } 218 if ("".equals(splitted[1])) { 219 sci.setHostPort(HOST_PORT); 220 } else { 221 sci.setHostPort(Integer.parseInt(splitted[1])); 222 } 223 224 if (splitted.length>2) { 225 if (HTTPS.equals(splitted[2])) { 226 sci.setSecure(true); 227 } 228 } 229 } 230 return sci; 231 } 232 } 233 | Popular Tags |