FileDocCategorySizeDatePackage
Application.javaAPI DocGlassfish v2 API6857Fri May 04 22:34:30 BST 2007com.sun.enterprise.ddgenerator.sun

Application

public class Application extends Object implements DDGenerator
Class description
author
Sreenivas Munnangi

Fields Summary
private com.sun.enterprise.deployment.Application
application
private String
applicationDirectory
Constructors Summary
public Application()


      
    
public Application(com.sun.enterprise.deployment.Application application, String applicationDirectory)

	this.application = application;
	this.applicationDirectory = applicationDirectory;
    
Methods Summary
public voidgenerate()


	if (application == null) return;

	java.util.Set ejbBundleDescriptors = application.getEjbBundleDescriptors();

	// Determine if sun-ejb.xml needs to be generated

	boolean generate = false;

	for(Iterator it=ejbBundleDescriptors.iterator(); it.hasNext(); ) {
		EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) it.next();
		com.sun.enterprise.ddgenerator.sun.EjbModule ejbModule =
			new com.sun.enterprise.ddgenerator.sun.EjbModule(ejbBundleDescriptor, 
				applicationDirectory);
		if (! ejbModule.hasSunDescriptor()) {
			generate = true;
		}
	}

	if (generate == false) return;

	// Backup existing sun descriptor

	for(Iterator it=ejbBundleDescriptors.iterator(); it.hasNext(); ) {
		EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) it.next();
		com.sun.enterprise.ddgenerator.sun.EjbModule ejbModule =
			new com.sun.enterprise.ddgenerator.sun.EjbModule(ejbBundleDescriptor, 
				applicationDirectory);
		ejbModule.backupSunDescriptor();
	}

	// Generate sun descriptor

	for(Iterator it=ejbBundleDescriptors.iterator(); it.hasNext(); ) {
		EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) it.next();
		com.sun.enterprise.ddgenerator.sun.EjbModule ejbModule =
			new com.sun.enterprise.ddgenerator.sun.EjbModule(ejbBundleDescriptor, 
				applicationDirectory);
		ejbModule.generate();
	}

	// update referencing descriptors

	java.util.Vector ejbRefDescriptorsV = application.getEjbReferenceDescriptors();

	if (ejbRefDescriptorsV == null) {
		save();
		return;
	}

	int ejbRefDescriptorsSize = ejbRefDescriptorsV.size();

	for (int i=0; i<ejbRefDescriptorsSize; i++) {
		EjbReferenceDescriptor ejbRefDescriptor = 
			(EjbReferenceDescriptor) ejbRefDescriptorsV.get(i);
		updateEjbRefDescriptorJndiName(ejbRefDescriptor, ejbBundleDescriptors);
	}

	// save application descriptor

	save();

    
public static voidmain(java.lang.String[] args)


	String appDir = "/home/sreeni/TEMP/stateless-converter_1";

        System.out.println("Application");

        System.out.println("Press enter to continue ...");
	try {
		System.in.read();
	} catch (java.io.IOException ioe) {
	}

	FileArchive in = new FileArchive();

	try {
		in.open(appDir);
	} catch (java.io.IOException ioe) {
	}


	ApplicationArchivist archivist = new ApplicationArchivist();
	archivist.setXMLValidation(false);
	archivist.setClassLoader(null);
	com.sun.enterprise.deployment.Application application = null;
	try {
		application = (com.sun.enterprise.deployment.Application) archivist.open(in);
	} catch (java.io.IOException ioe) {
	} catch (org.xml.sax.SAXParseException saxpe) {
	}

	com.sun.enterprise.ddgenerator.sun.Application app = 
		new com.sun.enterprise.ddgenerator.sun.Application(application, appDir); 

	app.generate();
    
private voidsave()


	FileArchive in = new FileArchive();

	try {
		in.open(applicationDirectory);
	} catch (java.io.IOException ioe) {
	}

	DescriptorArchivist archivist = new DescriptorArchivist();

	try {
		archivist.write(application, in);
	} catch (java.io.IOException ioe) {
	}

    
public voidsetApplicationDirectory(java.lang.String applicationDirectory)

	this.applicationDirectory = applicationDirectory;
    
public voidsetDescriptor(com.sun.enterprise.deployment.Descriptor descriptor)

	this.application = (com.sun.enterprise.deployment.Application) descriptor;
    
private voidupdateEjbRefDescriptorJndiName(EjbReferenceDescriptor ejbRefDescriptor, java.util.Set ejbBundleDescriptors)


	for(Iterator it=ejbBundleDescriptors.iterator(); it.hasNext(); ) {

		EjbBundleDescriptor ejbBundleDescriptor = (EjbBundleDescriptor) it.next();
		
		java.util.Set ejbDescriptors = ejbBundleDescriptor.getEjbs();

		for (Iterator jt = ejbDescriptors.iterator(); jt.hasNext();) {

			EjbDescriptor ejbDescriptor = (EjbDescriptor) jt.next();
			if ((ejbDescriptor.getHomeClassName()).equals(ejbRefDescriptor.getHomeClassName())) {
				ejbRefDescriptor.setJndiName(ejbDescriptor.getJndiName());
				return;
			}
		}
	}