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

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

hopefully that"s the only file i missed ...

  • Property svn:keywords set to Author Date Id Revision
File size: 11.6 KB
Line 
1/*
2 * NzdlMultiWayWrapper.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
23import java.util.Map;
24import java.util.Set;
25import java.util.HashSet;
26import java.util.HashMap;
27import java.util.Hashtable;
28import java.util.List;
29import java.util.Date;
30import java.util.Hashtable;
31import java.util.Properties;
32import java.util.Enumeration;
33import java.util.Iterator;
34import java.io.Writer;
35import java.io.FileWriter;
36import org.nzdl.gsdl.corba.gsdlInterface.*;
37import org.nzdl.gsdl.util.NzdlServiceFactory;
38import org.nzdl.gsdl.util.NzdlPreferences;
39
40
41/**
42 * A NzdlCrossCollectionWrapper is a wrapper around one or
43 * more Collections to make them appear as a single collection.
44 *
45 * NzdlCrossCollectionWrapper assumes that docIDs are unique.
46 * If they aren't, some _very_ strange things are going to
47 * happen...
48 *
49 * @author Stuart Yeates ([email protected])
50 * @see org.nzdl.gsdl.service.NzdlCollectionInfo
51 * @version $Revision: 2285 $
52 */
53public class NzdlCrossCollectionWrapper
54 extends NzdlWrapper {
55
56 Set collectionSet;
57 String collectionName;
58 /**
59 * The bean constructor ...
60 */
61 public NzdlCrossCollectionWrapper() {
62 super(null);
63 }
64 /**
65 * The normal constructor
66 */
67 public NzdlCrossCollectionWrapper(NzdlService server,
68 Set collectionSet,
69 String collectionName) {
70 super(server);
71 this.collectionSet = collectionSet;
72 this.collectionName = collectionName;
73 }
74 /**
75 * The normal constructor
76 */
77 public NzdlCrossCollectionWrapper(NzdlService server,
78 String substring) {
79 super(server);
80
81 Set collections = super.getCollectionSet();
82
83 if (collections.size() == 0) {
84 System.err.println("NzdlCrossCollectionWrapper found no collections.");
85 this.collectionSet = new HashSet();
86 this.collectionName = ":::NoCoLlEcTiOn:::";
87 return;
88 }
89
90 if (substring == null || substring == "") {
91 this.collectionSet = collections;
92 this.collectionName = "Union Collection";
93 System.err.println("NzdlCrossCollectionWrapper init1 collcount: "
94 + collectionSet.size());
95 } else {
96 Set allCollections = collections;
97 Set ourCollections = new HashSet();
98
99 Iterator iter = collectionSet.iterator();
100 while(iter.hasNext()) {
101 String coll = (String) iter.next();
102 // handle the case that we've talking via a NzdlMultiWayWrapper
103 String collname = NzdlMultiWayWrapper.findCollection(coll);
104 if (collname.startsWith(substring))
105 if (collname.indexOf("nuipepa") == -1)
106 ourCollections.add(coll);
107 }
108 this.collectionSet = ourCollections;
109 this.collectionName = "\"" + substring + "\" Union Collection";
110 System.err.println("NzdlCrossCollectionWrapper init2 collcount: "
111 + collectionSet.size());
112 }
113 }
114
115 /**
116 * Allow the client to configure a CORBA server.
117 * @param key the parameter to be set.
118 * @param values what that parameter will be set to.
119 */
120 public void configure( String _key, Set _values ) {
121 super.configure(_key, _values);
122 }
123
124 /**
125 * Obtain the set of collection names for a Greenstone library.
126 * @return A set of collection names in string format.
127 */
128 public Set getCollectionSet( ) {
129 System.err.println("in getCollectionSet " + this.collectionName);
130 Set result = super.getCollectionSet();
131 result.add(this.collectionName);
132 System.err.println("getCollectionSet done " + this.collectionName);
133 return result;
134 }
135
136 /**
137 * Check if ORB knows of this collection.
138 * @param name the name of a collecion to be searched for.
139 * @return boolean <TT>true</TT> if collection is found, else <TT>false</TT>.
140 */
141 public boolean hasCollection( String _name ) {
142 if (_name.equalsIgnoreCase(collectionName))
143 return true;
144 else
145 return super.hasCollection(_name);
146 }
147
148
149 /**
150 * Check if ORB can communicate with of this collection.
151 * @param name the name of a collecion to be pinged.
152 * @return boolean <TT>true</TT> if collection returned ping, else
153 * <TT>false</TT>.
154 */
155 public boolean pingCollection( String _name ) {
156 if (_name.equalsIgnoreCase(collectionName))
157 return true;
158 else
159 return super.pingCollection(_name);
160 }
161
162 /**
163 * Extract information on this collection into a
164 * {@link NzdlCollectionInfo NzdlCollectionInfo} object
165 * @param name the collection to be retrieved.
166 * @return an instance of
167 * {@link NzdlCollectionInfo NzdlCollectionInfo} containing data on a
168 * collection
169 */
170 public NzdlCollectionInfo getCollectionInfo( String _name ) {
171 if (_name.equalsIgnoreCase(collectionName)) {
172 corbaColInfoResponse fake = new corbaColInfoResponse();
173
174 Iterator iter = collectionSet.iterator();
175 while(iter.hasNext()) {
176 String collectionName = (String) iter.next();
177 NzdlCollectionInfo info = super.getCollectionInfo(collectionName);
178 corbaColInfoResponse real = info.getInfo();
179 fake.numDocs += real.numDocs;
180 fake.numWords += real.numWords;
181 fake.numBytes += real.numBytes;
182 fake.isPublic = real.isPublic;
183 fake.isBeta = real.isBeta;
184 fake.ccsCols = real.ccsCols;
185 fake.languages = real.languages;
186 fake.collectionMeta = real.collectionMeta;
187 fake.format = real.format;
188 fake.building = real.building;
189 fake.httpdomain = real.httpdomain;
190 fake.httpprefix = real.httpprefix;
191 }
192
193 fake.buildDate = 1;
194
195 return new NzdlCollectionInfo(fake);
196 } else {
197 return super.getCollectionInfo(_name);
198 }
199 }
200
201 /**
202 * Returns the set of filters for the service object.
203 * @param name the collection name
204 * @return a set of strings that name the filters, for example
205 * BrowseFilter, QueryFilter and NullFilter.
206 */
207 public Set getFilterSet( String _name ) {
208 if (_name.equalsIgnoreCase(collectionName)) {
209 Set results = new HashSet();
210 Iterator iter = collectionSet.iterator();
211 while(iter.hasNext()) {
212 String collectionName = (String) iter.next();
213 results.addAll(super.getFilterSet(collectionName));
214 }
215 return results;
216 } else {
217 return super.getFilterSet(_name);
218 }
219 }
220
221 /**
222 * @param name the collection name
223 * @return the Set of (name, value) value pairs for all metadata
224 * associated with a collection
225 */
226 public Set getMetaTagSet( String _name ) {
227 if (_name.equalsIgnoreCase(collectionName)) {
228 Set results = new HashSet();
229 Iterator iter = collectionSet.iterator();
230 while(iter.hasNext()) {
231 String collectionName = (String) iter.next();
232 results.addAll(super.getMetaTagSet(collectionName));
233 }
234 return results;
235 } else {
236 return super.getMetaTagSet(_name);
237 }
238 }
239
240 /**
241 * Returns the Greenstone Markup Language (GML) text for a particular
242 * document from a collection.
243 * @param name the name of the collection.
244 * @param docID the document identity string
245 * @return the GML document in the form of a string.
246 */
247 public String getDocument( String _name, String _docID ) {
248 if (_name.equalsIgnoreCase(collectionName)) {
249 String results = new String();
250 Iterator iter = collectionSet.iterator();
251 while(iter.hasNext()) {
252 String collectionName = (String) iter.next();
253 results = results + super.getDocument(collectionName, _docID);
254 }
255 return results;
256 } else {
257 return super.getDocument(_name,_docID);
258 }
259 }
260
261 /**
262 * Returns the set of value(s) for a metatag from a particular document.
263 * @param name collection name
264 * @param docID the document identifier.
265 * @param metaTag the metatag name such as: Title, Author, Date and Images.
266 * @return The set of value(s) for the requested metatag and document. In
267 * cases such as Title, Author, Date there will probably be only one value
268 * per document.
269 */
270 public Set getMetaData( String _name, String _docID, String _metaTag ) {
271 if (_name.equalsIgnoreCase(collectionName)) {
272 Set results = new HashSet();
273 Iterator iter = collectionSet.iterator();
274 while(iter.hasNext()) {
275 String collectionName = (String) iter.next();
276 results.addAll(super.getMetaData(collectionName,_docID,_metaTag));
277 }
278 return results;
279 } else {
280 return super.getMetaData(_name,_docID,_metaTag);
281 }
282 }
283
284 /**
285 * Returns a map of value(s) for a metatag from a list of documents.
286 * @param name collection name
287 * @param docIDs a list of document identifier strings.
288 * @param metaTag the metatag name such as: Title, Author, Date and Images.
289 * @return The map of value(s) for the requested metatag and document. In
290 * cases such as Title, Author, Date there will probably be only one value
291 * per document.
292 */
293 public Map getMetaData( String _name, List _docIDs, String _metaTag ) {
294 if (_name.equalsIgnoreCase(collectionName)) {
295 Map results = new HashMap();
296 Iterator iter = collectionSet.iterator();
297 while(iter.hasNext()) {
298 String collectionName = (String) iter.next();
299 results.putAll(super.getMetaData(collectionName,_docIDs,_metaTag));
300 }
301 return results;
302 } else {
303 return super.getMetaData(_name,_docIDs,_metaTag);
304 }
305 }
306
307
308 corbaTermInfo[] concat(corbaTermInfo[] first, corbaTermInfo[] second) {
309 corbaTermInfo[] result =
310 new corbaTermInfo[first.length + second.length];
311 for (int i = 0;i<first.length;i++)
312 result[i] = first[i];
313 for (int i = 0;i<second.length;i++)
314 result[first.length+ i] = second[i];
315 return result;
316 }
317
318 corbaResultDocInfo[] concat(corbaResultDocInfo[] first, corbaResultDocInfo[] second) {
319 corbaResultDocInfo[] result =
320 new corbaResultDocInfo[first.length + second.length];
321 for (int i = 0;i<first.length;i++)
322 result[i] = first[i];
323 for (int i = 0;i<second.length;i++)
324 result[first.length+ i] = second[i];
325 return result;
326 }
327
328 /**
329 * Services a {@link NzdlRequest NzdlRequest} to a collection and places
330 * the results into a {@link NzdlResponse NzdlResponse} object. <br>
331 * Pre: Created instances of NzdlRequest and NzdlResponse. <br>
332 * Post: Placed the result data into NzdlResponse object.
333 * @param name the collection name.
334 * @param request an instance of NzdlRequest with query data to be serviced
335 * @param response an instance of NzdlResponse. where the results of
336 * sevciving the query will be placed
337 */
338 public void service( String _name, NzdlRequest _request,
339 NzdlResponse _response ) {
340 if (_name.equalsIgnoreCase(collectionName)) {
341 corbaFilterResponse fake = new corbaFilterResponse();
342 Iterator iter = collectionSet.iterator();
343 while(iter.hasNext()) {
344 String collectionName = (String) iter.next();
345 NzdlResponse response = new NzdlResponse();
346 super.service(collectionName,_request,response);
347 fake.numDocs = fake.numDocs + response.getResponse().numDocs;
348 fake.termInfo = concat(fake.termInfo,response.getResponse().termInfo);
349 fake.docInfo = concat(fake.docInfo,response.getResponse().docInfo);
350 _response.setResponse(fake);
351 }
352 } else {
353 super.service(_name,_request,_response);
354 }
355 }
356}
Note: See TracBrowser for help on using the repository browser.