FileDocCategorySizeDatePackage
AppInfoCollector.javaAPI DocGlassfish v2 API7072Fri May 04 22:34:44 BST 2007com.sun.enterprise.diagnostics.collect

AppInfoCollector

public class AppInfoCollector extends Object implements Collector
Responsible for collecting applications deployment descriptors and generated files.
author
Manisha Umbarje

Fields Summary
private String
destFolder
private String
repositoryFolder
private com.sun.enterprise.diagnostics.ServiceConfig
config
private static Logger
logger
Constructors Summary
public AppInfoCollector(String repositoryFolder, String destFolder)
Creates new instance of AppInfoCollector

param
repositoryFolder central/cache repository root
param
destFolder destination folder in which files are collected

                            
         
        this.destFolder = destFolder;
        this.repositoryFolder = repositoryFolder;
        this.config = config;
    
Methods Summary
public com.sun.enterprise.diagnostics.Datacapture()
Captures applications deployment descriptors and generated files

throws
DiagnosticException

        WritableDataImpl dataImpl = new WritableDataImpl(DataType.APPL_INFO);
        dataImpl.addChild(captureAppRelatedInfo(Constants.GENERATED_DIR));
        dataImpl.addChild(
                captureAppRelatedInfo(Constants.APPLICATIONS_DIR,
                new DDFilter()));
        return dataImpl;
    
private com.sun.enterprise.diagnostics.DatacaptureAppRelatedInfo(java.lang.String relativePath)
Captures files

param
relativePath directory to be copied relative to central/cache repository
throw
DiagnosticException

        try {
            String sourceFolder = repositoryFolder + File.separator + relativePath;
            String destFileObj = destFolder + File.separator + relativePath;       
            FileUtils.copyDir(sourceFolder, destFileObj, true);
            return new FileData(destFileObj, DataType.APPL_INFO);
        } catch(IOException ioe) {
            logger.log(Level.WARNING, "diagnostic-service.copy_failed" ,
                    new Object[]{relativePath, ioe.getMessage()});
        }
        return null;
    
private com.sun.enterprise.diagnostics.DatacaptureAppRelatedInfo(java.lang.String relativePath, java.io.FilenameFilter filter)
Capture filtered files

param
relativePath directory to be copied relative to central/cache repository
param
filter file name filter

        WritableDataImpl dataImpl = new WritableDataImpl(relativePath);
        String sourceFolderName = repositoryFolder + File.separator + relativePath;
   
        File sourceFolder = new File(sourceFolderName);
        String[] filteredChildren = null;
        String[] children = null;

        // Assumes that there is no further sub directory , if children
        // satisfying the filter are found
        if (filter != null) {
            filteredChildren = sourceFolder.list(filter);
         }
         // Visit subfolders to search files with matching the filter
        
        if (filteredChildren != null) {
            if(filteredChildren.length ==  0) {
                children = sourceFolder.list();
                for (int i = 0 ; i < children.length; i++) {
                    String childName =  relativePath + File.separator + children[i];
                    String absoluteChildName = repositoryFolder  + File.separator + childName;
                    File child = new File(absoluteChildName);
                    if (child.isDirectory())
                        dataImpl.addChild(captureAppRelatedInfo(childName, filter));
                }
            } else {
                for (int i = 0 ; i < filteredChildren.length; i++) {
                    String childName =  relativePath + File.separator +
                            filteredChildren[i];
                    String absoluteChildName = repositoryFolder  +
                            File.separator + childName;
                    File child = new File(absoluteChildName);
                    try {
                        String dest = destFolder + File.separator + childName;
                        FileUtils.copyFile(absoluteChildName, dest);
                        dataImpl.addChild(new FileData(dest, DataType.APPL_INFO));
                    }catch(IOException ioe) {
                        logger.log(Level.WARNING, "diagnostic-service.copy_failed" ,
                            new Object[]{absoluteChildName, ioe.getMessage()});
                    }
                }// for
            }//else
        }//if
        return dataImpl;