All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.uci.ics.jung.io.graphml.parser.ElementParserRegistry Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2008, The JUNG Authors
 *
 * All rights reserved.
 *
 * This software is open-source under the BSD license; see either
 * "license.txt" or
 * https://github.com/jrtom/jung/blob/master/LICENSE for a description.
 */

package edu.uci.ics.jung.io.graphml.parser;

import java.util.HashMap;
import java.util.Map;

import com.google.common.base.Function;

import edu.uci.ics.jung.graph.Hypergraph;
import edu.uci.ics.jung.io.graphml.EdgeMetadata;
import edu.uci.ics.jung.io.graphml.GraphMLConstants;
import edu.uci.ics.jung.io.graphml.GraphMetadata;
import edu.uci.ics.jung.io.graphml.HyperEdgeMetadata;
import edu.uci.ics.jung.io.graphml.KeyMap;
import edu.uci.ics.jung.io.graphml.NodeMetadata;

/**
 * Registry for all element parsers.
 * 
 * @author Nathan Mittler - [email protected]
 */
public class ElementParserRegistry, V, E> {

    final private Map parserMap = new HashMap();

    final private ElementParser unknownElementParser = new UnknownElementParser();

    public ElementParserRegistry(KeyMap keyMap, 
            Function graphTransformer,
            Function vertexTransformer,
            Function edgeTransformer,
            Function hyperEdgeTransformer) {
        
        // Create the parser context.
        ParserContext context = new ParserContext(this, keyMap, graphTransformer, 
                vertexTransformer, edgeTransformer, hyperEdgeTransformer);
    
        parserMap.put(GraphMLConstants.DEFAULT_NAME, new StringElementParser(context));
        parserMap.put(GraphMLConstants.DESC_NAME, new StringElementParser(context));
        parserMap.put(GraphMLConstants.KEY_NAME, new KeyElementParser(context));
        parserMap.put(GraphMLConstants.DATA_NAME, new DataElementParser(context));
        parserMap.put(GraphMLConstants.PORT_NAME, new PortElementParser(context));
        parserMap.put(GraphMLConstants.NODE_NAME, new NodeElementParser(context));
        parserMap.put(GraphMLConstants.GRAPH_NAME, new GraphElementParser(context));
        parserMap.put(GraphMLConstants.ENDPOINT_NAME, new EndpointElementParser(context));
        parserMap.put(GraphMLConstants.EDGE_NAME, new EdgeElementParser(context));
        parserMap.put(GraphMLConstants.HYPEREDGE_NAME, new HyperEdgeElementParser(context));
    }

    public ElementParser getUnknownElementParser() {
        return unknownElementParser;
    }

    public ElementParser getParser(String localName) {
        ElementParser parser = parserMap.get(localName);
        if (parser == null) {
            parser = unknownElementParser;
        }

        return parser;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy