Changeset 8990


Ignore:
Timestamp:
2005-02-09T17:22:09+13:00 (19 years ago)
Author:
mdewsnip
Message:

Now caches the metadata mapping so subsequent reads don't require reading the profile.xml file each time. This makes a huge difference when opening collections containing a lot of metadata that must be mapped into a metadata set.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/metadata/ProfileXMLFile.java

    r8164 r8990  
    3838    extends File
    3939{
     40    private HashMap metadata_mapping = null;
     41
     42
    4043    public ProfileXMLFile(String profile_xml_file_path)
    4144    {
     
    4447
    4548
    46     public String getMetadataElementFor(String source_metadata_element_name_full)
     49    public String getMetadataElementFor(String metadata_element_name_full)
    4750    {
    48     // Parse the profile.xml file
    49     Document document = XMLTools.parseXMLFile(this);
    50     if (document == null) {
    51         System.err.println("Error: Could not parse profile.xml file " + getAbsolutePath());
     51    if (getMetadataMapping() == null) {
    5252        return null;
    5353    }
    5454
    55     // Read all the Action elements in the file
    56     NodeList action_elements_nodelist = document.getElementsByTagName("Action");
    57     for (int i = 0; i < action_elements_nodelist.getLength(); i++) {
    58         Element current_action_element = (Element) action_elements_nodelist.item(i);
    59 
    60         // Does this action map the desired element?
    61         if (current_action_element.getAttribute("source").equals(source_metadata_element_name_full)) {
    62         return current_action_element.getAttribute("target");
    63         }
    64     }
    65 
    66     // No import mapping for this element
    67     return null;
     55    return (String) metadata_mapping.get(metadata_element_name_full);
    6856    }
    6957
     
    7159    public HashMap getMetadataMapping()
    7260    {
    73     HashMap metadata_import_mapping = new HashMap();
     61    // If we have already loaded the metadata mapping, use it
     62    if (metadata_mapping != null) {
     63        return metadata_mapping;
     64    }
     65
     66    // Build the metadata mapping from the profile.xml file
     67    metadata_mapping = new HashMap();
    7468
    7569    // Parse the profile.xml file
     
    8680        String source_metadata_element_name_full = current_action_element.getAttribute("source");
    8781        String target_metadata_element_name_full = current_action_element.getAttribute("target");
    88         metadata_import_mapping.put(source_metadata_element_name_full, target_metadata_element_name_full);
     82        metadata_mapping.put(source_metadata_element_name_full, target_metadata_element_name_full);
    8983    }
    9084
    91     return metadata_import_mapping;
     85    return metadata_mapping;
    9286    }
    9387
     
    110104    // Rewrite the profile.xml file
    111105    XMLTools.writeXMLFile(this, document);
     106
     107    // Invalidate the metadata mapping
     108    metadata_mapping = null;
    112109    }
    113110}
Note: See TracChangeset for help on using the changeset viewer.