L
- the type of listeners compatible with this resourcepublic interface Resource<L extends Listener> extends Nameable, Registrable
Listener
instances. In general
a resource implements listener registration mechanism as well as other
supporting utilities for specific listener type. Resource may be also
a source of listener events or act as a bridge between the event source
and the listeners.
Each resource is identified by its name returned by getName()
method. Resource names should be fully qualified and unique for different
resource implementations as resources with the same names are considered
equal by the equals(Object)
method.
A resource must use Listener.equals(java.lang.Object)
to determine whether two
listeners should be considered as the same. Similarly a resource should
always check if it supports the encountered listener type and appropriately
throw a ClassCastException
. Resource does not permit null
listeners.
Listener
,
Resources
,
DefaultResources
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o)
Compares the specified object with this resource for equality.
|
java.lang.String |
getName()
Returns a fully qualified name of this resource.
|
int |
hashCode()
Returns the hash code value for this resource.
|
void |
register(L listener)
Registers a listener to this resource.
|
<U extends Listener> |
registered(java.lang.Class<U> type)
Returns all registered listeners assignable to the specified
listener type.
|
boolean |
registered(Listener listener)
Determines whether the specified listener
is registered to this resource.
|
void |
unregister(L listener)
Unregisters a listener from this resource.
|
postRegister, postUnregister, preRegister, preUnregister
void register(L listener)
Warning: Does not invoke listener registration hooks.
Only ListenerManager.register(Listener)
is responsible
for proper hook method invocation during the registration process.
listener
- the listener to be registered, not null
java.lang.ClassCastException
- if the type of the specified listener
prevents it from being registered to this resourceListenerAlreadyRegistredException
- if the specified listener
is already registered and this resource panicsjava.lang.NullPointerException
- if the specified listener is null
UnsupportedResourceException
- if the resource does not support
this operation (it could mean that it is not implemented yet)void unregister(L listener)
Warning: Does not invoke listener unregistration hooks.
Only ListenerManager.unregister(Listener)
is responsible
for proper hook method invocation during the unregistration process.
listener
- the listener to be unregistered, not null
java.lang.ClassCastException
- if the type of the specified listener
prevents it from being unregistered from this resourceListenerNotRegistredException
- if the specified listener
is not registered and this resource panicsjava.lang.NullPointerException
- if the specified listener is null
UnsupportedResourceException
- if the resource does not support
this operation (it could mean that it is not implemented yet)<U extends Listener> java.util.Collection<U> registered(java.lang.Class<U> type)
type
- the listener type of the registered listeners,
not null
java.lang.NullPointerException
- if the specified listener
type is null
boolean registered(Listener listener)
listener
- the listener to be checked, not null
true
if the specified listener is registered
to this resource, false
otherwisejava.lang.NullPointerException
- if the specified listener is null
boolean equals(@Nullable java.lang.Object o)
true
if the specified object is also resource
and the two resources have the same name. This definition ensures
that this method works properly across different implementations
of the resource interface.equals
in class java.lang.Object
o
- an object to be compared for equality with this resourcetrue
if the specified object is equal to
this resource, false
otherwiseint hashCode()
hashCode
in class java.lang.Object