FileDocCategorySizeDatePackage
J2EEModule.javaAPI DocGlassfish v2 API14116Fri May 04 22:24:10 BST 2007com.sun.enterprise.admin.mbeans

J2EEModule

public class J2EEModule extends Object
Provides API for getting attribute values like moduleType, location, etc. for j2ee stand-alone modules and the sub-modules within.
author
Sreenivas Munnangi

Fields Summary
private static final com.sun.enterprise.util.i18n.StringManager
localStrings
private static final Logger
sLogger
private String
standaloneModuleName
private String
subModuleName
private javax.enterprise.deploy.shared.ModuleType
moduleType
private String
ddLocation
Constructors Summary
public J2EEModule()
null constructor


           
       
    
public J2EEModule(String standaloneModuleName)
constructor for stand-alone module


	if ((standaloneModuleName == null) ||
            (standaloneModuleName.length() < 1)) {
		sLogger.log(Level.WARNING, getLogMsg("invalid standAloneModuleName"));
		throw new ServerInstanceException ( localStrings.getString(
			"admin.mbeans.J2EEModule.invalidStandaloneModuleName"));
	}
	this.standaloneModuleName = standaloneModuleName;
    
public J2EEModule(String standaloneModuleName, String subModuleName)
constructor for sub-module


	this(standaloneModuleName);

	if ((subModuleName == null) ||
            (subModuleName.length() < 1)) {
		sLogger.log(Level.WARNING, 
			getLogMsg("invalid sub module for the given stand-alone module"));
		throw new ServerInstanceException (localStrings.getString(
			"admin.mbeans.J2EEModule.invalidSubModuleName"));
	}
	this.subModuleName = subModuleName;
    
Methods Summary
java.lang.StringgetDDLocation(java.lang.String standaloneModuleName)
Returns deployment descriptors location for the given stand-alone module Now the ddLocation is set as part of determininig moduleType In future if rewuired this method can be used to provide enhanced functionality.

	sLogger.log(Level.FINE, getLogMsg(
		"getDDLocation for standaloneModuleName " + standaloneModuleName));
	return ddLocation;
    
java.lang.StringgetDDLocation(java.lang.String standaloneModuleName, java.lang.String subModuleName)
Returns deployment descriptors location for the given combination of stand-alone module and sub-module Now the ddLocation is set as part of determininig moduleType In future if rewuired this method can be used to provide enhanced functionality.

	sLogger.log(Level.FINE, getLogMsg(
		"getDDLocation for standaloneModuleName " + 
		standaloneModuleName + " " + 
		"subModuleName = " + subModuleName));
	return ddLocation;
    
public java.lang.StringgetDeploymentDescriptorsLocation()
Returns the deployment descriptors location for this module, i.e. where the deployment descriptors are stored.


	if (ddLocation != null) {
		ddLocation = RelativePathResolver.resolvePath(ddLocation);
		return ddLocation;
	}

	if (subModuleName == null) {
		ddLocation = getDDLocation(standaloneModuleName);
	} else {
		ddLocation = getDDLocation(standaloneModuleName, subModuleName);
	}

	if (ddLocation != null) {
		ddLocation = RelativePathResolver.resolvePath(ddLocation);
	}

	return ddLocation;
    
private java.lang.StringgetLogMsg(java.lang.String str)
private method for decorating log messages with class name and other appropriate info

	return (this.getClass().getName() + ":" +
		str);
     
public javax.enterprise.deploy.shared.ModuleTypegetModuleType()
Returns module type If both standaloneModuleName and subModuleName are valid strings then the assumption is that standaloneModuleName represents a valid j2ee application and subModuleName represents a module within the application. If subModuleName is null then the assumption is that the standaloneModuleName is a valid j2ee stand-alone module.


	if (moduleType != null) return moduleType;

	if (subModuleName == null) {
		moduleType = getModuleType(standaloneModuleName);
	} else {
		moduleType = getModuleType(standaloneModuleName, subModuleName);
	}

	return moduleType;
     
