Search this API

y.io.graphml.input
Class GraphMLParser

java.lang.Object
  extended by y.io.graphml.input.GraphMLParser

public class GraphMLParser
extends java.lang.Object

Core parser class for GraphML.

This class allows for low-level customization of the parsing process. Usually, it is used by one of GraphMLHandler's read methods which calls one the various parse method overloads. It should rarely be necessary to use this class directly.

See Also:
GraphMLHandler
 

Constructor Summary
GraphMLParser()
           
 
Method Summary
 void addDeserializationHandler(DeserializationHandler listener)
          Register an event listener that can be used to handle DeserializationEvents.
 void addInputHandlerProvider(InputHandlerProvider provider)
          Register an event listener that can be used to handle QueryInputHandlersEvents.
protected  void configureDefaultDeserializationHandlers()
          Register default event handlers for the fireDeserializationEvent(DeserializationEvent) event.
protected  void configureDefaultInputHandlers()
          Register default event handlers for the QueryInputHandlersEvent event.
protected  GraphMLParseContext createParseContext(Graph graph)
          Create the initial GraphMLParseContext instance.
 java.lang.Object deserialize(GraphMLParseContext context, org.w3c.dom.Node element, java.lang.Class targetType)
          Deserialize the content of element.
protected  void fireDeserializationEvent(DeserializationEvent event)
          Notifies all registered DeserializationHandler instances of event.
protected  void fireQueryInputHandlersEvent(QueryInputHandlersEvent event)
          Notifies all registered InputHandlerProvider instances of event.
 java.lang.Object getDeserializationProperty(java.lang.Object key)
          Retrieve a deserialization property that has been set by setDeserializationProperty(Object,Object).
 java.util.Collection getInputHandlers(GraphMLParseContext context, org.w3c.dom.Element keyDefinition)
          Dynamically retrieve all InputHandler instances that can process a GraphML attribute with key definition keyDefinition.
 ParseEventHandler getParseEventHandler()
          Return a ParseEventHandler that can be used to subscribe to various events in the parse process.
protected  java.lang.Object lookup(java.lang.Class type)
          Dynamically retrieve an instance of type.
 void parse(org.w3c.dom.Document document, Graph graph, GraphElementFactory elementFactory)
          Parse the XML document document into an graph instance, to create the elements.
 void parse(java.io.InputStream stream, Graph graph, GraphElementFactory elementFactory)
          Parse the input stream into an graph instance, to create the elements.
 void removeDeserializationHandler(DeserializationHandler listener)
          Unregister an event listener that has been registered with addDeserializationHandler(DeserializationHandler).
 void removeDeserializationProperty(java.lang.Object key)
          Remove a deserialization property that has been set by setDeserializationProperty(Object,Object).
 void removeInputHandlerProvider(InputHandlerProvider provider)
          Unregister an event listener that has been registered with addInputHandlerProvider(InputHandlerProvider).
 void removeLookup(java.lang.Class t)
          Remove an implementation oft that has been set with setLookup(Class,Object).
 void setDeserializationProperty(java.lang.Object key, java.lang.Object value)
          Set an initial deserialization property that allows to fine tune the parse process.
 void setLookup(java.lang.Class t, java.lang.Object instance)
          Register an initial implementation of t for use with Lookup.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphMLParser

public GraphMLParser()
Method Detail

addInputHandlerProvider

public void addInputHandlerProvider(InputHandlerProvider provider)
Register an event listener that can be used to handle QueryInputHandlersEvents.

Registering a listener allows to use InputHandlers dynamically, depending on the actual input. For each key definition, a QueryInputHandlersEvent is fired and propagated to all registered event listeners.

Usually, this method should not be used directly, register event listeners with GraphMLHandler.addInputHandlerProvider(InputHandlerProvider) on an GraphMLHandler instance instead.

Parameters:
provider - Event listener for the QueryInputHandlersEvent
See Also:
fireQueryInputHandlersEvent(QueryInputHandlersEvent), removeInputHandlerProvider(InputHandlerProvider), GraphMLHandler.addInputHandlerProvider(InputHandlerProvider)

removeInputHandlerProvider

