|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.ws4d.java.service.ServiceCommons org.ws4d.java.service.DefaultService
public class DefaultService
Default implementation of a DPWS service.
This class should be used to create a DPWS service. A new service should
extend the DefaultService
class and add operations to the newly
created service. It is also possible to use the default implementation.
public class SampleService extends DefaultService { public SampleService() { // create operations here, add them to the service } }
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.ws4d.java.service.ServiceCommons |
---|
ServiceCommons.OperationSignature, ServiceCommons.PortType |
Constructor Summary | |
---|---|
DefaultService()
Default DPWS service. |
|
DefaultService(int configurationId)
Default DPWS service with given configuration identifier. |
Method Summary | |
---|---|
void |
addBinding(CommunicationBinding binding)
Adds the given binding to this Bindable . |
void |
addEventSource(EventSource event)
Add an event to this service. |
void |
addGroup(HTTPGroup group)
|
void |
addOperation(Operation operation)
Add an operation to this service. |
void |
addPortType(QName portTypeName)
Add a port type (name) to this service. |
void |
addUser(HTTPUser user)
|
void |
clearBindings()
Removes all bindings from this Bindable instance. |
void |
define(URI wsdlUri)
Enables dynamic service creation from an existing WSDL description. |
void |
define(WSDL wsdl)
Enables dynamic service creation from an existing WSDL description. |
EventSource |
getAnyEventSource(QName portType,
java.lang.String eventName)
Returns the first (or last, or ANY other) event source with the specified portType and eventName . |
Operation |
getAnyOperation(QName portType,
java.lang.String operationName)
Returns the first (or last, or ANY other) operation with the specified portType and operationName . |
Iterator |
getBindings()
Returns an iterator over all bindings
assigned to this Bindable instance. |
int |
getConfigurationID()
Gets configuration identifier. |
WSDL |
getDescription(java.lang.String targetNamespace)
Returns a WSDL document describing this service by the given namespace. |
Iterator |
getDescriptionsForPortTypes()
Returns an iterator containing all WSDL documents describing this service. |
Iterator |
getEprInfos()
Returns an iterator of EprInfo . |
EventSource |
getEventSource(QName portType,
java.lang.String eventName,
java.lang.String inputName,
java.lang.String outputName)
Gets event source of specified portType with given
eventName . |
EventSource |
getEventSource(java.lang.String outputAction)
Gets event source with specified unique outputAction . |
Iterator |
getEventSources()
Gets all events sources. |
Iterator |
getEventSources(QName portType)
Gets all event sources of the specified service port type. |
Operation |
getOperation(QName portType,
java.lang.String opName,
java.lang.String inputName,
java.lang.String outputName)
Gets an operation of specified portType with given
opName . |
Operation |
getOperation(java.lang.String inputAction)
Gets operation with specified unique inputAction . |
Iterator |
getOperations()
Gets all operations. |
Iterator |
getOperations(QName portType)
Gets all operations of the specified service port type. |
DeviceReference |
getParentDeviceReference()
Gets device reference of parent device. |
Iterator |
getPortTypes()
Gets service port types. |
URI |
getServiceId()
Gets service id |
ServiceReference |
getServiceReference()
Gets the service reference. |
long |
getStatus(ClientSubscription subscription)
Returns the duration in milliseconds until expiration of the specified client subscription. |
Iterator |
getTargetNamespaces()
Returns the namespaces based on the port types for this service. |
boolean |
hasBindings()
Returns true only if this Bindable instance has
at least one binding assigned. |
boolean |
isRemote()
Is the service remote (proxy) or local? |
boolean |
isRunning()
Returns true , if this local service is currently in the
running state. |
void |
pause()
Pauses service. |
boolean |
removeBinding(CommunicationBinding binding)
Removes the specified binding from this Bindable instance. |
long |
renew(ClientSubscription subscription,
long duration)
Renews an existing subscription with a new duration. |
void |
setParentDevice(LocalDevice device)
Sets the parent device for this service. |
void |
setServiceId(URI serviceId)
Sets the service identifier for this service. |
void |
start()
Starts this service. |
void |
stop()
Stops this service. |
ClientSubscription |
subscribe(EventSink sink,
java.lang.String clientSubscriptionId,
URISet eventActionURIs,
long duration)
Initializes event receiving from specified event sender. |
boolean |
supportsBindingChanges()
Returns true , if it is safe to call one of the mutator
methods ((Bindable.addBinding(CommunicationBinding) ,
Bindable.removeBinding(CommunicationBinding) , (Bindable.clearBindings() ,
etc.) at this time without getting an IllegalStateException . |
void |
unsubscribe(ClientSubscription subscription)
Unsubscribe specified subscription. |
Methods inherited from class org.ws4d.java.service.ServiceCommons |
---|
getCertificate, getDescriptions, getPortTypeAttribute, getPortTypeAttributes, getPrivateKey, hasPortTypeAttributes, isSecure, setCertificate, setPortTypeAttribute, setPortTypeAttributes, setPrivateKey, setSecure, setSecureService, toString |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.ws4d.java.service.Service |
---|
getCertificate, getDescriptions, getPortTypeAttribute, getPortTypeAttributes, hasPortTypeAttributes, isSecure, setCertificate, setSecure |
Constructor Detail |
---|
public DefaultService()
No configuration identifier used. No configuration will be loaded for this service.
public DefaultService(int configurationId)
Creates an default DPWS service and tries to load the configuration properties for the service.
configurationId
- configuration identifier.Method Detail |
---|
public void start() throws java.io.IOException
LocalService
start
in interface LocalService
java.io.IOException
public void stop() throws java.io.IOException
LocalService
stop
in interface LocalService
java.io.IOException
public void pause()
LocalService
pause
in interface LocalService
public boolean isRunning()
LocalService
true
, if this local service is currently in the
running state. Returns false
otherwise.
isRunning
in interface LocalService
public ServiceReference getServiceReference()
Service
getServiceReference
in interface Service
public boolean hasBindings()
Bindable
true
only if this Bindable
instance has
at least one binding
assigned. Returns
false
, if it doesn't have any bindings.
hasBindings
in interface Bindable
public Iterator getBindings()
Bindable
bindings
assigned to this Bindable
instance. This iterator will have
no next elements (rather than being ), if the
Bindable
doesn't have any bindings.
- Specified by:
getBindings
in interface Bindable
- Returns:
- an iterator over all available
bindings
public boolean supportsBindingChanges()
Bindable
true
, if it is safe to call one of the mutator
methods ((Bindable.addBinding(CommunicationBinding)
,
Bindable.removeBinding(CommunicationBinding)
, (Bindable.clearBindings()
,
etc.) at this time without getting an IllegalStateException
.
Returns false
otherwise.
Some implementations of this interface may not allow for bindings to be
added or removed all the time, but rather only when the actual
implementation is in a certain set of states (note that this set could be
empty or contain solely a single set). By calling this method and
observing its return value it is possible for a client to determine
whether this Bindable
supports changes within its current
state.
supportsBindingChanges
in interface Bindable
true
if this Bindable
instance may be
modified at the moment without throwing
IllegalStateException
s, false
otherwiseBindable.addBinding(CommunicationBinding)
,
Bindable.removeBinding(CommunicationBinding)
,
Bindable.clearBindings()
public void addBinding(CommunicationBinding binding) throws WS4DIllegalStateException
Bindable
Bindable
. Does nothing if the
Bindable
already contains the binding.
addBinding
in interface Bindable
binding
- the binding to add
WS4DIllegalStateException
- in case this Bindable
doesn't currently support modifications (see
Bindable.supportsBindingChanges()
)public boolean removeBinding(CommunicationBinding binding) throws WS4DIllegalStateException
Bindable
Bindable
instance.
Does nothing, if the Bindable
doesn't contain the given
binding. Returns true
if the binding was removed and
false
if it didn't exist.
removeBinding
in interface Bindable
binding
- the binding to remove
true
if this Bindable
instance had the
given binding assigned and it was removed successfully,
false
otherwise
WS4DIllegalStateException
- in case this Bindable
doesn't currently support modifications (see
Bindable.supportsBindingChanges()
)public void clearBindings() throws WS4DIllegalStateException
Bindable
Bindable
instance. Does
nothing if there are no bindings assigned.
clearBindings
in interface Bindable
WS4DIllegalStateException
- in case this Bindable
doesn't support modifications at the current time (see
Bindable.supportsBindingChanges()
)public boolean isRemote()
Service
isRemote
in interface Service
public URI getServiceId()
Service
getServiceId
in interface Service
public Iterator getOperations()
Service
getOperations
in interface Service
getOperations
in class ServiceCommons
public Iterator getOperations(QName portType)
Service
getOperations
in interface Service
getOperations
in class ServiceCommons
portType
- specific port type
public Operation getOperation(QName portType, java.lang.String opName, java.lang.String inputName, java.lang.String outputName)
Service
portType
with given
opName
. The inputName
and/or
outputName
may be null
only if the requested
operation doesn't have any input/output. Otherwise, this method won't get
any results.
When an operation is added to a service, and it doesn't provide an
explicit name for either its input or output elements (see
OperationCommons.setInputName(String)
and
OperationCommons.setOutputName(String)
), a default name is generated
according to the WSDL 1.1 Specification. As long as there are other
operations with the same input/output name which have already been added
to this service, an incremental index is appended to the default
generated name.
portType
and with the given opName
is
NOT overloaded (i.e. there is no other operation within the same
port type with the same operation name), then you can use method
Service.getAnyOperation(QName, String)
instead of this one.
getOperation
in interface Service
getOperation
in class ServiceCommons
portType
- specific port type of operationopName
- name of operationinputName
- the name of the input element which belongs to this
operation according to its WSDL; must be null
, if
operation has no inputoutputName
- the name of the output element which belongs to this
operation according to its WSDL; must be null
, if
operation has no output
null
, if not foundService.getAnyOperation(QName, String)
public Operation getOperation(java.lang.String inputAction)
Service
inputAction
.
getOperation
in interface Service
getOperation
in class ServiceCommons
inputAction
- the WS-Addressing action URI of the requested
operation according to its WSDL
null
, if not foundpublic Operation getAnyOperation(QName portType, java.lang.String operationName)
Service
portType
and operationName
. Note that
there might be more than one operation with the same name and port type
in the case of overloading. In such situations, it is the user's
responsibility to determine which of the overloaded versions was returned
by this method. This method returns null
, if there are no
operations matching the portType
and
operationName
arguments.
This method is useful in case it is known that there is only one operation with a given name within a port type.
getAnyOperation
in interface Service
getAnyOperation
in class ServiceCommons
portType
- the port type to which the desired operationoperationName
- the name of the operation
Service.getOperation(QName, String, String, String)
public Iterator getEventSources()
Service
getEventSources
in interface Service
getEventSources
in class ServiceCommons
public Iterator getEventSources(QName portType)
Service
getEventSources
in interface Service
getEventSources
in class ServiceCommons
portType
- specific port type
public EventSource getEventSource(QName portType, java.lang.String eventName, java.lang.String inputName, java.lang.String outputName)
Service
portType
with given
eventName
. The inputName
and/or
outputName
may be null
only if the requested
event source doesn't have any input/output. Otherwise, this method won't
find any results. *
When an event source is added to a service, and it doesn't provide an
explicit name for either its input or output elements (see
OperationCommons.setInputName(String)
and
OperationCommons.setOutputName(String)
), a default name is
therefore generated according to the WSDL 1.1 Specification. If there are
other event sources with the same input/output name already added to this
service, an incremental index is appended to the default generated name.
portType
and with the given eventName
is
NOT overloaded (i.e. there is no other event source within the
same port type with the same event name), then you can use method
Service.getAnyEventSource(QName, String)
instead of this one.
getEventSource
in interface Service
getEventSource
in class ServiceCommons
portType
- specific port type of operationeventName
- name of event sourceinputName
- the name of the input element that belongs to this event
source according to its WSDL; must be null
, if
event source has no inputoutputName
- the name of the output element that belongs to this
event source according to its WSDL; must be null
,
if event source has no output
null
, if not foundService.getAnyEventSource(QName, String)
public EventSource getEventSource(java.lang.String outputAction)
Service
outputAction
.
getEventSource
in interface Service
getEventSource
in class ServiceCommons
outputAction
- the WS-Addressing action URI of the requested event
source according to its WSDL
null
if not foundpublic EventSource getAnyEventSource(QName portType, java.lang.String eventName)
Service
portType
and eventName
. Note that
there might be more than one event source with the same name and port
type in the case of overloading. In such situations, it is the user's
responsibility to determine which of the overloaded versions was returned
by this method. This method returns null
, if there are no
event source matching the portType
and
eventName
arguments.
This method is useful in case it is known that there is only one event source with a given name within a port type.
getAnyEventSource
in interface Service
getAnyEventSource
in class ServiceCommons
portType
- the port type the desired event source belongs toeventName
- the name of the event source
Service.getEventSource(QName, String, String, String)
public void setServiceId(URI serviceId)
The service identifier identifies the service uniquely for the parent device.
serviceId
- the service identifier to set.public Iterator getPortTypes()
Service
getPortTypes
in interface Service
public void addPortType(QName portTypeName)
LocalService
addPortType
in interface LocalService
portTypeName
- the name of the port type to add.public Iterator getEprInfos()
Service
EprInfo
.
getEprInfos
in interface Service
EprInfo
.public void addOperation(Operation operation)
LocalService
addOperation
in interface LocalService
operation
- operation to add.public void addEventSource(EventSource event)
LocalService
addEventSource
in interface LocalService
event
- event to add.public int getConfigurationID()
The configuration identifier is necessary to resolve properties based configuration.
public void setParentDevice(LocalDevice device)
Every service is assigned to one device.
setParentDevice
in interface LocalService
devicet
- the device which the service should be assigned to.public DeviceReference getParentDeviceReference()
Service
null
in case this service doesn't reside on a device or its
underlying device is not known at this time.
getParentDeviceReference
in interface Service
null
public Iterator getTargetNamespaces()
public Iterator getDescriptionsForPortTypes()
LocalService
getDescriptionsForPortTypes
in interface LocalService
public WSDL getDescription(java.lang.String targetNamespace)
getDescription
in interface Service
targetNamespace
- the namespace.
public void define(URI wsdlUri) throws java.io.IOException
This method analyzes the WSDL loaded from wsdlUri
and adds
all supported port types found to this service. For each supported
operation (i.e. either one-way or request-response transmission types),
an instance of class OperationStub
is created and added, whereas
for each event source (aka. notification or solicit-response transmission
types) an instance of class DefaultEventSource
is added.
The actual business logic of imported one-way or request-response
operations can be specified on the corresponding OperationStub
instance after having obtained it from this service via one of the
getOperation(...)
methods like this:
DefaultService myService = ...; myService.define("http://www.example.org/myService/description.wsdl"); InvokeDelegate myDelegate = ...; Operation myOp = (OperationStub) myService.getOperation("http://www.example.org/MyServicePortType/MyOperation"); myOp.setDelegate(myDelegate);The
InvokeDelegate
instance above defines the actual code to be
executed when the myOperation
gets called. Its
InvokeDelegate.invoke(Operation, ParameterValue)
method receives
the parameters sent to the operation, as well as the operation instance
itself. The latter is useful for implementors who want to share a single
InvokeDelegate
instance between different operations.
Note that the cast to OperationStub
above is only safe if the
operation being obtained was actually created via a call to this
define(URI)
method - in any other case, e.g. when it was added
manually by means of addOperation(Operation)
, this cast will
most likely result in a java.lang.ClassCastException
.
wsdlUri
- URI pointing to the location of the WSDL document to
define this service from; the URI may have an arbitrary schema
(e.g. file, http, https, etc.) as long as there is runtime
support available for accessing it within the DPWS framework,
see DPWSFramework.getResourceAsStream(URI)
java.io.IOException
- if a failure occurs while attempting to obtain the
WSDL from the given URI
public void define(WSDL wsdl) throws java.io.IOException
This method analyzes the WSDL loaded from wsdlUri
and adds
all supported port types found to this service. For each supported
operation (i.e. either one-way or request-response transmission types),
an instance of class OperationStub
is created and added, whereas
for each event source (aka. notification or solicit-response transmission
types) an instance of class DefaultEventSource
is added.
The actual business logic of imported one-way or request-response
operations can be specified on the corresponding OperationStub
instance after having obtained it from this service via one of the
getOperation(...)
methods like this:
DefaultService myService = ...; myService.define("http://www.example.org/myService/description.wsdl"); InvokeDelegate myDelegate = ...; Operation myOp = (OperationStub) myService.getOperation("http://www.example.org/MyServicePortType/MyOperation"); myOp.setDelegate(myDelegate);The
InvokeDelegate
instance above defines the actual code to be
executed when the myOperation
gets called. Its
InvokeDelegate.invoke(Operation, ParameterValue)
method receives
the parameters sent to the operation, as well as the operation instance
itself. The latter is useful for implementors who want to share a single
InvokeDelegate
instance between different operations.
Note that the cast to OperationStub
above is only safe if the
operation being obtained was actually created via a call to this
define(URI)
method - in any other case, e.g. when it was added
manually by means of addOperation(Operation)
, this cast will
most likely result in a java.lang.ClassCastException
.
wsdl
- the WSDL object which should be used to define the serivce.
java.io.IOException
- if a failure occurs while attempting to obtain the
WSDL from the given URI
public ClientSubscription subscribe(EventSink sink, java.lang.String clientSubscriptionId, URISet eventActionURIs, long duration) throws EventingException, TimeoutException
Service
subscribe
in interface Service
sink
- event sink which will receive the notifications.eventActionURIs
- a set of action URIs to subscribe toduration
- duration in millis of subscription. If 0, subscription
does not expire.
EventingException
TimeoutException
public void unsubscribe(ClientSubscription subscription) throws EventingException, TimeoutException
Service
unsubscribe
in interface Service
subscription
- subscription to terminate.
EventingException
TimeoutException
public long renew(ClientSubscription subscription, long duration) throws EventingException, TimeoutException
Service
renew
in interface Service
EventingException
TimeoutException
public long getStatus(ClientSubscription subscription) throws EventingException, TimeoutException
Service
getStatus
in interface Service
EventingException
TimeoutException
public void addUser(HTTPUser user)
public void addGroup(HTTPGroup group)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |