Changeset 3847
- Timestamp:
- 2003-03-11T16:49:45+13:00 (21 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3/collection
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/Collection.java
r3512 r3847 44 44 extends ServiceCluster { 45 45 46 protected XMLTransformer transformer_ = null; 46 47 /** same as setClusterName */ 47 48 public void setCollectionName(String name) { … … 52 53 service_map_ = new HashMap(); 53 54 converter_ = new XMLConverter(); 55 transformer_ = new XMLTransformer(); 54 56 doc_ = converter_.newDOM(); 55 57 description_ = doc_.createElement(GSXML.COLLECTION_ELEM); 56 58 service_info_ = doc_.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER); 57 59 meta_info_ = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 60 description_.appendChild(meta_info_); 61 description_.appendChild(service_info_); 58 62 59 63 } … … 76 80 } 77 81 // read the collection build configuration file 78 File config_file_ = new File(GSFile.collectionBuildConfigFile(site_home_, cluster_name_)); 79 80 if (!config_file_.exists()) { 81 System.err.println(config_file_+" does not exist"); 82 File build_config_file = new File(GSFile.collectionBuildConfigFile(site_home_, cluster_name_)); 83 File coll_config_file = new File(GSFile.collectionConfigFile(site_home_, cluster_name_)); 84 85 if (!coll_config_file.exists()) { 86 System.err.println(coll_config_file+" does not exist"); 82 87 System.err.println("couldn't configure collection: "+cluster_name_); 83 88 return false; 84 89 } 85 86 Document doc = converter_.getDOM(config_file_); 87 Element e = doc.getDocumentElement(); 88 89 return configure(e); 90 91 } 92 93 90 91 if (!build_config_file.exists()) { 92 System.err.println(build_config_file+" does not exist"); 93 System.err.println("couldn't configure collection: "+cluster_name_); 94 return false; 95 } 96 97 // get the xml for both files 98 Element coll_config_xml = converter_.getDOM(coll_config_file).getDocumentElement(); 99 Element build_config_xml = converter_.getDOM(build_config_file).getDocumentElement(); 100 101 // process the metadata 102 Element meta_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 103 configureMetadata(meta_list); 104 meta_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 105 configureMetadata(meta_list); 106 107 // now do the services 108 109 Element service_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER); 110 configureServiceRack(service_list, coll_config_xml); 111 112 //System.out.println("description="); 113 //System.out.println(converter_.getString(description_)); 114 return true; 115 116 } 117 118 /** we need to overwrite this, cos in a collection, some of the info for the service racks is in the collectionConfig.xml file - this needs to be added to the xml for the service rack before configure is called */ 119 protected boolean configureServiceRack(Element service_rack_list, 120 Element coll_config_xml) { 121 122 // create all the services 123 NodeList nodes = service_rack_list.getElementsByTagName(GSXML.SERVICE_CLASS_ELEM); 124 if (nodes.getLength()==0) { 125 System.err.println("Cluster configuration error: cluster "+cluster_name_+" has no service modules!"); 126 return false; 127 } 128 129 for(int i=0; i<nodes.getLength(); i++) { 130 131 // the xml request to send to the serviceRack to query what 132 // services it provides 133 Element message = doc_.createElement(GSXML.MESSAGE_ELEM); 134 Element request = doc_.createElement(GSXML.REQUEST_ELEM); 135 message.appendChild(request); 136 request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 137 request.setAttribute(GSXML.INFO_ATT, GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER); 138 139 140 Element n = (Element)nodes.item(i); 141 String servicetype = n.getAttribute(GSXML.NAME_ATT); 142 143 addExtraServiceRackInfo(n, coll_config_xml); // add in any display or format stuff from collectionConfig.xml 144 145 try { 146 ServiceRack s = (ServiceRack)Class.forName("org.greenstone.gsdl3.service."+servicetype).newInstance(); 147 148 s.setSiteHome(site_home_); 149 s.setClusterName(cluster_name_); 150 s.setMessageRouter(router_); 151 // pass the xml node to the service for configuration 152 s.configure(n); 153 154 // find out the supported service types for this service module 155 Node types = s.process(message); 156 NodeList typenodes = ((Element)types).getElementsByTagName(GSXML.SERVICE_ELEM); 157 158 for (int j=0; j<typenodes.getLength();j++) { 159 String service = ((Element) typenodes.item(j)).getAttribute(GSXML.NAME_ATT); 160 service_map_.put(service, s); 161 162 // also add info to the ServiceInfo XML element 163 service_info_.appendChild(doc_.importNode(typenodes.item(j), true)); 164 } 165 } catch (Exception e) { 166 System.err.println("ServiceCluster Error: configure exception: couldn't create service module:org.greenstone.gsdl3.service."+servicetype+"\n"+e.getMessage() + e.getClass() ); 167 e.printStackTrace(); 168 //return false; 169 } 170 171 } 172 // add elements to description 173 description_.appendChild(service_info_); 174 175 return true; 176 177 178 } 179 180 /** the service rack desription in buildConfig.xml is not complete - 181 * any display or format info specified in the collectionConfig.xml file 182 * is not copied over. So that info needs to be added to the service rack 183 * description before configuring the service. 184 * extra info is possible for index and classifier elements so far */ 185 protected boolean addExtraServiceRackInfo(Element service_rack_info, 186 Element coll_config_xml) { 187 188 NodeList indexes = service_rack_info.getElementsByTagName(GSXML.INDEX_ELEM); 189 190 if (indexes !=null) { 191 Element config_search = (Element)GSXML.getChildByTagName(coll_config_xml, 192 GSXML.SEARCH_ELEM); 193 addFormatInfo(indexes, GSXML.INDEX_ELEM, config_search); 194 195 } 196 197 NodeList classifiers = service_rack_info.getElementsByTagName(GSXML.CLASSIFIER_ELEM); 198 if (classifiers !=null) { 199 Element config_browse = (Element)GSXML.getChildByTagName(coll_config_xml, 200 GSXML.BROWSE_ELEM); 201 202 addFormatInfo(classifiers, GSXML.CLASSIFIER_ELEM, config_browse); 203 204 } 205 return true; 206 } 207 208 protected boolean addFormatInfo(NodeList node_list, String node_name, 209 Element extra_info) { 210 211 //Document doc = node_list.item(0).getOwnerDocument(); 212 for (int i=0; i<node_list.getLength();i++) { 213 Element node = (Element)node_list.item(i); 214 String name = node.getAttribute(GSXML.NAME_ATT); 215 Document doc = node.getOwnerDocument(); 216 Element node_extra = GSXML.getNamedElement(extra_info, 217 node_name, 218 GSXML.NAME_ATT, 219 name); 220 if (node_extra == null) { 221 System.out.println("haven't found extra info for "+node_name+" named "+name); 222 } 223 // get the display elements if any - displayName 224 NodeList display_names = node_extra.getElementsByTagName(GSXML.DISPLAYNAME_ELEM); 225 if (display_names !=null) { 226 Element display = doc.createElement(GSXML.DISPLAY_ELEM); 227 for (int j=0; j<display_names.getLength(); j++) { 228 Element e = (Element)display_names.item(j); 229 230 Element display_name = GSXML.createTextElement(doc, GSXML.DISPLAY_NAME_ELEM, GSXML.getNodeText(e)); 231 display_name.setAttribute(GSXML.LANG_ATT, e.getAttribute(GSXML.LANG_ATT)); 232 display.appendChild(display_name); 233 } 234 node.appendChild(display); 235 } 236 237 // get the format element if any 238 Element format = (Element)GSXML.getChildByTagName(node_extra, GSXML.FORMAT_ELEM); 239 if (format==null) { 240 format = (Element)GSXML.getChildByTagName(extra_info, 241 GSXML.FORMAT_ELEM); 242 } 243 if (format!=null) { // append to index info 244 245 // find the transform xsl file 246 String transform_file = GSFile.configFileFormatStylesheet(); 247 if (transform_file.equals("")) { 248 System.out.println("Collection: couldn't find the config file format transform file!!"); 249 // just append the original instead 250 node.appendChild(doc.importNode(format, true)); 251 } else { 252 253 Document stylesheet = converter_.getDOM(new File(transform_file)); 254 Element new_format = (Element)transformer_.transform(stylesheet, format); 255 256 node.appendChild(doc.importNode(new_format, true)); 257 } 258 } 259 } 260 return true; 261 } 262 263 94 264 } 95 265 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java
r3647 r3847 94 94 service_info_ = doc_.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER); 95 95 meta_info_ = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 96 description_.appendChild(meta_info_); 97 description_.appendChild(service_info_); 96 98 97 99 } … … 135 137 return this.configure(sc); 136 138 } 139 137 140 138 public boolean configure(Element cluster_info) { 141 public boolean configure(Element service_cluster_info) { 142 143 // do the metadata 144 145 // get the metadata - for now just add it to the list 146 Element meta_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 147 if (meta_list !=null) { 148 if (!configureMetadata(meta_list)) { 149 150 System.err.println("couldn't configure the metadata"); 151 } 152 } 153 154 // do the service racks 155 Element service_rack_list = (Element)GSXML.getChildByTagName(service_cluster_info, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER); 156 if (service_rack_list == null) { 157 // is this an error? could you ever have a service cluster 158 // without service racks??? 159 System.err.println("cluster has no service racks!!"); 160 } else { 161 162 boolean result = configureServiceRack(service_rack_list); 163 if (result == false) { 164 System.err.println("couldn't configure the service racks!!"); 165 return false; 166 } 167 } 168 169 return true; 170 } 171 172 protected boolean configureMetadata(Element metadata_list) { 173 NodeList metanodes = metadata_list.getElementsByTagName(GSXML.METADATA_ELEM); 174 if (metanodes.getLength()>0) { 175 for(int k=0; k<metanodes.getLength(); k++) { 176 meta_info_.appendChild(doc_.importNode(metanodes.item(k),true)); 177 } 178 } 179 return true; 180 } 181 182 183 protected boolean configureServiceRack(Element service_rack_list) { 139 184 140 185 // create all the services 141 NodeList nodes = cluster_info.getElementsByTagName(GSXML.SERVICE_CLASS_ELEM);186 NodeList nodes = service_rack_list.getElementsByTagName(GSXML.SERVICE_CLASS_ELEM); 142 187 if (nodes.getLength()==0) { 143 188 System.err.println("Cluster configuration error: cluster "+cluster_name_+" has no service modules!"); … … 147 192 for(int i=0; i<nodes.getLength(); i++) { 148 193 149 // the xml request to send to the service sImplto query what194 // the xml request to send to the serviceRack to query what 150 195 // services it provides 151 196 Element message = doc_.createElement(GSXML.MESSAGE_ELEM); … … 186 231 187 232 } 188 189 // get the metadata - for now just add it to the list190 Element meta_list = (Element) GSXML.getChildByTagName(cluster_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);191 NodeList metanodes = meta_list.getElementsByTagName(GSXML.METADATA_ELEM);192 193 if (metanodes.getLength()>0) {194 for(int k=0; k<metanodes.getLength(); k++) {195 meta_info_.appendChild(doc_.importNode(metanodes.item(k),true));196 }197 }198 199 233 // add elements to description 200 234 description_.appendChild(service_info_); 201 description_.appendChild(meta_info_);202 235 return true; 203 236 204 237 205 238 } 239 206 240 207 241 /**
Note:
See TracChangeset
for help on using the changeset viewer.