- Timestamp:
- 2003-06-06T15:44:35+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/msm/MetadataSet.java
r4488 r4504 196 196 /** Method to add a new metadata element to this metadata set, if and only if the element is not already present. 197 197 * @param others_element An <strong>Element</strong> we wish to add to this metadata set, that currently belongs to some other set. 198 * @param model A <strong>GValueModel</strong> value tree 198 199 * @return <i>null</i> if the add is successful, otherwise a <strong>String</strong> containing an error message (phrase key). 199 200 */ 200 public String addElement(Element others_element ) {201 public String addElement(Element others_element, GValueModel model) { 201 202 if(!containsElement(others_element.getAttribute("name"))) { 202 // First get ownership of the new element, then add it. 203 Node our_element = document.importNode(others_element, true); 203 // First get ownership of the new element, then add it. 204 Element our_element = (Element)document.importNode(others_element, true); 205 // add the value tree 204 206 root.appendChild(our_element); 207 if (model != null) { 208 addValueTree(new ElementWrapper(our_element), model); 209 } 205 210 return null; 206 211 } 207 212 else { 208 return " Element name already exists!";213 return "MSMPrompt.Name_Exists"; 209 214 } 210 215 } … … 213 218 * @param others_element An <strong>Element</strong> we wish to add to this metadata set, that currently belongs to some other set. 214 219 * @param new_name The new name to be given this element, as a <strong>String</strong>. 220 * @param model A <strong>GValueModel</strong> value tree 215 221 * @return <i>null</i> if the add is successful, otherwise a <strong>String</strong> containing an error message (phrase key). 216 222 */ 217 public String addElement(Element others_element, String new_name ) {223 public String addElement(Element others_element, String new_name, GValueModel model) { 218 224 if(!containsElement(new_name)) { 219 225 // First get ownership of the new element, then add it. 220 226 Element our_element = 221 227 (Element) document.importNode(others_element, true); 222 228 // Change name 223 229 our_element.setAttribute("name", new_name); 224 // Add it 230 // we also want to change the english identifier of this element 231 MSMUtils.setIdentifier(our_element, new_name); 232 // Add it to teh set 225 233 root.appendChild(our_element); 234 // add the value tree 235 if (model != null) { 236 addValueTree(new ElementWrapper(our_element), model); 237 } 226 238 return null; 227 239 } … … 232 244 /** Add a value tree to a given metadata element. 233 245 * @param element The <strong>ElementWrapper</strong> containing the element you wish to add a value tree for. 234 * @param value_tree The root <strong>Element</strong> of the value tree.246 * @param model A <strong>GValueModel</strong> value tree 235 247 */ 236 248 public void addValueTree(ElementWrapper element, GValueModel model) { … … 443 455 public GValueModel getValueTree(ElementWrapper element) { 444 456 GValueModel value_tree = null; 445 ///ystem.err.println("Retrieving value tree for element: " + element.toString());446 457 // Stinking hashtable get doesn't use the overridden equals. So I'll do a loop, which should be pretty small ie O(n) for n metadata elements. 447 458 for(Enumeration keys = value_trees.keys(); keys.hasMoreElements(); ) { … … 449 460 if(sibling.equals(element)) { 450 461 value_tree = (GValueModel) value_trees.get(sibling); 462 break; 451 463 } 452 464 } … … 468 480 */ 469 481 public void removeElement(Element element) { 482 // we need to remove the value tree too!! 483 removeValueTree(new ElementWrapper(element)); 470 484 root.removeChild(element); 471 485 } 472 486 /** Used to remove the value tree for a specific element. 473 487 * @param element The <strong>ElementWrapper</strong> whose tree you wish to remove. 474 * @return The <strong> Element</strong> at the root of the value tree we just removed.475 */ 476 public ElementremoveValueTree(ElementWrapper element) {488 * @return The <strong>GValueModel</strong> we just removed 489 */ 490 public GValueModel removeValueTree(ElementWrapper element) { 477 491 for(Enumeration keys = value_trees.keys(); keys.hasMoreElements(); ) { 478 492 ElementWrapper sibling = (ElementWrapper) keys.nextElement(); 479 493 if(sibling.equals(element)) { 480 Element tree_root = (Element) value_trees.get(sibling);494 GValueModel value_tree = (GValueModel) value_trees.get(sibling); 481 495 value_trees.remove(sibling); 482 return tree_root;496 return value_tree; 483 497 } 484 498 }
Note:
See TracChangeset
for help on using the changeset viewer.