FileDocCategorySizeDatePackage
NamingConventions.javaAPI DocGlassfish v2 API27004Fri May 04 22:34:12 BST 2007com.sun.enterprise.appclient.jws

NamingConventions

public class NamingConventions extends Object
Defines strings and algorithms used in constructing names, URLs, etc. related to supporting Java Web Start access to app clients.

The logic for building names, URLs, etc. is collected into this one class so it is easier to understand go to make changes.

author
tjquinn

Fields Summary
public static final String
SYSTEM_WEBAPP_URL
fixed prefix for URLs handled by the Java Web Start support web app
public static final String
APPCLIENT_CATEGORY
Category definitions
public static final String
APPLICATION_CATEGORY
public static final String
APPSERVER_CATEGORY
public static final String
APPSERVER_SIGNED_CATEGORY
public static final String
APPSERVER_LIB_FILES
Subcategories of appserver content.
public static final String
APPSERVER_MQLIB_FILES
public static final String
APPSERVER_JMSRALIB_FILES
public static final String
APPSERVER_EXTJAR_FILES
public static final String
APPSERVER_DERBY_FILES
public static final String
APPCLIENT_MAIN_JNLP_TEMPLATE_NAME
Templates for dynamic documents are packaged in the jar file with this class. These names are used in getResource method invocations to retrieve the templates.
public static final String
APPCLIENT_CLIENT_JNLP_TEMPLATE_NAME
public static final String
APPCLIENT_MAIN_HTML_TEMPLATE_NAME
public static final String
APPCLIENT_CLIENT_HTML_TEMPLATE_NAME
public static final String
APPCLIENT_MAIN_JNLP_EXT_TEMPLATE_NAME
private static final String
MAIN_JNLP_SUFFIX
Several generated virtual file names use the context root as part of the name with fixed suffix appended.
private static final String
MAIN_HTML_SUFFIX
private static final String
CLIENT_JNLP_SUFFIX
private static final String
CLIENT_HTML_SUFFIX
private static final String
MAIN_EXT_JNLP_SUFFIX
public static final String
JWS_LOGGER
the logger to use for Java Web Start-related code
private com.sun.enterprise.instance.AppsManager
appsManager
the instance's apps manager
private com.sun.enterprise.instance.AppclientModulesManager
appclientModulesManager
the instance's app client modules manager
Constructors Summary
public NamingConventions()
Creates a new instance of NamingConventions, locating the required manager objects automatically.

throws
ConfigException in case of any problem locating the app server objects that provide the AppsManager and AppclientModulesManager objects.

    
                                    
        
        ServerContext appServerContext;
        InstanceEnvironment instEnv;
        
        if ((appServerContext = ApplicationServer.getServerContext()) == null) {
            throw new ConfigException("Error getting current app server context; ApplicationServer.getServerContext() returned null");
        }
        if ((instEnv = appServerContext.getInstanceEnvironment()) == null) {
            throw new ConfigException("Error getting current instance environment; appServercontext.getInstanceEnvironment() returned null");
        }
        appsManager = new AppsManager(instEnv, false);
        appclientModulesManager = new AppclientModulesManager(instEnv, false);
    
public NamingConventions(com.sun.enterprise.instance.AppsManager appsManager, com.sun.enterprise.instance.AppclientModulesManager appclientModulesManager)
Creates a new instance of NamingConventions, using previously-created references to the two manager objects.

param
appsManager the AppsManager instance to use for looking up applications
param
appclientsManager the AppclientModulesManager instance to use for looking up app clients

        this.appsManager = appsManager;
        this.appclientModulesManager = appclientModulesManager;
    
Methods Summary
public static java.lang.StringappServerCodebasePath()

        return SYSTEM_WEBAPP_URL + "/" + APPSERVER_CATEGORY;
    
public static java.lang.StringappclientCodebasePath(AppclientContentOrigin origin)

        String result = SYSTEM_WEBAPP_URL + "/" + APPCLIENT_CATEGORY + /* "/" + */ origin.getContextRoot();
        return result;
    
