| java.lang.Object com.hp.hpl.jena.rdf.listeners.StatementListener com.hp.hpl.jena.ontology.event.OntEventManager
OntEventManager | public class OntEventManager extends StatementListener (Code) | |
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
, based on command pattern, against specific
.
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.
author: Ian Dickinson, HP Labs author: (email) version: CVS $Id: OntEventManager.java,v 1.9 2008/01/02 12:10:36 andy_seaborne Exp $ |
Constructor Summary | |
public | OntEventManager(OntModel m) Construct an ontology event manager for the given ontology model. |
OntEventManager | public OntEventManager(OntModel m)(Code) | | 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.
Parameters: m - An ontology model |
addDefaultHandler | public void addDefaultHandler(OntEventHandler handler)(Code) | | Add the given handler as the default event handler, which will be invoked if
no other handler is applicable to a given event.
Parameters: handler - The event handler object |
addHandler | public void addHandler(Resource event, OntEventHandler handler)(Code) | | Add the given handler as the handler for the given event type, replacing
any existing handler.
Parameters: event - The event type to be handled, as a resource Parameters: handler - The event handler object |
addHandlers | public void addHandlers(Object[][] handlers)(Code) | | Add the given handlers as the handler for the given event types, replacing
any existing handlers.
Parameters: handlers - An array of pairs, where the first element of each pairis the resource denoting the event to be handled, and the second is the handler object |
addedStatement | public void addedStatement(Statement s)(Code) | | Handle the addition of a statement to the model.
Parameters: s - The added statement |
getDefaultHandler | public OntEventHandler getDefaultHandler()(Code) | | Answer the default event handler, or null if not defined
The default event handler, or null |
getHandler | public OntEventHandler getHandler(Resource event)(Code) | | Answer the event handler for the given event, or null if not defined
Parameters: event - An event type to look up The current handler for the event, or null |
hasHandler | public boolean hasHandler(Resource event)(Code) | | Answer true if there is a defined handler for the given event type.
Parameters: event - An event type, as a resource True if there is a defined handler for the event |
listRegisteredEvents | public Iterator listRegisteredEvents()(Code) | | Answer an iterator over the events that are registered in this
event manager.
An iterator over the event types of events that have registered handlers |
raise | public void raise(Resource event, boolean added, Model source, RDFNode arg0, RDFNode arg1, RDFNode arg2)(Code) | | Raise an event to be handled by the attached event handlers.
Parameters: event - The resource representing the event type Parameters: added - True if this is an addition to the model, false otherwise Parameters: source - The model that caused the event to be raised Parameters: arg0 - The first argument to the event Parameters: arg1 - The second argument to the event, or null Parameters: arg2 - The third argument to the event, or null |
removeHandler | public void removeHandler(Resource event)(Code) | | Remove any existing handler for the given event type.
Parameters: event - The event for which the handler is to be removed |
removedStatement | public void removedStatement(Statement s)(Code) | | Handle the removal of a statement to the model
Parameters: s - The removed statement |
|
|