public void removeInputHandlerProvider(InputHandlerProvider provider)
Unregister an event listener that has been registered with addInputHandlerProvider(InputHandlerProvider).

Parameters:
provider - Event listener for the QueryInputHandlersEvent
See Also:
fireQueryInputHandlersEvent(QueryInputHandlersEvent), addInputHandlerProvider(InputHandlerProvider), GraphMLHandler.removeInputHandlerProvider(InputHandlerProvider)

fireQueryInputHandlersEvent

protected void fireQueryInputHandlersEvent(QueryInputHandlersEvent event)
                                    throws GraphMLParseException
Notifies all registered InputHandlerProvider instances of event.

For each graphml key definition, a QueryInputHandlersEvent is fired and propagated to all registered event listeners.

Parameters:
event - The event that has been raised.
Throws:
GraphMLParseException
See Also:
InputHandler, InputHandlerProvider, addInputHandlerProvider(InputHandlerProvider), GraphMLHandler.fireQueryInputHandlersProviders(QueryInputHandlersEvent)

addDeserializationHandler

public void addDeserializationHandler(DeserializationHandler listener)
Register an event listener that can be used to handle DeserializationEvents.

Registering a listener allows to use custom deserialization code.

Usually, this method should not be used directly, register event listeners with GraphMLHandler.addDeserializationHandler(DeserializationHandler) on an GraphMLHandler instance instead.

Parameters:
listener - Event listener for the DeserializationEvent
See Also:
fireDeserializationEvent(DeserializationEvent), removeDeserializationHandler(DeserializationHandler), GraphMLHandler.addDeserializationHandler(DeserializationHandler)

removeDeserializationHandler

public void removeDeserializationHandler(DeserializationHandler listener)
Unregister an event listener that has been registered with addDeserializationHandler(DeserializationHandler).

Parameters:
listener - Event listener for the DeserializationEvent
See Also:
fireDeserializationEvent(DeserializationEvent), addDeserializationHandler(DeserializationHandler), GraphMLHandler.removeDeserializationHandler(DeserializationHandler)

fireDeserializationEvent

protected void fireDeserializationEvent(DeserializationEvent event)
                                 throws GraphMLParseException
Notifies all registered DeserializationHandler instances of event.

Usually, this method is called indirectly through calls to GraphMLParseContext.deserialize(GraphMLParseContext,org.w3c.dom.Node,Class) to parse Xml content to an object.

Parameters:
event - The event that has been raised.
Throws:
GraphMLParseException
See Also:
DeserializationHandler, addDeserializationHandler(DeserializationHandler), GraphMLParseContext.deserialize(GraphMLParseContext,org.w3c.dom.Node,Class), GraphMLHandler.fireDeserializationEvent(DeserializationEvent)

configureDefaultDeserializationHandlers

protected void configureDefaultDeserializationHandlers()
Register default event handlers for the fireDeserializationEvent(DeserializationEvent) event.

This implementation does not register any default event handlers

See Also:
GraphMLHandler.configureDeserializationHandlers(y.base.Graph,GraphMLParser)

configureDefaultInputHandlers

protected void configureDefaultInputHandlers()
Register default event handlers for the QueryInputHandlersEvent event.

This implementation does not register any default event handlers

See Also:
GraphMLHandler.configureInputHandlers(y.base.Graph, GraphMLParser)

deserialize

public java.lang.Object deserialize(GraphMLParseContext context,
                                    org.w3c.dom.Node element,
                                    java.lang.Class targetType)
                             throws GraphMLParseException
Deserialize the content of element.

Typically, this method is called only indirectly by calls to GraphMLParseContext.deserialize(GraphMLParseContext, org.w3c.dom.Node, Class)}. This implementation calls fireDeserializationEvent(DeserializationEvent).

Parameters:
context - The current parse context.
element - The XML content that should be deserialized.
targetType - the target type of the result.
Returns:
An instance of targetType that is represented by element.
Throws:
GraphMLParseException
See Also:
GraphMLParseContext.deserialize(GraphMLParseContext, org.w3c.dom.Node, Class)

getInputHandlers

public java.util.Collection getInputHandlers(GraphMLParseContext context,
                                             org.w3c.dom.Element keyDefinition)
                                      throws GraphMLParseException
