public class GraphMLParser extends Object
This class allows for low-level customization of the parsing process. Usually, it is used by one of
GraphMLIOHandler
's Read
methods which calls one the various Parse
method overloads. It
should rarely be necessary to use this class directly.
GraphMLIOHandler
Constructor and Description |
---|
GraphMLParser() |
Modifier and Type | Method and Description |
---|---|
void |
addHandleDeserializationListener(IEventHandler<HandleDeserializationEventArgs> handleDeserializationEvent)
Adds the given listener for the
HandleDeserialization event that occurs when XML content is about to be
deserialized. |
void |
addParsedListener(IEventHandler<ParseEventArgs> parsedEvent)
Adds the given listener for the
Parsed event that occurs when the the document has been parsed. |
void |
addParsingListener(IEventHandler<ParseEventArgs> parsingEvent)
Adds the given listener for the
Parsing event that occurs when the parsing of the document is just about to
begin. |
void |
addQueryInputHandlersListener(IEventHandler<QueryInputHandlersEventArgs> queryInputHandlersEvent)
Adds the given listener for the
QueryInputHandlers event that occurs when IInputHandler s are queried. |
protected IParseContext |
createParseContext(IGraph graph)
Create the initial
IParseContext instance. |
<T> T |
deserialize(Class<T> targetType,
IParseContext context,
Node element)
Deserialize the content of
element . |
<T> T |
getDeserializationProperty(TypedKey<T> key)
Retrieve a deserialization property that has been set by
setDeserializationProperty(TypedKey, Object) . |
List<IInputHandler> |
getInputHandlers(IParseContext context,
Element keyDefinition)
Dynamically retrieve all
IInputHandler instances that process a GraphML attribute with key definition
keyDefinition . |
Object |
lookup(Class type)
Dynamically retrieve an instance of
type . |
protected void |
onHandleDeserialization(HandleDeserializationEventArgs args)
Fires the
HandleDeserialization event. |
protected void |
onParsed(ParseEventArgs args)
Raises the
Parsed event. |
protected void |
onParsing(ParseEventArgs args)
Raises the
Parsing event. |
protected void |
onQueryInputHandlers(QueryInputHandlersEventArgs args)
Fires the
QueryInputHandlers event. |
void |
parse(IGraph graph,
Document document,
IGraphElementFactory elementFactory)
Parse the XML document
document into an graph instance, using elementFactory to create the
elements. |
void |
parse(IGraph graph,
InputStream stream,
IGraphElementFactory elementFactory)
Parse the input
stream into an graph instance, using elementFactory to create the elements. |
void |
parse(IGraph graph,
InputStream stream,
URI baseUri,
IGraphElementFactory elementFactory)
Parse the input
stream into an graph instance, using elementFactory
to create the elements. |
void |
parse(IGraph graph,
Reader reader,
IGraphElementFactory elementFactory)
Parse the input
reader into an graph instance, using elementFactory to create the elements. |
void |
parse(IGraph graph,
Reader reader,
URI baseUri,
IGraphElementFactory elementFactory)
Parse the input
reader into an graph instance, using elementFactory
to create the elements. |
void |
parse(IGraph graph,
String uri,
IGraphElementFactory elementFactory)
Parse the input
uri into an graph instance, using elementFactory to create the elements. |
<T> void |
removeDeserializationProperty(TypedKey<T> key)
Remove a deserialization property that has been set by
setDeserializationProperty(TypedKey, Object) . |
void |
removeHandleDeserializationListener(IEventHandler<HandleDeserializationEventArgs> handleDeserializationEvent)
Removes the given listener for the
HandleDeserialization event that occurs when XML content is about to be
deserialized. |
<T> void |
removeLookup(Class<T> tType)
Remove an implementation of
T that has been set with setLookup(Class, Object) . |
void |
removeParsedListener(IEventHandler<ParseEventArgs> parsedEvent)
Removes the given listener for the
Parsed event that occurs when the the document has been parsed. |
void |
removeParsingListener(IEventHandler<ParseEventArgs> parsingEvent)
Removes the given listener for the
Parsing event that occurs when the parsing of the document is just about to
begin. |
void |
removeQueryInputHandlersListener(IEventHandler<QueryInputHandlersEventArgs> queryInputHandlersEvent)
Removes the given listener for the
QueryInputHandlers event that occurs when
IInputHandler s are queried. |
<T> void |
setDeserializationProperty(TypedKey<T> key,
T value)
Set a deserialization property that allows to fine tune the parsing process.
|
<T> void |
setLookup(Class<T> tType,
T instance)
Register an implementation of
T for use with lookup(Class) . |
public final void addHandleDeserializationListener(IEventHandler<HandleDeserializationEventArgs> handleDeserializationEvent)
HandleDeserialization
event that occurs when XML content is about to be
deserialized.
Subscribe to this event to provide custom deserialization handling for XML content.
The event handlers added to this event are called in inverse order, i.e. handlers that have been added later are called earlier.
The current XML content is provided by XmlNode
. If you want to
return deserialized content, set the value of the Result
property.
handleDeserializationEvent
- The listener to add.GraphMLIOHandler.addHandleDeserializationListener(IEventHandler)
,
removeHandleDeserializationListener(IEventHandler)
public final void addParsedListener(IEventHandler<ParseEventArgs> parsedEvent)
Parsed
event that occurs when the the document has been parsed.parsedEvent
- The listener to add.onParsed(ParseEventArgs)
,
removeParsedListener(IEventHandler)
public final void addParsingListener(IEventHandler<ParseEventArgs> parsingEvent)
Parsing
event that occurs when the parsing of the document is just about to
begin.
This event can be used to register to the fine-grained events available in the
Context
's ParseEvents
and the configure
the parsing process on a per parse case.
parsingEvent
- The listener to add.onParsing(ParseEventArgs)
,
removeParsingListener(IEventHandler)
public final void addQueryInputHandlersListener(IEventHandler<QueryInputHandlersEventArgs> queryInputHandlersEvent)
QueryInputHandlers
event that occurs when IInputHandler
s are queried.
Subscribe to this event to dynamically register one or more IInputHandler
instance(s) for a given GraphML
attribute key definition.
The current key definition is provided by KeyDefinition
. If you
want to register an IInputHandler
for this GraphML attribute, you can add the handler with
QueryInputHandlersEventArgs.addInputHandler(IInputHandler)
.
queryInputHandlersEvent
- The listener to add.GraphMLIOHandler.addQueryInputHandlersListener(IEventHandler)
,
removeQueryInputHandlersListener(IEventHandler)
protected IParseContext createParseContext(IGraph graph)
IParseContext
instance.graph
- The graph that is parsed.IParseContext
instance that is suitable for graph
.public <T> T deserialize(Class<T> targetType, IParseContext context, Node element)
element
.
Typically, this method is called only indirectly by calls to IParseContext.deserialize(Class, IParseContext, Node)
or IParseContext.deserialize(Class, Node)
. This implementation calls
onHandleDeserialization(HandleDeserializationEventArgs)
, which in turn raises the HandleDeserialization
event.
T
- The desired type of the result.targetType
- The desired type of the result.context
- The current parse context.element
- The XML content that should be deserialized.T
that is represented by element
.IParseContext.deserialize(Class, IParseContext, Node)
,
IParseContext.deserialize(Class, Node)
,
addHandleDeserializationListener(IEventHandler)
public <T> T getDeserializationProperty(TypedKey<T> key)
setDeserializationProperty(TypedKey, Object)
.
The return value is automatically converted to type T
.
T
- The target type of the property.tType
- The target type of the property.key
- The key for the property.IParseContext.getDeserializationProperty(TypedKey)
public List<IInputHandler> getInputHandlers(IParseContext context, Element keyDefinition)
IInputHandler
instances that process a GraphML attribute with key definition
keyDefinition
.
Typically, this method is called only indirectly by the parse process. This implementation calls
onQueryInputHandlers(QueryInputHandlersEventArgs)
, which in turn raises the QueryInputHandlers
event.
context
- The current parse context.keyDefinition
- The key definition element of the GraphML attribute.IInputHandlers
that claim to be responsible for handling the given GraphML attribute.public Object lookup(Class type)
type
.type
- The type for which an implementation is needed.type
, or null
.protected void onHandleDeserialization(HandleDeserializationEventArgs args)
HandleDeserialization
event.args
- The arguments that get passed to the HandleDeserialization
event.GraphMLIOHandler.onHandleDeserialization(HandleDeserializationEventArgs)
protected void onParsed(ParseEventArgs args)
Parsed
event.
This method is called when the document has been parsed and after DocumentParsed
is called.
args
- The ParseEventArgs
instance containing the event data.addParsedListener(IEventHandler)
protected void onParsing(ParseEventArgs args)
Parsing
event.
This method is called just before the parsing starts and before DocumentParsing
is called.
args
- The ParseEventArgs
instance containing the event data.addParsingListener(IEventHandler)
protected void onQueryInputHandlers(QueryInputHandlersEventArgs args)
QueryInputHandlers
event.args
- The arguments that get passed to the QueryInputHandlers
event.GraphMLIOHandler.onQueryInputHandlers(QueryInputHandlersEventArgs)
public void parse(IGraph graph, Document document, IGraphElementFactory elementFactory) throws IOException
document
into an graph
instance, using elementFactory
to create the
elements.
Typically, this method is called indirectly from
GraphMLIOHandler.read(IGraph, Document)
.
IOException
graph
- The graph instance that is populated.document
- The XML document instance to parse.elementFactory
- The IGraphElementFactory
instance that is used to create the elements.GraphMLIOHandler.read(IGraph, Document)
public void parse(IGraph graph, InputStream stream, IGraphElementFactory elementFactory) throws IOException
stream
into an graph
instance, using elementFactory
to create the elements.
Typically, this method is called indirectly from
GraphMLIOHandler.read(IGraph, InputStream)
.
IOException
- If the XML could not be read.graph
- The graph instance that is populated.stream
- The input stream to parse.elementFactory
- The IGraphElementFactory
instance that is used to create the elements.GraphMLIOHandler.read(com.yworks.yfiles.graph.IGraph, java.io.InputStream, java.net.URI)
public void parse(IGraph graph, InputStream stream, URI baseUri, IGraphElementFactory elementFactory) throws IOException
stream
into an graph
instance, using elementFactory
to create the elements.
Typically, this method is called indirectly from
GraphMLIOHandler.read(com.yworks.yfiles.graph.IGraph, java.io.InputStream, java.net.URI)
.IOException
- If the XML could not be read.stream
- The input stream to parse.baseUri
- The base URI which is used for the GraphML file being parsed to resolve relative paths.graph
- The graph instance that is populated.elementFactory
- The IGraphElementFactory
instance that is used to create the elements.GraphMLIOHandler.read(com.yworks.yfiles.graph.IGraph, java.io.InputStream, java.net.URI)
public void parse(IGraph graph, Reader reader, IGraphElementFactory elementFactory) throws IOException
reader
into an graph
instance, using elementFactory
to create the elements.
Typically, this method is called indirectly from
GraphMLIOHandler.read(IGraph, Reader)
.
IOException
- If the XML could not be read.graph
- The graph instance that is populated.reader
- The input reader to parse.elementFactory
- The IGraphElementFactory
instance that is used to create the elements.GraphMLIOHandler.read(com.yworks.yfiles.graph.IGraph, java.io.Reader, java.net.URI)
public void parse(IGraph graph, Reader reader, URI baseUri, IGraphElementFactory elementFactory) throws IOException
reader
into an graph
instance, using elementFactory
to create the elements.
Typically, this method is called indirectly from
GraphMLIOHandler.read(com.yworks.yfiles.graph.IGraph, java.io.Reader, java.net.URI)
.IOException
- If the XML could not be read.reader
- The input reader to parse.baseUri
- The base URI which is used for the GraphML file being parsed to resolve relative paths.graph
- The graph instance that is populated.elementFactory
- The IGraphElementFactory
instance that is used to create the elements.GraphMLIOHandler.read(com.yworks.yfiles.graph.IGraph, java.io.Reader, java.net.URI)
public void parse(IGraph graph, String uri, IGraphElementFactory elementFactory) throws IOException
uri
into an graph
instance, using elementFactory
to create the elements.
Typically, this method is called indirectly from
GraphMLIOHandler.read(IGraph, Reader, java.net.URI)
.
IOException
- If the XML could not be read.graph
- The graph instance that is populated.uri
- The URI to the input to parse.elementFactory
- The IGraphElementFactory
instance that is used to create the elements.GraphMLIOHandler.read(IGraph, Reader, java.net.URI)
public <T> void removeDeserializationProperty(TypedKey<T> key)
setDeserializationProperty(TypedKey, Object)
.key
- The key for the property.IParseContext.getDeserializationProperty(TypedKey)
public final void removeHandleDeserializationListener(IEventHandler<HandleDeserializationEventArgs> handleDeserializationEvent)
HandleDeserialization
event that occurs when XML content is about to be
deserialized.
Subscribe to this event to provide custom deserialization handling for XML content.
The event handlers added to this event are called in inverse order, i.e. handlers that have been added later are called earlier.
The current XML content is provided by XmlNode
. If you want to
return deserialized content, set the value of the Result
property.
handleDeserializationEvent
- The listener to remove.GraphMLIOHandler.addHandleDeserializationListener(IEventHandler)
,
addHandleDeserializationListener(IEventHandler)
public <T> void removeLookup(Class<T> tType)
T
that has been set with setLookup(Class, Object)
.public final void removeParsedListener(IEventHandler<ParseEventArgs> parsedEvent)
Parsed
event that occurs when the the document has been parsed.parsedEvent
- The listener to remove.onParsed(ParseEventArgs)
,
addParsedListener(IEventHandler)
public final void removeParsingListener(IEventHandler<ParseEventArgs> parsingEvent)
Parsing
event that occurs when the parsing of the document is just about to
begin.
This event can be used to register to the fine-grained events available in the
Context
's ParseEvents
and the configure
the parsing process on a per parse case.
parsingEvent
- The listener to remove.onParsing(ParseEventArgs)
,
addParsingListener(IEventHandler)
public final void removeQueryInputHandlersListener(IEventHandler<QueryInputHandlersEventArgs> queryInputHandlersEvent)
QueryInputHandlers
event that occurs when
IInputHandler
s are queried.
Subscribe to this event to dynamically register one or more IInputHandler
instance(s) for a given GraphML
attribute key definition.
The current key definition is provided by KeyDefinition
. If you
want to register an IInputHandler
for this GraphML attribute, you can add the handler with
QueryInputHandlersEventArgs.addInputHandler(IInputHandler)
.
queryInputHandlersEvent
- The listener to remove.GraphMLIOHandler.addQueryInputHandlersListener(IEventHandler)
,
addQueryInputHandlersListener(IEventHandler)
public <T> void setDeserializationProperty(TypedKey<T> key, T value)
key
- The key for the property.value
- The property value.IParseContext.getDeserializationProperty(TypedKey)
public <T> void setLookup(Class<T> tType, T instance)
T
for use with lookup(Class)
.T
- The type of instance
.tType
- The type of instance
.instance
- The implementation of T
for lookup retrieval.