KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > thirdparty > ant > RMIC


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * RMIC.java
20  *
21  * The RMI generator wrapps the ANT rmi task.
22  */

23
24 // package path
25
package com.rift.coad.lib.thirdparty.ant;
26
27 // java imports
28
import java.io.File JavaDoc;
29 import java.io.ByteArrayOutputStream JavaDoc;
30 import java.net.URL JavaDoc;
31
32 // ant imports
33
import org.apache.tools.ant.Project;
34 import org.apache.tools.ant.Target;
35 import org.apache.tools.ant.taskdefs.Rmic;
36 import org.apache.tools.ant.types.Path;
37
38 // coadunation import
39
import com.rift.coad.BaseClassLoader;
40
41 /**
42  * The RMI generator wrapps the ANT rmi task.
43  *
44  * @author Brett Chaldecott
45  */

46 public class RMIC extends Rmic {
47     
48     /**
49      * Creates a new instance of RMIC
50      *
51      * @param base The base path to the file.
52      * @param className The name of the class.
53      * @param dest The destination of the compiled file.
54      */

55     public RMIC(File JavaDoc[] base, String JavaDoc className, File JavaDoc dest) {
56         project = new Project();
57         project.init();
58         taskType = "rmic";
59         taskName = "rmic";
60         target = new Target();
61         Path path = new Path(project);
62         for (int index = 0; index < base.length; index++) {
63             path.add(new Path(project,base[index].getAbsolutePath()));
64         }
65         if (this.getClass().getClassLoader() instanceof BaseClassLoader) {
66             BaseClassLoader baseClassLoader =
67                     (BaseClassLoader)this.getClass().getClassLoader();
68             URL JavaDoc urls[] = baseClassLoader.getURLs();
69             for (int index = 0; index < urls.length; index++) {
70                 path.add(new Path(project,urls[index].getFile()));
71             }
72         }
73         
74         
75         this.setProject(project);
76         this.setClasspath(path);
77         this.setClassname(className);
78         this.setBase(dest);
79         this.setIiop(true);
80         this.setIiopopts("-poa");
81     }
82     
83     
84     /**
85      * Creates a new instance of RMIC
86      *
87      * @param base The base path to the file.
88      * @param source The source for the files
89      * @param includes The includes to compile.
90      * @param dest The destination
91      */

92     public RMIC(File JavaDoc[] base, File JavaDoc source, String JavaDoc includes, File JavaDoc dest) {
93         project = new Project();
94         project.init();
95         taskType = "rmic";
96         taskName = "rmic";
97         target = new Target();
98         Path path = new Path(project);
99         for (int index = 0; index < base.length; index++) {
100             path.add(new Path(project,base[index].getAbsolutePath()));
101         }
102         if (this.getClass().getClassLoader() instanceof BaseClassLoader) {
103             BaseClassLoader baseClassLoader =
104                     (BaseClassLoader)this.getClass().getClassLoader();
105             URL JavaDoc urls[] = baseClassLoader.getURLs();
106             for (int index = 0; index < urls.length; index++) {
107                 path.add(new Path(project,urls[index].getFile()));
108             }
109         }
110         
111         
112         this.setProject(project);
113         this.setClasspath(path);
114         this.setSourceBase(source);
115         this.setIncludes(includes);
116         this.setBase(dest);
117         this.setIiop(true);
118         this.setIiopopts("-poa");
119     }
120     
121     
122     /**
123      * This method executes the rmi parser.
124      *
125      * @exception AntException
126      */

127     public void parse() throws AntException {
128         AntListener listener = new AntListener();
129         project.addBuildListener(listener);
130         try {
131             execute();
132         } catch (Exception JavaDoc ex) {
133             throw new AntException("Failed to parse the file : "
134                     + ex.getMessage() + " [" +
135                     listener.getMessage() + "]",ex);
136         }
137     }
138 }
139
Popular Tags