blob: 584e21ba03e6b61416caf304e0df4229b54af7aa [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.rmi.rmic.newrmic;
27
28import com.sun.javadoc.ClassDoc;
29import com.sun.javadoc.RootDoc;
30import java.io.File;
31import java.text.MessageFormat;
32import java.util.ArrayList;
33import java.util.Collections;
34import java.util.List;
35
36import static sun.rmi.rmic.newrmic.Constants.*;
37
38/**
39 * The environment for an rmic compilation batch.
40 *
41 * A BatchEnvironment contains a RootDoc, which is the entry point
42 * into the doclet environment for the associated rmic compilation
43 * batch. A BatchEnvironment collects the source files generated
44 * during the batch's execution, for eventual source code compilation
45 * and, possibly, deletion. Errors that occur during generation
46 * activity should be reported through the BatchEnvironment's "error"
47 * method.
48 *
49 * A protocol-specific generator class may require the use of a
50 * particular BatchEnvironment subclass for enhanced environment
51 * functionality. A BatchEnvironment subclass must declare a
52 * public constructor with one parameter of type RootDoc.
53 *
54 * WARNING: The contents of this source file are not part of any
55 * supported API. Code that depends on them does so at its own risk:
56 * they are subject to change or removal without notice.
57 *
58 * @author Peter Jones
59 **/
60public class BatchEnvironment {
61
62 private final RootDoc rootDoc;
63
64 /** cached ClassDoc for certain types used by rmic */
65 private final ClassDoc docRemote;
66 private final ClassDoc docException;
67 private final ClassDoc docRemoteException;
68 private final ClassDoc docRuntimeException;
69
70 private boolean verbose = false;
71 private final List<File> generatedFiles = new ArrayList<File>();
72
73 /**
74 * Creates a new BatchEnvironment with the specified RootDoc.
75 **/
76 public BatchEnvironment(RootDoc rootDoc) {
77 this.rootDoc = rootDoc;
78
79 /*
80 * Initialize cached ClassDoc for types used by rmic. Note
81 * that any of these could be null if the boot class path is
82 * incorrect, which could cause a NullPointerException later.
83 */
84 docRemote = rootDoc().classNamed(REMOTE);
85 docException = rootDoc().classNamed(EXCEPTION);
86 docRemoteException = rootDoc().classNamed(REMOTE_EXCEPTION);
87 docRuntimeException = rootDoc().classNamed(RUNTIME_EXCEPTION);
88 }
89
90 /**
91 * Returns the RootDoc for this environment.
92 **/
93 public RootDoc rootDoc() {
94 return rootDoc;
95 }
96
97 public ClassDoc docRemote() { return docRemote; }
98 public ClassDoc docException() { return docException; }
99 public ClassDoc docRemoteException() { return docRemoteException; }
100 public ClassDoc docRuntimeException() { return docRuntimeException; }
101
102 /**
103 * Sets this environment's verbosity status.
104 **/
105 public void setVerbose(boolean verbose) {
106 this.verbose = verbose;
107 }
108
109 /**
110 * Returns this environment's verbosity status.
111 **/
112 public boolean verbose() {
113 return verbose;
114 }
115
116 /**
117 * Adds the specified file to the list of source files generated
118 * during this batch.
119 **/
120 public void addGeneratedFile(File file) {
121 generatedFiles.add(file);
122 }
123
124 /**
125 * Returns the list of files generated during this batch.
126 **/
127 public List<File> generatedFiles() {
128 return Collections.unmodifiableList(generatedFiles);
129 }
130
131 /**
132 * Outputs the specified (non-error) message.
133 **/
134 public void output(String msg) {
135 rootDoc.printNotice(msg);
136 }
137
138 /**
139 * Reports an error using the specified resource key and text
140 * formatting arguments.
141 **/
142 public void error(String key, String... args) {
143 rootDoc.printError(Resources.getText(key, args));
144 }
145}