Dynamically retrieve all InputHandler instances that can process a GraphML attribute with key definition keyDefinition.

Typically, this method is called only indirectly by the parse process. This implementation calls fireQueryInputHandlersEvent(QueryInputHandlersEvent).

Parameters:
context - The current parse context.
keyDefinition - The key definition element of the GraphML attribute.
Returns:
A list of InputHandlers that claim to be responsible for handling the given GraphML attribute.
Throws:
GraphMLParseException

parse

public void parse(org.w3c.dom.Document document,
                  Graph graph,
                  GraphElementFactory elementFactory)
           throws GraphMLParseException
Parse the XML document document into an graph instance, to create the elements.

Typically, this method is called indirectly from parse(java.io.InputStream,y.base.Graph,GraphElementFactory) or GraphMLHandler.read(y.base.Graph,org.w3c.dom.Document).

Parameters:
document - The XML document instance to parse.
graph - The graph instance that is populated.
elementFactory - The GraphElementFactory instance that is used to create the elements.
Throws:
GraphMLParseException
See Also:
GraphMLHandler.read(Graph,Document)

parse

public void parse(java.io.InputStream stream,
                  Graph graph,
                  GraphElementFactory elementFactory)
           throws GraphMLParseException
Parse the input stream into an graph instance, to create the elements.

Typically, this method is called indirectly from GraphMLHandler.read(Graph,InputStream).

Parameters:
stream - The input stream to parse.
graph - The graph instance that is populated.
elementFactory - The GraphElementFactory instance that is used to create the elements.
Throws:
GraphMLParseException
See Also:
GraphMLHandler.read(Graph,InputStream)

createParseContext

protected GraphMLParseContext createParseContext(Graph graph)
Create the initial GraphMLParseContext instance.

Parameters:
graph - The graph that is parsed.
Returns:
An GraphMLParseContext instance that is suitable for graph.

setDeserializationProperty

public void setDeserializationProperty(java.lang.Object key,
                                       java.lang.Object value)
Set an initial deserialization property that allows to fine tune the parse process.

To dynamically set or change property values during the parse process, create a new ChildParseContext and set the property with the corresponding property handling methods.

Parameters:
key - The key for the property.
value - The property value.
See Also:
getDeserializationProperty(Object), GraphMLParseContext.getDeserializationProperty(Object)

removeDeserializationProperty

public void removeDeserializationProperty(java.lang.Object key)
Remove a deserialization property that has been set by setDeserializationProperty(Object,Object).

Parameters:
key - The key for the property.
See Also:
GraphMLParseContext.getDeserializationProperty(Object), setDeserializationProperty(Object,Object)

getDeserializationProperty

public java.lang.Object getDeserializationProperty(java.lang.Object key)
Retrieve a deserialization property that has been set by setDeserializationProperty(Object,Object).

Parameters:
key - The key for the property.
See Also:
GraphMLParseContext.getDeserializationProperty(Object), setDeserializationProperty(Object,Object)

setLookup

public void setLookup(java.lang.Class t,
                      java.lang.Object instance)
Register an initial implementation of t for use with Lookup.

To dynamically modify lookup behaviour during the parse process, create a new ChildParseContext and use the corresponding lookup handling methods.

Parameters:
t - The type for which an implementation should be registered
instance - The implementation of t for lookup retrieval.
See Also:
lookup, Lookup.lookup(Class)

removeLookup

public void removeLookup(java.lang.Class t)
Remove an implementation oft that has been set with setLookup(Class,Object).

To dynamically modify lookup behaviour during the parse process, create a new ChildParseContext and use the corresponding lookup handling methods.

Parameters:
t - The type for which an implementation should be removed
See Also:
setLookup(Class, Object), lookup, Lookup.lookup(Class)

lookup

protected java.lang.Object lookup(java.lang.Class type)
Dynamically retrieve an instance of type.

Parameters:
type - The type for which an implementation is needed.
Returns:
An implementation of type, or null.
See Also:
Lookup.lookup(Class), setLookup(Class,Object)

getParseEventHandler

public ParseEventHandler getParseEventHandler()
Return a ParseEventHandler that can be used to subscribe to various events in the parse process.

Returns:
A ParseEventHandler implementation.

© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.