at.ac.tuwien.infosys.sm4all.copal.api.util
Class BaseRegistry<K,V>

java.lang.Object
  extended by at.ac.tuwien.infosys.sm4all.copal.api.util.BaseObservable<RegistryObservable.RegistrationState,V,RegistryObservable.RegistryObserver<V>>
      extended by at.ac.tuwien.infosys.sm4all.copal.api.util.BaseRegistry<K,V>
Type Parameters:
K - the type of keys maintained by this Registry.
V - the type of values maintained by this Registry.
All Implemented Interfaces:
Observable<RegistryObservable.RegistrationState,V,RegistryObservable.RegistryObserver<V>>, Registry<K,V>, RegistryObservable<V>
Direct Known Subclasses:
Attributes, Authorizations, RegistryService

public abstract class BaseRegistry<K,V>
extends BaseObservable<RegistryObservable.RegistrationState,V,RegistryObservable.RegistryObserver<V>>
implements Registry<K,V>, RegistryObservable<V>

The abstract class which can be used as base class for any Registry.

Author:
sanjin

Nested Class Summary
 
Nested classes/interfaces inherited from interface at.ac.tuwien.infosys.sm4all.copal.api.util.RegistryObservable
RegistryObservable.RegistrationState, RegistryObservable.RegistryObserver<T>
 
Constructor Summary
BaseRegistry()
           
 
Method Summary
 void attach(RegistryObservable.RegistryObserver<V> observer)
          Attaches specified Observer so it will in future receive notifications on changes.
 void detach(RegistryObservable.RegistryObserver<V> observer)
          Detach specified Observer so it will not receive any future notifications on changes.
 V get(K key)
          Returns a value registered with specified key or null if there is no such value.
protected abstract  K getKey(V value)
          Return the key for specified value.
protected  java.util.Collection<V> getValues()
          Returns all registered values.
 boolean isRegistered(K key)
          Returns if there is a value registered with specified key.
 void register(V value)
          Registers specified value.
protected  void set(V... values)
          Register specified values.
protected  void setValues(V... values)
          Register specified values and remove all previously registered values.
 void unregister(K key)
          Unregisters value associated with specified key.
protected  void unregisterAll()
          Unregisters all registered values.
 
Methods inherited from class at.ac.tuwien.infosys.sm4all.copal.api.util.BaseObservable
detachAll, getObservers, notifyAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface at.ac.tuwien.infosys.sm4all.copal.api.util.Registry
getAll
 

Constructor Detail

BaseRegistry

public BaseRegistry()
Method Detail

attach

public void attach(RegistryObservable.RegistryObserver<V> observer)
Description copied from class: BaseObservable
Attaches specified Observer so it will in future receive notifications on changes.

Specified by:
attach in interface Observable<RegistryObservable.RegistrationState,V,RegistryObservable.RegistryObserver<V>>
Overrides:
attach in class BaseObservable<RegistryObservable.RegistrationState,V,RegistryObservable.RegistryObserver<V>>
Parameters:
observer - the Observer.

detach

public void detach(RegistryObservable.RegistryObserver<V> observer)
Description copied from class: BaseObservable
Detach specified Observer so it will not receive any future notifications on changes.

Specified by:
detach in interface Observable<RegistryObservable.RegistrationState,V,RegistryObservable.RegistryObserver<V>>
Overrides:
detach in class BaseObservable<RegistryObservable.RegistrationState,V,RegistryObservable.RegistryObserver<V>>
Parameters:
observer - the QueryObserver.

register

public void register(V value)
              throws AlreadyRegisteredException
Registers specified value. If there is already a value associated with same key the old value will remain registered and this method will throw AlreadyRegisteredException.

Specified by:
register in interface Registry<K,V>
Parameters:
value - the value.
Throws:
java.lang.NullPointerException - if specified value is null.
AlreadyRegisteredException - if a value with same key is already registered.
See Also:
set(Object...)

unregister

public void unregister(K key)
                throws NotRegisteredException
Unregisters value associated with specified key. If there is no value associated with specified key the registry remains unchanged and this method will throw NotRegisteredException.

Specified by:
unregister in interface Registry<K,V>
Parameters:
key - the key.
Throws:
java.lang.NullPointerException - if specified key is null.
NotRegisteredException - if there is no value associated with specified key.

isRegistered

public boolean isRegistered(K key)
Returns if there is a value registered with specified key.

Specified by:
isRegistered in interface Registry<K,V>
Parameters:
key - the key.
Returns:
if there is a value registered with specified key.
Throws:
java.lang.NullPointerException - if specified key is null.

get

public V get(K key)
Returns a value registered with specified key or null if there is no such value.

Specified by:
get in interface Registry<K,V>
Parameters:
key - the key.
Returns:
value registered with specified key or null if there is no such value.
Throws:
java.lang.NullPointerException - if specified key is null.

getKey

protected abstract K getKey(V value)
Return the key for specified value.

Parameters:
value - the value.
Returns:
the key.

set

protected void set(V... values)
Register specified values. If there is already a value associated with same key, the old value will be overwritten with new value and returned.

Parameters:
values - the values.
Throws:
java.lang.NullPointerException - if specified array of values or any value in the array is null.
See Also:
register(Object)

unregisterAll

protected void unregisterAll()
Unregisters all registered values.


getValues

protected java.util.Collection<V> getValues()
Returns all registered values.

Returns:
all registered values.

setValues

protected void setValues(V... values)
Register specified values and remove all previously registered values.

Parameters:
values - the values.
Throws:
java.lang.NullPointerException - if specified array of values or any value in the array is null.


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