001: /*
002: * CoadunationLib: The coaduntion implementation library.
003: * Copyright (C) 2006 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * RMIC.java
020: *
021: * The RMI generator wrapps the ANT rmi task.
022: */
023:
024: // package path
025: package com.rift.coad.lib.thirdparty.ant;
026:
027: // java imports
028: import java.io.File;
029: import java.io.ByteArrayOutputStream;
030: import java.net.URL;
031:
032: // ant imports
033: import org.apache.tools.ant.Project;
034: import org.apache.tools.ant.Target;
035: import org.apache.tools.ant.taskdefs.Rmic;
036: import org.apache.tools.ant.types.Path;
037:
038: // coadunation import
039: import com.rift.coad.BaseClassLoader;
040:
041: /**
042: * The RMI generator wrapps the ANT rmi task.
043: *
044: * @author Brett Chaldecott
045: */
046: public class RMIC extends Rmic {
047:
048: /**
049: * Creates a new instance of RMIC
050: *
051: * @param base The base path to the file.
052: * @param className The name of the class.
053: * @param dest The destination of the compiled file.
054: */
055: public RMIC(File[] base, String className, File dest) {
056: project = new Project();
057: project.init();
058: taskType = "rmic";
059: taskName = "rmic";
060: target = new Target();
061: Path path = new Path(project);
062: for (int index = 0; index < base.length; index++) {
063: path.add(new Path(project, base[index].getAbsolutePath()));
064: }
065: if (this .getClass().getClassLoader() instanceof BaseClassLoader) {
066: BaseClassLoader baseClassLoader = (BaseClassLoader) this
067: .getClass().getClassLoader();
068: URL urls[] = baseClassLoader.getURLs();
069: for (int index = 0; index < urls.length; index++) {
070: path.add(new Path(project, urls[index].getFile()));
071: }
072: }
073:
074: this .setProject(project);
075: this .setClasspath(path);
076: this .setClassname(className);
077: this .setBase(dest);
078: this .setIiop(true);
079: this .setIiopopts("-poa");
080: }
081:
082: /**
083: * Creates a new instance of RMIC
084: *
085: * @param base The base path to the file.
086: * @param source The source for the files
087: * @param includes The includes to compile.
088: * @param dest The destination
089: */
090: public RMIC(File[] base, File source, String includes, File dest) {
091: project = new Project();
092: project.init();
093: taskType = "rmic";
094: taskName = "rmic";
095: target = new Target();
096: Path path = new Path(project);
097: for (int index = 0; index < base.length; index++) {
098: path.add(new Path(project, base[index].getAbsolutePath()));
099: }
100: if (this .getClass().getClassLoader() instanceof BaseClassLoader) {
101: BaseClassLoader baseClassLoader = (BaseClassLoader) this
102: .getClass().getClassLoader();
103: URL urls[] = baseClassLoader.getURLs();
104: for (int index = 0; index < urls.length; index++) {
105: path.add(new Path(project, urls[index].getFile()));
106: }
107: }
108:
109: this .setProject(project);
110: this .setClasspath(path);
111: this .setSourceBase(source);
112: this .setIncludes(includes);
113: this .setBase(dest);
114: this .setIiop(true);
115: this .setIiopopts("-poa");
116: }
117:
118: /**
119: * This method executes the rmi parser.
120: *
121: * @exception AntException
122: */
123: public void parse() throws AntException {
124: AntListener listener = new AntListener();
125: project.addBuildListener(listener);
126: try {
127: execute();
128: } catch (Exception ex) {
129: throw new AntException("Failed to parse the file : "
130: + ex.getMessage() + " [" + listener.getMessage()
131: + "]", ex);
132: }
133: }
134: }
|