JDOMExternalizableInterface 

HOME INDEX SEARCH GO  

 <<O>>  Difference Topic JDOMExternalizableInterface (r1.1 - 19 Jun 2002 - DanBachelder)
Added:
>
>

%META:TOPICINFO{author="DanBachelder" date="1024461720" format="1.0" version="1.1"}% %META:TOPICPARENT{name="IntellijPluginDocumentation"}% JDOMExternalizable is the interface you implement to read and write your configuration... implement the two methods kinda like this:

public class MyComponent  implements ProjectComponent, JDOMExternalizable {
    private Map someMap = new HashMap();

    /**
     * you need to write all your state to the element passed in. you "own"
     * this element.       this method writes your state out whenever IDEA 
     * decides it's time... make it run as fast as you can :)
     */ 
    public void writeExternal(Element element) throws WriteExternalException {
        // iterate over keys
        Iterator keyIterator = someMap.keySet().iterator();
        while (keyIterator.hasNext()) {
            String key = (String)keyIterator.next();
            
            //create a new element named "map_entry"
            Element entryElement = new Element("map_entry");
            // add an attribute named "name" and put your key in as the value
            entryElement = entryElement.setAttribute("name", key);
            // likewise with "value"
            entryElement = entryElement.setAttribute("value", someMap.get(key).toString());
            // add your new element back to what was passed in.
            element.addContent(entryElement);
        }
    }
    
    /**
     * the Element passed in is the root of your configuration... you "own"
     * this element. this method is run once when your component is first 
     * created.. so get all your goodies at once.
     */
    public void readExternal(Element element) throws InvalidDataException {
        // get all elements named "map_entries" 
        List entries = element.getChildren("map_entries");
        for (int i = 0; i < entries.size(); i++) {
            Element entry = (Element) entries.get(i);

            // get the attributes from the entry 
            String name = entry.getAttribute("name").getValue();
            String value = entry.getAttribute("value").getValue();
            // put them in the map for the plugin to use later
            someMap.put(name, value);
        }
}

see PluginDocumentation for more info...

-- DanBachelder - 19 Jun 2002


View | Diffs | r1.1 | More

e d i t a t t a c h r e f - b y d i f f s
Ideas,requests,problems regarding this site? Send feedback.
Copyright @ 2000-2003 by the contribution authors. All material on this collaboration tool is the property of the contributing authors.

Revision -
Revision r1.1 - 19 Jun 2002 - 04:42 GMT - DanBachelder
Copyright © 2001 by the contributing authors. All material on this collaboration tool is the property of the contributing authors.
Ideas, requests, problems regarding this site? Send feedback.