Changeset 7522
- Timestamp:
- 2004-06-01T17:27:14+12:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/msm/MetadataXMLFileManager.java
r7293 r7522 218 218 } 219 219 220 /*221 // returns metadata file from cache or creates a new one222 public MetadataXMLFile getDummyDocument(File file) {223 ///ystem.err.println("Get the MetadataXMLFile for " + file.getAbsolutePath());224 MetadataXMLFile metadata_xml = null;225 // Determine the name of the target files metadata.xml file.226 File metadata_file = null;227 if(file.isFile()) {228 metadata_file = new File(file.getParentFile(), StaticStrings.METADATA_XML);229 }230 else {231 metadata_file = new File(file, StaticStrings.METADATA_XML);232 }233 // Then try to retrieve it from cache. First we consider the case of a cache hit.234 if(containsKey(metadata_file)) {235 metadata_xml = (MetadataXMLFile) get(metadata_file);236 }237 else {238 metadata_xml = new MetadataXMLFile();239 put(metadata_file, metadata_xml);240 }241 return metadata_xml;242 }243 */244 245 /*246 public synchronized void dummyGetMetadata(File file) {247 String filename = null;248 if(file.isFile()) {249 filename = file.getName();250 file = file.getParentFile();251 }252 MetadataXMLFile document = getDummyDocument(file);253 }254 */255 220 256 221 /** Recover the metadata associated with a particular file. Note that this call is synchronized, so that all of the data holders don't need to be. */ … … 370 335 */ 371 336 public synchronized void metadataChanged(MSMEvent event) { 337 System.err.println("In MetadataXMLFileManager::metadataChanged(" + event + ")..."); 372 338 File file = event.getFile(); 373 339 if(file == null) { … … 396 362 // File level 397 363 if(file.isFile()) { 364 System.err.println("Calling metadata_xml.addMetadata(" + new_metadata + ")..."); 398 365 metadata_xml.addMetadata(file.getName(), new_metadata, event.getAction() == MetaEditPrompt.ACCUMULATE); 399 366 } … … 511 478 } 512 479 513 private Metadata checkCache(Metadata metadata) { 514 if(metadata != null) { 515 //if(metadata_cache.contains(metadata.getElement(), metadata.getValueNode())) { 516 // metadata = (Metadata) metadata_cache.get(metadata.getElement(), metadata.getValueNode()); 517 // System.err.println("cache contains teh value"); 518 // } 519 // the element name was used as the key 520 if(metadata_cache.contains(metadata.getElement().getElement().getAttribute("name"), metadata.getValue())) { 521 metadata = (Metadata) metadata_cache.get(metadata.getElement().getElement().getAttribute("name"), metadata.getValue()); 522 } 523 } 480 481 private Metadata checkCache(Metadata metadata) 482 { 483 Gatherer.println("Checking cache for " + metadata + "..."); 484 485 if (metadata == null) { 486 return null; 487 } 488 489 // Check if the metadata cache already contains this (element, value) pair 490 String element_name = metadata.getElement().toString(); 491 if (metadata_cache.contains(element_name, metadata.getValue())) { 492 // If so, return the cached metadata value 493 Gatherer.println("In cache!"); 494 return (Metadata) metadata_cache.get(element_name, metadata.getValue()); 495 } 496 497 // Not cached, so return the original Metadata object 524 498 return metadata; 525 499 } 526 500 527 /** A separately threaded class to load all of the current metadata.xml files. Note that files can still be loaded on demand if they're not already in the cache. Also provides the functionality to block any other thread until the loading is complete, such as is necessary when moving values about in the value tree hierarchy. */528 /*529 private class GDMLoader530 extends Thread {531 private boolean complete = false;532 private boolean dummy_load = false;533 534 GDMLoader(boolean dummy_load) {535 super("blarg");536 this.dummy_load = dummy_load;537 }538 539 540 public void run() {541 // Can't open a collections metadata when the collection isn't open!542 while(!Gatherer.c_man.ready()) {543 try {544 wait(100);545 }546 catch(Exception error) {547 }548 }549 // Now for each non-file directory in the tree, ask it to load its metadata550 ArrayList remaining = new ArrayList();551 remaining.add((FileNode)Gatherer.c_man.getRecordSet().getRoot());552 int remaining_size = 0;553 while((remaining_size = remaining.size()) > 0) {554 FileNode record = (FileNode) remaining.remove(remaining_size - 1);555 if(!record.isLeaf()) {556 ///atherer.println("Retrieving metadata.xml for " + record);557 if (this.dummy_load) {558 dummyGetMetadata(record.getFile());559 } else {560 getMetadata(record.getFile());561 }562 for(int i = 0; i < record.getChildCount(); i++) {563 remaining.add(record.getChildAt(i));564 }565 566 ///atherer.println("Retrieving metadata.xml for " + record);567 getMetadata(record.getFile());568 569 record.unmap();570 }571 record = null;572 }573 remaining = null;574 complete = true;575 }576 public void waitUntilComplete() {577 try {578 while(!complete) {579 sleep(100); // 1 second hopefully.580 }581 }582 catch(Exception error) {583 Gatherer.printStackTrace(error);584 }585 }586 }587 */588 501 589 502 protected boolean removeEldestEntry(Map.Entry eldest) {
Note:
See TracChangeset
for help on using the changeset viewer.