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-08-19 11:34:46 -0700 (Thu, 19 Aug 2004) $'
8
 * '$Revision: 2240 $'
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

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

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

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

    
79
    /**
80
     * Query the metacat document store with the given metacat-compatible
81
     * query document, and return the result set as a Reader.
82
     *
83
     * @param xmlQuery a Reader for accessing the XML version of the query
84
     * @return a Reader for accessing the result set
85
     */
86
    public Reader query(Reader xmlQuery) throws MetacatInaccessibleException,
87
                                                IOException;
88

    
89
    /**
90
     * Insert an XML document into the repository.
91
     *
92
     * @param docid the docid to insert the document
93
     * @param xmlDocument a Reader for accessing the XML document to be inserted
94
     * @param schema a Reader for accessing the DTD or XML Schema for
95
     *               the document
96
     * @return the metacat response message
97
     * @throws InsufficientKarmaException when the user has insufficent rights
98
     *                                    for the operation
99
     * @throws MetacatInaccessibleException when the metacat server can not be
100
     *                                    reached or does not respond
101
     * @throws MetacatException when the metacat server generates another error
102
     * @throws IOException when there is an error reading the xml document
103
     */
104
    public String insert(String docid, Reader xmlDocument, Reader schema)
105
        throws InsufficientKarmaException, MetacatException, IOException,
106
        MetacatInaccessibleException;
107

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

    
127
    /**
128
     * Upload an XML document into the repository.
129
     *
130
     * @param docid the docid to insert the document
131
     * @param xmlDocument a Reader for accessing the document to be inserted
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 upload(String docid, File file)
141
        throws InsufficientKarmaException, MetacatException, IOException,
142
        MetacatInaccessibleException;
143

    
144
    /**
145
     * Delete an XML document in the repository.
146
     *
147
     * @param docid the docid to delete
148
     * @return the metacat response message
149
     * @throws InsufficientKarmaException when the user has insufficent rights
150
     *                                    for the operation
151
     * @throws MetacatInaccessibleException when the metacat server can not be
152
     *                                    reached or does not respond
153
     * @throws MetacatException when the metacat server generates another error
154
     */
155
    public String delete(String docid)
156
        throws InsufficientKarmaException, MetacatException,
157
        MetacatInaccessibleException;
158

    
159
    /**
160
     * When the MetacatFactory creates an instance it needs to set the
161
     * MetacatUrl to which connections should be made.
162
     *
163
     * @param metacatUrl the URL for the metacat server
164
     */
165
    public void setMetacatUrl(String metacatUrl);
166

    
167
    /**
168
     * Get the session identifier for this session.
169
     *
170
     * @returns the sessionId as a String, or null if the session is invalid
171
     */
172
    public String getSessionId();
173

    
174
    /**
175
     * Set the session identifier for this session.  This identifier was
176
     * previously established with a call to login.  To continue to use the
177
     * same session, set the session id before making a call to one of the
178
     * metacat access methods (e.g., read, query, insert, etc.).
179
     *
180
     * @param String the sessionId from a previously established session
181
     */
182
    public void setSessionId(String sessionId);
183
}
(2-2/7)