FileDocCategorySizeDatePackage
Archivist.javaAPI DocGlassfish v2 API63993Fri May 04 22:31:36 BST 2007com.sun.enterprise.deployment.archivist

Archivist

public abstract class Archivist extends Object
This abstract class contains all common behaviour for Achivisits. Archivists classes are responsible for reading and writing correct J2EE Archives
author
Jerome Dochez
version

Fields Summary
protected static final Logger
logger
public static final String
MANIFEST_VERSION_VALUE
protected String
path
protected boolean
handleRuntimeInfo
protected boolean
annotationProcessingRequested
protected Manifest
manifest
protected com.sun.enterprise.deployment.deploy.shared.AbstractArchiveFactory
abstractArchiveFactory
protected PluggableArchivists
pa
plugable archivist factory for creating sub modules archivists
private static final com.sun.enterprise.util.LocalStringManagerImpl
localStrings
protected ClassLoader
classLoader
private boolean
isValidatingXML
private boolean
isValidatingRuntimeXML
private String
validationLevel
private String
runtimeValidationLevel
private com.sun.enterprise.deployment.annotation.ErrorHandler
annotationErrorHandler
private static final String
WSDL
private static final String
XML
private static final String
XSD
protected static final String
APPLICATION_EXTENSION
protected static final String
APPCLIENT_EXTENSION
protected static final String
WEB_EXTENSION
protected static final String
EJB_EXTENSION
protected static final String
CONNECTOR_EXTENSION
protected static final String
UPLOAD_EXTENSION
private static final String
PROCESS_ANNOTATION_FOR_OLD_DD
private static final boolean
processAnnotationForOldDD
Constructors Summary
public Archivist()
Creates new Archivist


        
      
        // by default we are dealing with jar files, can be changed with 
        // setAbstractArchiveFactory
        abstractArchiveFactory = new JarArchiveFactory();
        annotationErrorHandler = new DefaultErrorHandler();
    
Methods Summary
protected static voidaddFileToArchive(com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive, java.lang.String filePath, java.lang.String entryName)
add a file to an output abstract archive

param
archive abstraction to use when adding the file
param
path to the file to add
param
entryName the entry name in the archive

            
        FileInputStream is = new FileInputStream(new File(filePath));
        OutputStream os = archive.putNextEntry(entryName);
        ArchivistUtils.copyWithoutClose(is, os);
        is.close();
        archive.closeEntry();
    
protected com.sun.enterprise.deployment.util.ModuleDescriptoraddToArchive(ApplicationArchivist appArch, java.lang.String externalDD)
Add this archive to an application archivist

param
application archive to add itself to
param
library jars for this archive
param
external deployment descriptor path

                 

        AbstractArchive archiveToBeAdded = abstractArchiveFactory.openArchive(path);
        File archiveFile = new File(path);
        AbstractArchive appArchive = abstractArchiveFactory.openArchive(appArch.getArchiveUri());
	String archiveName = getUniqueEntryFilenameFor(appArchive, archiveFile.getName());
        appArchive.close();
        Descriptor descriptor = null;
	if (externalDD != null && !"".equals(externalDD)) {
            File externalDescriptorFile = new File(externalDD);            
            if (externalDescriptorFile.exists()) {
                FileInputStream fis = new FileInputStream(externalDescriptorFile);
                try {
                    DeploymentDescriptorFile ddf = getStandardDDFile();
                    descriptor = ddf.read(fis);                                       
                } catch(SAXParseException pe) {
                    archiveToBeAdded.close();
                    pe.printStackTrace();     
                    // propagate
                    throw pe;
                } 
            }
        }
        if (descriptor==null) {
            // We get the deployment descriptors, including maybe the 
            // runtime deployment descriptors
	    descriptor = open(archiveToBeAdded);
        }
        archiveToBeAdded.close();
        
        // Create a new module descriptor for this new module
        if (descriptor instanceof BundleDescriptor) {
            ModuleDescriptor newModule = new ModuleDescriptor();
            newModule.setArchiveUri(archiveName);
            newModule.setModuleType(getModuleType());
            newModule.setDescriptor((BundleDescriptor) descriptor);
            newModule.setManifest(getManifest());
            if (externalDD != null && !"".equals(externalDD)) {
                newModule.setAlternateDescriptor(externalDD);
            }        
            return newModule;
        } else {
            return null;
        }
    
public voidapplyRuntimeInfo(java.io.File runtimeDD, java.io.File output)
apply runtimne info to this archive descriptors and saves it


        // update the runtime info
        getConfigurationDDFile().read(getDescriptor(), new FileInputStream(runtimeDD));

        // save the runtime info...
        saveRuntimeInfo(output);
    
public booleancontainsRuntimeDeploymentDescriptors(com.sun.enterprise.deployment.deploy.shared.AbstractArchive in)

return
true if the passed AbstractArchive contains runtime deployment descriptors information

        
        String ddFileName = getRuntimeDeploymentDescriptorPath();
        if (ddFileName==null) {
            return false;
        }
        for (Enumeration e = in.entries();e.hasMoreElements();) {
            String entryName = (String) e.nextElement();
            if (entryName.equals(ddFileName)) {
                return true;
            }
        }
        // we iterated all archive elements, could not find our 
        // runtime DD file, it's a pure j2ee archive
        return false;
    
public static voidcopyAnEntry(com.sun.enterprise.deployment.deploy.shared.AbstractArchive in, com.sun.enterprise.deployment.deploy.shared.AbstractArchive out, java.lang.String entryName)

        InputStream is = null;
        InputStream is2 = null;
        try {
            is = in.getEntry(entryName);
            is2 = out.getEntry(entryName);
            if (is != null && is2 == null) {
                OutputStream os = out.putNextEntry(entryName);
                ArchivistUtils.copyWithoutClose(is, os);
            }
        } finally {
            /*
             *Close any streams that were opened.
             */
            if (is != null) {
                is.close();
            }
            if (is2 != null) {
                is2.close();
            }
            out.closeEntry();
        }
    
