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

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
All Implemented Interfaces:
Observable<QueryState,ContextQuery,QueryObserver>, org.osgi.framework.BundleActivator
Direct Known Subclasses:
ActionQuery, ProcessedEventQuery

public abstract class ContextQuery
extends BaseObservable<QueryState,ContextQuery,QueryObserver>
implements org.osgi.framework.BundleActivator

This class is used by the ContextListeners to tell on which ContextEvents the listeners are interested in. Two properties are used to select ContextEvents:

Author:
fei, sanjin

Constructor Summary
protected ContextQuery(java.lang.String name, java.lang.String listenedType)
          Create instance of query.
protected ContextQuery(java.lang.String name, java.lang.String listenedType, java.lang.String criteria)
          Creates an instance of query.
 
Method Summary
 void attach(QueryObserver observer)
          Attach specified QueryObserver so it will in future receive QueryState change notifications of this ContextQuery.
 void destroy()
          Destroys this ContextQuery.
 boolean equals(java.lang.Object obj)
          Compares this ContextQuery to the specified Object.
 java.lang.String getCriteria()
          Returns the logical expression this ContextQuery.
 java.lang.String getListenedType()
          Returns the name of listened ContextEventType.
 java.lang.String getName()
          Returns the globally unique name of this ContextQuery.
 boolean hasCriteria()
          Returns if this ContextQuery has the criteria defined.
 int hashCode()
          Returns hash code for this ContextQuery.
 boolean isDestroyed()
          Returns if this ContextQuery is destroyed.
abstract  void onEvent(ContextEvent event)
          This method is called when a ContextEvent with same event name occurs for which the criteria is satisfied.
abstract  void start(org.osgi.framework.BundleContext bundleContext)
           
abstract  void stop(org.osgi.framework.BundleContext bundleContext)
           
 
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

ContextQuery

protected ContextQuery(java.lang.String name,
                       java.lang.String listenedType,
                       java.lang.String criteria)
Creates an instance of query. The name should be globally unique, meaning that if two ContextQuerys have same name then their listenedTypes and criterias are equal. The listenedType is name of ContextEventType on which criteria is executed. The criteria is the logical statement which further separates the events of interest. If ContextQuery should catch all listenedType events, we set criteria to be null or blank string or use ContextQuery(String, String) constructor.

Parameters:
name - the globally unique name of the ContextQuery.
listenedType - the name of listened ContextEventType.
criteria - the logical expression of the ContextQuery.
Throws:
java.lang.NullPointerException - if specified name or listened type is null.
java.lang.IllegalArgumentException - if specified name or listened type is an empty or blank string.

ContextQuery

protected ContextQuery(java.lang.String name,
                       java.lang.String listenedType)
Create instance of query. The name should be globally unique, meaning that if two ContextQuerys have same name then their listenedTypes and criterias are equal. The listenedType is name of ContextEventType to be caught.

Parameters:
name - the globally unique name of the ContextQuery.
listenedType - the name of listened ContextEventType.
Throws:
java.lang.NullPointerException - if specified name or listened type is null.
java.lang.IllegalArgumentException - if specified name or listened type is an empty or blank string.
Method Detail

getName

public java.lang.String getName()
Returns the globally unique name of this ContextQuery.

Returns:
the globally unique name of this ContextQuery.

getListenedType

public java.lang.String getListenedType()
Returns the name of listened ContextEventType.

Returns:
the name of listened ContextEventType.
See Also:
ContextEventType.getName()

getCriteria

public java.lang.String getCriteria()
Returns the logical expression this ContextQuery.

Returns:
the logical expression this ContextQuery.

hasCriteria

public boolean hasCriteria()
Returns if this ContextQuery has the criteria defined.

Returns:
if this ContextQuery has the criteria defined.

isDestroyed

public boolean isDestroyed()
Returns if this ContextQuery is destroyed.

Returns:
if this ContextQuery is destroyed.

start

public abstract void start(org.osgi.framework.BundleContext bundleContext)
Specified by:
start in interface org.osgi.framework.BundleActivator

stop

public abstract void stop(org.osgi.framework.BundleContext bundleContext)
Specified by:
stop in interface org.osgi.framework.BundleActivator

destroy

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

Throws:
QueryDestroyedException - if ContextQuery has been already destroyed.

onEvent

public abstract void onEvent(ContextEvent event)
                      throws QueryDestroyedException
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.

Parameters:
event - the occurred ContextEvent.
Throws:
QueryDestroyedException - if ContextQuery has been previously destroyed.

attach

public void attach(QueryObserver observer)
Attach specified QueryObserver so it will in future receive QueryState change notifications of this ContextQuery.

Specified by:
attach in interface Observable<QueryState,ContextQuery,QueryObserver>
Overrides:
attach in class BaseObservable<QueryState,ContextQuery,QueryObserver>
Parameters:
observer - the QueryObserver.

hashCode

public int hashCode()
Returns hash code for this ContextQuery. The hash code for a ContextQuery object is computed as:
 name * 31 + listened type
 
using integer arithmetic.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this ContextQuery.

equals

public boolean equals(java.lang.Object obj)
Compares this ContextQuery to the specified Object. The result is true if and only if the argument is not null and is a ContextQuery object that has same name, listened type and criteria as this ContextQuery.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the Object to compare this ContextQuery against.
Returns:
true if ContextQuerys are equal; false otherwise.


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