FileDocCategorySizeDatePackage
SunDeploymentFactory.javaAPI DocGlassfish v2 API10346Fri May 04 22:34:28 BST 2007com.sun.enterprise.deployapi

SunDeploymentFactory

public class SunDeploymentFactory extends Object implements javax.enterprise.deploy.spi.factories.DeploymentFactory
Concrete implementation of the JSR 88 DeploymentFactory interface.
author
dochez
author
tjquinn

Fields Summary
private static com.sun.enterprise.util.LocalStringManagerImpl
xlocalStrings
private static String
DMGR_NOT_CONNECTED
private static final String
PE_BETA_URISTRING
private static final String
DEFAULT_URISTRING
private static final String
HTTPS
private static final String
URI_SEPARATOR
private static final String
LOCAL_HOST
private static final int
HOST_PORT
private static final String[]
supportedURIs
private static Hashtable
connectedDeploymentManagers
private static Hashtable
disconnectedDeploymentManagers
private static final String
HTTPS_PROTOCOL
private static final String
HTTP_PROTOCOL
Constructors Summary
public SunDeploymentFactory()
Creates a new instance of SunDeploymentFactory

    
           
      
    
Methods Summary
public javax.enterprise.deploy.spi.DeploymentManagergetDeploymentManager(java.lang.String uri, java.lang.String username, java.lang.String password)
Return a connected DeploymentManager instance.

param
uri The URI that specifies the connection parameters
param
username An optional username (may be null if no authentication is required for this platform).
param
password An optional password (may be null if no authentication is required for this platform).
return
A ready DeploymentManager instance.
throws
DeploymentManagerCreationException occurs when a DeploymentManager could not be returned (server down, unable to authenticate, etc).

        
        if (handlesURI(uri)) {
            ServerConnectionIdentifier hostInfo = null;
            try {
                hostInfo = parseURIForHostInfo(uri);
            } catch(Exception ex) {
                DeploymentManagerCreationException e = new DeploymentManagerCreationException(
                xlocalStrings.getLocalString(
                "enterprise.deployapi.spi.wronghostidentifier",
                "Wrong host identifier in uri {0} ", new Object[] { uri }));
                e.initCause(ex);
                throw e;
            }
            try {
                hostInfo.setUserName(username);
                hostInfo.setPassword(password);
                DeploymentManager answer = null;

                answer = new SunDeploymentManager(hostInfo);
                return answer;
            } catch(Throwable t) {
                DeploymentManagerCreationException e = new DeploymentManagerCreationException(xlocalStrings.getLocalString(
                "enterprise.deployapi.spi.exceptionwhileconnecting", //NOI18N
                "Exception while connecting to {0} : {1}", new Object[] { uri, t.getMessage() })); //NOI18N
                e.initCause(t);
                throw e;
            }
        } else {
            return null;
        }
    
public javax.enterprise.deploy.spi.DeploymentManagergetDisconnectedDeploymentManager(java.lang.String uri)
Return a disconnected DeploymentManager instance.

param
uri the uri of the DeploymentManager to return.
return
A DeploymentManager disconnected instance.
throws
DeploymentManagerCreationException occurs if the DeploymentManager could not be created.

        if (handlesURI(uri)) {
            return new SunDeploymentManager();
        } else {
            return null;
        }
    
public java.lang.StringgetDisplayName()
Provide a string with the name of this vendor's DeploymentManager.

return
the name of the vendor's DeploymentManager.

        return xlocalStrings.getLocalString(
                "enterprise.deployapi.spi.DisplayName",
                "Sun Java System Application Server");
    
public java.lang.StringgetProductVersion()
Provide a string identifying version of this vendor's DeploymentManager.

return
the name of the vendor's DeploymentManager.

        return xlocalStrings.getLocalString(
                "enterprise.deployapi.spi.ProductVersion", "9.0");
    
public booleanhandlesURI(java.lang.String uri)
Tests whether this factory can create a DeploymentManager object based on the specificed URI. This does not indicate whether such an attempt will be successful, only whether the factory can handle the uri.

param
uri The uri to check
return
true if the factory can handle the uri.

        if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
            DOLUtils.getDefaultLogger().fine("handlesURI: URI ["+uri+"]");// NOI18N
        }
        
        if (uri != null) {
            try {
                return (parseURIForHostInfo(uri)!=null);
            } catch (Exception ex) {
                DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.deplyomentManagerLoadFailure", // NOI18N
                new Object[] {uri});
            }
        }
        return false;
    
public com.sun.enterprise.deployment.client.ServerConnectionIdentifierparseURIForHostInfo(java.lang.String uri)

return
the host name/port from the URI passed see JSR88 paragraph 9.2.3

        
        String targetURI = null;
        for (int i=0;i<supportedURIs.length;i++) {
            if (uri.indexOf(supportedURIs[i])==0) {
                targetURI = supportedURIs[i];
            }
        }
        
        //if the URI does not contain DEFAULT_URISTRINNG or PE_BETA_URISTRING,
        //then the URI is not valid.
        if (targetURI == null) {
            throw new Exception(xlocalStrings.getLocalString(
            "enterprise.deployapi.spi.invaliduri", // NOI18N
            "Invalid URI"));    // NOI18N
        }
        
        ServerConnectionIdentifier sci = new ServerConnectionIdentifier();
        
        if(uri.length() == targetURI.length()) {
            sci.setHostName(LOCAL_HOST);
            sci.setHostPort(HOST_PORT);
        } else {
            String reminder = uri.substring(targetURI.length());
            String[] splitted = reminder.split(URI_SEPARATOR);
            if (splitted.length<2) {
                throw new Exception(xlocalStrings.getLocalString(
                    "enterprise.deployapi.spi.invaliduri", // NOI18N
                    "Invalid URI"));    // NOI18N                
            }
            if ("".equals(splitted[0])) {
                sci.setHostName(LOCAL_HOST);
            } else {
                sci.setHostName(splitted[0]);
            }
            if ("".equals(splitted[1])) {
                sci.setHostPort(HOST_PORT);
            } else {
                sci.setHostPort(Integer.parseInt(splitted[1]));
            }
            
            if (splitted.length>2) {
                if (HTTPS.equals(splitted[2])) {
                    sci.setSecure(true);
                }
            }
        }
        return sci;