All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ow2.util.ant.archive.file.EjbFile Maven / Gradle / Ivy

/**
 * Copyright 2007-2012 Bull S.A.S.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.ow2.util.ant.archive.file;

import java.io.File;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Jar;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.ZipFileSet;
import org.ow2.util.ant.archive.api.IEjb;
import org.ow2.util.ant.archive.info.ArchiveInfo;
import org.ow2.util.ant.archive.info.EjbInfo;

/**
 * Creates an EJB-JAR file.
 * @author Florent Benoit
 */
public class EjbFile extends Jar implements IEjb {

    /**
     * Path to the Standard deployment descriptor.
     */
    private static final String DEPLOYMENT_DESCRIPTOR = "META-INF/ejb-jar.xml";

    /**
     * Path to the Persistence deployment descriptor.
     */
    private static final String PERSISTENCE_DEPLOYMENT_DESCRIPTOR = "META-INF/persistence.xml";

    /**
     * Path to the Specific deployment descriptor.
     */
    private static final String SPECIFIC_DEPLOYMENT_DESCRIPTOR = "META-INF/easybeans.xml";

    /**
     * Reference to the archive info object.
     */
    private ArchiveInfo archiveInfo = null;

    /**
     * Creates an archive for the given project.
     * @param p the given project
     */
    public EjbFile(final Project p) {
        super();
        setProject(p);
    }

    /**
     * Sets the information about an archive.
     * @param archiveInfo the object that holds data information.
     */
    public void setArchiveInfo(final ArchiveInfo archiveInfo) {
        this.archiveInfo = archiveInfo;
    }

    /**
     * Sets the information about an EJB archive.
     * @param ejbInfo the object that holds data information.
     */
    public void setEjbInfo(final EjbInfo ejbInfo) {
        setArchiveInfo(ejbInfo);
    }

    /**
     * Execute the task.
     */
    @Override
    public void execute() {

        // Deployment descriptor
        if (this.archiveInfo.getDD() != null) {
            setDD(this.archiveInfo.getDD());
        }

        // Specific Deployment descriptor
        if (this.archiveInfo.getSpecificDD() != null) {
            setSpecificDD(this.archiveInfo.getSpecificDD());
        }

        // Persistence Deployment descriptor
        if (this.archiveInfo.getPersistenceDD() != null) {
            setPersistenceDD(this.archiveInfo.getPersistenceDD());
        }

        // Manifest
        if (this.archiveInfo.getManifest() != null) {
            setManifest(this.archiveInfo.getManifest());
        }

        // dest file
        setDestFile(this.archiveInfo.getDest());

        // fileset
        for (FileSet fileSet : this.archiveInfo.getFileSetList()) {
            addFileset(fileSet);
        }

        super.execute();
    }

    /**
     * Add the given DD file into the archive.
     * @param dd the path to the DDesc file.
     */
    public void setDD(final File dd) {
        ZipFileSet zipFileSet = new ZipFileSet();
        zipFileSet.setFile(dd);
        zipFileSet.setFullpath(DEPLOYMENT_DESCRIPTOR);
        addFileset(zipFileSet);
    }

    /**
     * Add the given Specific DD file into the archive.
     * @param dd the path to the DDesc file.
     */
    public void setSpecificDD(final File dd) {
        ZipFileSet zipFileSet = new ZipFileSet();
        zipFileSet.setFile(dd);
        zipFileSet.setFullpath(SPECIFIC_DEPLOYMENT_DESCRIPTOR);
        addFileset(zipFileSet);
    }


    /**
     * Add the given persistence DD file into the archive.
     * @param persistenceDD the path to the DDesc file.
     */
    public void setPersistenceDD(final File persistenceDD) {
        ZipFileSet zipFileSet = new ZipFileSet();
        zipFileSet.setFile(persistenceDD);
        zipFileSet.setFullpath(PERSISTENCE_DEPLOYMENT_DESCRIPTOR);
        addFileset(zipFileSet);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy