Example usage for org.xml.sax SAXNotSupportedException SAXNotSupportedException

List of usage examples for org.xml.sax SAXNotSupportedException SAXNotSupportedException

Introduction

In this page you can find the example usage for org.xml.sax SAXNotSupportedException SAXNotSupportedException.

Prototype

public SAXNotSupportedException(String message) 

Source Link

Document

Construct a new exception with the given message.

Usage

From source file:edu.uci.ics.jung.io.GraphMLReader.java

@Override
public void startElement(String uri, String name, String qName, Attributes atts)
        throws SAXNotSupportedException {
    String tag = qName.toLowerCase();
    TagState state = tag_state.get(tag);
    if (state == null)
        state = TagState.OTHER;//from w  ww  . j  a  va  2 s  . c o  m

    switch (state) {
    case GRAPHML:
        break;

    case VERTEX:
        if (this.current_graph == null)
            throw new SAXNotSupportedException("Graph must be defined prior to elements");
        if (this.current_edge != null || this.current_vertex != null)
            throw new SAXNotSupportedException("Nesting elements not supported");

        createVertex(atts);

        break;

    case ENDPOINT:
        if (this.current_graph == null)
            throw new SAXNotSupportedException("Graph must be defined prior to elements");
        if (this.current_edge == null)
            throw new SAXNotSupportedException("No edge defined for endpoint");
        if (this.current_states.getFirst() != TagState.HYPEREDGE)
            throw new SAXNotSupportedException("Endpoints must be defined inside hyperedge");
        Map<String, String> endpoint_atts = getAttributeMap(atts);
        String node = endpoint_atts.remove("node");
        if (node == null)
            throw new SAXNotSupportedException("Endpoint must include an 'id' attribute");
        V v = vertex_ids.getKey(node);
        if (v == null)
            throw new SAXNotSupportedException("Endpoint refers to nonexistent node ID: " + node);

        this.current_vertex = v;
        hyperedge_vertices.add(v);
        break;

    case EDGE:
    case HYPEREDGE:
        if (this.current_graph == null)
            throw new SAXNotSupportedException("Graph must be defined prior to elements");
        if (this.current_edge != null || this.current_vertex != null)
            throw new SAXNotSupportedException("Nesting elements not supported");

        createEdge(atts, state);
        break;

    case GRAPH:
        if (this.current_graph != null && graph_factory != null)
            throw new SAXNotSupportedException("Nesting graphs not currently supported");

        // graph factory is null if there's only one graph
        if (graph_factory != null)
            current_graph = graph_factory.create();

        // reset all non-key data structures (to avoid collisions between different graphs)
        clearData();

        // set up default direction of edges
        Map<String, String> graph_atts = getAttributeMap(atts);
        String default_direction = graph_atts.remove("edgedefault");
        if (default_direction == null)
            throw new SAXNotSupportedException("All graphs must specify a default edge direction");
        if (default_direction.equals("directed"))
            this.default_edgetype = EdgeType.DIRECTED;
        else if (default_direction.equals("undirected"))
            this.default_edgetype = EdgeType.UNDIRECTED;
        else
            throw new SAXNotSupportedException(
                    "Invalid or unrecognized default edge direction: " + default_direction);

        // put remaining attribute/value pairs in graph_data
        addExtraData(graph_atts, graph_metadata, current_graph);

        break;

    case DATA:
        if (this.current_states.contains(TagState.DATA))
            throw new SAXNotSupportedException("Nested data not supported");
        handleData(atts);
        break;

    case KEY:
        createKey(atts);
        break;

    default:
        break;
    }

    current_states.addFirst(state);
}

From source file:edu.uci.ics.jung.io.GraphMLReader.java

protected <T> void addDatum(Map<String, GraphMLMetadata<T>> metadata, T current_elt, String text)
        throws SAXNotSupportedException {
    if (metadata.containsKey(this.current_key)) {
        SettableTransformer<T, String> st = (SettableTransformer<T, String>) (metadata
                .get(this.current_key).transformer);
        st.set(current_elt, text);//from  w  ww  .  j  av a 2  s . co  m
    } else
        throw new SAXNotSupportedException("key " + this.current_key + " not valid for element " + current_elt);
}

From source file:edu.uci.ics.jung.io.GraphMLReader.java