javax.enterprise.deploy.shared.ModuleTypegetModuleType(java.lang.String standaloneModuleName)
Returns moduleType for the given stand-alone module


	sLogger.log(Level.FINE, 
		getLogMsg("getModuleType for standaloneModuleName" + 
		standaloneModuleName));

        // iterate through each of module types

        ModuleType moduleType = null;

        try {

            // Application
            Applications appsConfigBean =
                    (Applications) ConfigBeansFactory.getConfigBeanByXPath(
		    AdminService.getAdminService().getAdminContext().getAdminConfigContext(),
		    ServerXPathHelper.XPATH_APPLICATIONS);

            // J2EEApplication
            J2eeApplication[] j2eeApps = appsConfigBean.getJ2eeApplication();
            if (j2eeApps != null) {
                for(int i=0; i<j2eeApps.length; i++) {
                    if ((j2eeApps[i].getName()).equals(standaloneModuleName)) {
			ddLocation = j2eeApps[i].getLocation();
			return ModuleType.EAR;
                    }
                }
            }        

            // EJBModule
            EjbModule[] eModules = appsConfigBean.getEjbModule();
            if (eModules != null) {
                for(int i=0; i<eModules.length; i++) {
                    if ((eModules[i].getName()).equals(standaloneModuleName)) {
			ddLocation = eModules[i].getLocation();
			return ModuleType.EJB;
                    }
                }
            }

            // WebModule
            WebModule[] wModules = appsConfigBean.getWebModule();
            if (wModules != null) {
                for(int i=0; i<wModules.length; i++) {
                    if ((wModules[i].getName()).equals(standaloneModuleName)) {
			ddLocation = wModules[i].getLocation();
			return ModuleType.WAR;
                    }
                }
            }

            // ResourceAdapterModule
            ConnectorModule[] connectorConfigBeans = appsConfigBean.getConnectorModule();
            if (connectorConfigBeans != null) {
                for(int i = 0; i < connectorConfigBeans.length; i++) {
                    if ((connectorConfigBeans[i].getName()).equals(standaloneModuleName)) {
			ddLocation = connectorConfigBeans[i].getLocation();
			return ModuleType.RAR;
                    }
                }
            }

            // AppClient Module
            AppclientModule[] acModules = appsConfigBean.getAppclientModule();
            if (acModules != null) {
                for(int i = 0; i < acModules.length; i++) {
                    if ((acModules[i].getName()).equals(standaloneModuleName)) {
			ddLocation = acModules[i].getLocation();
			return ModuleType.CAR;
                    }
                }
            }

            // Lifecycle Module
	    LifecycleModule[] lcModules = appsConfigBean.getLifecycleModule();
            if (lcModules != null) {
                for(int i = 0; i < lcModules.length; i++) {
                    if ((lcModules[i].getName()).equals(standaloneModuleName)) {
			return XModuleType.LCM;
                    }
                }
            }

            // Custom MBean Module
	    Mbean[] mbModules = appsConfigBean.getMbean();
            if (mbModules != null) {
                for(int i = 0; i < mbModules.length; i++) {
                    if ((mbModules[i].getName()).equals(standaloneModuleName)) {
			return XModuleType.CMB;
                    }
                }
            }

        } catch (Exception e) {
                throw new ServerInstanceException(e.getLocalizedMessage());
        }
        return moduleType;
    
javax.enterprise.deploy.shared.ModuleTypegetModuleType(java.lang.String standaloneModuleName, java.lang.String subModuleName)
Returns moduleType for the given combination of stand-alone module and sub-module


	sLogger.log(Level.FINE, getLogMsg("getModuleType " +
		"standaloneModuleName = " + standaloneModuleName + " " +
		"subModuleName = " + subModuleName));

        ModuleType moduleType = null;

        try {
            // Get application descriptor

            AppsManager am = InstanceFactory.createAppsManager(
		    ApplicationServer.getServerContext().getInstanceName());

            Application appD = (Application)
                DeploymentUtils.getDescriptor(standaloneModuleName, am);

            // Get the bundle descriptor for the given module
            // and determine its' type

            BundleDescriptor bd = null;
            java.util.Set bds = appD.getBundleDescriptors();
            for(Iterator it=bds.iterator(); it.hasNext(); ) {
                bd = (BundleDescriptor)it.next();
                if ((bd.getModuleDescriptor().getArchiveUri()).equals(subModuleName) ||
                     bd.getModuleID().equals(subModuleName) ||
		     bd.getName().equals(subModuleName)) {
                        moduleType = bd.getModuleType();
			// set dd location
			ddLocation = am.getLocation(standaloneModuleName) +
				File.separator +
				FileUtils.makeFriendlyFileName(
					bd.getModuleDescriptor().getArchiveUri());
			break;
                }
            }

        } catch (Exception e) {
            throw new ServerInstanceException(e.getLocalizedMessage());
        }

        return moduleType;

    
public java.lang.StringgetStringForDDxml(java.lang.String fileName)
Method to read deployment descriptor xml and return it as String


	    try {
            return FileUtils.getFileContents(fileName);
        } catch (FileNotFoundException fnfe) {
            sLogger.log(Level.WARNING, getLogMsg(
			"getStringForDDxml FileNotFoundException " + fileName));
	    	throw new ServerInstanceException(fnfe.getLocalizedMessage());
        } catch (IOException ioe) {
            sLogger.log(Level.WARNING, getLogMsg(
			"getStringForDDxml IOException " + fileName));
	    	throw new ServerInstanceException(ioe.getLocalizedMessage());
        }