All Packages Class Hierarchy This Package Previous Next Index
Class uhr.core.attract.ServiceClientAideStd
java.lang.Object
|
+----uhr.core.attract.ServiceClientAideStd
- public class ServiceClientAideStd
- extends Object
- implements ServiceClientAide
This serves as an "aide-de-camp" to a ServiceClient.
An aide-de-camp is a subordinate acting as a confidential
assistant to a superior. This is similar to a delegate.
The benefit is fewer methods in the ServiceClient interface
and greater reuse.
Note this implementation relies on the use of Attractors
as identifiers for ServiceNeeds, via the equals() method in
each. Thus ServiceNeeds should not override the equals()
in Attractors.
-
ServiceClientAideStd(ServiceClient)
-
-
addDeferredNeed(String,
String, Object)
- Creates and adds a deferred ServiceNeed with the type and a
single attribute.
-
addNeed(ServiceNeed)
- Adds a ServiceNeed.
-
addNeed(String,
String, Object)
- Creates and adds a ServiceNeed with the type and a single
attribute.
-
enumerateServiceNeeds()
- Returns the client's needs.
-
getService(Attractor)
- Returns the service for the attractor or null if none is stored
in this class.
-
getServiceNeed(Attractor)
- Returns the ServiceItem having the attractor or null if none.
-
satisfyDeferredNeed(Attractor)
- Satisfies the deferred need with the attractor.
-
setServiceNeeded(ServiceNeed,
Object)
- Sets the service provided by a host and identifed by the need.
ServiceClientAideStd
public ServiceClientAideStd(ServiceClient client)
addNeed
public void addNeed(ServiceNeed need)
- Adds a ServiceNeed. The needer uses this method to populate the
aide with needs, which MUST be done before the aide is
exposed. This method also adds the client to the need.
- Parameters:
- need - describes the service needed.
- Throws: IllegalArgumentException
- if the attractor is null.
- Throws: IllegalStateException
- if the attractor in the need
has already been added. Identical attractors in the same need
are ambiguous.
addNeed
public ServiceNeed addNeed(String type,
String attributeName,
Object attributeValue)
- Creates and adds a ServiceNeed with the type and a single
attribute. This is a convenience method.
- Parameters:
- type - the need type.
- attributeName - the attribute name.
- attributeValue - the attribute value.
- Returns:
- the need created.
addDeferredNeed
public ServiceNeed addDeferredNeed(String type,
String attributeName,
Object attributeValue)
- Creates and adds a deferred ServiceNeed with the type and a
single attribute. This is a convenience method.
- Parameters:
- type - the need type.
- attributeName - the attribute name.
- attributeValue - the attribute value.
- Returns:
- the need created.
enumerateServiceNeeds
public Enumeration enumerateServiceNeeds()
- Returns the client's needs. There is usually at least one.
- Returns:
- all the client's ServiceNeeds. The order is
irrelevant.
getServiceNeed
public ServiceNeed getServiceNeed(Attractor attractor)
- Returns the ServiceItem having the attractor or null if none.
Note that any attractor can be used, not just the one in the
need. This allows lookup without the original attractor.
- Parameters:
- attractor - identifies the desired ServiceNeed.
- Returns:
- the desired need or null.
setServiceNeeded
public void setServiceNeeded(ServiceNeed need,
Object service)
- Sets the service provided by a host and identifed by the need.
This method is a callback from whoever is performing the hookup.
If this is called and the client's service is not
null, this is a replacement call. Hereafter the client should
use the new reference and should release the old reference.
- Parameters:
- id - the service id. Normally this is no extra work on the
client's part at all.
- need - the need that described the service.
- service - the attracted service, which must be cast
to the type for that service.
- Throws: IllegalArgumentException
- if the id is unrecognized.
getService
public Object getService(Attractor attractor)
- Returns the service for the attractor or null if none is stored
in this class.
If null is returned the service may be unavailable, not
available yet, the ServiceNeed was optional, an exception has
occured, etc. If null ServiceSource can be used if set. If null
the attraction is said to be unsatisfied.
If not null then the attraction is currently satisfied.
This method is used to check satisfaction integrity
and for service replacement.
- Parameters:
- attractor - identifies the ServiceNeed.
- Returns:
- the service for the id stored here.
satisfyDeferredNeed
public void satisfyDeferredNeed(Attractor attractor)
- Satisfies the deferred need with the attractor. Does nothing if
already satisfied.
- Parameters:
- attractor - identifies the ServiceNeed.
- Throws: IllegalStateException
- if the serviceID is not found
or the need is not deferred.
All Packages Class Hierarchy This Package Previous Next Index