@Override
public void endElement(String uri, String name, String qName) throws SAXNotSupportedException {
    String text = current_text.toString().trim();
    current_text.setLength(0);/*from   w w w . j a v  a 2 s  . c o  m*/

    String tag = qName.toLowerCase();
    TagState state = tag_state.get(tag);
    if (state == null)
        state = TagState.OTHER;
    if (state == TagState.OTHER)
        return;

    if (state != current_states.getFirst())
        throw new SAXNotSupportedException(
                "Unbalanced tags: opened " + tag_state.getKey(current_states.getFirst()) + ", closed " + tag);

    switch (state) {
    case VERTEX:
    case ENDPOINT:
        current_vertex = null;
        break;

    case EDGE:
        current_edge = null;
        break;

    case HYPEREDGE:
        current_graph.addEdge(current_edge, hyperedge_vertices);
        hyperedge_vertices.clear();
        current_edge = null;
        break;

    case GRAPH:
        current_graph = null;
        break;

    case KEY:
        current_key = null;
        break;

    case DESC:
        switch (this.current_states.get(1)) // go back one
        {
        case GRAPH:
            graph_desc.put(current_graph, text);
            break;
        case VERTEX:
        case ENDPOINT:
            vertex_desc.put(current_vertex, text);
            break;
        case EDGE:
        case HYPEREDGE:
            edge_desc.put(current_edge, text);
            break;
        case DATA:
            switch (key_type) {
            case GRAPH:
                graph_metadata.get(current_key).description = text;
                break;
            case VERTEX:
                vertex_metadata.get(current_key).description = text;
                break;
            case EDGE:
                edge_metadata.get(current_key).description = text;
                break;
            case ALL:
                graph_metadata.get(current_key).description = text;
                vertex_metadata.get(current_key).description = text;
                edge_metadata.get(current_key).description = text;
                break;
            default:
                throw new SAXNotSupportedException("Invalid key type" + " specified for default: " + key_type);
            }

            break;
        default:
            break;
        }
        break;
    case DATA:
        this.key_type = KeyType.NONE;
        switch (this.current_states.get(1)) {
        case GRAPH:
            addDatum(graph_metadata, current_graph, text);
            break;
        case VERTEX:
        case ENDPOINT:
            addDatum(vertex_metadata, current_vertex, text);
            break;
        case EDGE:
        case HYPEREDGE:
            addDatum(edge_metadata, current_edge, text);
            break;
        default:
            break;
        }
        break;
    case DEFAULT_KEY:
        if (this.current_states.get(1) != TagState.KEY)
            throw new SAXNotSupportedException(
                    "'default' only defined in context of 'key' tag: " + "stack: " + current_states.toString());

        switch (key_type) {
        case GRAPH:
            graph_metadata.get(current_key).default_value = text;
            break;
        case VERTEX:
            vertex_metadata.get(current_key).default_value = text;
            break;
        case EDGE:
            edge_metadata.get(current_key).default_value = text;
            break;
        case ALL:
            graph_metadata.get(current_key).default_value = text;
            vertex_metadata.get(current_key).default_value = text;
            edge_metadata.get(current_key).default_value = text;
            break;
        default:
            throw new SAXNotSupportedException("Invalid key type" + " specified for default: " + key_type);
        }

        break;
    default:
        break;
    }

    current_states.removeFirst();
}

From source file:edu.uci.ics.jung.io.GraphMLReader.java

protected void handleData(Attributes atts) throws SAXNotSupportedException {
    switch (this.current_states.getFirst()) {
    case GRAPH:/*from w  ww  . j  av  a  2s  .  co m*/
        break;
    case VERTEX:
    case ENDPOINT:
        break;
    case EDGE:
        break;
    case HYPEREDGE:
        break;
    default:
        throw new SAXNotSupportedException("'data' tag only defined "
                + "if immediately containing tag is 'graph', 'node', " + "'edge', or 'hyperedge'");
    }
    this.current_key = getAttributeMap(atts).get("key");
    if (this.current_key == null)
        throw new SAXNotSupportedException("'data' tag requires a key specification");
    if (this.current_key.equals(""))
        throw new SAXNotSupportedException("'data' tag requires a non-empty key");
    if (!getGraphMetadata().containsKey(this.current_key) && !getVertexMetadata().containsKey(this.current_key)
            && !getEdgeMetadata().containsKey(this.current_key)) {
        throw new SAXNotSupportedException("'data' tag's key specification must reference a defined key");
    }

}

