📄 onteventmanager.java
字号:
* @param arg2 The third argument to the event, or null
*/
public void raise( Resource event, boolean added, Model source, RDFNode arg0, RDFNode arg1, RDFNode arg2 ) {
OntEventHandler h = getHandler( event );
if (h != null) {
h.action( event, added, source, arg0, arg1, arg2 );
}
else if (m_defaultHandler != null) {
// if no assigned handler, call the default handler
m_defaultHandler.action( event, added, source, arg0, arg1, arg2 );
}
}
/**
* <p>Add the given handler as the default event handler, which will be invoked if
* no other handler is applicable to a given event.</p>
* @param handler The event handler object
*/
public void addDefaultHandler( OntEventHandler handler ) {
m_defaultHandler = handler;
}
/**
* <p>Add the given handler as the handler for the given event type, replacing
* any existing handler.</p>
* @param event The event type to be handled, as a resource
* @param handler The event handler object
*/
public void addHandler( Resource event, OntEventHandler handler ) {
m_handlers.put( event, handler );
}
/**
* <p>Add the given handlers as the handler for the given event types, replacing
* any existing handlers.</p>
* @param handlers An array of pairs, where the first element of each pair
* is the resource denoting the event to be handled, and the second is the
* handler object
*/
public void addHandlers( Object[][] handlers ) {
for (int i = 0; i < handlers.length; ) {
Resource r = (Resource) handlers[i][0];
OntEventHandler h = (OntEventHandler) handlers[i][1];
addHandler( r, h );
}
}
/**
* <p>Answer the event handler for the given event, or null if not defined</p>
* @param event An event type to look up
* @return The current handler for the event, or null
*/
public OntEventHandler getHandler( Resource event ) {
return (OntEventHandler) m_handlers.get( event );
}
/**
* <p>Answer the default event handler, or null if not defined</p>
* @return The default event handler, or null
*/
public OntEventHandler getDefaultHandler() {
return m_defaultHandler;
}
/**
* <p>Remove any existing handler for the given event type.</p>
* @param event The event for which the handler is to be removed
*/
public void removeHandler( Resource event ) {
m_handlers.remove( event );
}
/**
* <p>Answer true if there is a defined handler for the given event type.</p>
* @param event An event type, as a resource
* @return True if there is a defined handler for the event
*/
public boolean hasHandler( Resource event ) {
return m_handlers.containsKey( event );
}
/**
* <p>Answer an iterator over the events that are registered in this
* event manager.</p>
* @return An iterator over the event types of events that have registered handlers
*/
public Iterator listRegisteredEvents() {
return m_handlers.keySet().iterator();
}
// Internal implementation methods
//////////////////////////////////
/**
* <p>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.</p>
* @param map The map to update
* @param p An ontology language profile
* @param source A table of initialisation data
*/
private void initialiseTable( Map map, Profile p, Object[][] source ) {
for (int i = 0; i < source.length; i++) {
// get the initialisation data from the table
Resource evType = (Resource) source[i][0];
Resource key = ((ProfileAccessor) source[i][1]).get( p );
if (key != null) {
// is defined for this term
map.put( key, evType );
}
}
}
/**
* <p>Process an incoming added or removed statement to raise the appropriate ontology event.</p>
* @param s
* @param added
*/
private void processStatement( Statement s, boolean added ) {
// first check if this an rdf:type statement
if (s.getPredicate().equals( RDF.type )) {
// yes - now is it a builtin type?
Resource type = s.getResource();
Resource evType = (Resource) m_rdfTypeToEventType.get( type );
if (evType != null) {
// was a known type, so we know which event to raise
raise( evType, added, s.getModel(), s.getSubject(), null, null );
}
else {
// must be an individual
raise( OntEventsVocab.individualDeclaration, added, s.getModel(), s.getSubject(), type, null );
}
}
else {
// not rdf:type, but may still be a known predicate
Property pred = s.getPredicate();
Resource evType = (Resource) m_predicateToEventType.get( pred );
if (evType != null) {
// was a known predicate, so we know which event to raise
raise( evType, added, s.getModel(), s.getSubject(), s.getObject(), null );
}
else {
// default - assume user data
raise( OntEventsVocab.userData, added, s.getModel(), s.getSubject(), pred, s.getObject() );
}
}
}
//==============================================================================
// Inner class definitions
//==============================================================================
/** Simple wrapper to allow us to dynamically extract elements from the profile */
private static interface ProfileAccessor {
public Resource get( Profile p );
}
}
/*
* (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -