|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.ceryle.wiki.plugin.assertion.AssertionHandlerImpl
org.ceryle.wiki.plugin.assertion.WikiMapManager
public class WikiMapManager
Usurps the function of an existing AssertionHandler by first harvesting its Assertions, disabling it, and then managing further maintenance of a TopicMap that is then synchronized by the events provided from the WikiEventManager for a given WikiEngine. Whereas the AssertionHandler provided support for its getAssertion() method via an internal cache of Assertions, once the WikiMapManager has taken over those queries are made directly on its managed TopicMap.
The initial harvest that builds the TopicMap from the wiki is done by
an AssertionHarvester, which
is part of the bootstrap process initiated by substituteManager().
Post-harvest, the WikiMapManager has the responsibility of converting all Topic Map objects into wiki-compatible objects, basically Strings and Assertions. It does not return anything within the org.ceryle.tm.* package.
Basically, if there are any AssertionPlugins on the wiki, it's likely that the AssertionHandler's cache is close to being in sync. The WikiMapManager's task is to explicitly call the AssertionHandler, request an synchronization whilst supplying a listener for the end of that AssertionCrawler task. If the synchronizer comes back successfully, this then triggers the next stage of the process:
This class began using native TM4J methods and was at one point being converted over to TMAPI, which was abandoned as the latter was not sufficient. Another issue is that the current Inference implementation is TM4J-based, so either a wrapper or alternative class needs to be written.
The one thing we haven't figured yet is when to trigger the usurpation, i.e., when to call the substituteManager() method. Currently this is being done in a rather pipe cleaners-and-glue way, simply waiting ten seconds after the wiki has been started. Ideally this should come from a post-instantiation event.
| Field Summary | |
|---|---|
static String |
PROPERTY_WIKI_TOPICMAP_PATH
Ceryle property determining the location of the written XTM TopicMap. |
static String |
PROPERTY_WIKIMAP_ENABLED
The System property name for the property enabling the usurpation of AssertionHandler by WikiMapManager. |
static String |
THREAD_GROUP_NAME
The name of the ThreadGroup used by the WikiMapManager and any assertion-related Threads. |
static String |
TOPICMAP_CATALOG
The filename of the TopicMap file meant to be loaded on wiki startup. |
| Fields inherited from class org.ceryle.wiki.plugin.assertion.AssertionHandlerImpl |
|---|
ASSERTION_LIFESPAN, m_engine, m_listener, m_refip, templateName |
| Fields inherited from interface org.ceryle.wiki.plugin.assertion.AssertionHandler |
|---|
SYNCHRONIZED, UNSYNCHRONIZED |
| Constructor Summary | |
|---|---|
WikiMapManager(AssertionHandler handler,
TopicMapProcessor tmprocessor)
Constructor for a WikiMapManager for the provided AssertionHandler that will be replaced by this WikiMapManager. |
|
| Method Summary | |
|---|---|
Assertion |
convertAssociation(Association association)
Provided an Associations, returns its corresponding Assertion. |
Collection |
convertAssociations(Collection associations)
Provided a Collection of Associations, returns a Collection of corresponding Assertions. |
Assertion |
createAssertion(String pagename,
Term subject,
Predicate predicate,
Property property)
Creates and returns a new property Assertion provided its parameters. |
Assertion |
createAssertion(String pagename,
Term subject,
Predicate predicate,
Term object,
boolean isTemplate)
Creates and returns a new Assertion, also creating its backing Topic Map Association. |
Assertion |
getAssertion(String pagename,
String subject,
String predicate,
String object)
Queries the set of existing Assertions for an Assertion matching the provided Subject, Predicate and Object. |
Assertion |
getAssertion(String pagename,
Term subject,
Predicate predicate,
Term object,
boolean isTemplate,
boolean create)
Returns an Assertion having the wiki page name, Predicate and Terms. |
int |
getAssertionCount()
Returns the count of all the Assertions. |
Collection |
getAssertions()
Returns a Collection containing all the Assertions (including Assertion templates). |
Collection |
getAssertions(Collection associations)
Returns the Collection of all Associations in the TopicMap having a Scope indicating that they are based on Assertions. |
Collection |
getAssertions(Collection associations,
String pagename,
String subject,
String predicate,
String object,
int templateMode,
int logicMode)
Returns the Collection of all Associations matching Assertions having pagename, subject, predicate, and/or object as Strings. |
Collection |
getAssertionTemplates()
Returns a Collection containing all the Assertion templates. |
String |
getBaseURI()
Return the base URI of the generated TopicMap. |
String |
getLabelForPage(String pagename)
A convenience method that returns a Topic-based label for the given page (referenced by name), returning the original pagename if the Topic does not provide an alternative. |
String |
getPageForTopic(Topic topic)
A convenience method that "converts" the Topic topic to its wiki page name (returning its label). |
Collection |
getPredicatesOfType(Collection associations,
Topic predicate)
Returns a Set view of all the Associations in the TopicMap tm having a Scope indicating that they are based on Assertions. |
Set |
getSubclasses(String pagename)
Returns the Set containing all subclasses of wiki page pagename, an empty Set if there are none. |
Set |
getSuperclasses(String pagename)
Returns the Set containing all superclasses of wiki page pagename, an empty Set if there are none. |
ThreadGroup |
getThreadGroup()
Returns the ThreadGroup used with the WikiMapManager and other assertion-related Threads (named "WikiMap"). |
Topic |
getTopicByName(TopicMap tm,
String label,
boolean create,
int errortype)
Returns a Topic with a base name in the XTM 'Display' scope of label, returning null if unable to locate the Topic or an error occurs (in the latter case the error is logged). |
TopicMap |
getTopicMap()
Returns the TopicMap created by the WikiMapManager for the WikiEngine as a TM4J TopicMap, null if the harvest process (that creates it) has not yet run. |
TopicMapProcessor |
getTopicMapProcessor()
Return the TopicMapProcessor used by this WikiMapManager. |
TopicNameIndex |
getTopicNameIndex()
Return the TopicNameIndex. |
protected void |
harvestComplete(AssertionHarvester harvester)
Called by the AssertionHarvester upon completion. |
protected void |
harvestTopicMap()
Upon receiving notification that the synchronization has successfully completed, begins the Rest of the Story. |
boolean |
hasAssertion(String pagename,
String subject,
String predicate,
String object,
int templateMode,
int logicMode)
Returns true if an Assertion equivalent to one created with the provided subject, predicate, and object is available. |
boolean |
isHarvested()
Returns true if the map has been harvested. |
boolean |
removeAssertion(Assertion assertion)
Returns true if the Assertion was successfully removed. |
void |
setTopicMapPath(File file)
Sets the path to file for the written XTM TopicMap. |
void |
substituteManager()
Begins the substitution process by replace the existing handler with this manager, disabling its listener and enabling the our own synchronize the existing AssertionHandler's caches, attaching a listener so that upon completion of the synchronization, begin harvesting the assertions into a Topic Map The actual substitution occurs after the synchronization thread has finished, by the harvestTopicMap() method. |
void |
synchronize(String pagename,
ActionListener listener)
Synchronizes the AssertionHandler's registry with the current set of wiki pages. |
String |
toXHTML(WikiContext context,
Assertion assertion)
Overrides the method in AssertionHandlerImpl, substituting Topic names where available, formatting the assertion into XHTML output suitable for display on the page. |
| Methods inherited from class org.ceryle.wiki.plugin.assertion.AssertionHandlerImpl |
|---|
clearRegistry, disableRegistry, getAssertion, getEngine, getFromRegistry, getReferenceInfoProvider, hasAssertion, isListenerEnabled, isSynchronizing, removeFromPageCache, setListenerEnabled, setRegistryIsChanging, setSynchronizing, updateCacheForPage |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.ceryle.wiki.plugin.assertion.AssertionHandler |
|---|
getAssertion, getEngine, getReferenceInfoProvider, hasAssertion, isListenerEnabled, setListenerEnabled |
| Field Detail |
|---|
public static final String PROPERTY_WIKIMAP_ENABLED
public static final String PROPERTY_WIKI_TOPICMAP_PATH
public static final String THREAD_GROUP_NAME
public static final String TOPICMAP_CATALOG
| Constructor Detail |
|---|
public WikiMapManager(AssertionHandler handler,
TopicMapProcessor tmprocessor)
handler - the AssertionHandler to be replaced by this WikiMapManager.tmprocessor - the TopicMapProcessor used.
IllegalArgumentException - if the AssertionHandler parameter is actually a WikiMapManager.
WikiMapException - if unable to create the manager.| Method Detail |
|---|
public void synchronize(String pagename,
ActionListener listener)
This is an AssertionHandler API method.
synchronize in interface AssertionHandlersynchronize in class AssertionHandlerImplpagename - the optional name of the wiki page that fired
the event triggering synchronization, used to
check for page-specific changes.listener - the optional listener may be used to receive
notification (via an ActionEvent fired by the
AssertionCrawler)
that the synchronization process has finished.
IllegalStateException - if this method is called, as it is only to
override and disable the superclass' method.
public Collection getAssertions()
throws AssertionException
This is an AssertionHandler API method.
getAssertions in interface AssertionHandlergetAssertions in class AssertionHandlerImplAssertionException - if an error occurs while creating the Collection of assertions.
public Collection getAssertionTemplates()
throws AssertionException
This is not an AssertionHandler API method.
AssertionExceptionpublic boolean isHarvested()
public Assertion getAssertion(String pagename,
Term subject,
Predicate predicate,
Term object,
boolean isTemplate,
boolean create)
throws AssertionException
This is an AssertionHandler API method.
getAssertion in interface AssertionHandlergetAssertion in class AssertionHandlerImplpagename - the wiki page name source of the Assertionsubject - the subject Term of the Assertionpredicate - the Predicate of the Assertionobject - the subject Term of the AssertionisTemplate - when true, queries for an assertion templatecreate - when true, permits creation of Assertion to fulfill a match
AssertionException - if an error occurs while creating the new Assertion
public Assertion createAssertion(String pagename,
Term subject,
Predicate predicate,
Term object,
boolean isTemplate)
throws AssertionException
NOTE: while this is a public method by virtue of it being part of the API, it should not be called directly since creation of Assertions is meant to be handled internal to the process.
createAssertion in interface AssertionHandlercreateAssertion in class AssertionHandlerImplpagename - the wiki page source of the Assertionsubject - the subject Term of the Assertionpredicate - the Predicate of the Assertionobject - the subject Term of the AssertionisTemplate - if true, the assertion is created as an assertion template.
AssertionException - if unable to create the new Assertion.to create an assertion or assertion template,
to create a property assertion
public Assertion createAssertion(String pagename,
Term subject,
Predicate predicate,
Property property)
throws AssertionException
NOTE: while this is a public method by virtue of it being part of the API, it should not be called directly since creation of Assertions is meant to be handled internal to the process.
createAssertion in interface AssertionHandlercreateAssertion in class AssertionHandlerImplpagename - the wiki page source of the Assertionsubject - the subject Term of the Assertionpredicate - the Predicate of the Assertionproperty - the Property being asserted.
AssertionException - if unable to create the new Assertion.to create an assertion or assertion template
public Assertion convertAssociation(Association association)
throws AssertionException
AssertionException - if an error occurs during conversion
IllegalStateException - if this method is called prior to creation of the TopicMap
public Collection convertAssociations(Collection associations)
throws AssertionException
IllegalStateException - if this method is called prior to creation of the TopicMap
AssertionException
public Assertion getAssertion(String pagename,
String subject,
String predicate,
String object)
throws AssertionException
getAssertion in interface AssertionHandlergetAssertion in class AssertionHandlerImplpagename - the wiki page name source of the Assertionsubject - the wiki page name of the Assertion's subjectpredicate - the wiki page name of the Assertion's predicateobject - the wiki page name of the Assertion's object
AssertionException
public boolean hasAssertion(String pagename,
String subject,
String predicate,
String object,
int templateMode,
int logicMode)
throws AssertionException
This is an AssertionHandler API method.
pagename - the wiki page source of the Assertionsubject - the wiki page name of the Assertion's subjectpredicate - the wiki page name of the Assertion's predicateobject - the wiki page name of the Assertion's objecttemplateMode - assertions or templates or both, as
AssertionQuery.TEMPLATES_EXCLUDE,
AssertionQuery.TEMPLATES_ONLY, or
AssertionQuery.TEMPLATES_INCLUDE.logicMode - the query is done as
AssertionQuery.LOGICAL_ALL,
AssertionQuery.LOGICAL_AND, or
AssertionQuery.LOGICAL_OR.
AssertionExceptionpublic boolean removeAssertion(Assertion assertion)
This is an AssertionHandler API method.
removeAssertion in interface AssertionHandlerremoveAssertion in class AssertionHandlerImplassertion - the Assertion to be removed.
IllegalStateException - if this method is called prior to creation of the TopicMap
public String toXHTML(WikiContext context,
Assertion assertion)
throws AssertionException
If the TopicMap is available it will be used to query for Topic labels for subject, predicate and object.
This is an AssertionHandler API method.
toXHTML in interface AssertionHandlertoXHTML in class AssertionHandlerImplcontext - optional; if supplied, used to provide link markup.assertion - the Assertion to be displayed.
AssertionException
public int getAssertionCount()
throws AssertionException
This is not an AssertionHandler API method.
AssertionExceptionpublic ThreadGroup getThreadGroup()
public TopicMapProcessor getTopicMapProcessor()
public void substituteManager()
harvestTopicMap() method.
If the harvest has already occurred, this method does nothing.
protected void harvestTopicMap()
If the harvest has already occurred, this method does nothing.
protected void harvestComplete(AssertionHarvester harvester)
public String getBaseURI()
public Collection getAssertions(Collection associations)
associations - the beginning Collection to query; if null, the entire TopicMap
IllegalStateException - if this method is called prior to creation of the TopicMap
public Collection getAssertions(Collection associations,
String pagename,
String subject,
String predicate,
String object,
int templateMode,
int logicMode)
throws AssertionException
NOTE: Despite a similar signature to the method in
AssertionHandlerImpl, this is
not an API method and queries the Topic Map, returning associations
rather than Assertions. If you want Assertions, pass the result through
#WikiMapManager#convertAssociations(Collection).
See org.ceryle.wiki.plugin.assertion.AssertionQuery for a
description of the permitted values for the template and logical mode.
Null values are ignored; the String array must either be null or contain exactly three elements (any or all of which can be null).
NOTE: Despite a similar signature (the difference being the type
of content in the Collection) to the method in
AssertionHandlerImpl, this is
not an API method and queries the WikiMapManager's Topic Map, returning
Associations rather than Assertions as in the AssertionHandlerImpl.
See org.ceryle.wiki.plugin.assertion.AssertionQuery for a
description of the permitted values for the template and logical mode.
Null values are ignored.
getAssertions in class AssertionHandlerImplassociations - the beginning Collection of Topic Map Associations to
query; if null, the entire TopicMap is queriedpagename - the name of the wiki page where the assertion was madesubject - the WikiName identifier for the subject of the querypredicate - the WikiName identifier for the predicate of the queryobject - the WikiName identifier for the object of the querytemplateMode - assertions or templates or both, as
AssertionQuery.TEMPLATES_EXCLUDE,
AssertionQuery.TEMPLATES_ONLY, or
AssertionQuery.TEMPLATES_INCLUDE.logicMode - the query is done as
AssertionQuery.LOGICAL_ALL,
AssertionQuery.LOGICAL_AND, or
AssertionQuery.LOGICAL_OR.
IllegalStateException - if this method is called prior to creation of the TopicMap
AssertionException - if an error occurs during the query
public Collection getPredicatesOfType(Collection associations,
Topic predicate)
IllegalStateException - if this method is called prior to creation of the TopicMap
public Topic getTopicByName(TopicMap tm,
String label,
boolean create,
int errortype)
throws AssertionException
tm - the parent TopicMaplabel - the label of the returned Topiccreate - if true and the Topic is not found, will createerrortype - the AssertionException error type
IllegalStateException - if this method is called prior to creation of the TopicMap
AssertionExceptionpublic Set getSuperclasses(String pagename)
public Set getSubclasses(String pagename)
public String getLabelForPage(String pagename)
IllegalStateException - if this method is called prior to creation of the TopicMappublic String getPageForTopic(Topic topic)
IllegalStateException - if this method is called prior to creation of the TopicMappublic TopicMap getTopicMap()
public TopicNameIndex getTopicNameIndex()
public void setTopicMapPath(File file)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||