private static java.lang.StringappclientJarFilename(java.lang.String regName)

        return regName + DeploymentImplConstants.ClientJarSuffix;
    
private static java.lang.StringchooseContextRoot(java.lang.String explicitValue, java.lang.String defaultValue)
Returns the explicit context root, if non-null, or the default value otherwise.

return
the correct context root value to be used

        return (explicitValue == null) ? defaultValue : explicitValue;
    
public static java.lang.StringcontentKeyToPath(java.lang.String contentKey)
Converts the content key into the corresponding path for URLs.

param
content key to be converted
return
the path to be used in URLs

        return contentKey;
    
public static java.lang.StringextJarFilePath(int extDirNumber, java.io.File extJarFile)

        String path = "/" + extDirNumber + "/" + extJarFile.getName();
        return path;
    
public static java.lang.StringfullJarPath(java.lang.String contentKey)

        return SYSTEM_WEBAPP_URL + contentKeyToPath(contentKey);
    
public static com.sun.enterprise.deployment.util.ModuleDescriptor[]getEligibleAppclientModuleDescriptors(com.sun.enterprise.deployment.Application app)
Returns an array of ModuleDescriptors corresponding to the app clients in this application that are eligible for Java Web Start access.

param
app Application containing (potentially) the nested app clients
return
array of ModuleDescriptor objects for eligible app clients

        return getEligibleAppclientModuleDescriptors(app, null);
    
public static com.sun.enterprise.deployment.util.ModuleDescriptor[]getEligibleAppclientModuleDescriptors(com.sun.enterprise.deployment.Application app, java.util.logging.Logger logger)
Returns an array of ModuleDescriptors corresponding to the app clients in this application that are eligible for Java Web Start access. Provides logging if the expected nested ModuleDescriptor(s) are not found.

param
Application containing (potentially) the nested app clients
param
logger the Logger to use for writing warnings
return
array of ModuleDescriptor objects for eligible app clients

        Vector<ModuleDescriptor> mds = new Vector<ModuleDescriptor>();

        /*
         *Iterate through the app's app client modules.  For each, get the bundle
         *descriptor and make sure it's an app client descriptor.  If so, get
         *that descriptor's Java Web Start access descriptor.  If that is null, or
         *if it's non-null and the JWS access descriptor says the app client is 
         *eligible for JWS access, add the module descriptor to the collection
         *to be returned.
         */
        for (Iterator it = app.getModulesByType(ModuleType.CAR); it.hasNext();) {
            Object o = it.next();
            if (o instanceof ModuleDescriptor) {
                ModuleDescriptor moduleDescriptor = (ModuleDescriptor) o;
                BundleDescriptor bd = moduleDescriptor.getDescriptor();
                if (bd instanceof ApplicationClientDescriptor) {
                    ApplicationClientDescriptor appclientDescriptor = (ApplicationClientDescriptor) bd;
                    JavaWebStartAccessDescriptor jwsAD = appclientDescriptor.getJavaWebStartAccessDescriptor();
                    if (jwsAD == null || jwsAD.isEligible()) {
                        mds.add(moduleDescriptor);
                    }
                } else {
                    if (logger != null) {
                        logger.warning("During app/app client loading, expected bundleDescriptor for app client module to be of type ApplicationClientDescriptor but it is " + bd.getClass().getName() + "; ignoring it and continuing");
                    }
                }
            } else {
                if (logger != null) {
                    logger.warning("During app/app client loading, expected descriptor of type ModuleDescriptor but found " + o.getClass().getName() + " instead; ignoring it and continuing");
                }
            }
        }
        return mds.toArray(new ModuleDescriptor[mds.size()]);
    
private static java.lang.StringgetExplicitContextRoot(com.sun.enterprise.deployment.util.ModuleDescriptor moduleDescr)
Returns the developer-specified context root from the app client's runtime descriptor.

