ICachedCommonService, CachedCommonServiceImpl : moved class to service package
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / main / java / eu / etaxonomy / taxeditor / service / CdmServiceRequestExecutor.java
1 package eu.etaxonomy.taxeditor.service;
2
3 import java.io.IOException;
4 import java.io.OutputStream;
5
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration;
8 import org.springframework.remoting.support.RemoteInvocation;
9 import org.springframework.remoting.support.RemoteInvocationResult;
10 import org.springframework.stereotype.Component;
11
12 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
13
14 @Component
15 public class CdmServiceRequestExecutor extends CdmAuthenticatedHttpInvokerRequestExecutor {
16
17 @Autowired
18 private ICdmEntitySessionManager cdmEntitySessionManager;
19
20 private RemoteInvocation currentRemoteInvocation;
21
22 @Override
23 protected void writeRemoteInvocation(RemoteInvocation invocation, OutputStream os) throws IOException {
24 currentRemoteInvocation = invocation;
25 super.writeRemoteInvocation(invocation, os);
26 }
27
28 @Override
29 protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config,
30 java.io.ByteArrayOutputStream baos)
31 throws java.io.IOException,
32 java.lang.ClassNotFoundException {
33 RemoteInvocationResult rir = fromCache(currentRemoteInvocation);
34
35 // if rir is not null at this point we assume that the
36 // the object has already been loaded in the cache and
37 // does not need to be reloaded
38
39 if(rir == null) {
40 rir = super.doExecuteRequest(config, baos);
41 if(rir.getValue() != null && !rir.hasException()) {
42 rir = new RemoteInvocationResult(cdmEntitySessionManager.load(rir.getValue()));
43 }
44 cache(currentRemoteInvocation, rir);
45 }
46 currentRemoteInvocation = null;
47
48 return rir;
49 }
50
51 public void cache(RemoteInvocation ri, RemoteInvocationResult rir) {
52
53 }
54
55 public RemoteInvocationResult fromCache(RemoteInvocation ri) {
56 return null;
57 }
58 }