public static voidcopyExtraElements(com.sun.enterprise.deployment.deploy.shared.AbstractArchive in, com.sun.enterprise.deployment.deploy.shared.AbstractArchive out)

        Enumeration entries = in.entries();
        if (entries!=null) {
            for (;entries.hasMoreElements();) {
                String anEntry = (String) entries.nextElement();
                if(anEntry.endsWith(PERSISTENCE_DD_ENTRY)) {
                    // Don't copy persistence.xml file because they are some times
                    // bundled inside war/WEB-INF/lib/*.jar and hence we always
                    // read them from exploded directory.
                    // see Integration Notice #80587
                    continue;
                }
                if (anEntry.indexOf(WSDL) != -1  ||
                    anEntry.indexOf(XML) != -1 ||
                    anEntry.indexOf(XSD) != -1) {
                    copyAnEntry(in, out, anEntry);
                }
            }
        }
     
public voidcopyInto(com.sun.enterprise.deployment.deploy.shared.AbstractArchive target)
Copy this archivist to a new abstract archive

param
out the new archive to use to copy our contents into

        AbstractArchive source = abstractArchiveFactory.openArchive(path);
        copyInto(source, target);
    
public voidcopyInto(com.sun.enterprise.deployment.deploy.shared.AbstractArchive source, com.sun.enterprise.deployment.deploy.shared.AbstractArchive target)
Copy source archivist to a target abstract archive. By default, every entry in source archive will be copied to the target archive, including the manifest of the source archive.

param
source the source archive to copy from
param
target the target archive to copy to
param
entriesToSkip the entries that will be skipped by target archive

        copyInto(source, target, null, true);
    
public voidcopyInto(com.sun.enterprise.deployment.deploy.shared.AbstractArchive source, com.sun.enterprise.deployment.deploy.shared.AbstractArchive target, boolean overwriteManifest)
Copy source archivist to a target abstract archive. By default, every entry in source archive will be copied to the target archive.

param
source the source archive to copy from
param
target the target archive to copy to
param
overwriteManifest if true, the manifest in source archive overwrites the one in target archive

        copyInto(source, target, null, overwriteManifest);
    
public voidcopyInto(com.sun.enterprise.deployment.deploy.shared.AbstractArchive source, com.sun.enterprise.deployment.deploy.shared.AbstractArchive target, java.util.Vector entriesToSkip)
Copy source archivist to a target abstract archive. By default, the manifest in source archive overwrites the one in target archive.

param
source the source archive to copy from
param
target the target archive to copy to
param
entriesToSkip the entries that will be skipped by target archive

   
        copyInto(source, target, entriesToSkip, true);
    
public voidcopyInto(com.sun.enterprise.deployment.deploy.shared.AbstractArchive source, com.sun.enterprise.deployment.deploy.shared.AbstractArchive target, java.util.Vector entriesToSkip, boolean overwriteManifest)
Copy this archivist to a new abstract archive

param
source the source archive to copy from
param
target the target archive to copy to
param
entriesToSkip the entries that will be skipped by target archive
param
overwriteManifest if true, the manifest in source archive overwrites the one in target archive

   
            
        copyJarElements(source, target, entriesToSkip);
        if (overwriteManifest) {
            Manifest m = source.getManifest();
            if (m != null) {
                OutputStream os = target.putNextEntry(JarFile.MANIFEST_NAME);
                m.write(os);
                target.closeEntry();
            }
        }
    
protected voidcopyJarElements(com.sun.enterprise.deployment.deploy.shared.AbstractArchive in, com.sun.enterprise.deployment.deploy.shared.AbstractArchive out, java.util.Vector ignoreList)
copy all contents of a jar file to a new jar file except for all the deployment descriptors files

param
input jar file
param
output jar file
param
vector of entry name to not copy from to source jar file

                    
        Enumeration entries = in.entries();
        // we need to add the list of existing entries in the output
        // archive to the list of files to ignore to avoid any collision
        for (Enumeration outEntriesItr = out.entries();outEntriesItr.hasMoreElements();) {
            if (ignoreList==null) {
                ignoreList = new Vector();
            }
            ignoreList.add(outEntriesItr.nextElement());
        }
        if (entries!=null) {
            for (;entries.hasMoreElements();) {
                String anEntry = (String) entries.nextElement();
                if (ignoreList==null || !ignoreList.contains(anEntry)) {
                    InputStream is = in.getEntry(anEntry);
                    OutputStream os = out.putNextEntry(anEntry);
                    ArchivistUtils.copyWithoutClose(is, os);
                    is.close();
                    out.closeEntry();
                }
            }  
        }
    
public voidcopyStandardDeploymentDescriptors(com.sun.enterprise.deployment.deploy.shared.AbstractArchive in, com.sun.enterprise.deployment.deploy.shared.AbstractArchive out)

        String entryName = getDeploymentDescriptorPath();
        copyAnEntry(in, out, entryName);
        
        Descriptor desc = getDescriptor();

        // only bundle descriptor can have web services
        if (desc instanceof BundleDescriptor) { 
            BundleDescriptor desc2 = (BundleDescriptor)desc;
            if (desc2.hasWebServices()) {
                DeploymentDescriptorFile webServicesDD = 
                    getWebServicesDDFile((BundleDescriptor)desc2);
                String anEntry = webServicesDD.getDeploymentDescriptorPath();
                copyAnEntry(in, out, anEntry);
            }
        }
    
public com.sun.enterprise.deployment.util.ModuleDescriptorcreateModuleDescriptor(BundleDescriptor descriptor)
creates a new module descriptor for this archivist

return
the new module descriptor

        ModuleDescriptor newModule = new ModuleDescriptor();
        newModule.setModuleType(getModuleType());
        newModule.setDescriptor(descriptor);
        setDescriptor(descriptor);        
        return newModule;
    
public voidextractEntry(java.lang.String entryName, java.io.File out)
extract a entry of this archive to a file

param
the entry name
param
the file to copy the entry into

        AbstractArchive archive = abstractArchiveFactory.openArchive(path);
        InputStream is = archive.getEntry(entryName);
        OutputStream os = new BufferedOutputStream(new FileOutputStream(out));
        ArchivistUtils.copy(new BufferedInputStream(is), os);
        archive.close();
    
