Package ome.system
Class OmeroContext
- java.lang.Object
-
- org.springframework.core.io.DefaultResourceLoader
-
- org.springframework.context.support.AbstractApplicationContext
-
- org.springframework.context.support.AbstractRefreshableApplicationContext
-
- org.springframework.context.support.AbstractRefreshableConfigApplicationContext
-
- org.springframework.context.support.AbstractXmlApplicationContext
-
- org.springframework.context.support.ClassPathXmlApplicationContext
-
- ome.system.OmeroContext
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanFactory
,org.springframework.beans.factory.BeanNameAware
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.HierarchicalBeanFactory
,org.springframework.beans.factory.InitializingBean
,org.springframework.beans.factory.ListableBeanFactory
,org.springframework.context.ApplicationContext
,org.springframework.context.ApplicationEventPublisher
,org.springframework.context.ConfigurableApplicationContext
,org.springframework.context.Lifecycle
,org.springframework.context.MessageSource
,org.springframework.core.env.EnvironmentCapable
,org.springframework.core.io.ResourceLoader
,org.springframework.core.io.support.ResourcePatternResolver
public class OmeroContext extends org.springframework.context.support.ClassPathXmlApplicationContext
Provides static access for the creation of singleton and non-singleton application contexts. Also provides context names as constant fields which can be used for the lookup of particular contexts, through eithergetInstance(String)
orServiceFactory(String)
. By passing aProperties
instance into thegetClientContext(Properties)
method, a non-static version is created. Currently this is only supported for the client context.- Since:
- OME3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
OmeroContext.Locator
provides access to the protected methods ofContextSingletonBeanFactoryLocator
which cannot be used externally.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CLIENT_CONTEXT
identifier for an OmeroContext configured in classpath*:beanRefContext.xml for use by remote (via JNDI/RMI) clients.static java.lang.String
MANAGED_CONTEXT
identifier for an OmeroContext configured in classpath*:beanRefContext.xml for use by server-side processes.-
Fields inherited from class org.springframework.context.support.AbstractApplicationContext
APPLICATION_EVENT_MULTICASTER_BEAN_NAME, LIFECYCLE_PROCESSOR_BEAN_NAME, logger, MESSAGE_SOURCE_BEAN_NAME
-
-
Constructor Summary
Constructors Constructor Description OmeroContext(java.lang.String configLocation)
OmeroContext(java.lang.String[] configLocations)
OmeroContext(java.lang.String[] configLocations, boolean refresh)
OmeroContext(java.lang.String[] configLocations, boolean refresh, org.springframework.context.ApplicationContext parent)
OmeroContext(java.lang.String[] configLocations, org.springframework.context.ApplicationContext parent)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyBeanPropertyValues(java.lang.Object target, java.lang.Class<? extends ServiceInterface> beanInterface)
Uses the methods of this context'sBeanFactory
to autowire any Object based on the service class.void
applyBeanPropertyValues(java.lang.Object target, java.lang.String beanName)
Uses the methods of this context'sBeanFactory
to autowire any Object based on the given beanName.void
closeAll()
closes all the nested OmeroContexts within this instance.static OmeroContext
getClientContext()
create (if necessary) and return the single default client OmeroContext.static OmeroContext
getClientContext(java.util.Properties props)
initialize a new client OmeroContext (namedCLIENT_CONTEXT
), using thegetContext(Properties, String)
method.static OmeroContext
getContext(java.util.Properties props, java.lang.String context)
initialize a new client OmeroContext using theProperties
provided as values for property (e.g.static OmeroContext
getInstance(java.lang.String beanFactoryName)
create (if necessary) and return the single default OmeroContext named by the beanFactoryName parameter.static OmeroContext
getManagedServerContext()
create (if necessary) and return the single default managed OmeroContext.java.lang.String
getProperty(java.lang.String propertyName)
protected void
onRefresh()
void
publishEvent(org.springframework.context.ApplicationEvent event)
void
publishMessage(InternalMessage msg)
Convenience method aroundpublishEvent(org.springframework.context.ApplicationEvent)
which catches allMessageException
and unwraps the containedThrowable
instance and rethrows.void
refreshAll()
refreshes all the nested OmeroContexts within this instance.void
refreshAllIfNecessary()
-
Methods inherited from class org.springframework.context.support.ClassPathXmlApplicationContext
getConfigResources
-
Methods inherited from class org.springframework.context.support.AbstractXmlApplicationContext
initBeanDefinitionReader, loadBeanDefinitions, loadBeanDefinitions, setValidating
-
Methods inherited from class org.springframework.context.support.AbstractRefreshableConfigApplicationContext
afterPropertiesSet, getConfigLocations, getDefaultConfigLocations, resolvePath, setBeanName, setConfigLocation, setConfigLocations, setId
-
Methods inherited from class org.springframework.context.support.AbstractRefreshableApplicationContext
assertBeanFactoryActive, cancelRefresh, closeBeanFactory, createBeanFactory, customizeBeanFactory, getBeanFactory, hasBeanFactory, refreshBeanFactory, setAllowBeanDefinitionOverriding, setAllowCircularReferences
-
Methods inherited from class org.springframework.context.support.AbstractApplicationContext
addApplicationListener, addBeanFactoryPostProcessor, close, containsBean, containsBeanDefinition, containsLocalBean, createEnvironment, destroy, destroyBeans, doClose, findAnnotationOnBean, finishBeanFactoryInitialization, finishRefresh, getAliases, getApplicationListeners, getApplicationName, getAutowireCapableBeanFactory, getBean, getBean, getBean, getBean, getBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanFactoryPostProcessors, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeansOfType, getBeansOfType, getBeansWithAnnotation, getDisplayName, getEnvironment, getId, getInternalParentBeanFactory, getInternalParentMessageSource, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getResourcePatternResolver, getResources, getStartupDate, getType, initApplicationEventMulticaster, initLifecycleProcessor, initMessageSource, initPropertySources, invokeBeanFactoryPostProcessors, isActive, isPrototype, isRunning, isSingleton, isTypeMatch, isTypeMatch, obtainFreshBeanFactory, onClose, postProcessBeanFactory, prepareBeanFactory, prepareRefresh, publishEvent, publishEvent, refresh, registerBeanPostProcessors, registerListeners, registerShutdownHook, resetCommonCaches, setDisplayName, setEnvironment, setParent, start, stop, toString
-
Methods inherited from class org.springframework.core.io.DefaultResourceLoader
addProtocolResolver, getClassLoader, getProtocolResolvers, getResource, getResourceByPath, setClassLoader
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
CLIENT_CONTEXT
public static final java.lang.String CLIENT_CONTEXT
identifier for an OmeroContext configured in classpath*:beanRefContext.xml for use by remote (via JNDI/RMI) clients.- See Also:
- Constant Field Values
-
MANAGED_CONTEXT
public static final java.lang.String MANAGED_CONTEXT
identifier for an OmeroContext configured in classpath*:beanRefContext.xml for use by server-side processes. All objects obtained from the context are in a state for immediate use.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OmeroContext
public OmeroContext(java.lang.String configLocation) throws org.springframework.beans.BeansException
- Throws:
org.springframework.beans.BeansException
-
OmeroContext
public OmeroContext(java.lang.String[] configLocations) throws org.springframework.beans.BeansException
- Throws:
org.springframework.beans.BeansException
-
OmeroContext
public OmeroContext(java.lang.String[] configLocations, boolean refresh) throws org.springframework.beans.BeansException
- Throws:
org.springframework.beans.BeansException
-
OmeroContext
public OmeroContext(java.lang.String[] configLocations, org.springframework.context.ApplicationContext parent) throws org.springframework.beans.BeansException
- Throws:
org.springframework.beans.BeansException
-
OmeroContext
public OmeroContext(java.lang.String[] configLocations, boolean refresh, org.springframework.context.ApplicationContext parent) throws org.springframework.beans.BeansException
- Throws:
org.springframework.beans.BeansException
-
-
Method Detail
-
getClientContext
public static OmeroContext getClientContext()
create (if necessary) and return the single default client OmeroContext. Any two calls to this method will return the same (==) context instance.- See Also:
CLIENT_CONTEXT
-
getClientContext
public static OmeroContext getClientContext(java.util.Properties props)
initialize a new client OmeroContext (namedCLIENT_CONTEXT
), using thegetContext(Properties, String)
method.
-
getContext
public static OmeroContext getContext(java.util.Properties props, java.lang.String context)
initialize a new client OmeroContext using theProperties
provided as values for property (e.g. ${name}) replacement in Spring. Two calls to this method with the same argument will return different ( =! ) contexts.- Parameters:
props
- Non-null properties for replacement.context
- Non-null name of context to find in beanRefContext.xml- See Also:
ServiceFactory(Login)
,ServiceFactory(Server)
,ServiceFactory(Properties)
-
getManagedServerContext
public static OmeroContext getManagedServerContext()
create (if necessary) and return the single default managed OmeroContext. Any two calls to this method will return the same (==) context instance. Managed means that the services are fully wrapped by interceptors, and are essentially the services made available remotely.- See Also:
MANAGED_CONTEXT
-
getInstance
public static OmeroContext getInstance(java.lang.String beanFactoryName)
create (if necessary) and return the single default OmeroContext named by the beanFactoryName parameter. Any two calls to this method with the same parameter will return the same (==) context instance.- See Also:
getClientContext()
,getManagedServerContext()
-
applyBeanPropertyValues
public void applyBeanPropertyValues(java.lang.Object target, java.lang.String beanName)
Uses the methods of this context'sBeanFactory
to autowire any Object based on the given beanName.- See Also:
AutowireCapableBeanFactory.applyBeanPropertyValues(java.lang.Object, java.lang.String)
-
applyBeanPropertyValues
public void applyBeanPropertyValues(java.lang.Object target, java.lang.Class<? extends ServiceInterface> beanInterface)
Uses the methods of this context'sBeanFactory
to autowire any Object based on the service class. This is used bySelfConfigurableService
instances to acquire dependencies.- See Also:
SelfConfigurableService
,AutowireCapableBeanFactory.applyBeanPropertyValues(java.lang.Object, java.lang.String)
-
refreshAll
public void refreshAll()
refreshes all the nested OmeroContexts within this instance. This is useful when using a static context, andProperties
which were pulled fromSystem.getProperties()
have been changed. If this is a server-side instance (MANAGED_CONTEXT
), this may take a significant amount of time.- See Also:
ConfigurableApplicationContext.refresh()
-
refreshAllIfNecessary
public void refreshAllIfNecessary()
-
closeAll
public void closeAll()
closes all the nested OmeroContexts within this instance. If this is a server-side instance (MANAGED_CONTEXT
), this may take a significant amount of time.- See Also:
ConfigurableApplicationContext.close()
-
getProperty
public java.lang.String getProperty(java.lang.String propertyName)
-
publishEvent
public void publishEvent(org.springframework.context.ApplicationEvent event)
- Specified by:
publishEvent
in interfaceorg.springframework.context.ApplicationEventPublisher
- Overrides:
publishEvent
in classorg.springframework.context.support.AbstractApplicationContext
-
publishMessage
public void publishMessage(InternalMessage msg) throws java.lang.Throwable
Convenience method aroundpublishEvent(org.springframework.context.ApplicationEvent)
which catches allMessageException
and unwraps the containedThrowable
instance and rethrows.- Parameters:
msg
-- Throws:
java.lang.Throwable
-
onRefresh
protected void onRefresh() throws org.springframework.beans.BeansException
- Overrides:
onRefresh
in classorg.springframework.context.support.AbstractApplicationContext
- Throws:
org.springframework.beans.BeansException
-
-