Changeset 28856
- Timestamp:
- 2014-02-27T13:53:11+13:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java
r28853 r28856 55 55 * 56 56 * 57 * @author Katherine Don58 * @version $Revision$59 * @see ModuleInterface60 * @see Collection61 * @see ServiceRack62 * @see Communicator63 *64 57 * Since some service classes are moved into a separate directory in order 65 58 * for them to be checked out from a different repository, we modify the … … 84 77 protected HashMap<String, ModuleInterface> module_map = null; 85 78 86 /** container Document to create XML Nodes */87 protected Document doc = null;88 79 /** the full description of this site */ 89 80 … … 121 112 { 122 113 this.converter = new XMLConverter(); 123 this.doc = this.converter.newDOM();124 114 } 125 115 … … 245 235 { 246 236 237 Document doc = this.converter.newDOM(); 247 238 Element message = this.converter.nodeToElement(message_node); 248 239 … … 256 247 NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM); 257 248 258 Element mainResult = this.doc.createElement(GSXML.MESSAGE_ELEM);249 Element mainResult = doc.createElement(GSXML.MESSAGE_ELEM); 259 250 260 251 // empty request … … 264 255 return mainResult; 265 256 } 266 267 Document message_doc = message.getOwnerDocument();268 257 269 258 // for now, just process each request one by one, and append the results to mainResult … … 298 287 if (result != null) 299 288 { 300 mainResult.appendChild( this.doc.importNode(result, true));289 mainResult.appendChild(doc.importNode(result, true)); 301 290 } 302 291 } … … 311 300 { 312 301 // why can't we do this outside the loop?? 313 Element mess = this.doc.createElement(GSXML.MESSAGE_ELEM);314 Element copied_request = (Element) this.doc.importNode(req, true);302 Element mess = doc.createElement(GSXML.MESSAGE_ELEM); 303 Element copied_request = (Element) doc.importNode(req, true); 315 304 mess.appendChild(copied_request); 316 305 … … 330 319 if (res != null) 331 320 { 332 mainResult.appendChild( this.doc.importNode(res, true));321 mainResult.appendChild(doc.importNode(res, true)); 333 322 } 334 323 } … … 336 325 { 337 326 // add in a place holder response 338 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);327 Element response = doc.createElement(GSXML.RESPONSE_ELEM); 339 328 response.setAttribute(GSXML.FROM_ATT, this_mod); 340 329 mainResult.appendChild(response); … … 475 464 476 465 // load up the services: serviceRackList 477 this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER); 466 Document doc = this.converter.newDOM(); 467 this.service_list = doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER); 478 468 Element service_rack_list_elem = (Element) GSXML.getChildByTagName(config_info, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER); 479 469 configureServices(service_rack_list_elem); 480 470 481 471 // load up the service clusters 482 this.cluster_list = this.doc.createElement(GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER);472 this.cluster_list = doc.createElement(GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER); 483 473 Element cluster_list_elem = (Element) GSXML.getChildByTagName(config_info, GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER); 484 474 configureClusters(cluster_list_elem); 485 475 486 476 // load up the collections 487 this.collection_list = this.doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);488 this.private_collection_list = this.doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);489 this.oai_collection_list = this.doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);477 this.collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 478 this.private_collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 479 this.oai_collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 490 480 configureCollections(); 491 481 492 482 // load up the external sites - this also adds their services/clusters/collections to the other lists - so must be done last 493 this.site_list = this.doc.createElement(GSXML.SITE_ELEM + GSXML.LIST_MODIFIER);483 this.site_list = doc.createElement(GSXML.SITE_ELEM + GSXML.LIST_MODIFIER); 494 484 Element site_list_elem = (Element) GSXML.getChildByTagName(config_info, GSXML.SITE_ELEM + GSXML.LIST_MODIFIER); 495 485 configureExternalSites(site_list_elem); 496 486 497 487 // load up the site metadata 498 this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);488 this.metadata_list = doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 499 489 Element metadata_list_elem = (Element) GSXML.getChildByTagName(config_info, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 500 490 loadMetadata(metadata_list_elem); … … 522 512 return true; 523 513 } 524 525 Element service_message = this.doc.createElement(GSXML.MESSAGE_ELEM);526 Element service_request = GSXML.createBasicRequest( this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", new UserContext());514 Document doc = this.converter.newDOM(); 515 Element service_message = doc.createElement(GSXML.MESSAGE_ELEM); 516 Element service_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", new UserContext()); 527 517 service_message.appendChild(service_request); 528 518 … … 573 563 else 574 564 { 565 Document service_list_doc = this.service_list.getOwnerDocument(); 575 566 for (int j = 0; j < services.getLength(); j++) 576 567 { … … 580 571 581 572 // add short info to service_list_ XML 582 this.service_list.appendChild( this.doc.importNode(services.item(j), true));573 this.service_list.appendChild(service_list_doc.importNode(services.item(j), true)); 583 574 } 584 575 } … … 610 601 } 611 602 603 Document doc = this.cluster_list.getOwnerDocument(); 612 604 for (int i = 0; i < service_clusters.getLength(); i++) 613 605 { … … 628 620 this.module_map.put(name, sc); // this replaces the old one if there was one already present 629 621 //add short info to cluster list 630 Element e = this.doc.createElement(GSXML.CLUSTER_ELEM);622 Element e = doc.createElement(GSXML.CLUSTER_ELEM); 631 623 e.setAttribute(GSXML.NAME_ATT, name); 632 624 this.cluster_list.appendChild(e); … … 688 680 689 681 logger.info("Activating collection: " + col_name + "."); 690 682 Document doc = this.collection_list.getOwnerDocument(); 691 683 // Look for the etc/collectionInit.xml file, and see what sort of Collection to load 692 684 Collection c = null; … … 730 722 // add to list of collections 731 723 this.module_map.put(col_name, c); 732 Element e = this.doc.createElement(GSXML.COLLECTION_ELEM);724 Element e = doc.createElement(GSXML.COLLECTION_ELEM); 733 725 e.setAttribute(GSXML.NAME_ATT, col_name); 734 726 … … 741 733 if (c.hasOAI()) 742 734 { 743 Element ane = this.doc.createElement(GSXML.COLLECTION_ELEM);735 Element ane = doc.createElement(GSXML.COLLECTION_ELEM); 744 736 ane.setAttribute(GSXML.NAME_ATT, col_name); 745 737 ane.setAttribute(OAIXML.LASTMODIFIED, "" + c.getLastmodified()); … … 859 851 // add to map of modules 860 852 this.module_map.put(name, comm); 861 this.site_list.appendChild(this. doc.importNode(site_elem, true));853 this.site_list.appendChild(this.site_list.getOwnerDocument().importNode(site_elem, true)); 862 854 // need to get collection list and service 863 855 // list from here- if the site isn't up yet, the site will … … 886 878 protected boolean loadMetadata(Element config_metadata_list) 887 879 { 888 880 889 881 // load up the sites 890 882 logger.info("loading site metadata..."); … … 902 894 } 903 895 896 Document doc = this.metadata_list.getOwnerDocument(); 904 897 for (int i = 0; i < metadata.getLength(); i++) 905 898 { 906 899 Element s = (Element) metadata.item(i); 907 this.metadata_list.appendChild( this.doc.importNode(s, true));900 this.metadata_list.appendChild(doc.importNode(s, true)); 908 901 } 909 902 return true; … … 923 916 924 917 logger.info(" getting info from site:" + site_name); 925 926 Element info_request = this.doc.createElement(GSXML.MESSAGE_ELEM);927 Element req = GSXML.createBasicRequest( this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", new UserContext());918 Document doc = this.converter.newDOM(); 919 Element info_request = doc.createElement(GSXML.MESSAGE_ELEM); 920 Element req = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", new UserContext()); 928 921 info_request.appendChild(req); 929 922 … … 948 941 // other collections ?? 949 942 e.setAttribute(GSXML.NAME_ATT, GSPath.prependLink(col_name, site_name)); 950 this.collection_list.appendChild( this.doc.importNode(e, true));943 this.collection_list.appendChild(doc.importNode(e, true)); 951 944 } 952 945 } … … 961 954 String serv_name = e.getAttribute(GSXML.NAME_ATT); 962 955 e.setAttribute(GSXML.NAME_ATT, GSPath.prependLink(serv_name, site_name)); 963 this.service_list.appendChild( this.doc.importNode(e, true));956 this.service_list.appendChild(doc.importNode(e, true)); 964 957 } 965 958 } … … 974 967 String clus_name = e.getAttribute(GSXML.NAME_ATT); 975 968 e.setAttribute(GSXML.NAME_ATT, GSPath.prependLink(clus_name, site_name)); 976 this.cluster_list.appendChild( this.doc.importNode(e, true));969 this.cluster_list.appendChild(doc.importNode(e, true)); 977 970 } 978 971 } … … 1090 1083 1091 1084 // message for self, should be type=describe/configure at this stage 1085 Document doc = this.converter.newDOM(); 1092 1086 String type = req.getAttribute(GSXML.TYPE_ATT); 1093 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);1087 Element response = doc.createElement(GSXML.RESPONSE_ELEM); 1094 1088 response.setAttribute(GSXML.FROM_ATT, ""); 1095 1089 if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE)) … … 1100 1094 if (param_list == null) 1101 1095 { 1102 response.appendChild(this.collection_list);1103 response.appendChild( this.cluster_list);1104 response.appendChild( this.site_list);1105 response.appendChild( this.service_list);1106 response.appendChild( this.metadata_list);1096 response.appendChild(doc.importNode(this.collection_list, true)); 1097 response.appendChild(doc.importNode(this.cluster_list, true)); 1098 response.appendChild(doc.importNode(this.site_list, true)); 1099 response.appendChild(doc.importNode(this.service_list, true)); 1100 response.appendChild(doc.importNode(this.metadata_list, true)); 1107 1101 return response; 1108 1102 } … … 1121 1115 if (info.equals(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER)) 1122 1116 { 1123 response.appendChild( this.collection_list);1117 response.appendChild(doc.importNode(this.collection_list, true)); 1124 1118 } 1125 1119 else if (info.equals(GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER)) 1126 1120 { 1127 response.appendChild( this.cluster_list);1121 response.appendChild(doc.importNode(this.cluster_list, true)); 1128 1122 } 1129 1123 else if (info.equals(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER)) 1130 1124 { 1131 response.appendChild( this.service_list);1125 response.appendChild(doc.importNode(this.service_list, true)); 1132 1126 } 1133 1127 else if (info.equals(GSXML.SITE_ELEM + GSXML.LIST_MODIFIER)) 1134 1128 { 1135 response.appendChild( this.site_list);1129 response.appendChild(doc.importNode(this.site_list, true)); 1136 1130 } 1137 1131 else if (info.equals(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER)) 1138 1132 { 1139 response.appendChild( this.metadata_list);1133 response.appendChild(doc.importNode(this.metadata_list, true)); 1140 1134 } 1141 1135 } … … 1150 1144 //this is the oai receptionist asking for a list of oai-support collections 1151 1145 response.setAttribute(GSXML.TYPE_ATT, OAIXML.OAI_SET_LIST); 1152 response.appendChild( this.oai_collection_list);1146 response.appendChild(doc.importNode(this.oai_collection_list, true)); 1153 1147 return response; 1154 1148 } … … 1191 1185 } 1192 1186 } 1193 Element s = GSXML.createTextElement( this.doc, GSXML.STATUS_ELEM, message);1187 Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, message); 1194 1188 response.appendChild(s); 1195 1189 } 1196 1190 //else if (action.equals(GSXML.SYSTEM_TYPE_ISPERSISTENT)) { 1197 // Element s = GSXML.createTextElement( this.doc, GSXML.STATUS_ELEM, "Persistent: true.");1191 // Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, "Persistent: true."); 1198 1192 // response.appendChild(s); 1199 1193 //} … … 1205 1199 // need to reconfigure the MR 1206 1200 this.configureLocalSite(); 1207 Element s = GSXML.createTextElement( this.doc, GSXML.STATUS_ELEM, "MessageRouter reconfigured successfully");1201 Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, "MessageRouter reconfigured successfully"); 1208 1202 response.appendChild(s); 1209 1203 … … 1268 1262 message = "Error in reconfiguring " + subset; 1269 1263 } 1270 Element s = GSXML.createTextElement( this.doc, GSXML.STATUS_ELEM, message);1264 Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, message); 1271 1265 response.appendChild(s); 1272 1266 } … … 1283 1277 if (success) 1284 1278 { 1285 Element s = GSXML.createTextElement( this.doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " deactivated", GSXML.SYSTEM_TYPE_DEACTIVATE, GSXML.SUCCESS);1279 Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " deactivated", GSXML.SYSTEM_TYPE_DEACTIVATE, GSXML.SUCCESS); 1286 1280 response.appendChild(s); 1287 1281 } 1288 1282 else 1289 1283 { 1290 Element s = GSXML.createTextElement( this.doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " could not be deactivated", GSXML.SYSTEM_TYPE_DEACTIVATE, GSXML.ERROR);1284 Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " could not be deactivated", GSXML.SYSTEM_TYPE_DEACTIVATE, GSXML.ERROR); 1291 1285 response.appendChild(s); 1292 1286 } … … 1312 1306 if (success) 1313 1307 { 1314 Element s = GSXML.createTextElement( this.doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " activated", GSXML.SYSTEM_TYPE_ACTIVATE, GSXML.SUCCESS);1308 Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " activated", GSXML.SYSTEM_TYPE_ACTIVATE, GSXML.SUCCESS); 1315 1309 response.appendChild(s); 1316 1310 } 1317 1311 else 1318 1312 { 1319 Element s = GSXML.createTextElement( this.doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " could not be activated", GSXML.SYSTEM_TYPE_ACTIVATE, GSXML.ERROR);1313 Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " could not be activated", GSXML.SYSTEM_TYPE_ACTIVATE, GSXML.ERROR); 1320 1314 response.appendChild(s); 1321 1315 } … … 1340 1334 protected Element modifyMessages(Element request, Element message, Element result) 1341 1335 { 1342 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM); 1336 Document doc = this.converter.newDOM(); 1337 Element response = doc.createElement(GSXML.RESPONSE_ELEM); 1343 1338 response.setAttribute(GSXML.FROM_ATT, ""); 1344 1339 response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_MESSAGING);
Note:
See TracChangeset
for help on using the changeset viewer.