001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2003-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.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: Config.java 7478 2005-10-07 11:54:55Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_lib.genbase.generator;
025:
026: import java.io.File;
027: import java.net.URL;
028: import java.net.URLClassLoader;
029: import java.util.Vector;
030: import org.objectweb.common.Env;
031: import org.objectweb.jonas.server.JClassLoader;
032:
033: /**
034: * Configuration object storing generation params.
035: */
036: public class Config {
037:
038: /** packed mode */
039: public static final int PACKED = 0;
040:
041: /** unpacked mode */
042: public static final int UNPACKED = 1;
043:
044: /** Java executable name */
045: private String nameJava = "java";
046:
047: /** Javac executable name */
048: private String nameJavac = "javac";
049:
050: /**
051: * Rmic executable name
052: */
053: private String nameRmic = "rmic";
054:
055: /** Javac options */
056: private Vector javacOpts = new Vector();
057:
058: /** Bin directory for JDK */
059: private String javaHomeBin = null;
060:
061: /** no config needed */
062: private boolean noConfig = false;
063:
064: /** verbose mode */
065: private boolean verbose = false;
066:
067: /** debug mode */
068: private boolean debug = false;
069:
070: /** classpath */
071: private String classpath = ".";
072:
073: /** output directory */
074: private File out = new File(".");
075:
076: /** keep alrady generated files */
077: private boolean keepGenerated = false;
078:
079: /** validating parser ? */
080: private boolean parseWithValidation = true;
081:
082: /** configuration error */
083: private boolean error = false;
084:
085: /** file input name */
086: private String inputname;
087:
088: /** help requested ? */
089: private boolean help = false;
090:
091: /** save mode (PACKED/UNPACKED) */
092: private int saveMode = PACKED;
093:
094: /**
095: * DTDs use is allowed
096: */
097: private boolean dtdsAllowed = false;
098:
099: /**
100: * Creates a new Config. Automatically setup javaHomeBin property. And
101: * create classpath from classloader.
102: */
103: public Config() {
104: // Setup java_home/bin directory
105: setJavaHomeBin(System.getProperty("java.home", ""));
106:
107: if (!("".equals(getJavaHomeBin()))) {
108: if (Env.isOsMacOsX()) {
109: setJavaHomeBin(getJavaHomeBin() + File.separator
110: + "bin" + File.separator);
111: } else {
112: // JRE Directory !
113: setJavaHomeBin(getJavaHomeBin() + File.separator + ".."
114: + File.separator + "bin" + File.separator);
115: }
116: }
117:
118: // classpath
119: URLClassLoader ucl = (URLClassLoader) (Thread.currentThread()
120: .getContextClassLoader());
121: boolean inClientContainer = false;
122: try {
123: ucl.loadClass("org.objectweb.jonas.server.Bootstrap");
124: } catch (ClassNotFoundException cnfe) {
125: // client side
126: inClientContainer = true;
127: }
128:
129: // if we're on the client side, we have no JClassLoader in the TCCL
130: // so we must use URLs of the UCL
131: if (inClientContainer) {
132: setClasspath(extractURLs(ucl));
133: } else {
134: setClasspath(((JClassLoader) ucl).getClassPath());
135: }
136: }
137:
138: /**
139: * @param ucl the ClassLoader to search in
140: * @return Returns the classpath representation of that ClassLoader
141: */
142: private String extractURLs(URLClassLoader ucl) {
143: URL[] urls = ucl.getURLs();
144: // for each URL
145: StringBuffer sb = new StringBuffer();
146: boolean first = true;
147: for (int i = 0; i < urls.length; i++) {
148: String file = urls[i].getFile();
149: if (!"".equals(file)) {
150: if (first) {
151: sb.append(file);
152: first = false;
153: } else {
154: sb.append(File.pathSeparator + file);
155: }
156: }
157: }
158: return sb.toString();
159: }
160:
161: /**
162: * @param nameJavac Set javac command name to use
163: */
164: public void setNameJavac(String nameJavac) {
165: this .nameJavac = nameJavac;
166: }
167:
168: /**
169: * @return Returns the javac command name to use
170: */
171: public String getNameJavac() {
172: return nameJavac;
173: }
174:
175: /**
176: * @param javacOpts Set javac Opts
177: */
178: public void setJavacOpts(Vector javacOpts) {
179: this .javacOpts = javacOpts;
180: }
181:
182: /**
183: * @return Returns the Javac Opts to use
184: */
185: public Vector getJavacOpts() {
186: return javacOpts;
187: }
188:
189: /**
190: * @param javaHomeBin JAVA_HOME/bin directory
191: */
192: public void setJavaHomeBin(String javaHomeBin) {
193: this .javaHomeBin = javaHomeBin;
194: }
195:
196: /**
197: * @return Returns the JAVA_HOME/bin directory
198: */
199: public String getJavaHomeBin() {
200: return javaHomeBin;
201: }
202:
203: /**
204: * @param noConfig Generate Configuration ?
205: */
206: public void setNoConfig(boolean noConfig) {
207: this .noConfig = noConfig;
208: }
209:
210: /**
211: * @return Returns noConfig option
212: */
213: public boolean isNoConfig() {
214: return noConfig;
215: }
216:
217: /**
218: * @param verbose Verbose ?
219: */
220: public void setVerbose(boolean verbose) {
221: this .verbose = verbose;
222: }
223:
224: /**
225: * @return Returns verbose option
226: */
227: public boolean isVerbose() {
228: return verbose;
229: }
230:
231: /**
232: * @param debug Debug ?
233: */
234: public void setDebug(boolean debug) {
235: this .debug = debug;
236: }
237:
238: /**
239: * @return Returns debug option
240: */
241: public boolean isDebug() {
242: return debug;
243: }
244:
245: /**
246: * @param classpath Classpath to use with java commands
247: */
248: public void setClasspath(String classpath) {
249: this .classpath = classpath;
250: }
251:
252: /**
253: * @return Retruns Classpath
254: */
255: public String getClasspath() {
256: return classpath;
257: }
258:
259: /**
260: * @param out Output directory
261: */
262: public void setOut(File out) {
263: this .out = out;
264: }
265:
266: /**
267: * @return Returns Ouput directory
268: */
269: public File getOut() {
270: return out;
271: }
272:
273: /**
274: * @param keepGenerated Kepp Generated files ?
275: */
276: public void setKeepGenerated(boolean keepGenerated) {
277: this .keepGenerated = keepGenerated;
278: }
279:
280: /**
281: * @return Returns keepGenerated option
282: */
283: public boolean isKeepGenerated() {
284: return keepGenerated;
285: }
286:
287: /**
288: * @param parseWithValidation Parse XML desc with validation ?
289: */
290: public void setParseWithValidation(boolean parseWithValidation) {
291: this .parseWithValidation = parseWithValidation;
292: }
293:
294: /**
295: * @return Returns validation
296: */
297: public boolean isParseWithValidation() {
298: return parseWithValidation;
299: }
300:
301: /**
302: * @param error Error Mode ?
303: */
304: public void setError(boolean error) {
305: this .error = error;
306: }
307:
308: /**
309: * @return Returns true if there is Configuration errors
310: */
311: public boolean isError() {
312: return error;
313: }
314:
315: /**
316: * @param inputname File inputname
317: */
318: public void setInputname(String inputname) {
319: this .inputname = inputname;
320: }
321:
322: /**
323: * @return Returns file input name
324: */
325: public String getInputname() {
326: return inputname;
327: }
328:
329: /**
330: * @param help Help Mode ?
331: */
332: public void setHelp(boolean help) {
333: this .help = help;
334: }
335:
336: /**
337: * @return Returns Help option.
338: */
339: public boolean isHelp() {
340: return help;
341: }
342:
343: /**
344: * Set Packed Mode for storing.
345: */
346: public void setSavePacked() {
347: this .saveMode = PACKED;
348: }
349:
350: /**
351: * Set UnPacked Mode for storing.
352: */
353: public void setSaveUnpacked() {
354: this .saveMode = UNPACKED;
355: }
356:
357: /**
358: * @return Returns Save mode
359: */
360: public int getSaveMode() {
361: return saveMode;
362: }
363:
364: /**
365: * @return Returns the nameRmic.
366: */
367: public String getNameRmic() {
368: return nameRmic;
369: }
370:
371: /**
372: * @param nameRmic The nameRmic to set.
373: */
374: public void setNameRmic(String nameRmic) {
375: this .nameRmic = nameRmic;
376: }
377:
378: /**
379: * @return the java command
380: */
381: public String getNameJava() {
382: return nameJava;
383: }
384:
385: /**
386: * @return true if the use of DTDs is allowed.
387: */
388: public boolean isDTDsAllowed() {
389: return dtdsAllowed;
390: }
391:
392: /**
393: * Use of DTDs
394: * @param dTDsAllowed The dtdsAllowed to set.
395: */
396: public void setDTDsAllowed(boolean dTDsAllowed) {
397: this.dtdsAllowed = dTDsAllowed;
398: }
399: }
|