001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.tools.xjc;
038:
039: import java.io.PrintStream;
040:
041: import com.sun.tools.xjc.api.ErrorListener;
042: import com.sun.tools.xjc.outline.Outline;
043:
044: /**
045: * Call-back interface that can be implemented by the caller of {@link Driver}
046: * to receive output from XJC.
047: *
048: * <p>
049: * Most of the messages XJC produce once the real work starts is structured
050: * as (message,source). Those outputs will be reported to various methods on
051: * {@link ErrorListener}, which is inherited by this interface.
052: *
053: * <p>
054: * The other messages (such as the usage screen when there was an error in
055: * the command line option) will go to the {@link #message(String)} method.
056: *
057: * @author Kohsuke Kawaguchi
058: * @since JAXB 2.0 EA
059: */
060: public abstract class XJCListener implements ErrorListener {
061:
062: /**
063: * @deprecated
064: * Override {@link #generatedFile(String, int, int)}.
065: * Deprecated in 2.0.1.
066: */
067: public void generatedFile(String fileName) {
068: }
069:
070: /**
071: * Called for each file generated by XJC.
072: *
073: * <p>
074: * XJC may generate not only source files but also resources files.
075: * The file name includes the path portions that correspond with the package name.
076: *
077: * <p>
078: * When generating files into a directory, file names will be relative to the
079: * output directory. When generating files into a zip file, file names will be
080: * those in the zip file.
081: *
082: * @param fileName
083: * file names like "org/acme/foo/Foo.java" or "org/acme/foo/jaxb.properties".
084: *
085: * @since 2.0.1
086: */
087: public void generatedFile(String fileName, int current, int total) {
088: generatedFile(fileName); // backward compatibility
089: }
090:
091: /**
092: * Other miscellenous messages that do not have structures
093: * will be reported through this method.
094: *
095: * This method is used like {@link PrintStream#println(String)}.
096: * The callee is expected to add '\n'.
097: */
098: public void message(String msg) {
099: }
100:
101: /**
102: * Called after the schema is compiled and the code generation strategy is determined,
103: * but before any code is actually generated as files.
104: *
105: * @param outline
106: * never null. this is the root object that represents the code generation strategy.
107: */
108: public void compiled(Outline outline) {
109: }
110:
111: /**
112: * XJC will periodically invoke this method to see if it should cancel a compilation.
113: *
114: * <p>
115: * As long as this method returns false, XJC will keep going. If this method ever returns
116: * true, XJC will abort the processing right away and
117: * returns non-zero from {@link Driver#run(String[], XJCListener)}.
118: * Note that XJC will not report an abortion through the {@link #message(String)} method.
119: *
120: * <p>
121: * Note that despite all the efforts to check this method frequently, XJC may still fail to
122: * invoke this method for a long time. Such scenario would include network related problems
123: * or other I/O block (you can't even interrupt the thread while I/O is blocking.)
124: * So just beware that this is not a cure-all.
125: *
126: * @return
127: * true if the {@link XJCListener} wants to abort the processing.
128: * @since 2.1
129: */
130: public boolean isCanceled() {
131: return false;
132: }
133: }
|