001: /*
002: * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.rmi.rmic.newrmic;
027:
028: import com.sun.javadoc.ClassDoc;
029: import com.sun.javadoc.RootDoc;
030: import java.io.File;
031: import java.text.MessageFormat;
032: import java.util.ArrayList;
033: import java.util.Collections;
034: import java.util.List;
035:
036: import static sun.rmi.rmic.newrmic.Constants.*;
037:
038: /**
039: * The environment for an rmic compilation batch.
040: *
041: * A BatchEnvironment contains a RootDoc, which is the entry point
042: * into the doclet environment for the associated rmic compilation
043: * batch. A BatchEnvironment collects the source files generated
044: * during the batch's execution, for eventual source code compilation
045: * and, possibly, deletion. Errors that occur during generation
046: * activity should be reported through the BatchEnvironment's "error"
047: * method.
048: *
049: * A protocol-specific generator class may require the use of a
050: * particular BatchEnvironment subclass for enhanced environment
051: * functionality. A BatchEnvironment subclass must declare a
052: * public constructor with one parameter of type RootDoc.
053: *
054: * WARNING: The contents of this source file are not part of any
055: * supported API. Code that depends on them does so at its own risk:
056: * they are subject to change or removal without notice.
057: *
058: * @version 1.10, 07/05/05
059: * @author Peter Jones
060: **/
061: public class BatchEnvironment {
062:
063: private final RootDoc rootDoc;
064:
065: /** cached ClassDoc for certain types used by rmic */
066: private final ClassDoc docRemote;
067: private final ClassDoc docException;
068: private final ClassDoc docRemoteException;
069: private final ClassDoc docRuntimeException;
070:
071: private boolean verbose = false;
072: private final List<File> generatedFiles = new ArrayList<File>();
073:
074: /**
075: * Creates a new BatchEnvironment with the specified RootDoc.
076: **/
077: public BatchEnvironment(RootDoc rootDoc) {
078: this .rootDoc = rootDoc;
079:
080: /*
081: * Initialize cached ClassDoc for types used by rmic. Note
082: * that any of these could be null if the boot class path is
083: * incorrect, which could cause a NullPointerException later.
084: */
085: docRemote = rootDoc().classNamed(REMOTE);
086: docException = rootDoc().classNamed(EXCEPTION);
087: docRemoteException = rootDoc().classNamed(REMOTE_EXCEPTION);
088: docRuntimeException = rootDoc().classNamed(RUNTIME_EXCEPTION);
089: }
090:
091: /**
092: * Returns the RootDoc for this environment.
093: **/
094: public RootDoc rootDoc() {
095: return rootDoc;
096: }
097:
098: public ClassDoc docRemote() {
099: return docRemote;
100: }
101:
102: public ClassDoc docException() {
103: return docException;
104: }
105:
106: public ClassDoc docRemoteException() {
107: return docRemoteException;
108: }
109:
110: public ClassDoc docRuntimeException() {
111: return docRuntimeException;
112: }
113:
114: /**
115: * Sets this environment's verbosity status.
116: **/
117: public void setVerbose(boolean verbose) {
118: this .verbose = verbose;
119: }
120:
121: /**
122: * Returns this environment's verbosity status.
123: **/
124: public boolean verbose() {
125: return verbose;
126: }
127:
128: /**
129: * Adds the specified file to the list of source files generated
130: * during this batch.
131: **/
132: public void addGeneratedFile(File file) {
133: generatedFiles.add(file);
134: }
135:
136: /**
137: * Returns the list of files generated during this batch.
138: **/
139: public List<File> generatedFiles() {
140: return Collections.unmodifiableList(generatedFiles);
141: }
142:
143: /**
144: * Outputs the specified (non-error) message.
145: **/
146: public void output(String msg) {
147: rootDoc.printNotice(msg);
148: }
149:
150: /**
151: * Reports an error using the specified resource key and text
152: * formatting arguments.
153: **/
154: public void error(String key, String... args) {
155: rootDoc.printError(Resources.getText(key, args));
156: }
157: }
|