public com.sun.enterprise.deployment.deploy.shared.AbstractArchiveFactorygetAbstractArchiveFactory()

return
the currently associated abstract archive factory

        return abstractArchiveFactory;
    
public com.sun.enterprise.deployment.annotation.ErrorHandlergetAnnotationErrorHandler()

return
annotation ErrorHandler of this archivist

        return annotationErrorHandler;
    
protected abstract java.lang.StringgetArchiveExtension()

return
The archive extension handled by a specific archivist

public java.lang.StringgetArchiveUri()

return
the path for this archivist's archive file

        return path;
    
public java.lang.StringgetClassPath()

return
the class-path as set in the manifest associated with the archive

        
        if (manifest==null) {
            return null;
        }
        
        Attributes atts = manifest.getMainAttributes();
        return atts.getValue(Attributes.Name.CLASS_PATH);        
    
public abstract DeploymentDescriptorFilegetConfigurationDDFile()

return
if exists the DeploymentDescriptorFile responsible for handling the configuration deployment descriptors

public abstract DescriptorgetDefaultBundleDescriptor()

return
a default BundleDescriptor for this archivist

public java.lang.StringgetDeploymentDescriptorPath()

return
the location of the DeploymentDescriptor file for a particular type of J2EE Archive

        return getStandardDDFile().getDeploymentDescriptorPath();
    
public abstract DescriptorgetDescriptor()

return
the Descriptor for this archvist

public java.util.VectorgetLibraries(com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive)

