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

Last change on this file since 23405 was 23405, checked in by sjb48, 13 years ago

FormatAction constructs message containing format string that is sent to the collection. The message knows the service, and if it is the browse service, then it also knows the classifer list number.

  • Property svn:keywords set to Author Date Id Revision
File size: 25.2 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: 23405 $
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 (!configureServiceRackList(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 configureServiceRackList(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_FORMAT_STRING)) {
513 logger.error("Received format string request");
514 String service = request.getAttribute("service");
515 logger.error("Service is " + service);
516 String classifier = null;
517 if(service.equals("ClassifierBrowse"))
518 {
519 classifier = request.getAttribute("classifier");
520 logger.error("Classifier is " + classifier);
521 }
522 Element format_element = (Element) GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM);
523 String format_string = GSXML.getNodeText(format_element);
524 logger.error("Format string: " + format_string);
525 logger.error("Config file location = " + GSFile.collectionConfigFile(this.site_home, this.cluster_name));
526 }
527 if (type.equals(GSXML.REQUEST_TYPE_SYSTEM)) {
528 response = processSystemRequest(request);
529 } else { // unknown type
530 logger.error("cant handle request of type "+ type);
531
532 }
533 return response;
534 }
535
536 protected Element processSystemRequest(Element request) {
537
538 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
539 response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
540 response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_SYSTEM);
541
542 // a list of system requests - should put any error messages
543 // or success messages into response
544 NodeList commands = request.getElementsByTagName(GSXML.SYSTEM_ELEM);
545 String message=null;
546 for (int i=0; i<commands.getLength(); i++) {
547 // all the commands should be Elements
548 Element elem = (Element)commands.item(i);
549 String action = elem.getAttribute(GSXML.TYPE_ATT);
550 if (action.equals(GSXML.SYSTEM_TYPE_CONFIGURE)) {
551 String subset = elem.getAttribute(GSXML.SYSTEM_SUBSET_ATT);
552 if (subset.equals("")) {
553 // need to reconfigure the service cluster
554
555 if (this.configure()) {
556 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " reconfigured");
557 response.appendChild(s);
558
559 } else {
560 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " could not be reconfigured");
561 response.appendChild(s);
562 }
563 } else if (this.configureSubset(subset)) {
564 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " "+subset+" reconfigured");
565 response.appendChild(s);
566 } else {
567 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " "+subset + " could not be reconfigured");
568 response.appendChild(s);
569 }
570 continue;
571 } // configure action
572
573 String module_name = elem.getAttribute(GSXML.SYSTEM_MODULE_NAME_ATT);
574 String module_type = elem.getAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT);
575 if (action.equals(GSXML.SYSTEM_TYPE_ACTIVATE)) {
576 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, "activate action not yet implemented - does it even make sense in this context??");
577 response.appendChild(s);
578 } else if (action.equals(GSXML.SYSTEM_TYPE_DEACTIVATE)) {
579 if (module_type.equals(GSXML.SERVICE_ELEM)) {
580 // deactivate the service
581 // remove from service_map
582 this.service_map.remove(module_name);
583 Element service_elem = GSXML.getNamedElement(this.service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, module_name);
584 service_list.removeChild(service_elem);
585 message = module_type+": "+module_name+" deactivated";
586 } else {
587 message = "can't deactivate "+module_type+" type modules!";}
588 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message);
589 response.appendChild(s);
590 } else {
591 logger.error("cant process system request, action "+action);
592 continue;
593 }
594 } // for each command
595 return response;
596 }
597
598 /**
599 * do a configure on only part of the collection
600 */
601 protected boolean configureSubset(String subset) {
602
603 File configFile = new File(GSFile.siteConfigFile(this.site_home));
604 if (!configFile.exists() ) {
605 logger.error("site config file: "+configFile.getPath()+" not found!");
606 // wont be able to do any of the requests
607 return false;
608
609 }
610
611 Document site_config_doc = this.converter.getDOM(configFile);
612 if (site_config_doc == null) {
613 logger.error("could not read in site config file: "+configFile.getPath());
614 return false;
615 }
616
617 Element site_config_elem = site_config_doc.getDocumentElement();
618 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);
619 if (cluster_config_elem == null) {
620 logger.error("site config file: "+configFile.getPath()+" has no element for cluster "+this.cluster_name);
621 // wont be able to do any of teh requests
622 return false;
623
624 }
625 if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
626 Element service_rack_list = (Element)GSXML.getChildByTagName(cluster_config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
627 clearServices();
628 return configureServiceRackList(service_rack_list, null);
629 } else if (subset.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
630 this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
631 Element metadata_list = (Element)GSXML.getChildByTagName(cluster_config_elem, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
632 return addMetadata(metadata_list);
633 } else if (subset.equals(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER)) {
634 this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
635 Element import_list = (Element)GSXML.getChildByTagName(cluster_config_elem,GSXML.IMPORT_ELEM);
636 if (import_list != null)
637 {
638 Element plugin_item_list = (Element)GSXML.getChildByTagName(cluster_config_elem,GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
639 return addPlugins(plugin_item_list);
640 }
641 else
642 return false;
643 } else {
644 logger.error("cannot process system request, configure "+subset);
645 return false;
646 }
647
648 }
649
650
651 protected boolean addAllDisplayInfo(Element description, String lang) {
652
653 NodeList items = this.display_item_list.getChildNodes();
654 for (int i=0; i<items.getLength(); i++) { // for each key
655 Element m = (Element) items.item(i);
656 // find the child with the correct language
657 Element new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang);
658 if (new_m==null && lang != DEFAULT_LANG) {
659 // use the default lang
660 new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG);
661 }
662 if (new_m==null) {
663 // just get the first one
664 new_m = (Element)GSXML.getChildByTagName(m, GSXML.DISPLAY_TEXT_ELEM);
665 }
666 description.appendChild(new_m.cloneNode(true));
667 }
668 return true;
669
670 }
671
672
673 protected Element getDisplayTextElement(String key, String lang) {
674
675 Element this_item = GSXML.getNamedElement(this.display_item_list, GSXML.DISPLAY_TEXT_ELEM, GSXML.NAME_ATT, key);
676 if (this_item == null) {
677 return null;
678 }
679
680 Element this_lang = GSXML.getNamedElement(this_item, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang);
681 if (this_lang == null && lang != DEFAULT_LANG) {
682 // try the default
683 this_lang = GSXML.getNamedElement(this_item, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG);
684 }
685 if (this_lang == null) {
686 // just return the first one
687 return GSXML.getFirstElementChild(this_item);//(Element)this_item.getFirstChild().cloneNode(true);
688 }
689 return (Element)this_lang.cloneNode(true);
690
691 }
692 public HashMap getServiceMap() {
693 return service_map;
694 }
695}
696
697
698
699
700
701
Note: See TracBrowser for help on using the repository browser.