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
;
14 import java
.util
.Properties
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.hibernate
.collection
.internal
.AbstractPersistentCollection
;
18 import org
.hibernate
.proxy
.AbstractLazyInitializer
;
19 import org
.springframework
.beans
.factory
.xml
.XmlBeanDefinitionReader
;
20 import org
.springframework
.context
.ApplicationListener
;
21 import org
.springframework
.context
.support
.GenericApplicationContext
;
22 import org
.springframework
.context
.support
.PropertySourcesPlaceholderConfigurer
;
23 import org
.springframework
.core
.io
.ClassPathResource
;
24 import org
.springframework
.core
.io
.Resource
;
26 import eu
.etaxonomy
.cdm
.api
.service
.ITestService
;
27 import eu
.etaxonomy
.cdm
.common
.monitor
.IProgressMonitor
;
28 import eu
.etaxonomy
.cdm
.common
.monitor
.NullProgressMonitor
;
29 import eu
.etaxonomy
.cdm
.io
.service
.IIOService
;
30 import eu
.etaxonomy
.taxeditor
.remoting
.cache
.CdmRemoteCacheManager
;
31 import eu
.etaxonomy
.taxeditor
.remoting
.source
.ICdmRemoteSource
;
32 import eu
.etaxonomy
.taxeditor
.service
.ICachedCommonService
;
33 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionManager
;
36 * CDM Application Controller class for remoting clients
38 * FIXME:Remoting extending {@link CdmApplicationController} is a temporary workaround.
39 * The {@link CdmApplicationController} should be split into a CdmApplicationControllerBase
40 * class with {@link CdmApplicationController} and this class as subclasses
43 public class CdmApplicationRemoteController
extends CdmApplicationController
{
45 private static final Logger logger
= Logger
.getLogger(CdmApplicationRemoteController
.class);
48 public static final Resource DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE
=
49 new ClassPathResource("/eu/etaxonomy/cdm/remotingApplicationContext.xml");
50 private final Resource applicationContextResource
;
51 private final IProgressMonitor progressMonitor
;
55 * Creates new instance of CdmApplicationRemoteController
57 * @param applicationContextResource
59 * @param omitTermLoading
60 * @param progressMonitor
64 // public static CdmApplicationRemoteController NewInstance(Resource applicationContextResource,
65 // ICdmRemoteSource remoteSource,
66 // IProgressMonitor progressMonitor,
67 // List<ApplicationListener> listeners) {
68 // return new CdmApplicationRemoteController(applicationContextResource,
76 * Creates new instance of CdmApplicationRemoteController
78 * @param applicationContextResource
80 * @param omitTermLoading
81 * @param progressMonitor
85 public static CdmApplicationRemoteController
NewInstance(ICdmRemoteSource remoteSource
,
86 IProgressMonitor progressMonitor
,
87 List
<ApplicationListener
> listeners
) {
89 return new CdmApplicationRemoteController(DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE
,
97 public static CdmApplicationRemoteController
NewInstance(ICdmRemoteSource remoteSource
,
99 IProgressMonitor progressMonitor
,
100 List
<ApplicationListener
> listeners
) {
102 return new CdmApplicationRemoteController(DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE
,
111 * Constructs CdmApplicationRemoteController
113 * @param applicationContextResource
114 * @param remoteSource
115 * @param omitTermLoading
116 * @param progressMonitor
119 private CdmApplicationRemoteController(Resource applicationContextResource
,
120 ICdmRemoteSource remoteSource
,
122 IProgressMonitor progressMonitor
,
123 List
<ApplicationListener
> listeners
){
124 logger
.info("Start CdmApplicationRemoteController with remote source: " + remoteSource
.getName());
125 this.applicationContextResource
=
126 applicationContextResource
!= null ? applicationContextResource
: DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE
;
127 this.progressMonitor
= progressMonitor
!= null ? progressMonitor
: new NullProgressMonitor();
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() + "'");
149 GenericApplicationContext applicationContext
= new GenericApplicationContext();
153 progressMonitor
.beginTask("Connecting to '" + remoteSource
.getName() + "'", nTasks
);
155 progressMonitor
.subTask("Initialising CDM Model Cache ...");
156 CdmRemoteCacheManager
.getInstance();
158 progressMonitor
.subTask("Loading context beans ...");
159 PropertySourcesPlaceholderConfigurer pspc
= new PropertySourcesPlaceholderConfigurer();
160 Properties properties
= new Properties();
161 properties
.setProperty("remoteServer", remoteSource
.getServer());
162 properties
.setProperty("remotePort", String
.valueOf(remoteSource
.getPort()));
163 properties
.setProperty("remoteContext", remoteSource
.getContextPath());
164 pspc
.setProperties(properties
);
165 applicationContext
.addBeanFactoryPostProcessor(pspc
);
166 applicationContext
.getEnvironment().setActiveProfiles("remoting");
167 XmlBeanDefinitionReader xmlReader
= new XmlBeanDefinitionReader(applicationContext
);
169 xmlReader
.setValidating(false);
171 xmlReader
.loadBeanDefinitions(applicationContextResource
);
172 if (listeners
!= null){
173 for(ApplicationListener listener
: listeners
){
174 applicationContext
.addApplicationListener(listener
);
177 progressMonitor
.worked(1);
179 progressMonitor
.subTask("Starting application context ...");
180 applicationContext
.refresh();
181 applicationContext
.start();
182 setApplicationContext(applicationContext
);
183 progressMonitor
.worked(1);
184 progressMonitor
.done();
191 * @see eu.etaxonomy.cdm.api.application.CdmApplicationController#init()
194 protected void init(){
196 // retrieving the application configuration
197 configuration
= (ICdmApplicationConfiguration
)applicationContext
.getBean("cdmApplicationRemoteConfiguration");
198 AbstractLazyInitializer
.setConfiguration((CdmApplicationRemoteConfiguration
)configuration
);
199 AbstractPersistentCollection
.setConfiguration((CdmApplicationRemoteConfiguration
)configuration
);
205 public ICdmEntitySessionManager
getCdmEntitySessionManager() {
206 return ((CdmApplicationRemoteConfiguration
)configuration
).getCdmEntitySessionManager();
209 public IIOService
getIOService(){
210 return (IIOService
) getBean("ioService");
213 public ITestService
getTestService(){
214 return (ITestService
) getBean("testService");
217 public ICachedCommonService
getCachedCommonService(){
218 return (ICachedCommonService
) getBean("cachedCommonService");