XRouteManager routeMgr = XRouteManager.getInstance(); XServiceModelNode node = new XServiceModelNode(); try { node.setupService( "getName", routeMgr.getRoute( "myCalculationService" ), null ); Object result = node.get(); assertTrue( result.toString().compareTo( CalcTestService.class.getName() ) == 0 ); ...Normally this method of invoking a service would not be used as the services can more easily be invoked by looking up the XServiceModelNode in the overall XModel. The nodes in the XModel are configured via the Services datasource as follow:
<?xml version="1.0" encoding="UTF-8"?> <Services> <service name="calcVolume" route="remote" processor="net.xoetrope.service.test.CalcTestService"> <arg name="roomWidth" type="double"/> <arg name="roomLength" type="double"/> <arg name="roomHeight" type="double"/> <return type="double"/> </service> <service name="calcRepayments" route="remote"> <arg name="term" type="int" mandatory="true"/> <arg name="value" type="double" mandatory="true"/> <arg name="deposit" type="double" mandatory="false"/> </service> <service name="getName" route="calcRoute"> <return type="String"/> </service> <service name="getNumber" route="calcRoute"> <return type="int"/> </service> </Services>
try { XServiceModelNode node = (XServiceModelNode)XModel.getInstance().get( "calcVolume" ); node.setAttribValue( 0, new Double( 3.9 )); node.setAttribValue( 1, new Double( 4.6 )); node.setAttribValue( 2, new Double( 2.5 )); Object result = node.get(); assertTrue( result instanceof Double ); assertTrue( ((Double)result).doubleValue() == 101.0 ); } catch ( Exception ex ) { ex.printStackTrace(); }Note that on the server side of a remote call the services may need to be implemented in the reverse order and in a slightly different order i.e. the server side will have to provide an implementation of the service.
Copyright (c) Xoetrope Ltd., 2001-2006, see license.txt for details
|
|