|
|||||||||
| Home >> All >> com >> hp >> hpl >> jena >> ontology >> [ event overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.hp.hpl.jena.ontology.event
Class OntEventManager

java.lang.Objectcom.hp.hpl.jena.rdf.listeners.StatementListener
com.hp.hpl.jena.ontology.event.OntEventManager
- All Implemented Interfaces:
- com.hp.hpl.jena.rdf.model.ModelChangedListener
- public class OntEventManager
- extends com.hp.hpl.jena.rdf.listeners.StatementListener
An adapter that translates RDF model-level changes into higher level changes that are appropriate to ontology users. The large number of specific events that the ontology model can produce makes the traditional Java style of listener interface impractical. Instead, this event manager allows the user to register handlers, based on command pattern, against specific event types.
For example, to register a handler for the declaration of an ontology class:
OntModel m = ...
OntEventManager em = m.getEventManager();
em.addHandler( OntEvents.CLASS_DECLARATION,
new OntEventHandler() {
public void action( Resource ev, boolean added,
RDFNode arg0, RDFNode arg1 ) {
OntClass c = (OntClass) arg0;
if (added) {
// class c added to model
}
else {
// class c removed from model
}
}
}
);
This listener acts as an adapter for graph events (i.e. adding and removing triples), converting them to higher-level ontology events. This is non-trivial, because Jena currently doesn't have a means of batching changes so that only consistent graph states are seen. For efficiency in non event-using models, this listener is only attached as a statement listener to the underlying graph when the first ontology event listener is added.
- Version:
- CVS $Id: OntEventManager.java,v 1.6 2005/02/21 12:06:02 andy_seaborne Exp $
| Nested Class Summary | |
private static interface |
OntEventManager.ProfileAccessor
Simple wrapper to allow us to dynamically extract elements from the profile |
| Field Summary | |
private OntEventHandler |
m_defaultHandler
Default event handler |
private java.util.Map |
m_handlers
Map from event types to handlers |
private java.util.Map |
m_predicateToEventType
Map from predicate to event type |
private java.util.Map |
m_rdfTypeToEventType
Map from rdf:type to event type |
private static java.lang.Object[][] |
s_predicateInit
Initialisation data for the predicate to event type table |
private static java.lang.Object[][] |
s_rdfTypeInit
Initialisation data for the rdf:type to event type table |
| Constructor Summary | |
OntEventManager(com.hp.hpl.jena.ontology.OntModel m)
Construct an ontology event manager for the given ontology model. |
|
| Method Summary | |
void |
addDefaultHandler(OntEventHandler handler)
Add the given handler as the default event handler, which will be invoked if no other handler is applicable to a given event. |
void |
addedStatement(com.hp.hpl.jena.rdf.model.Statement s)
Handle the addition of a statement to the model. |
void |
addHandler(com.hp.hpl.jena.rdf.model.Resource event,
OntEventHandler handler)
Add the given handler as the handler for the given event type, replacing any existing handler. |
void |
addHandlers(java.lang.Object[][] handlers)
Add the given handlers as the handler for the given event types, replacing any existing handlers. |
OntEventHandler |
getDefaultHandler()
Answer the default event handler, or null if not defined |
OntEventHandler |
getHandler(com.hp.hpl.jena.rdf.model.Resource event)
Answer the event handler for the given event, or null if not defined |
boolean |
hasHandler(com.hp.hpl.jena.rdf.model.Resource event)
Answer true if there is a defined handler for the given event type. |
private void |
initialiseTable(java.util.Map map,
com.hp.hpl.jena.ontology.Profile p,
java.lang.Object[][] source)
Initialise the given map from static initialisation data. |
java.util.Iterator |
listRegisteredEvents()
Answer an iterator over the events that are registered in this event manager. |
private void |
processStatement(com.hp.hpl.jena.rdf.model.Statement s,
boolean added)
Process an incoming added or removed statement to raise the appropriate ontology event. |
void |
raise(com.hp.hpl.jena.rdf.model.Resource event,
boolean added,
com.hp.hpl.jena.rdf.model.Model source,
com.hp.hpl.jena.rdf.model.RDFNode arg0,
com.hp.hpl.jena.rdf.model.RDFNode arg1,
com.hp.hpl.jena.rdf.model.RDFNode arg2)
Raise an event to be handled by the attached event handlers. |
void |
removedStatement(com.hp.hpl.jena.rdf.model.Statement s)
Handle the removal of a statement to the model |
void |
removeHandler(com.hp.hpl.jena.rdf.model.Resource event)
Remove any existing handler for the given event type. |
| Methods inherited from class com.hp.hpl.jena.rdf.listeners.StatementListener |
addedStatements, addedStatements, addedStatements, addedStatements, notifyEvent, removedStatements, removedStatements, removedStatements, removedStatements |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
s_rdfTypeInit
private static java.lang.Object[][] s_rdfTypeInit
- Initialisation data for the rdf:type to event type table
s_predicateInit
private static java.lang.Object[][] s_predicateInit
- Initialisation data for the predicate to event type table
m_handlers
private java.util.Map m_handlers
- Map from event types to handlers
m_rdfTypeToEventType
private java.util.Map m_rdfTypeToEventType
- Map from rdf:type to event type
m_predicateToEventType
private java.util.Map m_predicateToEventType
- Map from predicate to event type
m_defaultHandler
private OntEventHandler m_defaultHandler
- Default event handler
| Constructor Detail |
OntEventManager
public OntEventManager(com.hp.hpl.jena.ontology.OntModel m)
Construct an ontology event manager for the given ontology model. This involves registering adapters for the ontology events corresponding to the language profile of the given model.
| Method Detail |
addedStatement
public void addedStatement(com.hp.hpl.jena.rdf.model.Statement s)
Handle the addition of a statement to the model.
removedStatement
public void removedStatement(com.hp.hpl.jena.rdf.model.Statement s)
Handle the removal of a statement to the model
raise
public void raise(com.hp.hpl.jena.rdf.model.Resource event, boolean added, com.hp.hpl.jena.rdf.model.Model source, com.hp.hpl.jena.rdf.model.RDFNode arg0, com.hp.hpl.jena.rdf.model.RDFNode arg1, com.hp.hpl.jena.rdf.model.RDFNode arg2)
Raise an event to be handled by the attached event handlers.
addDefaultHandler
public void addDefaultHandler(OntEventHandler handler)
Add the given handler as the default event handler, which will be invoked if no other handler is applicable to a given event.
addHandler
public void addHandler(com.hp.hpl.jena.rdf.model.Resource event, OntEventHandler handler)
Add the given handler as the handler for the given event type, replacing any existing handler.
addHandlers
public void addHandlers(java.lang.Object[][] handlers)
Add the given handlers as the handler for the given event types, replacing any existing handlers.
getHandler
public OntEventHandler getHandler(com.hp.hpl.jena.rdf.model.Resource event)
Answer the event handler for the given event, or null if not defined
getDefaultHandler
public OntEventHandler getDefaultHandler()
Answer the default event handler, or null if not defined
removeHandler
public void removeHandler(com.hp.hpl.jena.rdf.model.Resource event)
Remove any existing handler for the given event type.
hasHandler
public boolean hasHandler(com.hp.hpl.jena.rdf.model.Resource event)
Answer true if there is a defined handler for the given event type.
listRegisteredEvents
public java.util.Iterator listRegisteredEvents()
Answer an iterator over the events that are registered in this event manager.
initialiseTable
private void initialiseTable(java.util.Map map, com.hp.hpl.jena.ontology.Profile p, java.lang.Object[][] source)
Initialise the given map from static initialisation data. This will be a mapping that allows us to determine the correct ontology event type for a given triple.
processStatement
private void processStatement(com.hp.hpl.jena.rdf.model.Statement s, boolean added)
Process an incoming added or removed statement to raise the appropriate ontology event.
|
|||||||||
| Home >> All >> com >> hp >> hpl >> jena >> ontology >> [ event overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC