com.mxgraph.io.graphml.mxGraphMlKeyManager Maven / Gradle / Ivy
/**
* $Id: mxGraphMlKeyManager.java,v 1.1 2011-09-19 15:10:46 gaudenz Exp $
* Copyright (c) 2010 David Benson, Gaudenz Alder
*/
package com.mxgraph.io.graphml;
import java.util.HashMap;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* This is a singleton class that contains a map with the key elements of the
* document. The key elements are wrapped in instances of mxGmlKey and
* may to be access by ID.
*/
public class mxGraphMlKeyManager
{
/**
* Map with the key elements of the document.
* The key is the key's ID.
*/
private HashMap keyMap = new HashMap();
private static mxGraphMlKeyManager keyManager = null;
/**
* Singleton pattern requires private constructor.
*/
private mxGraphMlKeyManager()
{
}
/**
* Returns the instance of mxGmlKeyManager.
* If no instance has been created until the moment, a new instance is
* returned.
* This method don't load the map.
* @return An instance of mxGmlKeyManager.
*/
public static mxGraphMlKeyManager getInstance()
{
if (keyManager == null)
{
keyManager = new mxGraphMlKeyManager();
}
return keyManager;
}
/**
* Load the map with the key elements in the document.
* The keys are wrapped for instances of mxGmlKey.
* @param doc Document with the keys.
*/
public void initialise(Document doc)
{
NodeList gmlKeys = doc.getElementsByTagName(mxGraphMlConstants.KEY);
int keyLength = gmlKeys.getLength();
for (int i = 0; i < keyLength; i++)
{
Element key = (Element) gmlKeys.item(i);
String keyId = key.getAttribute(mxGraphMlConstants.ID);
mxGraphMlKey keyElement = new mxGraphMlKey(key);
keyMap.put(keyId, keyElement);
}
}
public HashMap getKeyMap()
{
return keyMap;
}
public void setKeyMap(HashMap keyMap)
{
this.keyMap = keyMap;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy