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

edu.uci.ics.jung.io.graphml.parser.AbstractElementParser 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 javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;

import edu.uci.ics.jung.graph.Hypergraph;
import edu.uci.ics.jung.io.GraphIOException;
import edu.uci.ics.jung.io.graphml.Metadata;

/**
 * Base class for element parsers - provides some minimal functionality.
 * 
 * @author Nathan Mittler - [email protected]
 */
public abstract class AbstractElementParser,V,E> implements ElementParser {

    final private ParserContext parserContext;
    protected AbstractElementParser(ParserContext parserContext) {
        this.parserContext = parserContext;
    }
    
    public ParserContext getParserContext() {
        return this.parserContext;
    }
    
    public ElementParser getParser(String localName) {
        return parserContext.getElementParserRegistry().getParser(localName);
    }
    
    public void applyKeys(Metadata metadata) {
        getParserContext().getKeyMap().applyKeys(metadata);
    }
    
    public ElementParser getUnknownParser() {
        return parserContext.getElementParserRegistry().getUnknownElementParser();
    }
    
    protected void verifyMatch(StartElement start, EndElement end)
            throws GraphIOException {

        String startName = start.getName().getLocalPart();
        String endName = end.getName().getLocalPart();
        if (!startName.equals(endName)) {
            throw new GraphIOException(
                    "Failed parsing document: Start/end tag mismatch! "
                            + "StartTag:" + startName + ", EndTag: "
                            + endName);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy