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

Last change on this file since 16688 was 16688, checked in by davidb, 16 years ago

Changed 'Element process(Element)' in ModuleInterface to 'Node process(Node)'. After some deliberation is was decided this is a more useful (generic) layer of the DOM to pass information around in. Helps with the DocType problem when producing XSL Transformed pages, for example. When this was an Element, it would loose track of its DocType. Supporting method provided in XMLConverter 'Element nodeToElement(Node)' which checks a nodes docType and casts to Element if appropriate, or if a Document, typecasts to that and then extracts the top-level Element. With this fundamental change in ModuleInterface, around 20 files needed to be updated (Actions, Services, etc) that build on top of 'process()' to reflect this change, and use nodeToElement where necessary.

  • Property svn:keywords set to Author Date Id Revision
File size: 24.3 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: 16688 $
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 Element service_rack_list = (Element)GSXML.getChildByTagName(service_cluster_info, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
208 if (service_rack_list == null) {
209 // is this an error? could you ever have a service cluster
210 // without service racks???
211 logger.error("cluster has no service racks!!");
212 } else {
213
214 if (!configureServiceRack(service_rack_list, null)) {
215 logger.error("couldn't configure the service racks!!");
216 return false;
217 }
218 }
219
220 return true;
221 }
222
223 /** adds metadata from a metadataList into the metadata_list xml
224 */
225 protected boolean addMetadata(Element metadata_list) {
226 if (metadata_list == null) return false;
227 NodeList metanodes = metadata_list.getElementsByTagName(GSXML.METADATA_ELEM);
228 if (metanodes.getLength()>0) {
229 for(int k=0; k<metanodes.getLength(); k++) {
230 this.metadata_list.appendChild(this.doc.importNode(metanodes.item(k), true));
231 }
232 }
233
234 return true;
235 }
236
237 protected boolean addDisplayItems(Element display_list) {
238
239 if (display_list==null) return false;
240 NodeList displaynodes = display_list.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
241 if (displaynodes.getLength()>0) {
242 for(int k=0; k<displaynodes.getLength(); k++) {
243 Element d = (Element) displaynodes.item(k);
244 String lang = d.getAttribute(GSXML.LANG_ATT);
245 if (lang==null||lang.equals("")) {
246 //set the lang to teh default
247 d.setAttribute(GSXML.LANG_ATT, DEFAULT_LANG);
248 }
249 String name = d.getAttribute(GSXML.NAME_ATT);
250 Element this_item = GSXML.getNamedElement(this.display_item_list, GSXML.DISPLAY_TEXT_ELEM, GSXML.NAME_ATT, name);
251 if (this_item==null) {
252 this_item = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM);
253 this_item.setAttribute(GSXML.NAME_ATT, name);
254 this.display_item_list.appendChild(this_item);
255 }
256
257 this_item.appendChild(this.doc.importNode(d, true));
258 }
259 }
260
261 return true;
262 }
263
264 protected boolean addPlugins(Element plugin_list) {
265 if (plugin_list == null) return false;
266 NodeList pluginNodes = plugin_list.getElementsByTagName(GSXML.PLUGIN_ELEM);
267 if (pluginNodes.getLength() > 0) {
268 for (int k = 0; k < pluginNodes.getLength(); k++)
269 {
270 this.plugin_item_list.appendChild(this.doc.importNode(pluginNodes.item(k), true));
271 }
272 }
273
274 return true;
275 }
276
277 /** creates and configures all the services - extra_info is some more xml
278that is passed to teh service - eg used for coll config files for Collection
279 */
280 protected boolean configureServiceRack(Element service_rack_list,
281 Element extra_info) {
282
283 // empty the service map in case this is a reconfigure
284 service_map.clear();
285 this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
286
287 // create all the services
288 NodeList nodes = service_rack_list.getElementsByTagName(GSXML.SERVICE_CLASS_ELEM);
289 if (nodes.getLength()==0) {
290 logger.error("ServiceCluster configuration error: cluster "+this.cluster_name+" has no service modules!");
291 return false;
292 }
293
294 for(int i=0; i<nodes.getLength(); i++) {
295
296 // the xml request to send to the serviceRack to query what
297 // services it provides
298 Element message = this.doc.createElement(GSXML.MESSAGE_ELEM);
299 Element request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", "", "");
300 message.appendChild(request);
301
302 Element n = (Element)nodes.item(i);
303 String servicetype = n.getAttribute(GSXML.NAME_ATT);
304
305 ServiceRack s = null;
306
307 try {
308 // try for a default service in standard package
309 s = (ServiceRack)Class.forName("org.greenstone.gsdl3.service."+servicetype).newInstance();
310
311 } catch (Exception e) {}
312 if (s == null) {
313 try {
314 // name as is, in case package is already specified
315 s = (ServiceRack)Class.forName(servicetype).newInstance();
316 } catch (Exception e) {}
317 }
318
319 if (s == null) {
320 logger.error("Couldn't get an instance of class "+servicetype+", or org.greenstone.gsdl3.service."+servicetype);
321 continue;
322 }
323
324
325 s.setSiteHome(this.site_home);
326 s.setSiteAddress(this.site_http_address);
327 s.setClusterName(this.cluster_name);
328 s.setMessageRouter(this.router);
329 // pass the xml node to the service for configuration
330 if (s.configure(n, extra_info)) {
331
332 // find out the supported service types for this service module
333 Node types = s.process(message);
334 NodeList typenodes = ((Element)types).getElementsByTagName(GSXML.SERVICE_ELEM);
335
336 for (int j=0; j<typenodes.getLength();j++) {
337 String service = ((Element) typenodes.item(j)).getAttribute(GSXML.NAME_ATT);
338 if (service_map.get(service)!=null) {
339 char extra = '0';
340 String new_service = service+extra;
341
342 while (service_map.get(new_service)!=null) {
343 extra++;
344 new_service = service+extra;
345 }
346 this.service_name_map.put(new_service, service);
347 service=new_service;
348 ((Element) typenodes.item(j)).setAttribute(GSXML.NAME_ATT, service);
349 }
350 this.service_map.put(service, s);
351 // also add info to the ServiceInfo XML element
352 this.service_list.appendChild(this.doc.importNode(typenodes.item(j), true));
353 }
354 }
355 }
356
357 return true;
358
359
360 }
361
362
363 /**
364 * Process an XML document - uses Strings
365 * just calls process(Node).
366 *
367 * @param in the Document to process - a string
368 * @return the resultant document as a string - contains any error messages
369 * @see String
370 */
371 public String process(String in) {
372
373 Document doc = this.converter.getDOM(in);
374
375 Node res = process(doc);
376 return this.converter.getString(res);
377
378 }
379
380 /** process XML as Node
381 *
382 */
383 public Node process(Node message_node) {
384
385 Element message = this.converter.nodeToElement(message_node);
386
387 NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM);
388 Document mess_doc = message.getOwnerDocument();
389 Element mainResult = this.doc.createElement(GSXML.MESSAGE_ELEM);
390 if (requests.getLength()==0) {
391 logger.error("no requests for cluster:"+this.cluster_name);
392 // no requests
393 return mainResult; // for now
394 }
395 for (int i=0; i<requests.getLength(); i++) {
396 Element request = (Element)requests.item(i);
397 String to = request.getAttribute(GSXML.TO_ATT);
398
399 // the cluster name should be first, check, then remove
400 String clustername = GSPath.getFirstLink(to);
401 if (!clustername.equals(this.cluster_name)){
402 logger.error("cluster name wrong! was "+clustername+" should have been "+this.cluster_name);
403 continue; // ignore this request
404 }
405 to = GSPath.removeFirstLink(to);
406 request.setAttribute(GSXML.TO_ATT, to);
407
408 if (to.equals("")) { // this command is for me
409 Element response = processMessage(request);
410 mainResult.appendChild(response);
411
412 } else { // the request is for one of my services
413 String service = GSPath.getFirstLink(to);
414
415 if (!this.service_map.containsKey(service)) {
416 logger.error("non-existant service, "+service+", specified!");
417 continue;
418 }
419 String real_service = service;
420 if (this.service_name_map.containsKey(service)) {
421 real_service = (String)this.service_name_map.get(service);
422 // need to change the to att in the request - give the real service name
423 to = request.getAttribute(GSXML.TO_ATT);
424 String old_to = to;
425 to = GSPath.replaceFirstLink(to, real_service);
426 request.setAttribute(GSXML.TO_ATT, to);
427 }
428 // have to pass the request to the service
429 Element single_message = mess_doc.createElement(GSXML.MESSAGE_ELEM);
430 single_message.appendChild(request);
431 Node response_message = ((ModuleInterface)this.service_map.get(service)).process(single_message);
432 if (response_message != null) {
433 Element response = (Element) GSXML.getChildByTagName(response_message, GSXML.RESPONSE_ELEM);
434 String from = response.getAttribute(GSXML.FROM_ATT);
435 if (!real_service.equals(service)) {
436 // replace the real service name with the pseudo service name
437 from = GSPath.replaceFirstLink(from, service);
438 // also need to do it in the service itself
439 // shoudl this be done here??
440 Element service_elem = (Element) GSXML.getChildByTagName(response, GSXML.SERVICE_ELEM);
441 if (service_elem!= null) {
442 service_elem.setAttribute(GSXML.NAME_ATT, service);
443 }
444 }
445 from = GSPath.prependLink(from, this.cluster_name);
446 response.setAttribute(GSXML.FROM_ATT, from);
447 mainResult.appendChild(this.doc.importNode(response, true));
448 }
449
450 } // else
451
452
453 } // for each request
454 return mainResult;
455 }
456
457 /** handles requests made to the ServiceCluster itself
458 *
459 * @param req - the request Element- <request>
460 * @return the result Element - should be <response>
461 */
462 protected Element processMessage(Element request) {
463
464 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
465 response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
466 String type = request.getAttribute(GSXML.TYPE_ATT);
467 String lang = request.getAttribute(GSXML.LANG_ATT);
468 response.setAttribute(GSXML.TYPE_ATT, type);
469
470 if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE)) {
471 // create the collection element
472 Element description = (Element)this.description.cloneNode(false);
473 // set collection type : mg or mgpp
474 description.setAttribute(GSXML.TYPE_ATT, col_type);
475
476 response.appendChild(description);
477 // check the param list
478 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
479 if (param_list == null) {
480 addAllDisplayInfo(description, lang);
481 description.appendChild(this.service_list);
482 description.appendChild(this.metadata_list);
483 description.appendChild(this.plugin_item_list);
484 return response;
485 }
486
487 // go through the param list and see what components are wanted
488 NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
489 for (int i=0; i<params.getLength(); i++) {
490
491 Element param = (Element)params.item(i);
492 // Identify the structure information desired
493 if (param.getAttribute(GSXML.NAME_ATT).equals(GSXML.SUBSET_PARAM)) {
494 String info = param.getAttribute(GSXML.VALUE_ATT);
495 if (info.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
496 description.appendChild(this.service_list);
497 } else if (info.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
498 description.appendChild(metadata_list);
499 } else if (info.equals(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER)) {
500 addAllDisplayInfo(description, lang);
501 } else if (info.equals(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER)) {
502 description.appendChild(plugin_item_list);
503 }
504 }
505 }
506 return response;
507 }
508
509 if (type.equals(GSXML.REQUEST_TYPE_SYSTEM)) {
510 response = processSystemRequest(request);
511 } else { // unknown type
512 logger.error("cant handle request of type "+ type);
513
514 }
515 return response;
516 }
517
518 protected Element processSystemRequest(Element request) {
519
520 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
521 response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
522 response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_SYSTEM);
523
524 // a list of system requests - should put any error messages
525 // or success messages into response
526 NodeList commands = request.getElementsByTagName(GSXML.SYSTEM_ELEM);
527 String message=null;
528 for (int i=0; i<commands.getLength(); i++) {
529 // all the commands should be Elements
530 Element elem = (Element)commands.item(i);
531 String action = elem.getAttribute(GSXML.TYPE_ATT);
532 if (action.equals(GSXML.SYSTEM_TYPE_CONFIGURE)) {
533 String subset = elem.getAttribute(GSXML.SYSTEM_SUBSET_ATT);
534 if (subset.equals("")) {
535 // need to reconfigure the service cluster
536
537 if (this.configure()) {
538 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " reconfigured");
539 response.appendChild(s);
540
541 } else {
542 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " could not be reconfigured");
543 response.appendChild(s);
544 }
545 } else if (this.configureSubset(subset)) {
546 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " "+subset+" reconfigured");
547 response.appendChild(s);
548 } else {
549 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " "+subset + " could not be reconfigured");
550 response.appendChild(s);
551 }
552 continue;
553 } // configure action
554
555 String module_name = elem.getAttribute(GSXML.SYSTEM_MODULE_NAME_ATT);
556 String module_type = elem.getAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT);
557 if (action.equals(GSXML.SYSTEM_TYPE_ACTIVATE)) {
558 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, "activate action not yet implemented - does it even make sense in this context??");
559 response.appendChild(s);
560 } else if (action.equals(GSXML.SYSTEM_TYPE_DEACTIVATE)) {
561 if (module_type.equals(GSXML.SERVICE_ELEM)) {
562 // deactivate the service
563 // remove from service_map
564 this.service_map.remove(module_name);
565 Element service_elem = GSXML.getNamedElement(this.service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, module_name);
566 service_list.removeChild(service_elem);
567 message = module_type+": "+module_name+" deactivated";
568 } else {
569 message = "can't deactivate "+module_type+" type modules!";}
570 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message);
571 response.appendChild(s);
572 } else {
573 logger.error("cant process system request, action "+action);
574 continue;
575 }
576 } // for each command
577 return response;
578 }
579
580 /**
581 * do a configure on only part of the collection
582 */
583 protected boolean configureSubset(String subset) {
584
585 File configFile = new File(GSFile.siteConfigFile(this.site_home));
586 if (!configFile.exists() ) {
587 logger.error("site config file: "+configFile.getPath()+" not found!");
588 // wont be able to do any of the requests
589 return false;
590
591 }
592
593 Document site_config_doc = this.converter.getDOM(configFile);
594 if (site_config_doc == null) {
595 logger.error("could not read in site config file: "+configFile.getPath());
596 return false;
597 }
598
599 Element site_config_elem = site_config_doc.getDocumentElement();
600 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);
601 if (cluster_config_elem == null) {
602 logger.error("site config file: "+configFile.getPath()+" has no element for cluster "+this.cluster_name);
603 // wont be able to do any of teh requests
604 return false;
605
606 }
607 if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
608 Element service_rack_list = (Element)GSXML.getChildByTagName(cluster_config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
609
610 return configureServiceRack(service_rack_list, null);
611 } else if (subset.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
612 this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
613 Element metadata_list = (Element)GSXML.getChildByTagName(cluster_config_elem, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
614 return addMetadata(metadata_list);
615 } else if (subset.equals(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER)) {
616 this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
617 Element import_list = (Element)GSXML.getChildByTagName(cluster_config_elem,GSXML.IMPORT_ELEM);
618 if (import_list != null)
619 {
620 Element plugin_item_list = (Element)GSXML.getChildByTagName(cluster_config_elem,GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
621 return addPlugins(plugin_item_list);
622 }
623 else
624 return false;
625 } else {
626 logger.error("cannot process system request, configure "+subset);
627 return false;
628 }
629
630 }
631
632
633 protected boolean addAllDisplayInfo(Element description, String lang) {
634
635 NodeList items = this.display_item_list.getChildNodes();
636 for (int i=0; i<items.getLength(); i++) { // for each key
637 Element m = (Element) items.item(i);
638 // find the child with the correct language
639 Element new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang);
640 if (new_m==null && lang != DEFAULT_LANG) {
641 // use the default lang
642 new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG);
643 }
644 if (new_m==null) {
645 // just get the first one
646 new_m = (Element)GSXML.getChildByTagName(m, GSXML.DISPLAY_TEXT_ELEM);
647 }
648 description.appendChild(new_m.cloneNode(true));
649 }
650 return true;
651
652 }
653
654
655 protected Element getDisplayTextElement(String key, String lang) {
656
657 Element this_item = GSXML.getNamedElement(this.display_item_list, GSXML.DISPLAY_TEXT_ELEM, GSXML.NAME_ATT, key);
658 if (this_item == null) {
659 return null;
660 }
661
662 Element this_lang = GSXML.getNamedElement(this_item, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang);
663 if (this_lang == null && lang != DEFAULT_LANG) {
664 // try the default
665 this_lang = GSXML.getNamedElement(this_item, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG);
666 }
667 if (this_lang == null) {
668 // just return the first one
669 return GSXML.getFirstElementChild(this_item);//(Element)this_item.getFirstChild().cloneNode(true);
670 }
671 return (Element)this_lang.cloneNode(true);
672
673 }
674 public HashMap getServiceMap() {
675 return service_map;
676 }
677}
678
679
680
681
682
683
Note: See TracBrowser for help on using the repository browser.