source: SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUAbstractResult.java @ 2623

Last change on this file since 2623 was 2623, checked in by oschonef, 11 years ago
  • update copyright
  • fix some whitespace
  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1/**
2 * This software is copyright (c) 2011-2013 by
3 *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
4 * This is free software. You can redistribute it
5 * and/or modify it under the terms described in
6 * the GNU General Public License v3 of which you
7 * should have received a copy. Otherwise you can download
8 * it from
9 *
10 *   http://www.gnu.org/licenses/gpl-3.0.txt
11 *
12 * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
13 *
14 * @license http://www.gnu.org/licenses/gpl-3.0.txt
15 *  GNU General Public License v3
16 */
17package eu.clarin.sru.server;
18
19import javax.xml.stream.XMLStreamException;
20import javax.xml.stream.XMLStreamWriter;
21
22
23/**
24 * Base class for SRU responses.
25 */
26abstract class SRUAbstractResult {
27    private final SRUDiagnosticList diagnostics;
28
29
30    SRUAbstractResult(SRUDiagnosticList diagnosticList) {
31        if (diagnosticList == null) {
32            throw new NullPointerException("Implementation error: "
33                    + "diagnosticList must not be null!");
34        }
35        this.diagnostics = diagnosticList;
36    }
37
38
39    /**
40     * Add a non surrogate diagnostic to the response.
41     *
42     * @param code
43     *            numerical diagnostic code
44     * @param details
45     *            supplementary information available, often in a format
46     *            specified by the diagnostic or <code>null</code>
47     * @param message
48     *            human readable message to display to the end user or
49     *            <code>null</code>
50     */
51    protected final void addDiagnostic(int code, String details, String message) {
52        diagnostics.addDiagnostic(code, details, message);
53    }
54
55
56    /**
57     * Add a non surrogate diagnostic to the response.
58     *
59     * @param code
60     *            numerical diagnostic code
61     * @param details
62     *            supplementary information available, often in a format
63     *            specified by the diagnostic or <code>null</code>
64     */
65    protected final void addDiagnostic(int code, String details) {
66        addDiagnostic(code, details, null);
67    }
68
69
70    /**
71     * Add a non surrogate diagnostic to the response.
72     *
73     * @param code
74     *            numerical diagnostic code
75     */
76    protected final void addDiagnostic(int code) {
77        addDiagnostic(code, null, null);
78    }
79
80
81    /**
82     * Check, if extra response data should be serialized for this request.
83     * Default implementation is provided for convince and always returns
84     * <code>false</code>.
85     *
86     * @return <code>true</code> if extra response data should be serialized.
87     * @see #writeExtraResponseData(XMLStreamWriter)
88     */
89    public boolean hasExtraResponseData() {
90        return false;
91    }
92
93
94    /**
95     * Serialize extra response data for this request.
96     *
97     * @param writer
98     *            the {@link XMLStreamException} instance to be used
99     * @throws XMLStreamException
100     *             an error occurred while serializing the result
101     * @see #hasExtraResponseData()
102     */
103    public void writeExtraResponseData(XMLStreamWriter writer)
104            throws XMLStreamException {
105    }
106
107
108    /**
109     * Release this result and free any associated resources.
110     * <p>
111     * This method <strong>must not</strong> throw any exceptions
112     * </p>
113     * <p>
114     * Calling the method <code>close</code> on a result object that is already
115     * closed is a no-op.
116     * </p>
117     */
118    public void close() {
119    }
120
121} // abstract class SRUAbstractResult
Note: See TracBrowser for help on using the repository browser.