FileDocCategorySizeDatePackage
AppDD.javaAPI DocGlassfish v2 API10196Fri May 04 22:31:36 BST 2007com.sun.enterprise.deployment.backend

AppDD

public class AppDD extends Object
Code for parsing out the names of all modules in Application.xml
author
bnevins
version

Fields Summary
private File
file
private File
file2
private Set
ejbModules
private Set
warModules
private Set
rarModules
private Set
clientModules
private com.sun.enterprise.deployment.Application
app
private Set
contextRoots
private final Logger
logger
private static com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
public AppDD(File f)

		this(f, false);
	
public AppDD(File f, boolean validateXML)

		if(f == null || !f.exists()) {
			String msg = localStrings.getString(
					"enterprise.deployment.backend.bad_file_parameter", f );
			throw new IllegalArgumentException( msg );
		}
		
                File f2 = null;
		if(f.isDirectory())
		{
			File f1 = new File(f, "META-INF");
			f = new File(f1, "application.xml");//noi18n
			f2 = new File(f1, "sun-application.xml");//noi18n
		}

		//4669843 - 5/2/02 WBN: changed message and type of Exception -- it used to be IllegalArgumentException
		if(!f.exists() || f.isDirectory())  {
			String msg = localStrings.getString(
					"enterprise.deployment.backend.no_application_xml",
					f.getPath() );
			throw new IASDeploymentException( msg );
		}
		
		file = f;

                if(f2 != null && f2.exists() && f2.isFile())  {
                    file2 = f2;
                }

		try
		{
			parse(validateXML);
		}
		catch(Throwable t)
		{
                    
                    t.printStackTrace();
                    if(t instanceof IASDeploymentException)
                        throw (IASDeploymentException) t;
                    else {
                        String msg = localStrings.getString(
                        "enterprise.deployment.backend.error_parsing_application_xml",
                        file.getPath(), t );
                        throw new IASDeploymentException( msg, t );
                    }
		}
	
Methods Summary
public com.sun.enterprise.deployment.ApplicationgetApplication()

         
                return app;
        
public java.lang.String[]getClientModules()

		String[] ss = new String[clientModules.size()];
		
		return (String[])clientModules.toArray(ss);
	
public java.lang.String[]getContextRoots()

		String[] ss = new String[contextRoots.size()];
		
		return (String[])contextRoots.toArray(ss);
	
public java.lang.String[]getEjbModules()

		String[] ss = new String[ejbModules.size()];
		
		return (String[])ejbModules.toArray(ss);
	
public java.io.FilegetFile()

		return file;
	
public java.lang.String[]getRarModules()

		String[] ss = new String[rarModules.size()];
		
		return (String[])rarModules.toArray(ss);
	
public java.lang.String[]getWarModules()

		String[] ss = new String[warModules.size()];
		
		return (String[])warModules.toArray(ss);
	
private voidparse(boolean validateXML)

            FileInputStream fis = null;
            try {
		fis = new FileInputStream(file);
		ApplicationDeploymentDescriptorFile addf = new ApplicationDeploymentDescriptorFile();
                addf.setXMLValidation(validateXML);
                if (validateXML) {
                    addf.setXMLValidationLevel(addf.PARSING_VALIDATION);
                }

                app = (Application) addf.read(fis);

                // read runtime deployment descriptor file if it exists
                if (file2 != null) { 
                    FileInputStream fis2 = new FileInputStream(file2);
		    ApplicationRuntimeDDFile arddf = 
                        new ApplicationRuntimeDDFile();
                    arddf.setXMLValidation(validateXML);
                    if (validateXML) {
                        arddf.setXMLValidationLevel(arddf.PARSING_VALIDATION);
                    }
                    app = (Application)arddf.read(app, fis2); 
                    if (fis2 != null) {
                        fis2.close();
                    }

                }

		// WBN 4-19-2002 -- If we are using this class ONLY for getting
		// context-roots -- please note that node.getApplication(null) has 
		// already done all the time-consuming work.  The getXXXX methods 
		// simply return a reference.  So performance isn't an issue.
                
                for (Iterator modules = app.getModules(); modules.hasNext();) {
                    ModuleDescriptor md = (ModuleDescriptor) modules.next();
                    if (md.getModuleType().equals(ModuleType.EJB)) {
                        ejbModules.add(md.getArchiveUri());
                    } else 
                    if (md.getModuleType().equals(ModuleType.WAR)) {
                        warModules.add(md.getArchiveUri());
                    } else 
                    if (md.getModuleType().equals(ModuleType.CAR)) {
                        clientModules.add(md.getArchiveUri());
                    } else 
                    if (md.getModuleType().equals(ModuleType.RAR)) {
                        rarModules.add(md.getArchiveUri());
                    }                          
                }

		setContextRoots(app);
            } finally {
                if (fis != null) {
                    fis.close();
                }
            }
	
private voidsetContextRoots(com.sun.enterprise.deployment.Application app)

            assert app		!= null;
            assert warModules	!= null;
            assert contextRoots	== null;  // error to call this method more than once
            
            contextRoots = new HashSet();
            
            for(Iterator it = warModules.iterator(); it.hasNext(); ) {
                
                ModuleDescriptor md = app.getModuleDescriptorByUri((String) it.next());
                String cr = md.getContextRoot();                
                
                if(contextRoots.add(cr) == false) {
                    // this means that there is more than one web-module
                    // in the Application with the same context-root
                    
                    String msg = localStrings.getString(
                    "enterprise.deployment.backend.duplicate_context_root",
                    cr );
                    throw new IASDeploymentException( msg );
                }
            }
	
private java.lang.Stringtrim(java.lang.String s)

		// change <ejb>xxx</ejb> to xxx
		
		int index = s.indexOf(">");
		String ret = s.substring(index + 1);
		ret = ret.substring(0, ret.indexOf("<"));
		
		return ret;