From source file:net.itransformers.topologyviewer.gui.MyGraphMLReader.java

protected void handleData(Attributes atts) throws SAXNotSupportedException {
    switch (this.current_states.getFirst()) {
    case GRAPH://from  ww  w  .  j a  va 2 s  . c  o m
        break;
    case VERTEX:
    case ENDPOINT:
        break;
    case EDGE:
        break;
    case HYPEREDGE:
        break;
    default:
        throw new SAXNotSupportedException("'data' tag only defined "
                + "if immediately containing tag is 'graph', 'node', " + "'edge', or 'hyperedge'");
    }
    this.current_key = getAttributeMap(atts).get("key");
    if (this.current_key == null)
        throw new SAXNotSupportedException("'data' tag requires a key specification");
    if (this.current_key.equals(""))
        throw new SAXNotSupportedException("'data' tag requires a non-empty key");
    if (!getGraphMetadata().containsKey(this.current_key) && !getVertexMetadata().containsKey(this.current_key)
            && !getEdgeMetadata().containsKey(this.current_key)) {
        throw new SAXNotSupportedException(
                "'data' tag's key " + this.current_key + " specification must reference a defined key");
    }

}

From source file:edu.uci.ics.jung.io.GraphMLReader.java

protected void createKey(Attributes atts) throws SAXNotSupportedException {
    Map<String, String> key_atts = getAttributeMap(atts);
    String id = key_atts.remove("id");
    String for_type = key_atts.remove("for");

    if (for_type == null || for_type.equals("") || for_type.equals("all")) {
        vertex_metadata.put(id, new GraphMLMetadata<V>(null, null,
                new MapSettableTransformer<V, String>(new HashMap<V, String>())));
        edge_metadata.put(id, new GraphMLMetadata<E>(null, null,
                new MapSettableTransformer<E, String>(new HashMap<E, String>())));
        graph_metadata.put(id, new GraphMLMetadata<G>(null, null,
                new MapSettableTransformer<G, String>(new HashMap<G, String>())));
        key_type = KeyType.ALL;//from w w  w  .  j  av a2  s . c om
    } else {
        TagState type = tag_state.get(for_type);
        switch (type) {
        case VERTEX:
            vertex_metadata.put(id, new GraphMLMetadata<V>(null, null,
                    new MapSettableTransformer<V, String>(new HashMap<V, String>())));
            key_type = KeyType.VERTEX;
            break;
        case EDGE:
        case HYPEREDGE:
            edge_metadata.put(id, new GraphMLMetadata<E>(null, null,
                    new MapSettableTransformer<E, String>(new HashMap<E, String>())));
            key_type = KeyType.EDGE;
            break;
        case GRAPH:
            graph_metadata.put(id, new GraphMLMetadata<G>(null, null,
                    new MapSettableTransformer<G, String>(new HashMap<G, String>())));
            key_type = KeyType.GRAPH;
            break;
        default:
            throw new SAXNotSupportedException("Invalid metadata target type: " + for_type);
        }
    }

    this.current_key = id;

}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandler.java

/**
 * Processes a {@code <parser>} element.
 *
 * @param attrs//from   w  w w . ja  v  a 2 s  .co  m
 *            List of element attributes
 *
 * @throws SAXException
 *             if error occurs parsing element
 */
private void processParser(Attributes attrs) throws SAXException {
    if (currParser != null) {
        throw new SAXParseException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.malformed.configuration", PARSER_ELMT), currParseLocation);
    }
    String name = null;
    String className = null;
    String tags = null;
    for (int i = 0; i < attrs.getLength(); i++) {
        String attName = attrs.getQName(i);
        String attValue = attrs.getValue(i);
        if (NAME_ATTR.equals(attName)) {
            name = attValue;
        } else if (CLASS_ATTR.equals(attName)) {
            className = attValue;
        } else if (TAGS_ATTR.equals(attName)) {
            tags = attValue;
        }
    }

    notEmpty(name, PARSER_ELMT, NAME_ATTR);
    notEmpty(className, PARSER_ELMT, CLASS_ATTR);
    if (streamsConfigData.getParser(name) != null) {
        throw new SAXParseException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.duplicate.parser.definition", name), currParseLocation);
    }
    try {
        Object newParser = Utils.createInstance(className);
        if (!(newParser instanceof ActivityParser)) {
            throw new SAXNotSupportedException(StreamsResources.getStringFormatted(
                    StreamsResources.RESOURCE_BUNDLE_NAME, "ConfigParserHandler.not.implement.interface",
                    PARSER_ELMT, CLASS_ATTR, className, ActivityParser.class.getName(), getLocationInfo()));
        }
        currParser = (ActivityParser) newParser;
    } catch (Exception exc) {
        throw new SAXException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.failed.to.load", PARSER_ELMT, CLASS_ATTR, className, getLocationInfo()),
                exc);
    }
    if (currParser != null) {
        currParser.setName(name);
        currParser.setTags(tags);
        streamsConfigData.addParser(currParser);
    }
}

