source: trunk/java-client/org/nzdl/gsdl/service/NzdlMultiWayWrapper.java@ 2254

Last change on this file since 2254 was 2220, checked in by say1, 23 years ago

change int-> long in a number of places, new createNzdlService method taking only an IOR, added the start of a hli (high level interface

  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 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.Hashtable;
27import java.util.List;
28import java.util.Date;
29import java.util.Hashtable;
30import java.util.Properties;
31import java.util.Enumeration;
32import java.util.Iterator;
33import java.io.Writer;
34import java.io.FileWriter;
35import org.nzdl.gsdl.util.NzdlServiceFactory;
36import org.nzdl.gsdl.util.NzdlPreferences;
37
38
39/**
40 * A NzdlMultiWayWrapper multiple NzdlServices
41 *
42 * @author Brett Sheeran ([email protected]) (comments)
43 * @author Stuart Yeates ([email protected])
44 * @version $Revision: 2220 $
45 */
46public class NzdlMultiWayWrapper
47 extends NzdlWrapper {
48
49 Hashtable services;
50
51 /**
52 * The bean constructor ...
53 */
54 public NzdlMultiWayWrapper() {
55 super(null);
56 services = new Hashtable();
57 }
58 /**
59 * The normal constructor
60 */
61 public NzdlMultiWayWrapper(String [] _args,
62 Properties _props,
63 String _URL,
64 String _filename,
65 String _IOR) {
66 super(null);
67 services = new Hashtable();
68
69 Hashtable servers = NzdlServiceFactory.findIORs(_args,_props,_URL,_filename,_IOR);
70
71 Enumeration e = servers.keys() ;
72 for (int i = 0; e.hasMoreElements(); i++) {
73 String key = (String) e.nextElement();
74 NzdlService server = (NzdlService) servers.get(key);
75
76 if (NzdlPreferences.getBoolean("Log at the NzdlService level"))
77 server = new NzdlLogWrapper(server,
78 "log.file.after.split." + key + "cache",
79 "AFTER:" + key + ": ");
80 services.put("" +i, server);
81 }
82 }
83
84 String findServer(String _name) {
85 int separator = _name.indexOf(':');
86 String result = _name.substring(0,separator);
87 return result;
88 }
89 String findCollection(String _name) {
90 String result = "";
91 try {
92 int separator = _name.indexOf(':');
93 result = _name.substring(separator+1,_name.length());
94 } catch (Throwable t) {
95 System.err.println("Throwable: "+ t);
96 }
97 return result;
98 }
99
100 /**
101 * Allow the client to configure a CORBA server.
102 * @param key the parameter to be set.
103 * @param values what that parameter will be set to.
104 */
105 public void configure( String _key, Set _values ) {
106 Enumeration e = services.keys();
107 for (int i = 0; e.hasMoreElements(); i++) {
108 NzdlService server = (NzdlService) e.nextElement();
109 server.configure(_key,_values);
110 }
111 }
112
113 /**
114 * Obtain the set of collection names for a Greenstone library.
115 * @return A set of collection names in string format.
116 */
117 public Set getCollectionSet( ) {
118 Set results = new HashSet();
119
120 Enumeration e = services.keys();
121 for (int i = 0; e.hasMoreElements(); i++) {
122 String name = (String) e.nextElement();
123 NzdlService server = (NzdlService) services.get(name);
124 Set set = server.getCollectionSet();
125 Iterator s = set.iterator();
126 while (s.hasNext()) {
127 String coll = (String) s.next();
128 results.add("" + i + ":" + coll);
129 }
130 }
131 return results;
132 }
133
134 /**
135 * Check if ORB knows of this collection.
136 * @param name the name of a collecion to be searched for.
137 * @return boolean <TT>true</TT> if collection is found, else <TT>false</TT>.
138 */
139 public boolean hasCollection( String _name ) {
140
141 NzdlService server = (NzdlService) services.get( findServer(_name));
142 return server.hasCollection(findCollection(_name));
143 }
144
145 /**
146 * Check if ORB can communicate with of this collection.
147 * @param name the name of a collecion to be pinged.
148 * @return boolean <TT>true</TT> if collection returned ping, else
149 * <TT>false</TT>.
150 */
151 public boolean pingCollection( String _name ) {
152 NzdlService server = (NzdlService) services.get( findServer(_name));
153 return server.pingCollection(findCollection(_name));
154 }
155
156 /**
157 * Extract information on this collection into a
158 * {@link NzdlCollectionInfo NzdlCollectionInfo} object
159 * @param name the collection to be retrieved.
160 * @return an instance of
161 * {@link NzdlCollectionInfo NzdlCollectionInfo} containing data on a
162 * collection
163 */
164 public NzdlCollectionInfo getCollectionInfo( String _name ) {
165 NzdlService server = (NzdlService) services.get( findServer(_name));
166 NzdlCollectionInfo result = server.getCollectionInfo(findCollection(_name));
167 return result;
168 }
169
170 /**
171 * Returns the set of filters for the service object.
172 * @param name the collection name
173 * @return a set of strings that name the filters, for example
174 * BrowseFilter, QueryFilter and NullFilter.
175 */
176 public Set getFilterSet( String _name ) {
177 NzdlService server = (NzdlService) services.get( findServer(_name));
178 Set result = server.getFilterSet(findCollection(_name));
179 return result;
180 }
181
182 /**
183 * @param name the collection name
184 * @return the Set of (name, value) value pairs for all metadata
185 * associated with a collection
186 */
187 public Set getMetaTagSet( String _name ) {
188 NzdlService server = (NzdlService) services.get( findServer(_name));
189 Set result = server.getMetaTagSet(findCollection(_name));
190 return result;
191 }
192
193 /**
194 * Returns the Greenstone Markup Language (GML) text for a particular
195 * document from a collection.
196 * @param name the name of the collection.
197 * @param docID the document identity string
198 * @return the GML document in the form of a string.
199 */
200 public String getDocument( String _name, String _docID ) {
201 NzdlService server = (NzdlService) services.get( findServer(_name));
202 String result = server.getDocument(findCollection(_name), _docID);
203 return result;
204 }
205
206 /**
207 * Returns the set of value(s) for a metatag from a particular document.
208 * @param name collection name
209 * @param docID the document identifier.
210 * @param metaTag the metatag name such as: Title, Author, Date and Images.
211 * @return The set of value(s) for the requested metatag and document. In
212 * cases such as Title, Author, Date there will probably be only one value
213 * per document.
214 */
215 public Set getMetaData( String _name, String _docID, String _metaTag ) {
216 NzdlService server = (NzdlService) services.get( findServer(_name));
217 Set result = server.getMetaData( findCollection(_name), _docID, _metaTag );
218 return result;
219 }
220
221 /**
222 * Returns a map of value(s) for a metatag from a list of documents.
223 * @param name collection name
224 * @param docIDs a list of document identifier strings.
225 * @param metaTag the metatag name such as: Title, Author, Date and Images.
226 * @return The map of value(s) for the requested metatag and document. In
227 * cases such as Title, Author, Date there will probably be only one value
228 * per document.
229 */
230 public Map getMetaData( String _name, List _docIDs, String _metaTag ) {
231 NzdlService server = (NzdlService) services.get( findServer(_name));
232 Map result = server.getMetaData( findCollection(_name), _docIDs, _metaTag );
233 return result;
234 }
235
236 /**
237 * Services a {@link NzdlRequest NzdlRequest} to a collection and places
238 * the results into a {@link NzdlResponse NzdlResponse} object. <br>
239 * Pre: Created instances of NzdlRequest and NzdlResponse. <br>
240 * Post: Placed the result data into NzdlResponse object.
241 * @param name the collection name.
242 * @param request an instance of NzdlRequest with query data to be serviced
243 * @param response an instance of NzdlResponse. where the results of
244 * sevciving the query will be placed
245 */
246 public void service( String _name, NzdlRequest _request,
247 NzdlResponse _response ) {
248 NzdlService server = (NzdlService) services.get( findServer(_name));
249 server.service(findCollection(_name),_request,_response);
250 }
251
252}
Note: See TracBrowser for help on using the repository browser.