org.opcfoundation.ua.application
Class ServiceHandlerComposition

java.lang.Object
  extended by org.opcfoundation.ua.application.ServiceHandlerComposition
All Implemented Interfaces:
ServiceHandler

public class ServiceHandlerComposition
extends Object
implements ServiceHandler

Composition of ServiceHandlers.


Constructor Summary
ServiceHandlerComposition()
          Constructor for ServiceHandlerComposition.
 
Method Summary
 void add(Object o)
          Add ServiceHandler or Service handling object.
<T> T
getServiceHandlerByService(Class<? extends ServiceRequest> requestClass)
          Returns the service handler that handles given request.
 ServiceHandler[] getServiceHandlers()
          getServiceHandlers.
 void getSupportedServices(Collection<Class<? extends IEncodeable>> result)
          Get supported services.
static ServiceHandler of(Object... handlers)
          Create service handler composed of a set of service handlers.
static void readWithReflection(Object serviceHandler, ServiceHandlerComposition result)
          Reads supported service handler methods with reflection.
 void serve(EndpointServiceRequest<?,?> request)
          Serve a service request.
 boolean supportsService(Class<? extends IEncodeable> clazz)
          Queries whether this handler supports a given request class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceHandlerComposition

public ServiceHandlerComposition()

Constructor for ServiceHandlerComposition.

Method Detail

of

public static final ServiceHandler of(Object... handlers)
Create service handler composed of a set of service handlers. Service handlers either (a) implement ServiceHandler or implement service request methods, e.g. methods in SessionServiceSetHandler.

Parameters:
handlers - service handlers.
Returns:
a new service handler

add

public void add(Object o)
Add ServiceHandler or Service handling object. ServiceHandler is added as is, other objects are inspectew with reflected and suitable service handling methods are added. A method is suitable for service handing if it has no return arguments and one parametrized argument of EndpointServiceReqest. For example: new Object() { public void onTestStack( EndpointServiceRequest<TestStackRequest, TestStackResponse> req) {} }

Parameters:
o - ServiceHandler or Service handling object.

getServiceHandlers

public ServiceHandler[] getServiceHandlers()

getServiceHandlers.

Returns:
an array of ServiceHandler objects.

serve

public void serve(EndpointServiceRequest<?,?> request)
           throws ServiceResultException
Serve a service request.

The implementation is allowed to may submit the response later and from another thread.

Specified by:
serve in interface ServiceHandler
Parameters:
request - the service request
Throws:
ServiceResultException - if error

supportsService

public boolean supportsService(Class<? extends IEncodeable> clazz)
Queries whether this handler supports a given request class.

Specified by:
supportsService in interface ServiceHandler
Parameters:
clazz - class
Returns:
true if this service handler can handle given class

getSupportedServices

public void getSupportedServices(Collection<Class<? extends IEncodeable>> result)
Get supported services. Result will be filled with the request class of the supported services.

Specified by:
getSupportedServices in interface ServiceHandler
Parameters:
result - to be filled with request classes of supported services.

getServiceHandlerByService

public <T> T getServiceHandlerByService(Class<? extends ServiceRequest> requestClass)
Returns the service handler that handles given request.

Type Parameters:
T - service handler class
Parameters:
requestClass - request class
Returns:
the service handler or null

readWithReflection

public static void readWithReflection(Object serviceHandler,
                                      ServiceHandlerComposition result)
Reads supported service handler methods with reflection.

Parameters:
serviceHandler - service handler
result - composition where reflection based handlers are added


Copyright © 2018. All rights reserved.