at.ac.tuwien.infosys.sm4all.copal.api.query
Class ActionQuery

java.lang.Object
  extended by at.ac.tuwien.infosys.sm4all.copal.api.util.BaseObservable<QueryState,ContextQuery,QueryObserver>
      extended by at.ac.tuwien.infosys.sm4all.copal.api.query.ContextQuery
          extended by at.ac.tuwien.infosys.sm4all.copal.api.query.ActionQuery
All Implemented Interfaces:
Observable<QueryState,ContextQuery,QueryObserver>, Registry<java.lang.String,ContextProcessor>, org.osgi.framework.BundleActivator

public class ActionQuery
extends ContextQuery
implements Registry<java.lang.String,ContextProcessor>

This class is used with the ContextProcessors to create ContextQuerys which listen on occurrence of ContextEvents with a specific ContextEventType that require handling of their CurrentAction.

Author:
sanjin

Constructor Summary
ActionQuery(java.lang.String listenedType, java.lang.String actionName)
          Create instance of ContextQuery for ContextProcessors.
 
Method Summary
 void destroy()
          Destroys this ContextQuery.
 ContextProcessor get(java.lang.String processorName)
          Returns ContextProcessor with specified name or null if there is no such ContextProcessor registered.
 java.lang.String getActionName()
          Returns the name of handled CurrentAction.
 ContextProcessor[] getAll()
          Returns all currently registered ContextProcessors.
 boolean isRegistered(java.lang.String processorName)
          Returns if a ContextProcessor with specified name is currently registered.
 void onEvent(ContextEvent event)
          This method is called when a ContextEvent with same event name occurs for which the criteria is satisfied.
 void register(ContextProcessor processor)
          Register specified ContextProcessor with this ActionQuery .
 void start(org.osgi.framework.BundleContext context)
           
 void stop(org.osgi.framework.BundleContext context)
           
 void unregister(java.lang.String processorName)
          Unregister ContextProcessor with specified name from this ActionQuery.
 
Methods inherited from class at.ac.tuwien.infosys.sm4all.copal.api.query.ContextQuery
attach, equals, getCriteria, getListenedType, getName, hasCriteria, hashCode, isDestroyed
 
Methods inherited from class at.ac.tuwien.infosys.sm4all.copal.api.util.BaseObservable
detach, detachAll, getObservers, notifyAll
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ActionQuery

public ActionQuery(java.lang.String listenedType,
                   java.lang.String actionName)
Create instance of ContextQuery for ContextProcessors. It will catch only ContextEvents that have name of their ContextEventType equal to specified listened type and have name of their CurrentAction equal to specified action name.

Parameters:
listenedType - the name of listened ContextEventType.
actionName - the name of handled CurrentAction.
Throws:
java.lang.NullPointerException - if specified of listened ContextEventType or name of handled CurrentAction is null.
java.lang.IllegalArgumentException - if specified name of listened ContextEventType or name of handled CurrentAction is an empty or blank string.
Method Detail

getActionName

public java.lang.String getActionName()
Returns the name of handled CurrentAction.

Returns:
the name of handled CurrentAction.

start

public void start(org.osgi.framework.BundleContext context)
Specified by:
start in interface org.osgi.framework.BundleActivator
Specified by:
start in class ContextQuery

stop

public void stop(org.osgi.framework.BundleContext context)
Specified by:
stop in interface org.osgi.framework.BundleActivator
Specified by:
stop in class ContextQuery

destroy

public void destroy()
             throws QueryDestroyedException
Description copied from class: ContextQuery
Destroys this ContextQuery. All registered ContextListeners will be unregistered and any future registration of a ContextListener and receiving of events will not be possible.

Overrides:
destroy in class ContextQuery
Throws:
QueryDestroyedException - if ContextQuery has been already destroyed.

onEvent

public void onEvent(ContextEvent event)
             throws QueryDestroyedException
Description copied from class: ContextQuery
This method is called when a ContextEvent with same event name occurs for which the criteria is satisfied. This method in return calls all registered ContextListeners with specified ContextEvent.

Specified by:
onEvent in class ContextQuery
Parameters:
event - the occurred ContextEvent.
Throws:
QueryDestroyedException - if ContextQuery has been previously destroyed.

register

public void register(ContextProcessor processor)
              throws AlreadyRegisteredException,
                     QueryDestroyedException
Register specified ContextProcessor with this ActionQuery . If ContextEvent is caught, which requires the ProcessorAction, the specified ContextProcessor will be invoked.

Specified by:
register in interface Registry<java.lang.String,ContextProcessor>
Parameters:
processor - the ContextProcessor.
Throws:
AlreadyRegisteredException - if a ContextProcessor with same name is already registered.
java.lang.NullPointerException - if specified ContextProcessor is null.
java.lang.IllegalArgumentException - if specified ContextProcessor cannot handle the CurrentAction on the listened ContextEventType
QueryDestroyedException - if this ActionQuery has been previously destroyed.

unregister

public void unregister(java.lang.String processorName)
                throws NotRegisteredException
Unregister ContextProcessor with specified name from this ActionQuery. The ContextProcessor will not receive any further ContextEvents from this ActionQuery.

Specified by:
unregister in interface Registry<java.lang.String,ContextProcessor>
Parameters:
processorName - the name of the ContextProcessor.
Throws:
NotRegisteredException - if a ContextProcessor with specified name is not registered.
java.lang.NullPointerException - if specified name of the ContextProcessor is null.

isRegistered

public boolean isRegistered(java.lang.String processorName)
Returns if a ContextProcessor with specified name is currently registered.

Specified by:
isRegistered in interface Registry<java.lang.String,ContextProcessor>
Parameters:
processorName - the name of the ContextProcessor.
Returns:
if a ContextProcessor with specified name is currently registered.
Throws:
java.lang.NullPointerException - if specified name of ContextProcessor is null.

get

public ContextProcessor get(java.lang.String processorName)
Returns ContextProcessor with specified name or null if there is no such ContextProcessor registered.

Specified by:
get in interface Registry<java.lang.String,ContextProcessor>
Parameters:
processorName - the name of the ContextProcessor.
Returns:
the ContextProcessor or null if there is no such ContextProcessor registered.
Throws:
java.lang.NullPointerException - if specified name of ContextProcessor is null.

getAll

public ContextProcessor[] getAll()
Returns all currently registered ContextProcessors.

Specified by:
getAll in interface Registry<java.lang.String,ContextProcessor>
Returns:
all currently registered ContextProcessors.


Copyright © 2010 Distributed Systems Group, Vienna University of Technology. All Rights Reserved.