FileDocCategorySizeDatePackage
AppDeployerBase.javaAPI DocGlassfish v2 API17729Fri May 04 22:34:30 BST 2007com.sun.enterprise.deployment.backend

AppDeployerBase

public abstract class AppDeployerBase extends Deployer
Abstract base class for AppDeployer, AppRedeployer, AppUndeployer.

Fields Summary
private com.sun.enterprise.instance.ApplicationEnvironment
appEnv
private com.sun.enterprise.instance.AppsManager
appMgr
private String
appName
private boolean
isReg
private File
stubsDir
private File
jspDir
private File
xmlDir
private File
jwsDir
private File
appDir
private static com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
AppDeployerBase(DeploymentRequest r)

		super(r);
	
Methods Summary
protected voidbegin()
Before even attempting the deployment operation -- check and verify and set lots of useful variables and references.

		super.begin();
		
		try
		{
			appEnv = request.getAppEnv();

			if(appEnv == null) {
				String msg = localStrings.getString(
					"enterprise.deployment.backend.null_applicationenvironment_object");
				throw new IASDeploymentException( msg );
            }

			appMgr = new AppsManager(getInstanceEnv());
			appName = request.getName();
			
			if(!StringUtils.ok(appName)) {
				String msg = localStrings.getString(
						"enterprise.deployment.backend.null_appname" );

				throw new IASDeploymentException( msg );
			}
			
			isReg = DeploymentServiceUtils.isRegistered(
                            getAppName(), request.getType());
			verify();
		}
		catch(IASDeploymentException e)
		{
			throw e;
		}
		catch(Exception e)
		{
			throw new IASDeploymentException(e);
		}
		
	
protected voidgeneratePolicy()

	   try{
               // generate policy for all web modules with
               // moduleName + contextRoot and then generate for ejbs
               // with Appname
                Application applicationDD = request.getDescriptor();
                                                       
                // link with the ejb name       
                String linkName = null;
                boolean lastInService = false;
                for (Iterator iter = applicationDD.getWebBundleDescriptors().iterator();
                        iter.hasNext();){
                    String name 
                        = WebSecurityManager.getContextID((WebBundleDescriptor)iter.next());
                    lastInService = SecurityUtil.linkPolicyFile(name, linkName, lastInService);
                    linkName = name;
		}                                   
                for (Iterator iter = applicationDD.getEjbBundleDescriptors().iterator(); iter.hasNext();) {
                    String name =
                        EJBSecurityManager.getContextID((EjbBundleDescriptor)iter.next());
                    lastInService = SecurityUtil.linkPolicyFile(name, linkName, lastInService);
                    linkName = name;
                }
                // generate policies
               for (Iterator iter = applicationDD.getWebBundleDescriptors().iterator();
                        iter.hasNext();){
                    String name 
                        = WebSecurityManager.getContextID((WebBundleDescriptor)iter.next());
                    SecurityUtil.generatePolicyFile(name);
		}                               
                for (Iterator iter = applicationDD.getEjbBundleDescriptors().iterator(); iter.hasNext();) {
                    String name =
                        EJBSecurityManager.getContextID((EjbBundleDescriptor)iter.next());
                    SecurityUtil.generatePolicyFile(name);
                }
         } catch(IASSecurityException se){
	     // log this
	     String msg =
		 localStrings.getString("enterprise.deployment.backend.generate_policy_error", request.getName());
	     throw new IASDeploymentException(msg, se);
	 }
       
protected final java.io.FilegetAppDir()

		return appDir;
	
protected final com.sun.enterprise.instance.ApplicationEnvironmentgetAppEnv()

		return appEnv;
	
protected final java.lang.StringgetAppName()

		return appName;
	
protected final java.io.FilegetJSPDir()

		return jspDir;
	
protected final java.io.FilegetJWSDir()

                return jwsDir;
        
protected com.sun.enterprise.instance.BaseManagergetManager()

		return appMgr;
	
protected java.util.ListgetModuleClasspath(com.sun.enterprise.deployment.archivist.Archivist archivist, com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive)

return
the module classpath

	    try {
                Application application = request.getDescriptor();
                if (application==null) {
                    application = (Application)archivist.readStandardDeploymentDescriptor(archive);
                    application.setRegistrationName(request.getName());
                }
	    	return EJBClassPathUtils.getAppClassPath(
                	application, request.getDeployedDirectory().getAbsolutePath(), getManager());
	    } catch(Exception e) {
		throw new IASDeploymentException(e);
	    }
	
protected final java.io.FilegetModuleDir()

	    return appDir;
	
protected final java.io.FilegetStubsDir()

		return stubsDir;
	
protected final java.io.FilegetXMLDir()

       
                return xmlDir;
        
protected voidliquidate(boolean isRollback)

            if (request.isUnDeploy()) {
                if (! (DeploymentServiceUtils.isDirectoryDeployed(getAppName(),
                    request.getType()) || request.isReload()) ) {
                    cleanAndCheck(getAppDir());
                }
            } else {
                if (isArchive()) {
                    cleanAndCheck(getAppDir());
                }
            }

            if (isRollback) {
                DeleteOrKeepFailedStubs(getStubsDir());
            } else {
                cleanAndCheck(getStubsDir());
            }

            cleanAndCheck(getJSPDir());
            cleanAndCheck(getXMLDir());
            cleanAndCheck(getJWSDir());

            liquidateTimeStamp = System.currentTimeMillis();
        