return
a list of libraries included in the archivist

        
        Enumeration<String> entries = archive.entries();
        if (entries==null)
            return null;
        
        Vector libs = new Vector();        
        while (entries.hasMoreElements()) {
            
            String entryName = entries.nextElement();
            if (entryName.indexOf('/")!=-1) {
                continue; // not on the top level
            }
            if (entryName.endsWith(".jar")) {
                libs.add(entryName);
            }            
        }
        return libs;
    
public java.util.VectorgetListOfFilesToSkip()

return
the list of files that should not be copied from the old archive when a save is performed.

        
        Vector filesToSkip = new Vector();
        filesToSkip.add(getDeploymentDescriptorPath());
        if (manifest!=null) {
            filesToSkip.add(JarFile.MANIFEST_NAME);
        }
        if (getRuntimeDeploymentDescriptorPath()!=null) {
            filesToSkip.add(getRuntimeDeploymentDescriptorPath());
        }

        // Can't depend on having a descriptor, so skip all possible
        // web service deployment descriptor paths.
        filesToSkip.addAll(WebServicesDeploymentDescriptorFile.
                        getAllDescriptorPaths());

        return filesToSkip;
    
public java.util.jar.ManifestgetManifest()

return
the manifest file for this archive

        return manifest;
    
public abstract javax.enterprise.deploy.shared.ModuleTypegetModuleType()

return
the module type handled by this archivist as defined in the application DTD

public PluggableArchivistsgetPluggableArchivists()

return
the pluggable archivist factory

        if (pa==null) {
            return ArchivistFactory.getPluggableArchivists();
        } else {
            return pa;
        }
    
public java.lang.StringgetRuntimeDeploymentDescriptorPath()

return
the location of the runtime deployment descriptor file for a particular type of J2EE Archive

        DeploymentDescriptorFile ddFile = getConfigurationDDFile();
        if (ddFile!=null) {
            return ddFile.getDeploymentDescriptorPath();
        } else {
            return null;
        }
    
public booleangetRuntimeXMLValidation()

return
true if the runtime XML will be validated while reading.

        return isValidatingRuntimeXML;
    
public java.lang.StringgetRuntimeXMLValidationLevel()

return
the runtime xml validation reporting level

          return runtimeValidationLevel;
      
public abstract DeploymentDescriptorFilegetStandardDDFile()

return
the DeploymentDescriptorFile responsible for handling standard deployment descriptor

protected static java.io.FilegetTempFile(java.lang.String fileOrDirPath)
utility method to get a tmp file in the current user directory of the provided directory

param
File file or directory to use as temp location (use parent directory if a file is provided)

        if (fileOrDirPath!=null) {
            return getTempFile(new File(fileOrDirPath));
        } else {
            return getTempFile((File) null);
        }
    
protected static java.io.FilegetTempFile(java.io.File fileOrDir)
utility method to get a tmp file in the current user directory of the provided directory

param
File file or directory to use as temp location (use parent directory if a file is provided)

        
        File dir = null;
        if (fileOrDir==null) {
            dir=new File(System.getProperty("user.dir"));
        } else {            
            if (!fileOrDir.isDirectory()) {
                dir = fileOrDir.getParentFile();
                if (dir==null) {
                    dir=new File(System.getProperty("user.dir"));
                }     
            } else {
                dir = fileOrDir;
            }
        }
        return File.createTempFile("tmp", ".jar", dir);
    
protected java.lang.StringgetUniqueEntryFilenameFor(com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive, java.lang.String trialName)

returns
an entry name unique amongst names in this archive based on the triel name.

        Vector entriesNames = new Vector();
        Enumeration e = archive.entries();
        while (e!=null && e.hasMoreElements()) {
            entriesNames.add(e.nextElement());
        }
	return Descriptor.createUniqueFilenameAmongst(trialName, entriesNames);
    
public DeploymentDescriptorFilegetWebServicesDDFile(Descriptor desc)

param
arch archive for this module. can be null. only used for reading
return
the DeploymentDescriptorFile responsible for handling the web services deployment descriptors

        return new WebServicesDeploymentDescriptorFile(desc);
    
public java.lang.StringgetWebServicesDeploymentDescriptorPath()

return
the location of the web services related deployment descriptor file inside this archive or null if this archive does not support webservices implementation.

        return null;
    
public booleangetXMLValidation()

return
true if the Deployment Descriptors XML will be validated while reading.

	return isValidatingXML;
    
public java.lang.StringgetXMLValidationLevel()

return
the xml validation reporting level

	  return validationLevel;
      
public booleanhasRuntimeDeploymentDescriptor(com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive)


        //check null: since .par archive does not have runtime dds
        if (getConfigurationDDFile() != null) {
            InputStream runIs = archive.getEntry(
                getConfigurationDDFile().getDeploymentDescriptorPath());
            if (runIs != null) {
                runIs.close();
                return true;
            }
        }
        return false;
    
public booleanhasStandardDeploymentDescriptor(com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive)

        InputStream stIs = archive.getEntry(getDeploymentDescriptorPath());
        if (stIs != null) {
             stIs.close();
             return true;
        }
        return false;
    
protected voidinitializeContext(com.sun.enterprise.deployment.archivist.Archivist other)
initializes this instance from another archivist, this is used to transfer contextual information between archivists, for example whether we should handle runtime information and such

        handleRuntimeInfo = other.isHandlingRuntimeInfo();
        annotationProcessingRequested = other.isAnnotationProcessingRequested();
        isValidatingXML = other.isValidatingXML;
        validationLevel = other.validationLevel;
        abstractArchiveFactory = other.getAbstractArchiveFactory();
        classLoader = other.classLoader;
        annotationErrorHandler = other.annotationErrorHandler;
    
public booleanisAnnotationProcessingRequested()

return
true if this archivist will process annotation

        return annotationProcessingRequested;
    
public booleanisHandlingRuntimeInfo()

return
true if this archivist will save the runtime info

        return handleRuntimeInfo;
    
public RootDeploymentDescriptoropen(com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive)
Open a new archive file, read the XML descriptor and set the constructed DOL descriptor instance

param
path the archive file path
return
the deployment descriptor for this archive


        setManifest(archive.getManifest());
        
        RootDeploymentDescriptor descriptor = readDeploymentDescriptors(archive);
        if (descriptor!=null){
            postOpen(descriptor, archive);
        }
        return descriptor;
    
public RootDeploymentDescriptoropen(java.lang.String path)
Open a new archive file, read the XML descriptor and set the constructed DOL descriptor instance

param
path the archive file path
return
the deployment descriptor for this archive


        this.path = path;
	File file = new File(path);
	if (!file.exists()) {
	    throw new FileNotFoundException(path);	    
	}
        AbstractArchive abstractArchive = abstractArchiveFactory.openArchive(path);
        RootDeploymentDescriptor descriptor  = open(abstractArchive);
        
        abstractArchive.close();
     
        // attempt validation
        validate(null);

        return descriptor;
    
public RootDeploymentDescriptoropen(java.io.File file)
open a new archive file using a file descriptor

param
the archive to open

        return open(file.getAbsolutePath());
    
public booleanperformOptionalPkgDependenciesCheck(com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive)
Perform Optional packages dependencies checking on an archive

        
        boolean dependenciesSatisfied = true;
        Manifest m = archive.getManifest();
        if (m!=null) {
            dependenciesSatisfied=OptionalPkgDependency.optionalPkgDependencyLogic(m, archive.getArchiveUri());
        }
        // now check my libraries.
        Vector<String> libs = getLibraries(archive);
        if (libs!=null) {
            for (String libUri : libs) {
                JarInputStream jis=null;
                try {
                    jis = new JarInputStream(archive.getEntry(libUri));
                    m = jis.getManifest();
                    if (m!=null) {
                        if (!OptionalPkgDependency.optionalPkgDependencyLogic(m, libUri)) {
                            dependenciesSatisfied=false;
                        }                         
                    }
                } finally {
                    if (jis!=null)
                        jis.close();
                }
            }
        }
        return dependenciesSatisfied;
    
protected voidpostAnnotationProcess(RootDeploymentDescriptor descriptor, com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive)
perform any action after annotation processed

param
the deployment descriptor for the module
param
the module archive

    
protected abstract booleanpostHandles(com.sun.enterprise.deployment.deploy.shared.AbstractArchive abstractArchive)

return
true if the archivist is handling the provided archive

protected voidpostOpen(RootDeploymentDescriptor descriptor, com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive)
perform any post deployment descriptor reading action

param
the deployment descriptor for the module
param
the module archive

    
protected voidpostRuntimeDDsRead(RootDeploymentDescriptor descriptor, com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive)
perform any action after all runtime DDs read

param
the deployment descriptor for the module
param
the module archive

    
protected voidpostStandardDDsRead(RootDeploymentDescriptor descriptor, com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive)
perform any action after all standard DDs is read

param
the deployment descriptor for the module
param
the module archive

    
protected voidprepareForInclusion(com.sun.enterprise.deployment.deploy.shared.AbstractArchive out)
prepare an archivist for inclusion in a application archive.

param
archive file where this archivist will be saved

    
public voidprintDescriptor()
print the current descriptor associated with this archivist

        getDescriptor().visit((DescriptorVisitor) new TracerVisitor());
    
public com.sun.enterprise.deployment.annotation.ProcessingResultprocessAnnotations(BundleDescriptor bundleDesc, com.sun.enterprise.deployment.deploy.shared.AbstractArchive abstractArchive)
Process annotations in a bundle descriptor, the annoation processing is dependent on the type of descriptor being passed.


        AnnotatedElementHandler aeHandler =
                AnnotatedElementHandlerFactory.createAnnotatedElementHandler(
                bundleDesc);

        if (aeHandler == null) {
            return null;
        }
        
        Scanner scanner = ScannerFactory.createScanner(
                bundleDesc, this, abstractArchive, classLoader);
        if (!scanner.getElements().isEmpty()) {
            if (bundleDesc.isDDWithNoAnnotationAllowed()) {
                // if we come into this block, it means an old version 
                // of deployment descriptor has annotation which is not correct
                // throw exception in this case
                String ddName = 
                    getStandardDDFile().getDeploymentDescriptorPath();
                String explodedArchiveName = 
                    new File(abstractArchive.getArchiveUri()).getName();
                String archiveName = FileUtils.revertFriendlyFilenameExtension(
                    explodedArchiveName);
                throw new AnnotationProcessorException(
                    localStrings.getLocalString(
                    "enterprise.deployment.oldDDwithAnnotation", 
                    "{0} in archive {1} is of version {2}, which cannot support annotations in an application.  Please upgrade the deployment descriptor to be a version supported by Java EE 5.0 (or later).", 
                    new Object[] {ddName, archiveName, bundleDesc.getSpecVersion()}));
            }
            AnnotationProcessor ap = SJSASFactory.getAnnotationProcessor();
            ProcessingContext ctx = ap.createContext();
            if (annotationErrorHandler != null) {
                ctx.setErrorHandler(annotationErrorHandler);
            }
            ctx.setProcessingInput(scanner);
            ctx.pushHandler(aeHandler);
            
            // Make sure there is a classloader available on the descriptor
            // during annotation processing.
            ClassLoader originalBundleClassLoader = null;
            try {
                originalBundleClassLoader = bundleDesc.getClassLoader();
            } catch(Exception e) {
                // getClassLoader can throw exception if not available
            }
            
            // Only set classloader if it's not already set.
            if( originalBundleClassLoader == null ) {
                bundleDesc.setClassLoader(classLoader);
            }
            
            try {
                return ap.process(ctx);
            } finally {
                if( originalBundleClassLoader == null ) {
                    bundleDesc.setClassLoader(null);
                }
            }
        } else {
            bundleDesc.setFullFlag(true);
        }
        return null;
    
protected voidreadAnnotations(com.sun.enterprise.deployment.deploy.shared.AbstractArchive abstractArchive, BundleDescriptor descriptor)

        // if the system property is set to process annotation for pre-JavaEE5
        // DD, the semantics of isFull flag is: full attribute is set to 
        // true in DD. Otherwise the semantics is full attribute set to 
        // true or it is pre-JavaEE5 DD.
        boolean isFull = false;
        if (processAnnotationForOldDD) {
            isFull = descriptor.isFullAttribute();
        } else {
            isFull = descriptor.isFullFlag();
        }

        // only process annotation when these two requirements satisfied:
        // 1. It is not a full deployment descriptor
        // 2. It is called through dynamic deployment
        if (!isFull && annotationProcessingRequested 
            && classLoader != null) {
            try {
                ProcessingResult result = processAnnotations(descriptor, abstractArchive);
                if (result != null  &&
                        ResultType.FAILED.equals(result.getOverallResult())){
                    DOLUtils.getDefaultLogger().severe(localStrings.getLocalString(
                            "enterprise.deployment.archivist.annotationprocessingfailed",
                            "Annotations processing failed for {0}",
                            new Object[]{abstractArchive.getArchiveUri()}));
                }
            //XXX for backward compatible in case of having cci impl in EJB
            } catch(NoClassDefFoundError err) {
                 if (DOLUtils.getDefaultLogger().isLoggable(Level.WARNING)) {	
                     DOLUtils.getDefaultLogger().warning(
                         "Error in annotation processing: " + err);
                 }
            } catch(AnnotationProcessorException ex) {
                DOLUtils.getDefaultLogger().severe(ex.getMessage());
                DOLUtils.getDefaultLogger().log(Level.FINE, ex.getMessage(), ex);
                throw new IllegalStateException(ex);
            }
        } else if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
            DOLUtils.getDefaultLogger().fine("Annotation is not processed for this archive.");
        }
    
