2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.api
.application
;
11 import java
.util
.List
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.hibernate
.collection
.internal
.AbstractPersistentCollection
;
15 import org
.hibernate
.proxy
.AbstractLazyInitializer
;
16 import org
.springframework
.context
.ApplicationListener
;
17 import org
.springframework
.core
.io
.ClassPathResource
;
18 import org
.springframework
.core
.io
.Resource
;
20 import eu
.etaxonomy
.cdm
.api
.service
.ITestService
;
21 import eu
.etaxonomy
.cdm
.cache
.CdmRemoteCacheManager
;
22 import eu
.etaxonomy
.cdm
.common
.monitor
.IProgressMonitor
;
23 import eu
.etaxonomy
.cdm
.common
.monitor
.NullProgressMonitor
;
24 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
25 import eu
.etaxonomy
.cdm
.io
.service
.IIOService
;
26 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
27 import eu
.etaxonomy
.taxeditor
.service
.ICachedCommonService
;
28 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionManager
;
31 * CDM Application Controller class for remoting clients
33 * FIXME:Remoting extending {@link CdmApplicationController} is a temporary workaround.
34 * The {@link CdmApplicationController} should be split into a CdmApplicationControllerBase
35 * class with {@link CdmApplicationController} and this class as subclasses
37 public class CdmApplicationRemoteController
extends CdmApplicationController
{
39 private static final Logger logger
= Logger
.getLogger(CdmApplicationRemoteController
.class);
41 public static final Resource DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE
=
42 new ClassPathResource("/eu/etaxonomy/cdm/remotingApplicationContext.xml");
43 private final Resource applicationContextResource
;
44 private final IProgressMonitor progressMonitor
;
45 private final ICdmRemoteSource remoteSource
;
47 // public static CdmApplicationRemoteController NewInstance(Resource applicationContextResource,
48 // ICdmRemoteSource remoteSource,
49 // IProgressMonitor progressMonitor,
50 // List<ApplicationListener> listeners) {
51 // return new CdmApplicationRemoteController(applicationContextResource,
60 * Creates new instance of CdmApplicationRemoteController
62 * @param applicationContextResource
64 * @param omitTermLoading
65 * @param progressMonitor
69 public static CdmApplicationRemoteController
NewInstance(ICdmRemoteSource remoteSource
,
70 IProgressMonitor progressMonitor
,
71 List
<ApplicationListener
> listeners
) {
73 return new CdmApplicationRemoteController(DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE
,
80 public static CdmApplicationRemoteController
NewInstance(ICdmRemoteSource remoteSource
,
82 IProgressMonitor progressMonitor
,
83 List
<ApplicationListener
> listeners
) {
85 return new CdmApplicationRemoteController(DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE
,
93 * Constructs CdmApplicationRemoteController
95 * @param applicationContextResource
97 * @param omitTermLoading
98 * @param progressMonitor
101 private CdmApplicationRemoteController(Resource applicationContextResource
,
102 ICdmRemoteSource remoteSource
,
104 IProgressMonitor progressMonitor
,
105 List
<ApplicationListener
> listeners
){
106 logger
.info("Start CdmApplicationRemoteController with remote source: " + remoteSource
.getName());
107 this.applicationContextResource
=
108 applicationContextResource
!= null ? applicationContextResource
: DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE
;
109 this.progressMonitor
= progressMonitor
!= null ? progressMonitor
: new NullProgressMonitor();
110 this.remoteSource
= remoteSource
;
111 setNewRemoteSource(remoteSource
, validateXml
, listeners
);
116 * Creates and starts a new spring application context
118 * @param remoteSource object for connecting to an http-invoker server
119 * @param omitTermLoading
123 public boolean setNewRemoteSource(ICdmRemoteSource remoteSource
,
125 List
<ApplicationListener
> listeners
){
127 logger
.info("Connecting to '" + remoteSource
.getName() + "'");
131 progressMonitor
.beginTask("Connecting to '" + remoteSource
.getName() + "'", nTasks
);
133 progressMonitor
.subTask("Initialising CDM Model Cache ...");
134 CdmRemoteCacheManager
.getInstance();
135 CdmRemoteCacheManager
.removeEntityCaches();
136 progressMonitor
.worked(1);
137 progressMonitor
.subTask("Starting application context ...");
139 progressMonitor
.worked(1);
140 progressMonitor
.done();
145 protected void init(){
146 configuration
= new CdmApplicationRemoteConfiguration(remoteSource
);
147 ((CdmApplicationRemoteConfiguration
)configuration
).setApplicationContext(applicationContext
);
148 AbstractLazyInitializer
.setConfiguration((CdmApplicationRemoteConfiguration
)configuration
);
149 AbstractPersistentCollection
.setConfiguration((CdmApplicationRemoteConfiguration
)configuration
);
152 public ICdmEntitySessionManager
getCdmEntitySessionManager() {
153 return ((CdmApplicationRemoteConfiguration
)configuration
).getCdmEntitySessionManager();
156 public IIOService
getIOService(){
157 return ((CdmApplicationRemoteConfiguration
)configuration
).getIOService();
160 public ITestService
getTestService(){
161 return ((CdmApplicationRemoteConfiguration
)configuration
).getTestService();
164 public ICachedCommonService
getCachedCommonService(){
165 return ((CdmApplicationRemoteConfiguration
)configuration
).getCachedCommonService();
168 public IEditGeoService
getEditGeoService() {
169 return ((CdmApplicationRemoteConfiguration
)configuration
).getEditGeoService();