Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2000 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author: sgarg $'
7
 *     '$Date: 2004-09-02 14:38:51 -0700 (Thu, 02 Sep 2004) $'
8
 * '$Revision: 2264 $'
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 */
24

    
25
package edu.ucsb.nceas.metacat.client;
26

    
27
import java.io.Reader;
28
import java.io.IOException;
29
import java.io.File;
30
import java.io.InputStream;
31

    
32
/**
33
 *  This interface provides methods for initializing and logging in to a
34
 *  Metacat server, and then querying, reading, transforming, inserting,
35
 *  updating and deleting documents from that server.
36
 */
37
public interface Metacat
38
{
39
    /**
40
     *  Method used to log in to a metacat server. Implementations will need
41
     *  to cache a cookie value to make the session persistent.  Each time a
42
     *  call is made to one of the other methods (e.g., read), the cookie will
43
     *  need to be passed back to the metacat server along with the request.
44
     *
45
     *  @param username   the username of the user, like an LDAP DN
46
     *  @param password   the password for that user for authentication
47
     *  @return the response string from metacat in XML format
48
     *  @throws MetacatAuthException when the username/password could
49
     *                    not be authenticated
50
     */
51
    public String login(String username, String password)
52
           throws MetacatAuthException, MetacatInaccessibleException;
53

    
54
    /**
55
     *  Method used to log out a metacat server. The Metacat server will end
56
     *  the session when this call is invoked.
57
     *
58
     *  @return the response string from metacat in XML format
59
     *  @throws MetacatInaccessibleException when the metacat server can not be
60
     *                                    reached or does not respond
61
     */
62
    public String logout() throws MetacatInaccessibleException,
63
        MetacatException;
64

    
65
    /**
66
     * Read an XML document from the metacat server session, accessed by docid,
67
     * and returned as a Reader.
68
     *
69
     * @param docid the identifier of the document to be read
70
     * @return a Reader for accessing the document
71
     * @throws InsufficientKarmaException when the user has insufficent rights
72
     *                                    for the operation
73
     * @throws MetacatInaccessibleException when the metacat server can not be
74
     *                                    reached or does not respond
75
     * @throws MetacatException when the metacat server generates another error
76
     */
77
    public Reader read(String docid) throws InsufficientKarmaException,
78
        MetacatInaccessibleException, MetacatException;
79

    
80
    /**
81
     * Read inline data from the metacat server session, accessed by
82
     * inlinedataid, and returned as a Reader.
83
     *
84
     * @param inlinedataid the identifier of the document to be read
85
     * @return a Reader for accessing the document
86
     * @throws InsufficientKarmaException when the user has insufficent rights
87
     *                                    for the operation
88
     * @throws MetacatInaccessibleException when the metacat server can not be
89
     *                                    reached or does not respond
90
     * @throws MetacatException when the metacat server generates another error
91
     */
92
    public Reader readInlineData(String inlinedataid)
93
        throws InsufficientKarmaException,
94
        MetacatInaccessibleException, MetacatException;
95

    
96
    /**
97
     * Query the metacat document store with the given metacat-compatible
98
     * query document, and return the result set as a Reader.
99
     *
100
     * @param xmlQuery a Reader for accessing the XML version of the query
101
     * @return a Reader for accessing the result set
102
     */
103
    public Reader query(Reader xmlQuery) throws MetacatInaccessibleException,
104
                                                IOException;
105

    
106
    /**
107
     * Insert an XML document into the repository.
108
     *
109
     * @param docid the docid to insert the document
110
     * @param xmlDocument a Reader for accessing the XML document to be inserted
111
     * @param schema a Reader for accessing the DTD or XML Schema for
112
     *               the document
113
     * @return the metacat response message
114
     * @throws InsufficientKarmaException when the user has insufficent rights
115
     *                                    for the operation
116
     * @throws MetacatInaccessibleException when the metacat server can not be
117
     *                                    reached or does not respond
118
     * @throws MetacatException when the metacat server generates another error
119
     * @throws IOException when there is an error reading the xml document
120
     */
121
    public String insert(String docid, Reader xmlDocument, Reader schema)
122
        throws InsufficientKarmaException, MetacatException, IOException,
123
        MetacatInaccessibleException;
124

    
125
    /**
126
     * Update an XML document in the repository.
127
     *
128
     * @param docid the docid to update
129
     * @param xmlDocument a Reader for accessing the XML text to be updated
130
     * @param schema a Reader for accessing the DTD or XML Schema for
131
     *               the document
132
     * @return the metacat response message
133
     * @throws InsufficientKarmaException when the user has insufficent rights
134
     *                                    for the operation
135
     * @throws MetacatInaccessibleException when the metacat server can not be
136
     *                                    reached or does not respond
137
     * @throws MetacatException when the metacat server generates another error
138
     * @throws IOException when there is an error reading the xml document
139
     */
140
    public String update(String docid, Reader xmlDocument, Reader schema)
141
        throws InsufficientKarmaException, MetacatException, IOException,
142
        MetacatInaccessibleException;
143

    
144
    /**
145
     * Upload an XML document into the repository.
146
     *
147
     * @param docid the docid to insert the document
148
     * @param xmlDocument a Reader for accessing the document to be inserted
149
     * @return the metacat response message
150
     * @throws InsufficientKarmaException when the user has insufficent rights
151
     *                                    for the operation
152
     * @throws MetacatInaccessibleException when the metacat server can not be
153
     *                                    reached or does not respond
154
     * @throws MetacatException when the metacat server generates another error
155
     * @throws IOException when there is an error reading the xml document
156
     */
157
    public String upload(String docid, File file)
158
        throws InsufficientKarmaException, MetacatException, IOException,
159
        MetacatInaccessibleException;
160

    
161
    /**
162
     * Upload an XML document into the repository.
163
     *
164
     * @param docid the docid to insert the document
165
     * @param fileName the name of the document
166
     * @param fileData InputStream of the document that has to be inserted
167
     * @param size size of the data being sent. If more data is
168
     *             found in the InputStream, an error would be reported.
169
     * @return the metacat response message
170
     * @throws InsufficientKarmaException when the user has insufficent rights
171
     *                                    for the operation
172
     * @throws MetacatInaccessibleException when the metacat server can not be
173
     *                                    reached or does not respond
174
     * @throws MetacatException when the metacat server generates another error
175
     * @throws IOException when there is an error reading the xml document
176
     */
177
    public String upload(String docid, String fileName,
178
                         InputStream fileData, int size)
179
        throws InsufficientKarmaException, MetacatException, IOException,
180
        MetacatInaccessibleException;
181

    
182
    /**
183
     * Delete an XML document in the repository.
184
     *
185
     * @param docid the docid to delete
186
     * @return the metacat response message
187
     * @throws InsufficientKarmaException when the user has insufficent rights
188
     *                                    for the operation
189
     * @throws MetacatInaccessibleException when the metacat server can not be
190
     *                                    reached or does not respond
191
     * @throws MetacatException when the metacat server generates another error
192
     */
193
    public String delete(String docid)
194
        throws InsufficientKarmaException, MetacatException,
195
        MetacatInaccessibleException;
196

    
197
    /**
198
     * When the MetacatFactory creates an instance it needs to set the
199
     * MetacatUrl to which connections should be made.
200
     *
201
     * @param metacatUrl the URL for the metacat server
202
     */
203
    public void setMetacatUrl(String metacatUrl);
204

    
205
    /**
206
     * Get the session identifier for this session.
207
     *
208
     * @returns the sessionId as a String, or null if the session is invalid
209
     */
210
    public String getSessionId();
211

    
212
    /**
213
     * Set the session identifier for this session.  This identifier was
214
     * previously established with a call to login.  To continue to use the
215
     * same session, set the session id before making a call to one of the
216
     * metacat access methods (e.g., read, query, insert, etc.).
217
     *
218
     * @param String the sessionId from a previously established session
219
     */
220
    public void setSessionId(String sessionId);
221
}
(2-2/7)