source: trunk/java-client/org/nzdl/gsdl/service/NzdlServiceClient.java@ 2316

Last change on this file since 2316 was 2284, checked in by say1, 23 years ago

Cross collection searching

  • Property svn:keywords set to Author Date Id Revision
File size: 13.3 KB
Line 
1/*
2 * NzdlServiceClient.java
3 * Copyright (C) 2001 New Zealand Digital Library Project
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20//the package we're in
21package org.nzdl.gsdl.service;
22
23//import java.io.*;
24//import java.util.*;
25import java.util.Map;
26import java.util.Set;
27import java.util.List;
28import java.util.HashSet;
29import java.util.Properties;
30
31/* jdk 1.3 orb */
32import org.omg.CORBA.ORB;
33/* gsdl corba stuff */
34import org.nzdl.gsdl.corba.gsdlInterface.*;
35import org.nzdl.gsdl.util.*;
36
37/**
38 * Used to implement the {@link NzdlService NzdlService} object.
39 * NzdlService is an object that services CORBA client requests to a
40 * Greenstone Digital Library.
41 *
42 * @author Stuart Yeates ([email protected])
43 * @author Aziz Mahoui ([email protected])
44 * @author Gordon Paynter ([email protected])
45 * @author Brett Sheeran ([email protected]) (comments)
46 * @version $Revision: 2284 $
47 */
48public class NzdlServiceClient
49 extends java.lang.Object
50 implements NzdlService {
51
52 private corbaiface m_nzdlServer = null;
53
54 /**
55 * Creates an instance of Java's ORB (Object Request Broker) to interface
56 * to a Greenstone Digital Library.
57 * @param <b>args</b> command-line arguments from the application's main method, or
58 * alternatively, the name of the applet. This parameter is passed to
59 * <TT>ORB.init( _args, _props)</TT>. Args may be a <TT>null</TT>.
60 * @param <b>props</b> application specific properties.
61 * This parameter is passed to
62 * <TT>ORB.init( _args, _props)</TT>. props may be a <TT>null</TT>.
63 * @param <b>IOR</b> the Interoperable Object Reference, a string that identifies
64 * the computer on which corbaserver is running and the interface it
65 * supports.
66 * @see The Java documentation on the ORB class.
67 */
68 public NzdlServiceClient( String [] _args, Properties _props, String _IOR) {
69 corbaComErrorHolder error = NzdlCorbaFactory.createComErrorHolder();
70
71 try {
72
73 // getting a reference to the remote NZDL server
74 org.omg.CORBA.ORB orb = ORB.init( _args, _props);
75 org.omg.CORBA.Object obj = orb.string_to_object(_IOR) ;
76 m_nzdlServer = corbaifaceHelper.narrow(obj);
77
78 // basic setup
79 if (m_nzdlServer.initialise(error)) {
80 } else {
81 throw new Error("NzdlServiceClient initialisation unsuccessful.");
82 }
83
84 } catch (Exception e) {
85 System.err.println("Exception in NzdlServiceClient initialisation: \n" + e) ;
86 System.err.println("corbaComError value: " + error.value.value());
87 System.err.println("NzdlServiceClient initialisation unsuccessful.");
88 throw new Error("NzdlServiceClient initialisation unsuccessful.");
89 }
90 if (error.value.value() != corbaComError._corbaNoError) {
91 System.err.println("corbaComError value: " + error.value.value());
92 }
93
94 System.out.println("NzdlServiceClient initialisation successful.");
95 }
96
97
98 /**
99 * Allow the client to configure a CORBA server.
100 * @param key the parameter to be set.
101 * @param values what that parameter will be set to.
102 */
103 public void configure( String _key, Set _values ) {
104 if (_key == null || _key.equals("")){
105 throw new Error ("null or empty collection _key");
106 }
107 if (_values == null ){
108 throw new Error ("null or empty collection _values");
109 }
110 corbaComErrorHolder error = NzdlCorbaFactory.createComErrorHolder();
111 m_nzdlServer.configure( NzdlCorbaFactory.toCorbaText( _key ),
112 NzdlCorbaFactory.toCorbaTextArray( _values ),
113 error);
114 if (error.value.value() != corbaComError._corbaNoError) {
115 System.err.println("CORBA error:" + error.value.value());
116 }
117 }
118
119 /**
120 * Obtain the set of collection names for a Greenstone library.
121 * @return A set of collection names in string format.
122 */
123 public Set getCollectionSet( ) {
124 System.err.println("Client::getCollectionSet() start");
125 corbaComErrorHolder error = NzdlCorbaFactory.createComErrorHolder();
126 corbatext_tarrayHolder c_collSet = NzdlCorbaFactory.createCorbaTextArrayHolder();
127 m_nzdlServer.collectionList(c_collSet, error);
128 Set collSet = new HashSet();
129 for (int i=0; i<c_collSet.value.length; i++) {
130 String collName = NzdlCorbaFactory.toString( c_collSet.value[i] );
131 if (collName.indexOf("nuipepa") == -1)
132 collSet.add(collName);
133 }
134 if (error.value.value() != corbaComError._corbaNoError) {
135 System.err.println("CORBA error:" + error.value.value());
136 }
137 System.err.println("Client::getCollectionSet() end " + error.value.value());
138 return collSet ;
139 }
140
141 /**
142 * Check if ORB knows of this collection.
143 * @param name the name of a collecion to be searched for.
144 * @return boolean <TT>true</TT> if collection is found, else <TT>false</TT>.
145 */
146 public boolean hasCollection( String _name ) {
147 if (_name == null || _name.equals("")){
148 throw new Error ("null or empty collection _name");
149 }
150 corbaComErrorHolder c_err = NzdlCorbaFactory.createComErrorHolder();
151 org.omg.CORBA.BooleanHolder c_has = new org.omg.CORBA.BooleanHolder();
152 m_nzdlServer.hasCollection( NzdlCorbaFactory.toCorbaText(_name), c_has, c_err );
153 if (c_err.value.value() != 0)
154 System.err.println("hasCollection error " + c_err.value.value());
155 return c_has.value;
156 }
157
158
159 /**
160 * Check if ORB can communicate with of this collection.
161 * @param name the name of a collecion to be pinged.
162 * @return boolean <TT>true</TT> if collection returned ping, else
163 * <TT>false</TT>.
164 */
165 public boolean pingCollection( String _name ) {
166 if (_name == null || _name.equals("")){
167 throw new Error ("null or empty collection _name");
168 }
169 corbaComErrorHolder c_err = NzdlCorbaFactory.createComErrorHolder();
170 org.omg.CORBA.BooleanHolder c_ping = new org.omg.CORBA.BooleanHolder();
171 m_nzdlServer.ping( NzdlCorbaFactory.toCorbaText(_name), c_ping, c_err );
172 if (c_err.value.value() != 0)
173 System.err.println("pingCollection() error " + c_err.value.value());
174 return c_ping.value;
175 }
176
177 /**
178 * Extract information on this collection into a
179 * {@link NzdlCollectionInfo NzdlCollectionInfo} object
180 * @param name the collection to be retrieved.
181 * @return an instance of
182 * {@link NzdlCollectionInfo NzdlCollectionInfo} containing data on a
183 * collection
184 */
185 public NzdlCollectionInfo getCollectionInfo( String _name ) {
186 System.err.println("getCollectionInfo " + _name);
187 if (_name == null || _name.equals("")){
188 throw new Error ("null or empty collection _name");
189 }
190 corbaComErrorHolder c_err = NzdlCorbaFactory.createComErrorHolder();
191 corbaColInfoResponseHolder c_info = NzdlCorbaFactory.createColInfoResponseHolder();
192 m_nzdlServer.getCollectInfo( NzdlCorbaFactory.toCorbaText(_name), c_info, c_err );
193 if (c_err.value.value() != 0)
194 System.err.println("getCollectionInfo() error " + c_err.value.value());
195 return new NzdlCollectionInfo( c_info.value );
196 }
197
198 /**
199 * Returns the set of filters for the service object.
200 * @param name the collection name
201 * @return a set of strings that name the filters, for example
202 * BrowseFilter, QueryFilter and NullFilter.
203 */
204 public Set getFilterSet( String _name ) {
205 if (_name == null || _name.equals("")){
206 throw new Error ("null or empty filter _name");
207 }
208 corbaComErrorHolder c_err = NzdlCorbaFactory.createComErrorHolder();
209 corbatext_t c_name = NzdlCorbaFactory.toCorbaText( _name );
210 corbatext_tarrayHolder c_collSet = NzdlCorbaFactory.createCorbaTextArrayHolder();
211 m_nzdlServer.getFilterInfo(c_name, c_collSet,c_err);
212 if (c_err.value.value() != 0)
213 System.err.println("getCollectionInfo() error " + c_err.value.value());
214
215 Set collSet = new HashSet();
216 for (int i=0; i<c_collSet.value.length; i++) {
217 collSet.add( NzdlCorbaFactory.toString( c_collSet.value[i] ) );
218 }
219 return collSet ;
220
221 }
222
223 /**
224 * Not Currently implemented.
225 */
226 public Set getMetaTagSet( String _name ) {
227 if (_name == null || _name.equals("")){
228 throw new Error ("null or empty _name");
229 }
230 System.err.println("TO BE IMPLEMENTED: DON'T KNOW HOW YET !!! (getMetaTagSet)");
231 return null ;
232 }
233
234 /**
235 * Returns the Greenstone Markup Language (GML) text for a particular
236 * document from a collection.
237 * @param name the name of the collection.
238 * @param docID the document identity string
239 * @return the GML document in the form of a string.
240 */
241 public String getDocument( String _name, String _docID ) {
242 if (_name == null || _name.equals("")){
243 throw new Error ("null or empty _name");
244 }
245 if (_docID == null || _docID.equals("")){
246 throw new Error ("null or empty _docID");
247 }
248 corbatext_t c_name = NzdlCorbaFactory.toCorbaText( _name );
249 corbaDocRequestHolder c_request = NzdlCorbaFactory.createDocRequestHolder( _docID );
250 corbaDocResponseHolder c_response = NzdlCorbaFactory.createDocResponseHolder( );
251 corbaComErrorHolder c_err = NzdlCorbaFactory.createComErrorHolder();
252 m_nzdlServer.getDocument( c_name, c_request, c_response, c_err );
253 if (c_err.value.value() != 0)
254 System.err.println("getDocument() error " + c_err.value.value());
255 return NzdlCorbaFactory.toString( c_response.value.doc );
256 }
257
258 /**
259 * Returns the set of value(s) for a metatag from a particular document.
260 * @param name collection name
261 * @param docID the document identifier.
262 * @param metaTag the metatag name such as: Title, Author, Date and Images.
263 * @return The set of value(s) for the requested metatag and document. In
264 * cases such as Title, Author, Date there will probably be only one value
265 * per document.
266 */
267 public Set getMetaData( String _name, String _docID, String _metaTag ) {
268 if (_name == null || _name.equals("")){
269 throw new Error ("null or empty _name");
270 }
271 if (_docID == null || _docID.equals("")){
272 throw new Error ("null or empty _docID");
273 }
274 if (_metaTag == null || _metaTag.equals("")){
275 throw new Error ("null or empty _metaTag");
276 }
277 NzdlRequest request = new NzdlRequest( _docID, _metaTag );
278 NzdlResponse response = new NzdlResponse( );
279 service( _name, request, response );
280 if (response == null || response.getResponse() == null) {
281 return new HashSet();
282 }
283 NzdlResultSet resultSet = response.getResultSet();
284 /*
285 * Because a result set may contain several hits, we only return
286 * the set of metadata values of the specifed meta tag for the
287 * specified document ID.
288 */
289 return resultSet.getMetaData( _docID, _metaTag );
290 }
291
292 /**
293 * Returns a map of value(s) for a metatag from a list of documents.
294 * @param name collection name
295 * @param docIDs a list of document identifier strings.
296 * @param metaTag the metatag name such as: Title, Author, Date and Images.
297 * @return The map of value(s) for the requested metatag and document. In
298 * cases such as Title, Author, Date there will probably be only one value
299 * per document.
300 */
301 public Map getMetaData( String _name, List _docIDs, String _metaTag ) {
302 if (_name == null || _name.equals("")){
303 throw new Error ("null or empty _name");
304 }
305 if (_docIDs == null){
306 throw new Error ("null _docIDs");
307 }
308 if (_metaTag == null || _metaTag.equals("")){
309 throw new Error ("null or empty _metaTag");
310 }
311 NzdlRequest request = new NzdlRequest( _docIDs, _metaTag );
312 NzdlResponse response = new NzdlResponse( );
313 service( _name, request, response );
314 NzdlResultSet resultSet = response.getResultSet();
315 //return resultSet.getMetaData( _docID, _metaTag );
316 return resultSet.getMetaData( _metaTag );
317 //return resultSet.getAllMetaData( );
318 }
319
320 /**
321 * Services a {@link NzdlRequest NzdlRequest} to a collection and places
322 * the results into a {@link NzdlResponse NzdlResponse} object. <br>
323 * Pre: Created instances of NzdlRequest and NzdlResponse. <br>
324 * Post: Placed the result data into NzdlResponse object.
325 * @param name the collection name.
326 * @param request an instance of NzdlRequest with query data to be serviced
327 * @param response an instance of NzdlResponse. where the results of
328 * sevciving the query will be placed
329 */
330 public void service( String _name, NzdlRequest _request, NzdlResponse _response ) {
331 if (_name == null || _name.equals("")) {
332 throw new Error ("null or empty _name");
333 }
334 if (_request == null) {
335 throw new Error ("null _request");
336 }
337 if (_response == null) {
338 throw new Error ("null _response");
339 }
340 corbatext_t c_name = NzdlCorbaFactory.toCorbaText( _name );
341 corbaComErrorHolder c_err = NzdlCorbaFactory.createComErrorHolder();
342 m_nzdlServer.filter( c_name, _request.getFilter(), _response.getHolder(), c_err );
343 if (c_err.value.value() != 0)
344 System.err.println("service() error " + c_err.value.value());
345 }
346
347}
Note: See TracBrowser for help on using the repository browser.