1/*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.tools.internal.xjc;
27
28import java.io.PrintStream;
29
30import com.sun.tools.internal.xjc.api.ErrorListener;
31import com.sun.tools.internal.xjc.outline.Outline;
32
33/**
34 * Call-back interface that can be implemented by the caller of {@link Driver}
35 * to receive output from XJC.
36 *
37 * <p>
38 * Most of the messages XJC produce once the real work starts is structured
39 * as (message,source). Those outputs will be reported to various methods on
40 * {@link ErrorListener}, which is inherited by this interface.
41 *
42 * <p>
43 * The other messages (such as the usage screen when there was an error in
44 * the command line option) will go to the {@link #message(String)} method.
45 *
46 * @author Kohsuke Kawaguchi
47 * @since JAXB 2.0 EA
48 */
49public abstract class XJCListener implements ErrorListener {
50
51    /**
52     * @deprecated
53     *      Override {@link #generatedFile(String, int, int)}.
54     *      Deprecated in 2.0.1.
55     */
56    public void generatedFile(String fileName) {}
57
58    /**
59     * Called for each file generated by XJC.
60     *
61     * <p>
62     * XJC may generate not only source files but also resources files.
63     * The file name includes the path portions that correspond with the package name.
64     *
65     * <p>
66     * When generating files into a directory, file names will be relative to the
67     * output directory. When generating files into a zip file, file names will be
68     * those in the zip file.
69     *
70     * @param fileName
71     *      file names like "org/acme/foo/Foo.java" or "org/acme/foo/jaxb.properties".
72     *
73     * @since 2.0.1
74     */
75    public void generatedFile(String fileName, int current, int total ) {
76        generatedFile(fileName);    // backward compatibility
77    }
78
79    /**
80     * Other miscellenous messages that do not have structures
81     * will be reported through this method.
82     *
83     * This method is used like {@link PrintStream#println(String)}.
84     * The callee is expected to add '\n'.
85     */
86    public void message(String msg) {}
87
88    /**
89     * Called after the schema is compiled and the code generation strategy is determined,
90     * but before any code is actually generated as files.
91     *
92     * @param outline
93     *      never null. this is the root object that represents the code generation strategy.
94     */
95    public void compiled(Outline outline) {}
96
97    /**
98     * XJC will periodically invoke this method to see if it should cancel a compilation.
99     *
100     * <p>
101     * As long as this method returns false, XJC will keep going. If this method ever returns
102     * true, XJC will abort the processing right away and
103     * returns non-zero from {@link Driver#run(String[], XJCListener)}.
104     * Note that XJC will not report an abortion through the {@link #message(String)} method.
105     *
106     * <p>
107     * Note that despite all the efforts to check this method frequently, XJC may still fail to
108     * invoke this method for a long time. Such scenario would include network related problems
109     * or other I/O block (you can't even interrupt the thread while I/O is blocking.)
110     * So just beware that this is not a cure-all.
111     *
112     * @return
113     *      true if the {@link XJCListener} wants to abort the processing.
114     * @since 2.1
115     */
116    public boolean isCanceled() {
117        return false;
118    }
119}
120