public RootDeploymentDescriptorreadDeploymentDescriptors(com.sun.enterprise.deployment.deploy.shared.AbstractArchive abstractArchive)
Read the standard deployment descriptors (can contained in one or many file) and return the corresponding initialized descriptor instance. By default, the standard deployment descriptors are all contained in the xml file characterized with the path returned by

see
getDeploymentDescriptorPath
return
the initialized descriptor

            
        // read the standard deployment descriptors 
        BundleDescriptor descriptor = (BundleDescriptor)readStandardDeploymentDescriptor(abstractArchive);

        ModuleDescriptor newModule = createModuleDescriptor(descriptor);
        newModule.setArchiveUri(abstractArchive.getArchiveUri());
        
        readWebServicesDescriptor(abstractArchive, descriptor);

        // Now that we have parsed the standard DD, let's read all the
        // PersistenceUnits defined in this archive as well.
        readPersistenceDeploymentDescriptors(abstractArchive, getDescriptor());

        postStandardDDsRead(descriptor, abstractArchive);

        readAnnotations(abstractArchive, descriptor);
        postAnnotationProcess(descriptor, abstractArchive);

        // now read the runtime deployment descriptors
        readRuntimeDeploymentDescriptor(abstractArchive, descriptor);
        postRuntimeDDsRead(descriptor, abstractArchive);
	
	return descriptor;     	
    
protected voidreadPersistenceDeploymentDescriptor(com.sun.enterprise.deployment.deploy.shared.Archive subArchive, java.lang.String puRoot, Descriptor descriptor)

        final String subArchiveURI = AbstractArchive.class.cast(subArchive).getArchiveUri();
        if (logger.isLoggable(Level.FINE)) {
            logger.logp(Level.FINE, "Archivist",
                    "readPersistenceDeploymentDescriptor",
                    "PURoot = [{0}] subArchive = {1}",
                    new Object[]{puRoot, subArchiveURI});
        }
        final RootDeploymentDescriptor rootDD =
                RootDeploymentDescriptor.class.cast(descriptor);
        if (rootDD.getPersistenceUnitsDescriptor(puRoot) != null) {
            if (logger.isLoggable(Level.FINE)) {
                logger.logp(Level.FINE, "Archivist",
                        "readPersistenceDeploymentDescriptor",
                        "PU has been already read for = {0}",
                        subArchiveURI);
            }
            return;
        }
        PersistenceDeploymentDescriptorFile persistenceDeploymentDescriptorFile
                = new PersistenceDeploymentDescriptorFile();
        persistenceDeploymentDescriptorFile.setErrorReportingString(
                subArchiveURI.toString());
        persistenceDeploymentDescriptorFile.setXMLValidation(getXMLValidation());
        persistenceDeploymentDescriptorFile.setXMLValidationLevel(
                getXMLValidationLevel());
        InputStream is = subArchive.getEntry(
                persistenceDeploymentDescriptorFile.getDeploymentDescriptorPath());
        if (is == null) {
            if (logger.isLoggable(Level.FINE)) {
                logger.logp(Level.FINE, "Archivist",
                    "readPersistenceDeploymentDescriptor",
                    "{0} does not contain {1}, so it is not a PU Root.",
                    new Object[]{subArchiveURI,
                                 persistenceDeploymentDescriptorFile.getDeploymentDescriptorPath()});
            }
            return;
        }
        try {
            PersistenceUnitsDescriptor persistenceUnitsDescriptor =
                    PersistenceUnitsDescriptor.class.cast(
                            persistenceDeploymentDescriptorFile.read(rootDD, is));
            rootDD.addPersistenceUnitsDescriptor(puRoot,
                    persistenceUnitsDescriptor);
        } finally {
            is.close();
        }
    
