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: Generator.java 5590 2004-10-11 13:16:15Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ws.wsgen.generator;
025:
026: import java.io.File;
027: import java.util.Enumeration;
028: import java.util.Vector;
029:
030: import org.objectweb.common.Cmd;
031:
032: import org.objectweb.jonas_lib.I18n;
033: import org.objectweb.jonas_lib.genbase.GenBaseException;
034: import org.objectweb.jonas_lib.genbase.generator.AbsGenerator;
035: import org.objectweb.jonas_lib.genbase.generator.Config;
036:
037: import org.objectweb.jonas_ws.wsgen.WsGenException;
038:
039: import org.objectweb.util.monolog.api.BasicLevel;
040:
041: /**
042: * Generators provide a structure to be extended for specific generation
043: * mecanisms. Axis will provide an AxisWsClientGenerator that will be in charge
044: * of client side generation (WSDL2Java tool) and an AxisWsEndpointGenerator
045: * that will bother with server side artifact generation.
046: *
047: * @author Guillaume Sauthier
048: */
049: public abstract class Generator extends AbsGenerator {
050:
051: /**
052: * i18n
053: */
054: private static I18n i18n = I18n.getInstance(Generator.class);
055:
056: /**
057: * Creates a new Generator with the given Config.
058: *
059: * @param config internal configuration object.
060: *
061: * @throws GenBaseException When sources and target temporary directory cannot
062: * be created
063: */
064: public Generator(Config config) throws GenBaseException {
065: super (config);
066: }
067:
068: /**
069: * Generate files.
070: *
071: * @throws WsGenException When generation fails.
072: */
073: public abstract void generate() throws WsGenException;
074:
075: /**
076: * Compile generated java files into classes directory.
077: *
078: * @throws WsGenException When compilation fails
079: */
080: public void compile() throws WsGenException {
081: try {
082: // get all java files contained in the sources dir
083: Vector srcs = new Vector();
084: addJavaSources(getSources(), srcs);
085:
086: Cmd cmd = new Cmd(getConfig().getJavaHomeBin()
087: + getConfig().getNameJavac());
088: cmd.addArgument("-classpath");
089: cmd.addArgument(getConfig().getClasspath());
090: cmd.addArgument("-d");
091: cmd.addArgument(getClasses().getCanonicalPath());
092: cmd.addArguments(getConfig().getJavacOpts());
093:
094: if (srcs.size() != 0) {
095: for (Enumeration e = srcs.elements(); e
096: .hasMoreElements();) {
097: String srcName = ((File) e.nextElement())
098: .getCanonicalPath();
099: cmd.addArgument(srcName);
100: }
101:
102: getLogger().log(BasicLevel.DEBUG,
103: "Running '" + cmd.toString() + "'");
104: if (cmd.run()) {
105: getLogger()
106: .log(BasicLevel.INFO,
107: "WebServices Classes successfully compiled.");
108: } else {
109: String err = getI18n().getMessage(
110: "Generator.compile.error");
111: getLogger().log(BasicLevel.ERROR, err);
112: throw new WsGenException(err);
113: }
114: }
115: } catch (Exception e) {
116: String err = getI18n()
117: .getMessage("Generator.compile.error");
118: getLogger().log(BasicLevel.ERROR, err);
119: throw new WsGenException(err, e);
120: }
121: }
122:
123: /**
124: * @return the i18n.
125: */
126: protected static I18n getI18n() {
127: return i18n;
128: }
129: }
|