Hi All,
Since there is not enough documentation on notifications, I wanted to
solve my solution (the code may not be perfect, but it is something :-)
) with you just in case it may be of use for another person in the future.
Math.wsdl:
-------------------
<xsd:element name="MathResource">
<xsd:complexType >
<xsd:sequence>
<xsd:element name="Value" type="xsd:int"/>
<xsd:element name="LastOp" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="MathResourceProperties" >
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns:MathResource" minOccurs="1"
maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
MathQNames.java:
-------------------------------
public static final QName MATH_RESOURCE = new QName(NS, "MathResource");
MathService.java:
------------------------------
...
/* Constructor. Initializes RPs and topic */
public MathService() throws RemoteException {
/* Create RP set */
this.propSet = new SimpleResourcePropertySet(
MathQNames.RESOURCE_PROPERTIES);
/* Configure the Topics */
this.topicList = new SimpleTopicList(this);
mathResourceRP = new
SimpleResourceProperty(MathQNames.MATH_RESOURCE);
MathResource m = new MathResource();
m.setValue(0);
m.setLastOp("UNKNOWN");
mathResourceRP.add(m);
mathResourceRP = new ResourcePropertyTopic(mathResourceRP);
((ResourcePropertyTopic) mathResourceRP).setSendOldValue(false);
this.topicList.addTopic((Topic) mathResourceRP);
this.propSet.add(mathResourceRP);
}
public AddResponse add(int a) throws RemoteException {
Integer value = ((MathResource) mathResourceRP.get(0)).getValue();
String lastOp = ((MathResource) mathResourceRP.get(0)).getLastOp();
value = new Integer(value.intValue() + a);
MathResource m = new MathResource();
m.setValue(value);
m.setLastOp("ADDITION");
mathResourceRP.set(0, m);
return new AddResponse();
}
...
ValueListener.java:
--------------------------------
...
public void deliver(List topicPath, EndpointReferenceType producer,
Object message) {
ResourcePropertyValueChangeNotificationElementType notif_elem;
ResourcePropertyValueChangeNotificationType notif;
notif_elem = (ResourcePropertyValueChangeNotificationElementType)
message;
notif = notif_elem.getResourcePropertyValueChangeNotification();
if (notif != null) {
System.out.println("A notification has been delivered");
try {
Element doc = notif.getNewValue().get_any()[0].getAsDOM();
System.out.println("Value : " +
doc.getElementsByTagName("Value").item(0).getTextContent());
System.out.println("LastOp: " +
doc.getElementsByTagName("LastOp").item(0).getTextContent());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
...
topicExpression.setValue(MathQNames.MATH_RESOURCE);
...
Cheers
-fa
Fuat Akal wrote:
Hi All,
Is there anybody who could help me out defining a complex type as the
notification topic?
...