protected voidliquidate()

            liquidate(false);
        
protected com.sun.enterprise.deployment.ApplicationloadDescriptors()

return
a fully initialized and validated deployment descriptors for this deployment request.

            Application app = super.loadDescriptors();
            (new com.sun.enterprise.webservice.WsUtil()).genWSInfo(app, request);
            return app;
        
protected voidpredeploy()
Before even attempting the deployment operation -- check and verify and set lots of useful variables and references.

		try
		{
			appDir = setAppDir();
			request.setDeployedDirectory(appDir);
			setGeneratedDirs();
		}
		catch(IASDeploymentException e)
		{
			throw e;
		}
		catch(Exception e)
		{
			throw new IASDeploymentException(e);
		}
	
public voidremovePolicy()

            String name = request.getName();
            
            try {
                WebSecurityManagerFactory wsmf =
                        WebSecurityManagerFactory.getInstance();
                String[] webcontexts
                        = wsmf.getAndRemoveContextIdForWebAppName(name);
		if(webcontexts !=null){
                	for(int i=0; i<webcontexts.length; i++){
			   if(webcontexts[i] != null){
                    		SecurityUtil.removePolicy(webcontexts[i]);
                                wsmf.removeWebSecurityManager(webcontexts[i]);
			   }
                	}
		}

                // removing ejb policy
                EJBSecurityManagerFactory ejbsmf =
                    (EJBSecurityManagerFactory)EJBSecurityManagerFactory.getInstance();
                String[] ejbContextIds
                    = ejbsmf.getAndRemoveContextIdForEjbAppName(name);
                if (ejbContextIds != null) {
                    for (String ejbContextId : ejbContextIds) {
                        if (ejbContextId != null) {
                            SecurityUtil.removePolicy(ejbContextId);
                            ejbsmf.removeSecurityManager(ejbContextId);
                        }
                    }
                }

                //remove any remaining policy
                //This is to address the bug where the CONTEXT_ID in 
                //WebSecurityManagerFactory is not properly populated.
                //We force the sub-modules to be removed in this case.
                //This should not impact undeploy performance on DAS.
                //This needs to be fixed better later.
                String policyRootDir = System.getProperty(
                    "com.sun.enterprise.jaccprovider.property.repository");
                if (policyRootDir != null) {
                    List<String> contextIds = new ArrayList<String>();
                    File policyDir = new File(
                        policyRootDir + File.separator + name);
                    if (policyDir.exists()) {
                        File[] policies = policyDir.listFiles();
                        for (int i = 0; i < policies.length; i++) {
                            if (policies[i].isDirectory()) {
                                contextIds.add(name + '/" + policies[i].getName());
                            }
                        }
                    } else {
                        //we tried.  give up now.
                    }

                    if (contextIds.size() > 0) {
                        for (String cId : contextIds) {
                            SecurityUtil.removePolicy(cId);
                        }
                    }
                }

            } catch(IASSecurityException ex) {
                String msg = localStrings.getString(
                "enterprise.deployment.backend.remove_policy_error", name);
                logger.log(Level.WARNING, msg, ex);
                throw new IASDeploymentException(msg, ex);
            }
	
protected abstract java.io.FilesetAppDir()

private final voidsetGeneratedDirs()

		try
		{
			stubsDir	= new File(getAppEnv().getAppStubPath());
			jspDir		= new File(getAppEnv().getAppJSPPath());
			xmlDir		= new File(getAppEnv().getAppGeneratedXMLPath());
			jwsDir		= new File(getAppEnv().getJavaWebStartPath());
			request.setJSPDirectory(jspDir);
			request.setStubsDirectory(stubsDir);
			request.setGeneratedXMLDirectory(xmlDir);
		}
		catch(Exception e)
		{
			String msg = localStrings.getString(
				"enterprise.deployment.backend.error_getting_generated_dirs",
				e );
			throw new IASDeploymentException( msg );
		}
	
protected final voidverify()

		if(!request.isApplication()) {
			String msg = localStrings.getString(
			"enterprise.deployment.backend.attempt_to_deploy_non_application");
			throw new IASDeploymentException( msg );
		}
			
		if(request.isUnDeploy())
		{
			if(!isReg) {
				String msg = localStrings.getString(
				"enterprise.deployment.backend.undeploy_error_application_not_registered");
				throw new IASDeploymentException( msg );
			}
		}

		else if(request.isDeploy())
		{
			if(isReg)
			{
				String msg = localStrings.getString(
				"enterprise.deployment.backend.deploy_error_application_exists");
				throw new IASDeploymentException( msg );
			}

			// isReg is false.  This means that it isn't registered as an App.
			// But we might be clashing with a registered module of a different flavor.
			// E.g. there may be a web module already deployed with the same name.
			// this will throw an IASDeploymentException if it is registered to another type...

			checkRegisteredAnywhereElse(appName);
		}
		else if(request.isReDeploy())
		{
			if(!isReg)
			{
				String msg = localStrings.getString(
				"enterprise.deployment.backend.redeploy_error_application_does_not_exist");
				throw new IASDeploymentException( msg );
			}
		}