public voidreadPersistenceDeploymentDescriptors(com.sun.enterprise.deployment.deploy.shared.AbstractArchive archive, Descriptor descriptor)
This method is responsible for reading of any persistence DD defined in the SCOPE of this descriptor. Note, it only reads persistence DD defined in the current SCOPE.

param
archive is the archive that will be scanned for persistence DD
param
descriptor which will be populated with information read from persistence DD.
throws
IOException
throws
SAXParseException

        // This is a no-op implementation as opposed to an abstract method
        // because it gets called from ConnectorArchivist.
    
public voidreadRuntimeDDFromDeploymentPlan(com.sun.enterprise.deployment.deploy.shared.AbstractArchive planArchive, Descriptor descriptor)
Read the runtime deployment descriptors (can contained in one or many file) from a deployment plan archive, set the corresponding information in the passed descriptor.

        
        // if we are not supposed to handle runtime info, just pass
        String runtimeDDPath = getRuntimeDeploymentDescriptorPath();
        if (runtimeDDPath==null || planArchive==null) {
            return;
        }

        // list of entries in the deployment plan
        Vector dpEntries = new Vector();
        for (Enumeration e = planArchive.entries(); e.hasMoreElements();) {
            dpEntries.add(e.nextElement());
        }

        String entry = runtimeDDPath.substring(runtimeDDPath.lastIndexOf('/")+1);
        if (dpEntries.contains(entry)) {
            readRuntimeDDFromDeploymentPlan(entry, planArchive, descriptor);
        }
    
protected voidreadRuntimeDDFromDeploymentPlan(java.lang.String entry, com.sun.enterprise.deployment.deploy.shared.AbstractArchive planArchive, Descriptor descriptor)
Read the runtime deployment descriptors (can contained in one or many file) from a deployment plan archive, set the corresponding information in the passed descriptor.


        InputStream is = null;
        try {
            is = planArchive.getEntry(entry);
            DeploymentDescriptorFile confDD = getConfigurationDDFile();
            if (is!=null && confDD!=null) {
                if (planArchive.getArchiveUri()!=null) {
                    confDD.setErrorReportingString(planArchive.getArchiveUri());
                }
                confDD.setXMLValidation(getXMLValidation());
                confDD.read(descriptor, is);
            }
        } finally {
            if (is != null) {
            try {
                is.close();
            } catch (IOException ioe) { }
            }
        }
    
public voidreadRuntimeDeploymentDescriptor(com.sun.enterprise.deployment.deploy.shared.AbstractArchive abstractArchive, Descriptor descriptor)
Read the runtime deployment descriptors (can contained in one or many file) set the corresponding information in the passed descriptor. By default, the runtime deployment descriptors are all contained in the xml file characterized with the path returned by

see
getRuntimeDeploymentDescriptorPath
param
the initialized deployment descriptor

        
        // if we are not supposed to handle runtime info, just pass
        String ddFileEntryName = getRuntimeDeploymentDescriptorPath();
        if (!isHandlingRuntimeInfo() || ddFileEntryName==null) {
            return;
        }
        
        InputStream is = null;
        try {
            // apply the runtime settings if any
            is = abstractArchive.getEntry(ddFileEntryName);
            DeploymentDescriptorFile confDD = getConfigurationDDFile();
            if (abstractArchive.getArchiveUri()!=null) {
                confDD.setErrorReportingString(abstractArchive.getArchiveUri());
            }     
        
            if (is!=null && confDD!=null) {
                confDD.setXMLValidation(getRuntimeXMLValidation());
                confDD.setXMLValidationLevel(runtimeValidationLevel);
                confDD.read(descriptor, is);                      
            }
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException ioe) {
                }
            }
        }
    
public DescriptorreadStandardDeploymentDescriptor(com.sun.enterprise.deployment.deploy.shared.AbstractArchive abstractArchive)
Read the standard deployment descriptors (can contained in one or many file) and return the corresponding initialized descriptor instance. By default, the standard deployment descriptors are all contained in the xml file characterized with the path returned by

see
getDeploymentDescriptorPath
return
the initialized descriptor


        InputStream is = null;
        
        try {
            is = abstractArchive.getEntry(getStandardDDFile().getDeploymentDescriptorPath());
            if (is!=null) {
                DeploymentDescriptorFile ddFile = getStandardDDFile();
                ddFile.setXMLValidation(getXMLValidation());
                ddFile.setXMLValidationLevel(validationLevel);
                if (abstractArchive.getArchiveUri()!=null) {
                    ddFile.setErrorReportingString(abstractArchive.getArchiveUri());
                }
                Descriptor result = ddFile.read(is);
                return result;        
            } else {
                /*
                 *Always return at least the default, because the info is needed 
                 *when an app is loaded during a server restart and there might not
                 *be a physical descriptor file.
                 */
                return getDefaultBundleDescriptor();
            }
        } finally {
            if (is != null) {
                is.close();
            }
        }
    
protected voidreadWebServicesDescriptor(com.sun.enterprise.deployment.deploy.shared.AbstractArchive abstractArchive, Descriptor descriptor)
Read the (optional) webservices.xml descriptor in this module. Only applicable for web and ejb modules.


        DeploymentDescriptorFile confDD = getWebServicesDDFile(descriptor);
        if (abstractArchive.getArchiveUri()!=null) {
            confDD.setErrorReportingString(abstractArchive.getArchiveUri());
        }        
        InputStream is = null;
        try {
            is = abstractArchive.getEntry(confDD.getDeploymentDescriptorPath());
            if (is != null) {
                confDD.setXMLValidation(getXMLValidation());
                confDD.setXMLValidationLevel(validationLevel);
                confDD.read(descriptor, is);
            }
        } finally {
            if (is != null) {
                is.close();
            }
        }

    
