Class AbstractPluginContext
- java.lang.Object
-
- org.processmining.framework.plugin.impl.AbstractPluginContext
-
- All Implemented Interfaces:
GlobalContext
,ObjectConstructor
,PluginContext
public abstract class AbstractPluginContext extends java.lang.Object implements PluginContext
-
-
Constructor Summary
Constructors Modifier Constructor Description AbstractPluginContext(GlobalContext context, java.lang.String label)
Create a new root plugin instance context.protected
AbstractPluginContext(AbstractPluginContext context, java.lang.String label)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T extends Connection>
TaddConnection(T c)
Registers the given connection in the global context.void
clear()
PluginContext
createChildContext(java.lang.String label)
Returns a new plugin context instance, which can be used to invoke other plugins.PluginContextID
createNewPluginContextID()
The GlobalContext implementation should create IDs for all PluginContexts instantiated for it.protected abstract PluginContext
createTypedChildContext(java.lang.String label)
boolean
deleteChild(PluginContext child)
Delete this child from this context.boolean
equals(java.lang.Object o)
java.util.List<PluginContext>
getChildContexts()
Returns a list of all child contexts which have been created with createChildContext().ConnectionManager
getConnectionManager()
Returns the connection manager.ProMFuture<?>
getFutureResult(int i)
This method should only be used by a plugin, in the body of that plugin.GlobalContext
getGlobalContext()
PluginContextID
getID()
Each PluginContext should carry an ID.java.lang.String
getLabel()
Returns the label of this context.Logger.ListenerList
getLoggingListeners()
Returns the list of logging listeners registered to this context.PluginContext
getParentContext()
Returns the context which created this context or null if it has no parent.java.lang.Class<? extends PluginContext>
getPluginContextType()
Returns the specific type of the PluginContext.Pair<PluginDescriptor,java.lang.Integer>
getPluginDescriptor()
Return the plugin descriptor and method index of the plugin which is invoked in this context.PluginLifeCycleEventListener.List
getPluginLifeCycleEventListeners()
Returns the list of registered plugin life cycle listeners.PluginManager
getPluginManager()
Returns the plugin manager.Progress
getProgress()
Returns the progress object corresponding to this contextProgressEventListener.ListenerList
getProgressEventListeners()
Returns the list of registered progress listenersProvidedObjectManager
getProvidedObjectManager()
Returns the providedObject manager.PluginExecutionResult
getResult()
This method returns the PluginExecutionResult of the plugin which is invoked in this context.PluginContext
getRootContext()
Returns the root plugin context.boolean
hasPluginDescriptorInPath(PluginDescriptor plugin, int methodIndex)
void
invokeBinding(PluginParameterBinding binding, java.lang.Object... objects)
This method invokes the specified binding in a context which is a child of the main plugin context maintained by this globalContext.void
invokePlugin(PluginDescriptor plugin, int index, java.lang.Object... objects)
This method invokes the specified plugin in a context which is a child of the main plugin context maintained by this globalContext;boolean
isDistantChildOf(PluginContext context)
Returns true if this is a distant child of context, i.e.void
log(java.lang.String message)
Same as calling log(message, MessageLevel.NORMAL);void
log(java.lang.String message, Logger.MessageLevel level)
The provided String is provided to the context for information.void
log(java.lang.Throwable exception)
The provided Exception is provided to the context.void
setFuture(PluginExecutionResult futureToBe)
void
setPluginDescriptor(PluginDescriptor descriptor, int methodIndex)
java.lang.String
toString()
<T,C extends Connection>
java.util.Collection<T>tryToFindOrConstructAllObjects(java.lang.Class<T> type, java.lang.Class<C> connectionType, java.lang.String role, java.lang.Object... input)
Finds as many objects of the given type as can be found through the connections of the other given type.<T,C extends Connection>
TtryToFindOrConstructFirstNamedObject(java.lang.Class<T> type, java.lang.String name, java.lang.Class<C> connectionType, java.lang.String role, java.lang.Object... input)
Returns the first object of the given type as can be found through the connections of the other given type.<T,C extends Connection>
TtryToFindOrConstructFirstObject(java.lang.Class<T> type, java.lang.Class<C> connectionType, java.lang.String role, java.lang.Object... input)
Returns the first object of the given type as can be found through the connections of the other given type.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.processmining.framework.plugin.PluginContext
getExecutor
-
-
-
-
Field Detail
-
progress
protected Progress progress
-
-
Constructor Detail
-
AbstractPluginContext
public AbstractPluginContext(GlobalContext context, java.lang.String label)
Create a new root plugin instance context.- Parameters:
context
- the global context in which this instance context is used
-
AbstractPluginContext
protected AbstractPluginContext(AbstractPluginContext context, java.lang.String label)
-
-
Method Detail
-
getPluginDescriptor
public Pair<PluginDescriptor,java.lang.Integer> getPluginDescriptor()
Description copied from interface:PluginContext
Return the plugin descriptor and method index of the plugin which is invoked in this context. This descriptor is set by the PluginDescriptor.invoke() method and will not be set yet before PluginManager.invoke() is called.- Specified by:
getPluginDescriptor
in interfacePluginContext
- Returns:
- the descriptor of the plugin which is invoked in this context If the plugin is not set yet, a pair of (null,-1) is returned
-
getGlobalContext
public GlobalContext getGlobalContext()
-
getPluginLifeCycleEventListeners
public PluginLifeCycleEventListener.List getPluginLifeCycleEventListeners()
Description copied from interface:PluginContext
Returns the list of registered plugin life cycle listeners.- Specified by:
getPluginLifeCycleEventListeners
in interfacePluginContext
- Returns:
- the list of registered plugin life cycle listeners.
-
getProgressEventListeners
public ProgressEventListener.ListenerList getProgressEventListeners()
Description copied from interface:PluginContext
Returns the list of registered progress listeners- Specified by:
getProgressEventListeners
in interfacePluginContext
- Returns:
- the list of registered progress listeners
-
getProgress
public Progress getProgress()
Description copied from interface:PluginContext
Returns the progress object corresponding to this context- Specified by:
getProgress
in interfacePluginContext
- Returns:
- the progress object corresponding to this context
-
getID
public PluginContextID getID()
Description copied from interface:PluginContext
Each PluginContext should carry an ID. This ID is unique within this plugin context's global context.- Specified by:
getID
in interfacePluginContext
- Returns:
- the ID of this context
-
getConnectionManager
public ConnectionManager getConnectionManager()
Description copied from interface:GlobalContext
Returns the connection manager. The connection manager can be used to query for connections which are registered in ProM.- Specified by:
getConnectionManager
in interfaceGlobalContext
- Returns:
- the connection manager
-
getLabel
public java.lang.String getLabel()
Description copied from interface:PluginContext
Returns the label of this context.- Specified by:
getLabel
in interfacePluginContext
- Returns:
-
hasPluginDescriptorInPath
public boolean hasPluginDescriptorInPath(PluginDescriptor plugin, int methodIndex)
- Specified by:
hasPluginDescriptorInPath
in interfacePluginContext
-
setPluginDescriptor
public void setPluginDescriptor(PluginDescriptor descriptor, int methodIndex) throws FieldSetException, RecursiveCallException
- Specified by:
setPluginDescriptor
in interfacePluginContext
- Throws:
FieldSetException
RecursiveCallException
-
createChildContext
public PluginContext createChildContext(java.lang.String label)
Description copied from interface:PluginContext
Returns a new plugin context instance, which can be used to invoke other plugins.- Specified by:
createChildContext
in interfacePluginContext
- Returns:
- the new plugin context instance
-
getChildContexts
public java.util.List<PluginContext> getChildContexts()
Description copied from interface:PluginContext
Returns a list of all child contexts which have been created with createChildContext().- Specified by:
getChildContexts
in interfacePluginContext
- Returns:
-
getParentContext
public PluginContext getParentContext()
Description copied from interface:PluginContext
Returns the context which created this context or null if it has no parent.- Specified by:
getParentContext
in interfacePluginContext
- Returns:
-
createTypedChildContext
protected abstract PluginContext createTypedChildContext(java.lang.String label)
-
getResult
public PluginExecutionResult getResult()
This method returns the PluginExecutionResult of the plugin which is invoked in this context. This future result is set by PluginManager.invoke() and will not be available (will be null) until the invoke() method is called.- Specified by:
getResult
in interfacePluginContext
- Returns:
- The PluginExecutionResult that represents the result of this plugin invocation
- Throws:
FieldNotSetException
- If the future is not know to this context
-
getFutureResult
public ProMFuture<?> getFutureResult(int i)
Description copied from interface:PluginContext
This method should only be used by a plugin, in the body of that plugin. That is the only location, where it is guaranteed that each result object in getResults() can safely be cast to a ProMFuture.- Specified by:
getFutureResult
in interfacePluginContext
- Returns:
-
setFuture
public void setFuture(PluginExecutionResult futureToBe)
- Specified by:
setFuture
in interfacePluginContext
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isDistantChildOf
public boolean isDistantChildOf(PluginContext context)
Description copied from interface:PluginContext
Returns true if this is a distant child of context, i.e. true if getParent.getID().equals(context.getID()) || getParent().isDistantChildOf(context);- Specified by:
isDistantChildOf
in interfacePluginContext
- Returns:
-
log
public void log(java.lang.String message, Logger.MessageLevel level)
The provided String is provided to the context for information. It can for example signal a state change of a plugin. Note that some contexts can completely ignore this message.- Specified by:
log
in interfacePluginContext
- Parameters:
message
- the message to loglevel
- the message level
-
log
public void log(java.lang.String message)
Same as calling log(message, MessageLevel.NORMAL);- Specified by:
log
in interfacePluginContext
- Parameters:
message
- The message
-
log
public void log(java.lang.Throwable exception)
The provided Exception is provided to the context. It signals the context about an error in the plugin, that specifically lead to abnormal termination. The plugin signaling the exception is no longer executing!- Specified by:
log
in interfacePluginContext
- Parameters:
exception
- the exception thrown
-
getPluginManager
public PluginManager getPluginManager()
Returns the plugin manager. The plugin manager can be used to query for plugins which are registered in ProM.- Specified by:
getPluginManager
in interfaceGlobalContext
- Returns:
- the plugin manager
-
getProvidedObjectManager
public ProvidedObjectManager getProvidedObjectManager()
Returns the providedObject manager. The providedObject manager can be used to query for providedObjects which are registered in ProM. The manager should be a ProvidedObjectListener on all PluginInstanceContexts created by createRootInstanceContext.- Specified by:
getProvidedObjectManager
in interfaceGlobalContext
- Returns:
- the providedObject manager
-
createNewPluginContextID
public PluginContextID createNewPluginContextID()
The GlobalContext implementation should create IDs for all PluginContexts instantiated for it.- Specified by:
createNewPluginContextID
in interfaceGlobalContext
- Returns:
-
invokePlugin
public void invokePlugin(PluginDescriptor plugin, int index, java.lang.Object... objects)
This method invokes the specified plugin in a context which is a child of the main plugin context maintained by this globalContext;- Specified by:
invokePlugin
in interfaceGlobalContext
- Parameters:
plugin
-objects
- The objects to serve as input. Note that all elements should implement Object, or be a ProMFuture>.index
- The index of the plugin method that should be invoked.
-
invokeBinding
public void invokeBinding(PluginParameterBinding binding, java.lang.Object... objects)
Description copied from interface:GlobalContext
This method invokes the specified binding in a context which is a child of the main plugin context maintained by this globalContext. No results are provided to the method calling this method and the plugin is executed some time in the future, as decided by the implementing class.- Specified by:
invokeBinding
in interfaceGlobalContext
- Parameters:
binding
- The binding that should be invoked by the frameworkobjects
- The objects to serve as input as accepted by the given binding.
-
getLoggingListeners
public Logger.ListenerList getLoggingListeners()
Description copied from interface:PluginContext
Returns the list of logging listeners registered to this context.- Specified by:
getLoggingListeners
in interfacePluginContext
- Returns:
-
getRootContext
public PluginContext getRootContext()
Description copied from interface:PluginContext
Returns the root plugin context. This is an instance of PluginContext of which all other contexts are distant childs.- Specified by:
getRootContext
in interfacePluginContext
- Returns:
-
deleteChild
public boolean deleteChild(PluginContext child)
Description copied from interface:PluginContext
Delete this child from this context.- Specified by:
deleteChild
in interfacePluginContext
-
addConnection
public <T extends Connection> T addConnection(T c)
Description copied from interface:PluginContext
Registers the given connection in the global context. The implementation is addConnection(this,c);- Specified by:
addConnection
in interfacePluginContext
-
getPluginContextType
public java.lang.Class<? extends PluginContext> getPluginContextType()
Description copied from interface:GlobalContext
Returns the specific type of the PluginContext. This type is used to instantiate new contexts in which to invoke plugins.- Specified by:
getPluginContextType
in interfaceGlobalContext
- Returns:
- the type of PluginContext provided by this global context
-
tryToFindOrConstructAllObjects
public <T,C extends Connection> java.util.Collection<T> tryToFindOrConstructAllObjects(java.lang.Class<T> type, java.lang.Class<C> connectionType, java.lang.String role, java.lang.Object... input) throws ConnectionCannotBeObtained
Description copied from interface:ObjectConstructor
Finds as many objects of the given type as can be found through the connections of the other given type. If no objects can be found, it constructs as many objects of the given type as there are plugins available to the framework to do so. These plugins should be able to execute in a child of the given context and accept, in any order, exactly the input provided. Any other objects returned by the plugin, not being the requested type are added to the provided objects of the framework. Also, listeners are notified where applicable. If no plugings exist, or if these plugins fail, a ConnectionDoesntExistException is thrown.- Specified by:
tryToFindOrConstructAllObjects
in interfaceObjectConstructor
- Type Parameters:
T
- The type of the return object required.- Parameters:
type
- the type of the return object required.connectionType
- the type of the connections to use when trying to find the objects.role
- the assumed role of the object in the connection. Given a connection, the object can be retrieved through the role.input
- the input on which the plugin should work- Returns:
- a collection of objects as found or returned by the plugins.
- Throws:
ConnectionCannotBeObtained
-
tryToFindOrConstructFirstObject
public <T,C extends Connection> T tryToFindOrConstructFirstObject(java.lang.Class<T> type, java.lang.Class<C> connectionType, java.lang.String role, java.lang.Object... input) throws ConnectionCannotBeObtained
Description copied from interface:ObjectConstructor
Returns the first object of the given type as can be found through the connections of the other given type. If no objects can be found, it constructs as an object of the given type using a plugin available to the framework to do so. This plugins should be able to execute in a child of the given context and accept, in any order, exactly the input provided. Any other objects returned by the plugin, not being the requested type are added to the provided objects of the framework. Also, listeners are notified where applicable. If no plugins exist, or if these plugins fail, a ConnectionDoesntExistException is thrown.- Specified by:
tryToFindOrConstructFirstObject
in interfaceObjectConstructor
- Type Parameters:
T
- The type of the return object required.- Parameters:
type
- the type of the return object required.connectionType
- the type of the connections to use when trying to find the objects.role
- the assumed role of the object in the connection. Given a connection, the object can be retrieved through the role.input
- the input on which the plugin should work- Returns:
- a collection of objects as returned by the plugins.
- Throws:
ConnectionCannotBeObtained
-
tryToFindOrConstructFirstNamedObject
public <T,C extends Connection> T tryToFindOrConstructFirstNamedObject(java.lang.Class<T> type, java.lang.String name, java.lang.Class<C> connectionType, java.lang.String role, java.lang.Object... input) throws ConnectionCannotBeObtained
Description copied from interface:ObjectConstructor
Returns the first object of the given type as can be found through the connections of the other given type. If no objects can be found, it constructs as an object of the given type using a plugin available to the framework to do so. This plugins should be able to execute in a child of the given context and accept, in any order, exactly the input provided. Furthermore, the returned object should have the right label assigned to it in the plugin definition. Any other objects returned by the plugin, not being the requested type are added to the provided objects of the framework. Also, listeners are notified where applicable. If no plugins exist, or if these plugins fail, a ConnectionDoesntExistException is thrown.- Specified by:
tryToFindOrConstructFirstNamedObject
in interfaceObjectConstructor
- Type Parameters:
T
- The type of the return object required.- Parameters:
type
- the type of the return object required.name
- the name of the plugin to use.connectionType
- the type of the connections to use when trying to find the objects.role
- the assumed role of the object in the connection. Given a connection, the object can be retrieved through the role.input
- the input on which the plugin should work- Returns:
- a collection of objects as returned by the plugins.
- Throws:
ConnectionCannotBeObtained
-
clear
public void clear()
- Specified by:
clear
in interfacePluginContext
-
-