1 package eu
.etaxonomy
.taxeditor
.service
;
3 import java
.util
.HashMap
;
4 import java
.util
.HashSet
;
9 import org
.apache
.log4j
.Logger
;
10 import org
.springframework
.remoting
.support
.RemoteInvocation
;
11 import org
.springframework
.remoting
.support
.RemoteInvocationResult
;
13 import eu
.etaxonomy
.cdm
.api
.cache
.CdmServiceCacher
;
14 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
15 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
18 public class TermServiceRequestExecutor
extends CdmServiceRequestExecutor
{
19 private static final Logger logger
= Logger
.getLogger(TermServiceRequestExecutor
.class);
21 private static Map
<TermType
, RemoteInvocationResult
> termTypeMap
= new
22 HashMap
<TermType
, RemoteInvocationResult
>();
24 private static CdmServiceCacher cdmServiceCacher
;
26 public static void setDefaultCacher(CdmServiceCacher css
) {
27 cdmServiceCacher
= css
;
31 public void cache(RemoteInvocation ri
, RemoteInvocationResult rir
) {
32 if(cdmServiceCacher
!= null) {
33 if(ri
.getMethodName().equals("listByTermType")) {
34 if(ri
.getArguments()[1] == null) {
35 Set
<DefinedTermBase
> terms
= new HashSet
<DefinedTermBase
>();
36 if(rir
.getValue() != null) {
37 terms
.addAll((List
<DefinedTermBase
>)rir
.getValue());
39 for(DefinedTermBase
<?
> term
: terms
) {
40 cdmServiceCacher
.load(term
);
42 termTypeMap
.put((TermType
)ri
.getArguments()[0], rir
);
48 logger
.info("Default CdmServiceCacher is null. Cannot cache terms");
54 public RemoteInvocationResult
fromCache(RemoteInvocation ri
) {
55 return termTypeMap
.get(ri
.getArguments()[0]);