source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java@ 21312

Last change on this file since 21312 was 21312, checked in by kjdon, 14 years ago

a little bit of code rearranging and editing so that we can have a serviceRackList in collectionConfig.xml (as well as buildConfig.xml) - may want to manually specify one and not have to edit the file each time after a rebuild

  • Property svn:keywords set to Author Date Id Revision
File size: 24.4 KB
Line 
1/*
2 * ServiceCluster.java
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
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// leave the package name as is for now - should be changed to something better
20// cluster? groups?
21package org.greenstone.gsdl3.collection;
22
23
24import org.greenstone.gsdl3.util.*;
25import org.greenstone.gsdl3.core.*;
26import org.greenstone.gsdl3.service.*;
27
28// java XML classes we're using
29import org.w3c.dom.Document;
30import org.w3c.dom.Node;
31import org.w3c.dom.Element;
32import org.w3c.dom.NodeList;
33
34import java.io.File;
35import java.util.HashMap;
36import java.util.Iterator;
37
38import org.apache.log4j.*;
39
40/* ServiceCluster - a groups of services that are related in some way
41 * Implements ModuleInterface. Contains a list of services provided by the cluster, along with metadata about the cluster itself.
42 * a collection is a special type of cluster
43 * @author <a href="mailto:[email protected]">Katherine Don</a>
44 * @version $Revision: 21312 $
45 * @see ModuleInterface
46 */
47public class ServiceCluster
48 implements ModuleInterface {
49
50 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.collection.ServiceCluster.class.getName());
51
52 protected static final String CONFIG_ENCODING = "utf-8";
53
54 protected static final String DEFAULT_LANG = "en"; // hack for now, should be read from the coll cfg file? or site cfg file for cluster
55
56 /** base directory for the site that this cluster belongs to*/
57 protected String site_home = null;
58 /** http address of the site that this cluster belongs to */
59 protected String site_http_address = null;
60 /** The name of the cluster - for a collection, this is the collection name*/
61 protected String cluster_name = null;
62 /** collection type : mg or mgpp */
63 protected String col_type = "";
64
65 /** a reference to the message router */
66 protected MessageRouter router = null;
67 /** The map of services.
68 *
69 * Maps Services to ServiceRack objects
70 * @see ServiceRack
71 *
72 */
73 protected HashMap service_map=null;
74 /** maps pseudo service names to real service names - needed if we have two services with the same name for one collection */
75 protected HashMap service_name_map=null;
76
77 /** XML converter for String to DOM and vice versa */
78 protected XMLConverter converter=null;
79
80 /** container doc for description elements */
81 protected Document doc = null;
82 /** list of services */
83 protected Element service_list = null;
84 /** list of metadata - all metadata, regardless of language goes in here */
85 protected Element metadata_list = null;
86 /** language specific stuff */
87 //protected Element lang_specific_metadata_list = null;
88 protected Element display_item_list = null;
89 /** the element that will have any descriptions passed back in */
90 protected Element description = null;
91
92 /** list of plugin */
93 protected Element plugin_item_list = null;
94
95 public void setSiteHome(String home) {
96 this.site_home = home;
97 }
98
99 public void setSiteAddress(String address) {
100 this.site_http_address = address;
101 }
102
103 public void cleanUp() {
104 Iterator i = this.service_map.values().iterator();
105 while (i.hasNext()) {
106 ServiceRack s = (ServiceRack)i.next();
107 s.cleanUp();
108 }
109 }
110 public void setClusterName(String name) {
111 this.cluster_name = name;
112 this.description.setAttribute(GSXML.NAME_ATT, name);
113 }
114
115 public void setMessageRouter(MessageRouter m) {
116 this.router = m;
117 }
118
119 public ServiceCluster() {
120 this.service_map = new HashMap();
121 this.service_name_map = new HashMap();
122 this.converter = new XMLConverter();
123 this.doc = this.converter.newDOM();
124 this.description = this.doc.createElement(GSXML.CLUSTER_ELEM);
125 this.display_item_list = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
126 this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
127 this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
128 }
129
130 /**
131 * Configures the cluster.
132 *
133 * gsdlHome and clusterName must be set before configure is called.
134 *
135 * reads the site configuration file, and configures itself
136 * this calls configure(Element) with the XML element node from the config
137 * file.
138 * configure(Element) should be used if the config file has already been
139 * parsed. This method will work with any subclass.
140 *
141 * @return true if configure successful, false otherwise.
142 */
143 public boolean configure() {
144
145 if (this.site_home == null || this.cluster_name== null) {
146 logger.error("site_home and cluster_name must be set before configure called!");
147 return false;
148 }
149 logger.info("configuring service cluster");
150 // read the site configuration file
151 File config_file = new File(GSFile.siteConfigFile(this.site_home));
152
153 if (!config_file.exists()) {
154 logger.error("couldn't configure cluster: "+this.cluster_name +", "+config_file+" does not exist");
155 return false;
156 }
157
158 Document doc = this.converter.getDOM(config_file, CONFIG_ENCODING);
159 if (doc == null) {
160 logger.error("couldn't parse config file "+config_file.getPath());
161 return false;
162 }
163
164 // get the appropriate service cluster element
165 Element cluster_list = (Element)GSXML.getChildByTagName(doc.getDocumentElement(), GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);
166 Element sc = GSXML.getNamedElement(cluster_list, GSXML.CLUSTER_ELEM,
167 GSXML.NAME_ATT, this.cluster_name);
168
169 return this.configure(sc);
170 }
171
172
173 public boolean configure(Element service_cluster_info) {
174
175 // get the metadata - for now just add it to the list
176 Element meta_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
177 if (meta_list !=null) {
178 if (!addMetadata(meta_list)) {
179
180 logger.error(" couldn't configure the metadata");
181 }
182 }
183
184 // get the display info
185 Element display_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
186 if (display_list !=null) {
187 if (!addDisplayItems(display_list)) {
188
189 logger.error("couldn't configure the display items");
190 }
191 }
192
193 //get the plugin info
194 Element import_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.IMPORT_ELEM);
195 if (import_list != null)
196 {
197 Element plugin_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
198 if (plugin_list !=null) {
199 if (!addPlugins(plugin_list)) {
200
201 logger.error("couldn't configure the plugins");
202 }
203 }
204 }
205
206 // do the service racks
207 // empty the service map in case this is a reconfigure
208 clearServices();
209 Element service_rack_list = (Element)GSXML.getChildByTagName(service_cluster_info, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
210 if (service_rack_list == null) {
211 // is this an error? could you ever have a service cluster
212 // without service racks???
213 logger.error("cluster has no service racks!!");
214 } else {
215
216 if (!configureServiceRack(service_rack_list, null)) {
217 logger.error("couldn't configure the service racks!!");
218 return false;
219 }
220 }
221
222 return true;
223 }
224
225 /** adds metadata from a metadataList into the metadata_list xml
226 */
227 protected boolean addMetadata(Element metadata_list) {
228 if (metadata_list == null) return false;
229 NodeList metanodes = metadata_list.getElementsByTagName(GSXML.METADATA_ELEM);
230 if (metanodes.getLength()>0) {
231 for(int k=0; k<metanodes.getLength(); k++) {
232 this.metadata_list.appendChild(this.doc.importNode(metanodes.item(k), true));
233 }
234 }
235
236 return true;
237 }
238
239 protected boolean addDisplayItems(Element display_list) {
240
241 if (display_list==null) return false;
242 NodeList displaynodes = display_list.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
243 if (displaynodes.getLength()>0) {
244 for(int k=0; k<displaynodes.getLength(); k++) {
245 Element d = (Element) displaynodes.item(k);
246 String lang = d.getAttribute(GSXML.LANG_ATT);
247 if (lang==null||lang.equals("")) {
248 //set the lang to teh default
249 d.setAttribute(GSXML.LANG_ATT, DEFAULT_LANG);
250 }
251 String name = d.getAttribute(GSXML.NAME_ATT);
252 Element this_item = GSXML.getNamedElement(this.display_item_list, GSXML.DISPLAY_TEXT_ELEM, GSXML.NAME_ATT, name);
253 if (this_item==null) {
254 this_item = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM);
255 this_item.setAttribute(GSXML.NAME_ATT, name);
256 this.display_item_list.appendChild(this_item);
257 }
258
259 this_item.appendChild(this.doc.importNode(d, true));
260 }
261 }
262
263 return true;
264 }
265
266 protected boolean addPlugins(Element plugin_list) {
267 if (plugin_list == null) return false;
268 NodeList pluginNodes = plugin_list.getElementsByTagName(GSXML.PLUGIN_ELEM);
269 if (pluginNodes.getLength() > 0) {
270 for (int k = 0; k < pluginNodes.getLength(); k++)
271 {
272 this.plugin_item_list.appendChild(this.doc.importNode(pluginNodes.item(k), true));
273 }
274 }
275
276 return true;
277 }
278
279
280 protected void clearServices() {
281 service_map.clear();
282 this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
283 }
284 /** creates and configures all the services - extra_info is some more xml
285that is passed to teh service - eg used for coll config files for Collection
286 */
287 protected boolean configureServiceRack(Element service_rack_list,
288 Element extra_info) {
289
290 // create all the services
291 NodeList nodes = service_rack_list.getElementsByTagName(GSXML.SERVICE_CLASS_ELEM);
292 if (nodes.getLength()==0) {
293 logger.error("ServiceCluster configuration error: cluster "+this.cluster_name+" has no service modules!");
294 return false;
295 }
296
297 for(int i=0; i<nodes.getLength(); i++) {
298
299 // the xml request to send to the serviceRack to query what
300 // services it provides
301 Element message = this.doc.createElement(GSXML.MESSAGE_ELEM);
302 Element request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", "", "");
303 message.appendChild(request);
304
305 Element n = (Element)nodes.item(i);
306 String servicetype = n.getAttribute(GSXML.NAME_ATT);
307
308 ServiceRack s = null;
309
310 try {
311 // try for a default service in standard package
312 s = (ServiceRack)Class.forName("org.greenstone.gsdl3.service."+servicetype).newInstance();
313
314 } catch (Exception e) {}
315 if (s == null) {
316 try {
317 // name as is, in case package is already specified
318 s = (ServiceRack)Class.forName(servicetype).newInstance();
319 } catch (Exception e) {}
320 }
321
322 if (s == null) {
323 logger.error("Couldn't get an instance of class "+servicetype+", or org.greenstone.gsdl3.service."+servicetype);
324 continue;
325 }
326
327
328 s.setSiteHome(this.site_home);
329 s.setSiteAddress(this.site_http_address);
330 s.setClusterName(this.cluster_name);
331 s.setMessageRouter(this.router);
332 // pass the xml node to the service for configuration
333 if (s.configure(n, extra_info)) {
334
335 // find out the supported service types for this service module
336 Node types = s.process(message);
337 NodeList typenodes = ((Element)types).getElementsByTagName(GSXML.SERVICE_ELEM);
338
339 for (int j=0; j<typenodes.getLength();j++) {
340 String service = ((Element) typenodes.item(j)).getAttribute(GSXML.NAME_ATT);
341 if (service_map.get(service)!=null) {
342 char extra = '0';
343 String new_service = service+extra;
344
345 while (service_map.get(new_service)!=null) {
346 extra++;
347 new_service = service+extra;
348 }
349 this.service_name_map.put(new_service, service);
350 service=new_service;
351 ((Element) typenodes.item(j)).setAttribute(GSXML.NAME_ATT, service);
352 }
353 this.service_map.put(service, s);
354 // also add info to the ServiceInfo XML element
355 this.service_list.appendChild(this.doc.importNode(typenodes.item(j), true));
356 }
357 }
358 }
359
360 return true;
361
362
363 }
364
365
366 /**
367 * Process an XML document - uses Strings
368 * just calls process(Node).
369 *
370 * @param in the Document to process - a string
371 * @return the resultant document as a string - contains any error messages
372 * @see String
373 */
374 public String process(String in) {
375
376 Document doc = this.converter.getDOM(in);
377
378 Node res = process(doc);
379 return this.converter.getString(res);
380
381 }
382
383 /** process XML as Node
384 *
385 */
386 public Node process(Node message_node) {
387
388 Element message = this.converter.nodeToElement(message_node);
389
390 NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM);
391 Document mess_doc = message.getOwnerDocument();
392 Element mainResult = this.doc.createElement(GSXML.MESSAGE_ELEM);
393 if (requests.getLength()==0) {
394 logger.error("no requests for cluster:"+this.cluster_name);
395 // no requests
396 return mainResult; // for now
397 }
398 for (int i=0; i<requests.getLength(); i++) {
399 Element request = (Element)requests.item(i);
400 String to = request.getAttribute(GSXML.TO_ATT);
401
402 // the cluster name should be first, check, then remove
403 String clustername = GSPath.getFirstLink(to);
404 if (!clustername.equals(this.cluster_name)){
405 logger.error("cluster name wrong! was "+clustername+" should have been "+this.cluster_name);
406 continue; // ignore this request
407 }
408 to = GSPath.removeFirstLink(to);
409 request.setAttribute(GSXML.TO_ATT, to);
410
411 if (to.equals("")) { // this command is for me
412 Element response = processMessage(request);
413 mainResult.appendChild(response);
414
415 } else { // the request is for one of my services
416 String service = GSPath.getFirstLink(to);
417
418 if (!this.service_map.containsKey(service)) {
419 logger.error("non-existant service, "+service+", specified!");
420 continue;
421 }
422 String real_service = service;
423 if (this.service_name_map.containsKey(service)) {
424 real_service = (String)this.service_name_map.get(service);
425 // need to change the to att in the request - give the real service name
426 to = request.getAttribute(GSXML.TO_ATT);
427 String old_to = to;
428 to = GSPath.replaceFirstLink(to, real_service);
429 request.setAttribute(GSXML.TO_ATT, to);
430 }
431 // have to pass the request to the service
432 Element single_message = mess_doc.createElement(GSXML.MESSAGE_ELEM);
433 single_message.appendChild(request);
434 Node response_message = ((ModuleInterface)this.service_map.get(service)).process(single_message);
435 if (response_message != null) {
436 Element response = (Element) GSXML.getChildByTagName(response_message, GSXML.RESPONSE_ELEM);
437 String from = response.getAttribute(GSXML.FROM_ATT);
438 if (!real_service.equals(service)) {
439 // replace the real service name with the pseudo service name
440 from = GSPath.replaceFirstLink(from, service);
441 // also need to do it in the service itself
442 // shoudl this be done here??
443 Element service_elem = (Element) GSXML.getChildByTagName(response, GSXML.SERVICE_ELEM);
444 if (service_elem!= null) {
445 service_elem.setAttribute(GSXML.NAME_ATT, service);
446 }
447 }
448 from = GSPath.prependLink(from, this.cluster_name);
449 response.setAttribute(GSXML.FROM_ATT, from);
450 mainResult.appendChild(this.doc.importNode(response, true));
451 }
452
453 } // else
454
455
456 } // for each request
457 return mainResult;
458 }
459
460 /** handles requests made to the ServiceCluster itself
461 *
462 * @param req - the request Element- <request>
463 * @return the result Element - should be <response>
464 */
465 protected Element processMessage(Element request) {
466
467 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
468 response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
469 String type = request.getAttribute(GSXML.TYPE_ATT);
470 String lang = request.getAttribute(GSXML.LANG_ATT);
471 response.setAttribute(GSXML.TYPE_ATT, type);
472
473 if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE)) {
474 // create the collection element
475 Element description = (Element)this.description.cloneNode(false);
476 // set collection type : mg or mgpp
477 description.setAttribute(GSXML.TYPE_ATT, col_type);
478
479 response.appendChild(description);
480 // check the param list
481 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
482 if (param_list == null) {
483 addAllDisplayInfo(description, lang);
484 description.appendChild(this.service_list);
485 description.appendChild(this.metadata_list);
486 description.appendChild(this.plugin_item_list);
487 return response;
488 }
489
490 // go through the param list and see what components are wanted
491 NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
492 for (int i=0; i<params.getLength(); i++) {
493
494 Element param = (Element)params.item(i);
495 // Identify the structure information desired
496 if (param.getAttribute(GSXML.NAME_ATT).equals(GSXML.SUBSET_PARAM)) {
497 String info = param.getAttribute(GSXML.VALUE_ATT);
498 if (info.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
499 description.appendChild(this.service_list);
500 } else if (info.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
501 description.appendChild(metadata_list);
502 } else if (info.equals(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER)) {
503 addAllDisplayInfo(description, lang);
504 } else if (info.equals(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER)) {
505 description.appendChild(plugin_item_list);
506 }
507 }
508 }
509 return response;
510 }
511
512 if (type.equals(GSXML.REQUEST_TYPE_SYSTEM)) {
513 response = processSystemRequest(request);
514 } else { // unknown type
515 logger.error("cant handle request of type "+ type);
516
517 }
518 return response;
519 }
520
521 protected Element processSystemRequest(Element request) {
522
523 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
524 response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
525 response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_SYSTEM);
526
527 // a list of system requests - should put any error messages
528 // or success messages into response
529 NodeList commands = request.getElementsByTagName(GSXML.SYSTEM_ELEM);
530 String message=null;
531 for (int i=0; i<commands.getLength(); i++) {
532 // all the commands should be Elements
533 Element elem = (Element)commands.item(i);
534 String action = elem.getAttribute(GSXML.TYPE_ATT);
535 if (action.equals(GSXML.SYSTEM_TYPE_CONFIGURE)) {
536 String subset = elem.getAttribute(GSXML.SYSTEM_SUBSET_ATT);
537 if (subset.equals("")) {
538 // need to reconfigure the service cluster
539
540 if (this.configure()) {
541 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " reconfigured");
542 response.appendChild(s);
543
544 } else {
545 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " could not be reconfigured");
546 response.appendChild(s);
547 }
548 } else if (this.configureSubset(subset)) {
549 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " "+subset+" reconfigured");
550 response.appendChild(s);
551 } else {
552 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " "+subset + " could not be reconfigured");
553 response.appendChild(s);
554 }
555 continue;
556 } // configure action
557
558 String module_name = elem.getAttribute(GSXML.SYSTEM_MODULE_NAME_ATT);
559 String module_type = elem.getAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT);
560 if (action.equals(GSXML.SYSTEM_TYPE_ACTIVATE)) {
561 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, "activate action not yet implemented - does it even make sense in this context??");
562 response.appendChild(s);
563 } else if (action.equals(GSXML.SYSTEM_TYPE_DEACTIVATE)) {
564 if (module_type.equals(GSXML.SERVICE_ELEM)) {
565 // deactivate the service
566 // remove from service_map
567 this.service_map.remove(module_name);
568 Element service_elem = GSXML.getNamedElement(this.service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, module_name);
569 service_list.removeChild(service_elem);
570 message = module_type+": "+module_name+" deactivated";
571 } else {
572 message = "can't deactivate "+module_type+" type modules!";}
573 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message);
574 response.appendChild(s);
575 } else {
576 logger.error("cant process system request, action "+action);
577 continue;
578 }
579 } // for each command
580 return response;
581 }
582
583 /**
584 * do a configure on only part of the collection
585 */
586 protected boolean configureSubset(String subset) {
587
588 File configFile = new File(GSFile.siteConfigFile(this.site_home));
589 if (!configFile.exists() ) {
590 logger.error("site config file: "+configFile.getPath()+" not found!");
591 // wont be able to do any of the requests
592 return false;
593
594 }
595
596 Document site_config_doc = this.converter.getDOM(configFile);
597 if (site_config_doc == null) {
598 logger.error("could not read in site config file: "+configFile.getPath());
599 return false;
600 }
601
602 Element site_config_elem = site_config_doc.getDocumentElement();
603 Element cluster_config_elem = GSXML.getNamedElement((Element)GSXML.getChildByTagName(site_config_elem, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER), GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, this.cluster_name);
604 if (cluster_config_elem == null) {
605 logger.error("site config file: "+configFile.getPath()+" has no element for cluster "+this.cluster_name);
606 // wont be able to do any of teh requests
607 return false;
608
609 }
610 if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
611 Element service_rack_list = (Element)GSXML.getChildByTagName(cluster_config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
612 clearServices();
613 return configureServiceRack(service_rack_list, null);
614 } else if (subset.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
615 this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
616 Element metadata_list = (Element)GSXML.getChildByTagName(cluster_config_elem, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
617 return addMetadata(metadata_list);
618 } else if (subset.equals(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER)) {
619 this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
620 Element import_list = (Element)GSXML.getChildByTagName(cluster_config_elem,GSXML.IMPORT_ELEM);
621 if (import_list != null)
622 {
623 Element plugin_item_list = (Element)GSXML.getChildByTagName(cluster_config_elem,GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
624 return addPlugins(plugin_item_list);
625 }
626 else
627 return false;
628 } else {
629 logger.error("cannot process system request, configure "+subset);
630 return false;
631 }
632
633 }
634
635
636 protected boolean addAllDisplayInfo(Element description, String lang) {
637
638 NodeList items = this.display_item_list.getChildNodes();
639 for (int i=0; i<items.getLength(); i++) { // for each key
640 Element m = (Element) items.item(i);
641 // find the child with the correct language
642 Element new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang);
643 if (new_m==null && lang != DEFAULT_LANG) {
644 // use the default lang
645 new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG);
646 }
647 if (new_m==null) {
648 // just get the first one
649 new_m = (Element)GSXML.getChildByTagName(m, GSXML.DISPLAY_TEXT_ELEM);
650 }
651 description.appendChild(new_m.cloneNode(true));
652 }
653 return true;
654
655 }
656
657
658 protected Element getDisplayTextElement(String key, String lang) {
659
660 Element this_item = GSXML.getNamedElement(this.display_item_list, GSXML.DISPLAY_TEXT_ELEM, GSXML.NAME_ATT, key);
661 if (this_item == null) {
662 return null;
663 }
664
665 Element this_lang = GSXML.getNamedElement(this_item, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang);
666 if (this_lang == null && lang != DEFAULT_LANG) {
667 // try the default
668 this_lang = GSXML.getNamedElement(this_item, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG);
669 }
670 if (this_lang == null) {
671 // just return the first one
672 return GSXML.getFirstElementChild(this_item);//(Element)this_item.getFirstChild().cloneNode(true);
673 }
674 return (Element)this_lang.cloneNode(true);
675
676 }
677 public HashMap getServiceMap() {
678 return service_map;
679 }
680}
681
682
683
684
685
686
Note: See TracBrowser for help on using the repository browser.