protected booleanrenameTmp(java.lang.String from, java.lang.String to)
rename a tmp file

param
old name
param
new name

        
        AbstractArchive finalArchive = abstractArchiveFactory.openArchive(to);
        finalArchive.delete();
        AbstractArchive tmpArchive = abstractArchiveFactory.openArchive(from);
        boolean success = tmpArchive.renameTo(to);
        if (!success) {            
            throw new IOException("Error renaming JAR");
        }
        return success;
    
public voidsaveRuntimeInfo(java.io.File output)

        // if output file is null, we overwrite the current archive...
        File outputFile = output;        
        if (outputFile==null) {
            outputFile = getTempFile(path);
        }
        
        // copy all entries from source to target except the 
        // runtime descriptor file
        AbstractArchive out = abstractArchiveFactory.createArchive(outputFile.getAbsolutePath());
        AbstractArchive in = abstractArchiveFactory.openArchive(path);
        Vector skipFiles = new Vector();
        skipFiles.add(getRuntimeDeploymentDescriptorPath());
        copyInto(in, out, skipFiles);
        in.close();
        
        // now save the runtime deployment descriptor...
        OutputStream os = out.putNextEntry(getRuntimeDeploymentDescriptorPath());
        writeRuntimeDeploymentDescriptors(os);
        out.closeEntry();
        out.close();
        
        // if we overwrote the old archive, need to rename the tmp now
        if (output==null) {
            AbstractArchive finalArchive = abstractArchiveFactory.openArchive(path);
            finalArchive.delete();
            AbstractArchive tmpArchive = abstractArchiveFactory.openArchive(outputFile.getAbsolutePath());
            tmpArchive.renameTo(path);
        }
        
    
public voidsetAbstractArchiveFactory(com.sun.enterprise.deployment.deploy.shared.AbstractArchiveFactory aa)
sets the abstract archive factory associated with this archivist.

param
the new factory for creating abstract archives

        abstractArchiveFactory = aa;
    
public voidsetAnnotationErrorHandler(com.sun.enterprise.deployment.annotation.ErrorHandler annotationErrorHandler)
sets annotation ErrorHandler for this archivist

param
annotationErrorHandler

        this.annotationErrorHandler = annotationErrorHandler;
    
public voidsetAnnotationProcessingRequested(boolean annotationProcessingRequested)
sets if this archivist process annotation

param
true to process annotation

        this.annotationProcessingRequested = annotationProcessingRequested;
    
public voidsetArchiveUri(java.lang.String path)
Sets the path for this archivist's archive file

        this.path = path;
    
public voidsetClassLoader(java.lang.ClassLoader classLoader)
Sets the classloader for this archivist

param
class loader

        this.classLoader = classLoader;
    
public voidsetClassPath(java.lang.String newClassPath)
Sets the class-path for this archive

param
the new class-path

        
        if (manifest==null) {
            manifest = new Manifest();
        }
        
        Attributes atts = manifest.getMainAttributes();
        atts.putValue(Attributes.Name.CLASS_PATH.toString(), newClassPath);                
    
public abstract voidsetDescriptor(Descriptor descriptor)
Archivist read XML deployment descriptors and keep the parsed result in the DOL descriptor instances. Sets the descriptor for a particular Archivist type

public voidsetHandleRuntimeInfo(boolean handleRuntimeInfo)
sets if this archivist saves the runtime info

param
true to save the runtime info

        this.handleRuntimeInfo = handleRuntimeInfo;
    
public voidsetManifest(java.util.jar.Manifest m)
sets the manifest file for this archive

param
manifest to use at saving time

        manifest = m;
    
public voidsetModuleDescriptor(com.sun.enterprise.deployment.util.ModuleDescriptor module)
Archivists can be associated with a module descriptor once the XML deployment descriptors have been read and the DOL tree is initialized.

        setDescriptor(module.getDescriptor());
        setManifest(module.getManifest());
    
public voidsetPluggableArchivists(PluggableArchivists pa)
Sets the pluggable archivist factory for this instance

        this.pa = pa;
    
public voidsetRuntimeXMLValidation(boolean validate)
Turn on or off the XML Validation for runtime deployment descriptors loading

param
true to turn on XML validation

         isValidatingRuntimeXML = validate;
     
public voidsetRuntimeXMLValidationLevel(java.lang.String level)
Sets the runtime xml validation error reporting/recovering level. The reporting level is active only when xml validation is turned on @see setXMLValidation. so far, two values can be passed, medium which reports the xml validation and continue and full which reports the xml validation and stop the xml parsing.

 
         runtimeValidationLevel = level;
     
public voidsetXMLValidation(boolean validate)
Turn on or off the XML Validation for all standard deployment descriptors loading

param
true to turn on XML validation

	 isValidatingXML=validate;
     
public voidsetXMLValidationLevel(java.lang.String level)
Sets the xml validation error reporting/recovering level. The reporting level is active only when xml validation is turned on @see setXMLValidation. so far, two values can be passed, medium which reports the xml validation and continue and full which reports the xml validation and stop the xml parsing.

	 validationLevel = level;
     
public voidvalidate(java.lang.ClassLoader aClassLoader)
validates the DOL Objects associated with this archivist, usually it requires that a class loader being set on this archivist or passed as a parameter

   
    
public voidwrite()

        write(path);
    
public voidwrite(java.lang.String outPath)
saves the archive

param
outPath the file to use

        AbstractArchive in = abstractArchiveFactory.openArchive(path);        
        write(in, outPath);
        in.close();
    
public voidwrite(com.sun.enterprise.deployment.deploy.shared.AbstractArchive in, java.lang.String outPath)
save the archive

