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: Ejb.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.ant.archive;
025:
026: import java.io.File;
027:
028: import org.apache.tools.ant.BuildException;
029: import org.apache.tools.ant.Project;
030: import org.apache.tools.ant.Task;
031: import org.ow2.easybeans.ant.archive.api.IEjb;
032: import org.ow2.easybeans.ant.archive.exploded.EjbExploded;
033: import org.ow2.easybeans.ant.archive.file.EjbFile;
034: import org.ow2.easybeans.ant.archive.info.EjbInfo;
035:
036: /**
037: * Task that creates an EJB jar archive (.jar file or .jar directory).
038: * @author Florent Benoit
039: */
040: public class Ejb extends AbsArchive {
041:
042: /**
043: * Reference to the persistence deployment descriptor.
044: */
045: private File persistenceDeploymentDescriptor = null;
046:
047: /**
048: * Default constructor.
049: */
050: public Ejb() {
051: super ();
052: }
053:
054: /**
055: * Sets the reference to the persistence deployment descriptor.
056: * @param persistenceDD the given persistence deployment descriptor.
057: */
058: public void setPersistenceDD(final File persistenceDD) {
059: // Ignore empty value
060: if ("empty-value".equals(persistenceDD.getName())) {
061: return;
062: }
063:
064: if (!persistenceDD.exists()) {
065: throw new BuildException("The given file '" + persistenceDD
066: + "' for the deployment descriptor does not exist.");
067: }
068: this .persistenceDeploymentDescriptor = persistenceDD;
069: }
070:
071: /**
072: * Execute the task by using either exploded or file mode.
073: */
074: @Override
075: public void execute() {
076:
077: log("Building Ejb in '" + getDest() + "'.", Project.MSG_INFO);
078:
079: IEjb ejb = null;
080:
081: // 2 cases, exploded mode or not
082: if (isExploded()) {
083: ejb = new EjbExploded(getProject());
084: } else {
085: ejb = new EjbFile(getProject());
086: }
087:
088: // Set the name of the task
089: ((Task) ejb).setTaskName(getTaskName());
090:
091: // Build the info object
092: EjbInfo ejbInfo = new EjbInfo();
093: ejb.setEjbInfo(ejbInfo);
094:
095: // Fill archive properties
096: updateArchiveInfo(ejbInfo);
097: ejbInfo.setPersistenceDD(persistenceDeploymentDescriptor);
098:
099: // Execute the task
100: ejb.execute();
101:
102: }
103:
104: }
|