return
the developer-specified context root; null if none was specified

        /*
         *Return the developer-specified context root, if there is one.
         */
        String result = null;

        BundleDescriptor bd = moduleDescr.getDescriptor();
        if (bd instanceof ApplicationClientDescriptor) {
            ApplicationClientDescriptor acd = (ApplicationClientDescriptor) bd;
            JavaWebStartAccessDescriptor jwsAD = acd.getJavaWebStartAccessDescriptor();
            if (jwsAD != null) {
                result = jwsAD.getContextRoot();
            }
        }
        return result;
    
public java.lang.StringgetLaunchURLPath(java.lang.String appclientModuleID)
Returns the URL path for use in launching the stand-alone app client with the specified module ID.

param
moduleID the module ID of the stand-alone app client
return
String containing the URL path (excluding scheme, host, and port) for launching the app client; null if the app client is not eligible for Java Web Start access or cannot be queried

        String result = null;
        try {
            Application app = appclientModulesManager.getDescriptor(appclientModuleID, Thread.currentThread().getContextClassLoader(), false);
            /*
             *There should be exactly one app client ModuleDescriptor in this wrapper app.
             */
            ModuleDescriptor[] moduleDescrs = getEligibleAppclientModuleDescriptors(app);
            if (moduleDescrs.length == 1) {
                /*
                 *With the app client's module descr, find the path using either
                 *the developer-provided path or the default one.
                 */
                result = TopLevelAppclient.virtualContextRoot(app, moduleDescrs[0]);
            }
        } catch (ConfigException ce) {
            /*
             *Allow the return to be null if we cannot locate the app client.
             */
        }
        return result;
    
public java.lang.StringgetLaunchURLPath(java.lang.String appModuleID, java.lang.String appclientArchiveURI)
Returns the URL path for use in launching the app client with the specified archive URI embedded in the application with the specified module ID.

param
appModuleID the module ID of the application containing the app client
param
appclientArchiveURI the URI of the app client within the ear
return
String containing the URL path (excluding scheme, host, and port) for launching the app client; null if the app client is not eligible for Java Web Start access, or it or the containing app cannot be found

        String result = null;
        try {
            Application app = appsManager.getDescriptor(appModuleID, Thread.currentThread().getContextClassLoader(), false);
            ModuleDescriptor[] moduleDescrs = getEligibleAppclientModuleDescriptors(app);
            /*
             *Search the eligible module descriptors for one with an archive
             *URI that matches the desired one.
             */
            for (ModuleDescriptor m : moduleDescrs) {
                String archiveURI = m.getArchiveUri();
                if (archiveURI != null && archiveURI.equals(appclientArchiveURI)) {
                    result = NestedAppclient.virtualContextRoot(app, m);
                    break;
                }
            }
        } catch (ConfigException ce) {
            /*
             *Allow the return to be null if we cannot locate the app.
             */
        }
        return result;
    
public static java.lang.StringpathToContentKey(java.lang.String requestPath)
Performs any conversion needed from the HTTP request path information to the corresponding content key

param
the pathInfo from the HTTP request
return
the content key for the given request pathInfo

    
                                     
         
        return requestPath;
    
public static java.lang.StringrelativeFilePath(java.net.URI instanceRootDirURI, java.io.File targetFile)

        URI targetURI = targetFile.toURI();
        URI relativeURI = instanceRootDirURI.relativize(targetURI);
        return relativeURI.toString();
    
private static java.lang.StringtrimJarFileType(java.lang.String jarURI, java.lang.String replacement)
Replaces the final appearance of ".jar" in the input string with the replacement string.

param
the input string (typically the URI of the app client jar file)
param
the string to replace the final ".jar" in the original

        int startOfType = jarURI.lastIndexOf(".jar");
        if (startOfType == -1) {
            startOfType = jarURI.length();
        }
        String result = jarURI.substring(0, startOfType) + replacement;
        return result;
    
public static java.lang.StringwebAppURI()

        return SYSTEM_WEBAPP_URL;