param
input abstract archive to copy old elements from
param
outPath the file to use

        
        AbstractArchive oldArchive=null;
        try {
            oldArchive = abstractArchiveFactory.openArchive(outPath);
        } catch (IOException ioe) {
            // there could be many reasons why we cannot open this archive, 
            // we should continue
        }
        AbstractArchive out = null;
        BufferedOutputStream bos=null;
        try {
            String tmpName = null;
            if (oldArchive!=null && oldArchive.exists() && 
                !oldArchive.supportsElementsOverwriting()) {
                // this is a rewrite, get a temp file name...
                // I am creating a tmp file just to get a name
                File outputFile = getTempFile(outPath);    
                tmpName = outputFile.getAbsolutePath();
                outputFile.delete();
                out = abstractArchiveFactory.createArchive(tmpName);
                oldArchive.close();
            } else {
                out = abstractArchiveFactory.createArchive(outPath);
            }
        
            // write archivist content
            writeContents(in, out);
            out.close();    
            in.close();
            
            // if we were using a temp file, time to rewrite the original
            if (tmpName!=null) {
                AbstractArchive finalArchive = abstractArchiveFactory.openArchive(outPath);
                finalArchive.delete();
                AbstractArchive tmpArchive = abstractArchiveFactory.openArchive(tmpName);
                tmpArchive.renameTo(outPath);
            }       
        } catch (IOException ioe) {
            // cleanup
            if (out!=null) {
		try {
                    out.close();
                    //out.delete(); <-- OutputJarArchive.delete isn't supported.
	 	} catch (IOException outIoe) {
		    // ignore exceptions here, otherwise this will end up masking the real
		    // IOException in 'ioe'.
		}
            }
            // propagate exception
            throw ioe;
        }
    
public voidwrite(com.sun.enterprise.deployment.deploy.shared.AbstractArchive in, com.sun.enterprise.deployment.deploy.shared.AbstractArchive out)

        writeContents(in,out);
    
protected voidwriteContents(com.sun.enterprise.deployment.deploy.shared.AbstractArchive out)
writes the content of an archive to a JarFile

param
the jar output stream to write to

        AbstractArchive in = abstractArchiveFactory.openArchive(path);        
        writeContents(in, out);
        in.close();
    
protected voidwriteContents(com.sun.enterprise.deployment.deploy.shared.AbstractArchive in, com.sun.enterprise.deployment.deploy.shared.AbstractArchive out)
writes the content of an archive to a JarFile

param
the jar output stream to write to


        writeContents(in, out, null);
    
protected voidwriteContents(com.sun.enterprise.deployment.deploy.shared.AbstractArchive in, com.sun.enterprise.deployment.deploy.shared.AbstractArchive out, java.util.Vector entriesToSkip)
writes the content of an archive to a JarFile

param
the input archive
param
the archive output stream to write to
param
the files to not write from the original archive

        
        
        // Copy original jarFile elements
        if (in!=null && in.exists()) {
            if (entriesToSkip==null) {
                entriesToSkip = getListOfFilesToSkip();
            } else {
                entriesToSkip.addAll(getListOfFilesToSkip());
            }
            copyJarElements(in, out, entriesToSkip);            
        }
        
        // now the deployment descriptors
        writeDeploymentDescriptors(out);  
        
        // manifest file
        if (manifest!=null) {
            OutputStream os = out.putNextEntry(JarFile.MANIFEST_NAME);
            manifest.write(new DataOutputStream(os));
            out.closeEntry();
        }
    
public voidwriteDeploymentDescriptors(com.sun.enterprise.deployment.deploy.shared.AbstractArchive out)
writes the deployment descriptors (standard and runtime) to a JarFile using the right deployment descriptor path

out
the abstract archive file to write to

        
        // Standard DDs
        writeStandardDeploymentDescriptors(out);
	
        // the rest...
	writeExtraDeploymentDescriptors(out);
    
protected voidwriteExtraDeploymentDescriptors(com.sun.enterprise.deployment.deploy.shared.AbstractArchive out)
write all extra deployment descriptors (like cmp related and runtime dds)

out
the abstract archive file to write to

	writeRuntimeDeploymentDescriptors(out);
    
public voidwriteRuntimeDeploymentDescriptors(com.sun.enterprise.deployment.deploy.shared.AbstractArchive out)
writes the runtime deployment descriptors to an abstract archive

param
the abstract archive

        
        Descriptor desc = getDescriptor();

        // Runtime DDs
        if (isHandlingRuntimeInfo()) {
            DeploymentDescriptorFile confDD = getConfigurationDDFile();
            if (confDD!=null) {
                OutputStream os = out.putNextEntry(getRuntimeDeploymentDescriptorPath());
                confDD.write(desc, os);
                out.closeEntry();
            }        
        }
        
    
public voidwriteRuntimeDeploymentDescriptors(java.io.OutputStream os)
writes de configuration deployment descriptor to a new XML file

param
output stream to write the configuration deployment descriptors

        DeploymentDescriptorFile confDD = getConfigurationDDFile();
        if (confDD!=null) {
            confDD.write(getDescriptor(), os);
        }      
    
public voidwriteStandardDeploymentDescriptors(com.sun.enterprise.deployment.deploy.shared.AbstractArchive out)
writes the standard deployment descriptors to an abstract archive

param
the abstract archive to write to

        
        OutputStream os = out.putNextEntry(getDeploymentDescriptorPath());
        writeStandardDeploymentDescriptors(os);
        out.closeEntry();   
        
        Descriptor desc = getDescriptor();
        
        // only bundle descriptor can have web services
        if (desc instanceof BundleDescriptor) {            
            writeWebServicesDescriptors((BundleDescriptor) desc, out);
        }        
    
public voidwriteStandardDeploymentDescriptors(java.io.OutputStream os)
writes the standard deployment descriptor to an output stream

param
output stream to write out the descriptors

        getStandardDDFile().write(getDescriptor(), os);
    
protected voidwriteWebServicesDescriptors(BundleDescriptor desc, com.sun.enterprise.deployment.deploy.shared.AbstractArchive out)

return
whether this archivist should write a web services deployment descriptor

        if (desc.hasWebServices()) {            
            DeploymentDescriptorFile webServicesDD = getWebServicesDDFile(desc);
            OutputStream os = out.putNextEntry(webServicesDD.getDeploymentDescriptorPath());
            webServicesDD.write(desc, os);
            out.closeEntry();
        }