Package org.xdoclet.plugin.ejb

Source Code of org.xdoclet.plugin.ejb.AbstractEjbJarXmlPlugin

package org.xdoclet.plugin.ejb;

import java.io.File;
import java.util.Collection;
import java.util.Iterator;

import org.generama.TemplateEngine;
import org.generama.WriterMapper;

import com.thoughtworks.qdox.model.JavaClass;

/**
* Common superclass for all QDoxPlugins generating a single XML file
* containing information about multiple files.
*
* This plugin will only generate a destination file if at least one
* of the beans is dirty, or if force is set.
*
* @author Ive Hellemans
* @version $Revision$
*/
public abstract class AbstractEjbJarXmlPlugin extends EjbQDoxPlugin {

    /** Caches the result of calls to the isDestinationDirty method. */
    private Boolean isDestinationDirty;
   
    public AbstractEjbJarXmlPlugin(TemplateEngine templateEngine,
            WriterMapper writerMapper, EjbConfig config) {
        super(templateEngine, writerMapper, config);
    }

    /**
     * Starts the plugin only if at least one the source file has been
     * chnaged after the generated file - or when fore = true.
     *
     * Set force is true to force starting this plugin.
     */
    public void start() {
        if (force || isDestinationDirty()) {
            super.start();
        } else {
            System.out.println("Running " + getClass().getName());
        }
    }

    /**
     * Calculates whether or not the destination file is dirty, returning
     * true if any of the bean source files was changed after the last
     * time the destination file was generated.
     * 
     * TODO: take merge files into account
     */
    public boolean isDestinationDirty() {

        if (isDestinationDirty != null) {
            return isDestinationDirty.booleanValue();
        }

        boolean dirty = false;
        File destFile = getDestinationFile();
        if (destFile.exists()) {
            //Iterate over all beans & compare
            Collection beans = ejbUtils.getBeans(getMetadata());
            File sourceFile = null;
            for (Iterator iterator = beans.iterator(); iterator.hasNext();) {
                JavaClass javaClass = (JavaClass) iterator.next();
                sourceFile = getSourceFile(javaClass);
                if (destFile.lastModified() < sourceFile.lastModified()) {
                    System.out.println("dirty source = " + sourceFile.getAbsolutePath());
                    dirty = true;
                    break;
                }
            }
        } else {
            //File doesn't exist or force = true
            dirty = true;
        }

        //Cache the result and return
        isDestinationDirty = Boolean.valueOf(dirty);
        return dirty;
    }

}
TOP

Related Classes of org.xdoclet.plugin.ejb.AbstractEjbJarXmlPlugin

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.