001: /**
002: * EasyBeans
003: * Copyright (C) 2007 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: EjbFile.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.ant.archive.file;
025:
026: import java.io.File;
027:
028: import org.apache.tools.ant.Project;
029: import org.apache.tools.ant.taskdefs.Jar;
030: import org.apache.tools.ant.types.FileSet;
031: import org.apache.tools.ant.types.ZipFileSet;
032: import org.ow2.easybeans.ant.archive.api.IEjb;
033: import org.ow2.easybeans.ant.archive.info.ArchiveInfo;
034: import org.ow2.easybeans.ant.archive.info.EjbInfo;
035:
036: /**
037: * Creates an EJB-JAR file.
038: * @author Florent Benoit
039: */
040: public class EjbFile extends Jar implements IEjb {
041:
042: /**
043: * Path to the Standard deployment descriptor.
044: */
045: private static final String DEPLOYMENT_DESCRIPTOR = "META-INF/ejb-jar.xml";
046:
047: /**
048: * Path to the Persistence deployment descriptor.
049: */
050: private static final String PERSISTENCE_DEPLOYMENT_DESCRIPTOR = "META-INF/persistence.xml";
051:
052: /**
053: * Reference to the archive info object.
054: */
055: private ArchiveInfo archiveInfo = null;
056:
057: /**
058: * Creates an archive for the given project.
059: * @param p the given project
060: */
061: public EjbFile(final Project p) {
062: super ();
063: setProject(p);
064: }
065:
066: /**
067: * Sets the information about an archive.
068: * @param archiveInfo the object that holds data information.
069: */
070: public void setArchiveInfo(final ArchiveInfo archiveInfo) {
071: this .archiveInfo = archiveInfo;
072: }
073:
074: /**
075: * Sets the information about an EJB archive.
076: * @param ejbInfo the object that holds data information.
077: */
078: public void setEjbInfo(final EjbInfo ejbInfo) {
079: setArchiveInfo(ejbInfo);
080: }
081:
082: /**
083: * Execute the task.
084: */
085: @Override
086: public void execute() {
087:
088: // Deployment descriptor
089: if (archiveInfo.getDd() != null) {
090: setDD(archiveInfo.getDd());
091: }
092:
093: // Persistence Deployment descriptor
094: if (archiveInfo.getPersistenceDD() != null) {
095: setPersistenceDD(archiveInfo.getPersistenceDD());
096: }
097:
098: // dest file
099: setDestFile(archiveInfo.getDest());
100:
101: // fileset
102: for (FileSet fileSet : archiveInfo.getFileSetList()) {
103: addFileset(fileSet);
104: }
105:
106: super .execute();
107: }
108:
109: /**
110: * Add the given DD file into the archive.
111: * @param dd the path to the DDesc file.
112: */
113: public void setDD(final File dd) {
114: ZipFileSet zipFileSet = new ZipFileSet();
115: zipFileSet.setFile(dd);
116: zipFileSet.setFullpath(DEPLOYMENT_DESCRIPTOR);
117: addFileset(zipFileSet);
118: }
119:
120: /**
121: * Add the given persistence DD file into the archive.
122: * @param persistenceDD the path to the DDesc file.
123: */
124: public void setPersistenceDD(final File persistenceDD) {
125: ZipFileSet zipFileSet = new ZipFileSet();
126: zipFileSet.setFile(persistenceDD);
127: zipFileSet.setFullpath(PERSISTENCE_DEPLOYMENT_DESCRIPTOR);
128: addFileset(zipFileSet);
129: }
130:
131: }
|