+ private <T extends RpcService> T newRpcProxyForSession(Class<T> service) {
+
+ RpcMapper<T> mapper = mapping.rpcMapperForClass(service);
+ if (mapper == null) {
+ log.error("Mapper for " + service + "is unavailable.");
+ return null;
+ }
+ T proxy = mapper.getConsumerProxy(rpcProxyHandler);
+
+ return proxy;
+ }
+
+ private Future<RpcResult<? extends DataObject>> rpcProxyInvoked(
+ RpcService rpcProxy, QName rpcType, DataObject inputData) {
+ if (rpcProxy == null) {
+ throw new IllegalArgumentException("Proxy must not be null");
+ }
+ if (rpcType == null) {
+ throw new IllegalArgumentException(
+ "rpcType (QName) should not be null");
+ }
+ Future<RpcResult<? extends DataObject>> ret = null;
+
+ // Real invocation starts here
+ RpcMapper<? extends RpcService> mapper = mapping
+ .rpcMapperForProxy(rpcProxy);
+ RpcService impl = rpcImpls.get(mapper.getServiceClass());
+
+ if (impl == null) {
+ // RPC is probably remote
+ CompositeNode inputNode = null;
+ Mapper<? extends DataObject> inputMapper = mapper.getInputMapper();
+ if (inputMapper != null) {
+ inputNode = inputMapper.domFromObject(inputData);
+ }
+ Future<RpcResult<CompositeNode>> biResult = biSession.rpc(rpcType,
+ inputNode);
+ ret = new TranslatedFuture(biResult, mapper);
+
+ } else {
+ // RPC is local
+ Callable<RpcResult<? extends DataObject>> invocation = localRpcCallableFor(
+ impl, mapper, rpcType, inputData);
+ ret = executor.submit(invocation);
+ }
+ return ret;
+ }
+
+ private Callable<RpcResult<? extends DataObject>> localRpcCallableFor(
+ final RpcService impl,
+ final RpcMapper<? extends RpcService> mapper, final QName rpcType,
+ final DataObject inputData) {
+
+ return new Callable<RpcResult<? extends DataObject>>() {
+
+ @Override
+ public RpcResult<? extends DataObject> call() throws Exception {
+ return mapper.invokeRpcImplementation(rpcType, impl, inputData);
+ }
+ };
+ }
+
+ // Binding Independent invocation of Binding Aware RPC
+ private RpcResult<CompositeNode> invokeLocalRpc(QName rpc,
+ CompositeNode inputNode) {
+ RpcMapper<? extends RpcService> mapper = mapping.rpcMapperForData(rpc,
+ inputNode);
+
+ DataObject inputTO = mapper.getInputMapper().objectFromDom(inputNode);
+
+ RpcService impl = rpcImpls.get(mapper.getServiceClass());
+ if (impl == null) {
+ log.warn("Implementation for rpc: " + rpc + "not available.");
+ }
+ RpcResult<? extends DataObject> result = mapper
+ .invokeRpcImplementation(rpc, impl, inputTO);
+ DataObject outputTO = result.getResult();
+
+ CompositeNode outputNode = null;
+ if (outputTO != null) {
+ outputNode = mapper.getOutputMapper().domFromObject(outputTO);
+ }
+ return Rpcs.getRpcResult(result.isSuccessful(), outputNode,
+ result.getErrors());
+ }
+