From source file:edu.uci.ics.jung.io.GraphMLReader.java

@SuppressWarnings("unchecked")
protected void createVertex(Attributes atts) throws SAXNotSupportedException {
    Map<String, String> vertex_atts = getAttributeMap(atts);
    String id = vertex_atts.remove("id");
    if (id == null)
        throw new SAXNotSupportedException("node attribute list missing " + "'id': " + atts.toString());
    V v = vertex_ids.getKey(id);// ww  w.j  a v  a  2  s .c  o m

    if (v == null) {
        if (vertex_factory != null)
            v = vertex_factory.create();
        else
            v = (V) id;
        vertex_ids.put(v, id);
        this.current_graph.addVertex(v);

        // put remaining attribute/value pairs in vertex_data
        addExtraData(vertex_atts, vertex_metadata, v);
    } else
        throw new SAXNotSupportedException("Node id \"" + id + " is a duplicate of an existing node ID");

    this.current_vertex = v;
}

From source file:edu.uci.ics.jung.io.GraphMLReader.java

@SuppressWarnings("unchecked")
protected void createEdge(Attributes atts, TagState state) throws SAXNotSupportedException {
    Map<String, String> edge_atts = getAttributeMap(atts);

    String id = edge_atts.remove("id");
    E e;/*w  w w .  j av  a 2s. c om*/
    if (edge_factory != null)
        e = edge_factory.create();
    else if (id != null)
        e = (E) id;
    else
        throw new IllegalArgumentException(
                "If no edge factory is supplied, " + "edge id may not be null: " + edge_atts);

    if (id != null) {
        if (edge_ids.containsKey(e))
            throw new SAXNotSupportedException("Edge id \"" + id + "\" is a duplicate of an existing edge ID");
        edge_ids.put(e, id);
    }

    if (state == TagState.EDGE)
        assignEdgeSourceTarget(e, atts, edge_atts); //, id);

    // put remaining attribute/value pairs in edge_data
    addExtraData(edge_atts, edge_metadata, e);

    this.current_edge = e;
}

From source file:edu.uci.ics.jung.io.GraphMLReader.java

protected void assignEdgeSourceTarget(E e, Attributes atts, Map<String, String> edge_atts)//, String id)
        throws SAXNotSupportedException {
    String source_id = edge_atts.remove("source");
    if (source_id == null)
        throw new SAXNotSupportedException("edge attribute list missing " + "'source': " + atts.toString());
    V source = vertex_ids.getKey(source_id);
    if (source == null)
        throw new SAXNotSupportedException(
                "specified 'source' attribute " + "\"" + source_id + "\" does not match any node ID");

    String target_id = edge_atts.remove("target");
    if (target_id == null)
        throw new SAXNotSupportedException("edge attribute list missing " + "'target': " + atts.toString());
    V target = vertex_ids.getKey(target_id);
    if (target == null)
        throw new SAXNotSupportedException(
                "specified 'target' attribute " + "\"" + target_id + "\" does not match any node ID");

    String directed = edge_atts.remove("directed");
    EdgeType edge_type;/*  ww w.java 2s  .  c  o  m*/
    if (directed == null)
        edge_type = default_edgetype;
    else if (directed.equals("true"))
        edge_type = EdgeType.DIRECTED;
    else if (directed.equals("false"))
        edge_type = EdgeType.UNDIRECTED;
    else
        throw new SAXNotSupportedException("Unrecognized edge direction specifier 'direction=\"" + directed
                + "\"': " + "source: " + source_id + ", target: " + target_id);

    if (current_graph instanceof Graph)
        ((Graph<V, E>) this.current_graph).addEdge(e, source, target, edge_type);
    else
        this.current_graph.addEdge(e, new Pair<V>(source, target));
}