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.
11 package eu
.etaxonomy
.cdm
.api
.application
;
13 import java
.util
.List
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.hibernate
.collection
.internal
.AbstractPersistentCollection
;
17 import org
.hibernate
.proxy
.AbstractLazyInitializer
;
18 import org
.springframework
.context
.ApplicationListener
;
19 import org
.springframework
.core
.io
.ClassPathResource
;
20 import org
.springframework
.core
.io
.Resource
;
22 import eu
.etaxonomy
.cdm
.api
.longrunningService
.ILongRunningTasksService
;
23 import eu
.etaxonomy
.cdm
.api
.service
.ITestService
;
24 import eu
.etaxonomy
.cdm
.cache
.CdmRemoteCacheManager
;
25 import eu
.etaxonomy
.cdm
.common
.monitor
.IProgressMonitor
;
26 import eu
.etaxonomy
.cdm
.common
.monitor
.NullProgressMonitor
;
27 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
28 import eu
.etaxonomy
.cdm
.io
.service
.IIOService
;
29 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
30 import eu
.etaxonomy
.taxeditor
.service
.ICachedCommonService
;
31 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionManager
;
34 * CDM Application Controller class for remoting clients
36 * FIXME:Remoting extending {@link CdmApplicationController} is a temporary workaround.
37 * The {@link CdmApplicationController} should be split into a CdmApplicationControllerBase
38 * class with {@link CdmApplicationController} and this class as subclasses
41 public class CdmApplicationRemoteController
extends CdmApplicationController
{
43 private static final Logger logger
= Logger
.getLogger(CdmApplicationRemoteController
.class);
46 public static final Resource DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE
=
47 new ClassPathResource("/eu/etaxonomy/cdm/remotingApplicationContext.xml");
48 private final Resource applicationContextResource
;
49 private final IProgressMonitor progressMonitor
;
50 private final ICdmRemoteSource remoteSource
;
54 * Creates new instance of CdmApplicationRemoteController
56 * @param applicationContextResource
58 * @param omitTermLoading
59 * @param progressMonitor
63 // public static CdmApplicationRemoteController NewInstance(Resource applicationContextResource,
64 // ICdmRemoteSource remoteSource,
65 // IProgressMonitor progressMonitor,
66 // List<ApplicationListener> listeners) {
67 // return new CdmApplicationRemoteController(applicationContextResource,
75 * Creates new instance of CdmApplicationRemoteController
77 * @param applicationContextResource
79 * @param omitTermLoading
80 * @param progressMonitor
84 public static CdmApplicationRemoteController
NewInstance(ICdmRemoteSource remoteSource
,
85 IProgressMonitor progressMonitor
,
86 List
<ApplicationListener
> listeners
) {
88 return new CdmApplicationRemoteController(DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE
,
96 public static CdmApplicationRemoteController
NewInstance(ICdmRemoteSource remoteSource
,
98 IProgressMonitor progressMonitor
,
99 List
<ApplicationListener
> listeners
) {
101 return new CdmApplicationRemoteController(DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE
,
110 * Constructs CdmApplicationRemoteController
112 * @param applicationContextResource
113 * @param remoteSource
114 * @param omitTermLoading
115 * @param progressMonitor
118 private CdmApplicationRemoteController(Resource applicationContextResource
,
119 ICdmRemoteSource remoteSource
,
121 IProgressMonitor progressMonitor
,
122 List
<ApplicationListener
> listeners
){
123 logger
.info("Start CdmApplicationRemoteController with remote source: " + remoteSource
.getName());
124 this.applicationContextResource
=
125 applicationContextResource
!= null ? applicationContextResource
: DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE
;
126 this.progressMonitor
= progressMonitor
!= null ? progressMonitor
: new NullProgressMonitor();
127 this.remoteSource
= remoteSource
;
128 setNewRemoteSource(remoteSource
, validateXml
, listeners
);
136 * Creates and starts a new spring application context
138 * @param remoteSource object for connecting to an http-invoker server
139 * @param omitTermLoading
143 public boolean setNewRemoteSource(ICdmRemoteSource remoteSource
,
145 List
<ApplicationListener
> listeners
){
147 logger
.info("Connecting to '" + remoteSource
.getName() + "'");
151 progressMonitor
.beginTask("Connecting to '" + remoteSource
.getName() + "'", nTasks
);
153 progressMonitor
.subTask("Initialising CDM Model Cache ...");
154 CdmRemoteCacheManager
.getInstance();
155 CdmRemoteCacheManager
.removeEntityCaches();
156 progressMonitor
.worked(1);
157 progressMonitor
.subTask("Starting application context ...");
159 progressMonitor
.worked(1);
160 progressMonitor
.done();
165 protected void init(){
166 configuration
= new CdmApplicationRemoteConfiguration(remoteSource
);
167 ((CdmApplicationRemoteConfiguration
)configuration
).setApplicationContext(applicationContext
);
168 AbstractLazyInitializer
.setConfiguration((CdmApplicationRemoteConfiguration
)configuration
);
169 AbstractPersistentCollection
.setConfiguration((CdmApplicationRemoteConfiguration
)configuration
);
172 public ICdmEntitySessionManager
getCdmEntitySessionManager() {
173 return ((CdmApplicationRemoteConfiguration
)configuration
).getCdmEntitySessionManager();
176 public IIOService
getIOService(){
177 return ((CdmApplicationRemoteConfiguration
)configuration
).getIOService();
180 public ILongRunningTasksService
getLongRunningTasksService(){
181 return ((CdmApplicationRemoteConfiguration
)configuration
).getLongRunningTasksService();
184 public ITestService
getTestService(){
185 return ((CdmApplicationRemoteConfiguration
)configuration
).getTestService();
188 public ICachedCommonService
getCachedCommonService(){
189 return ((CdmApplicationRemoteConfiguration
)configuration
).getCachedCommonService();
192 public IEditGeoService
getEditGeoService() {
193 return ((CdmApplicationRemoteConfiguration
)configuration
).getEditGeoService();