diff --git a/voila-runtime-core/pom.xml b/voila-runtime-core/pom.xml
index 5d11bc616c381bbaf5be26cf3911c5edb4c11bb4..62fdfdbdc3ca6c3b62cec8a82b073ddbcd386515 100644
--- a/voila-runtime-core/pom.xml
+++ b/voila-runtime-core/pom.xml
@@ -30,6 +30,12 @@
Variant of {@link org.springframework.beans.factory.access.SingletonBeanFactoryLocator} + * which creates its internal bean factory reference as an + * {@link org.springframework.context.ApplicationContext} instead of + * SingletonBeanFactoryLocator's simple BeanFactory. For almost all usage scenarios, + * this will not make a difference, since within that ApplicationContext or BeanFactory + * you are still free to define either BeanFactory or ApplicationContext instances. + * The main reason one would need to use this class is if bean post-processing + * (or other ApplicationContext specific features are needed in the bean reference + * definition itself). + * + *
Note: This class uses classpath*:beanRefContext.xml
+ * as the default resource location for the bean factory reference definition files.
+ * It is not possible nor legal to share definitions with SingletonBeanFactoryLocator
+ * at the same time.
+ *
+ * @author Colin Sampaleanu
+ * @author Juergen Hoeller
+ * @see org.springframework.beans.factory.access.SingletonBeanFactoryLocator
+ * @see org.springframework.context.access.DefaultLocatorFactory
+ */
+public class ContextSingletonBeanFactoryLocator extends SingletonBeanFactoryLocator {
+
+ private static final String DEFAULT_RESOURCE_LOCATION = "classpath*:beanRefContext.xml";
+
+ /** The keyed singleton instances */
+ private static final Map The default implementation simply builds a
+ * {@link org.springframework.context.support.ClassPathXmlApplicationContext}.
+ */
+ @Override
+ protected BeanFactory createDefinition(String resourceLocation, String factoryKey) {
+ return new ClassPathXmlApplicationContext(new String[] {resourceLocation}, false);
+ }
+
+ /**
+ * Overrides the default method to refresh the ApplicationContext, invoking
+ * {@link ConfigurableApplicationContext#refresh ConfigurableApplicationContext.refresh()}.
+ */
+ @Override
+ protected void initializeDefinition(BeanFactory groupDef) {
+ if (groupDef instanceof ConfigurableApplicationContext) {
+ ((ConfigurableApplicationContext) groupDef).refresh();
+ }
+ }
+
+ /**
+ * Overrides the default method to operate on an ApplicationContext, invoking
+ * {@link ConfigurableApplicationContext#refresh ConfigurableApplicationContext.close()}.
+ */
+ @Override
+ protected void destroyDefinition(BeanFactory groupDef, String selector) {
+ if (groupDef instanceof ConfigurableApplicationContext) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Context group with selector '" + selector +
+ "' being released, as there are no more references to it");
+ }
+ ((ConfigurableApplicationContext) groupDef).close();
+ }
+ }
+
+}
diff --git a/voila-runtime-core/src/main/java/it/mice/voila/runtime/util/GlobalContext.java b/voila-runtime-core/src/main/java/it/mice/voila/runtime/util/GlobalContext.java
index d705a607c9c0b167192af1f1de42c123a7d18582..958f8187d2cca6856c6108b9bdcbcf8755befb0a 100644
--- a/voila-runtime-core/src/main/java/it/mice/voila/runtime/util/GlobalContext.java
+++ b/voila-runtime-core/src/main/java/it/mice/voila/runtime/util/GlobalContext.java
@@ -20,7 +20,7 @@ public class GlobalContext {
* @see org.springframework.context.access.ContextSingletonBeanFactoryLocator
*/
public static BeanFactoryLocator getBeanFactoryLocator() {
- return SingletonBeanFactoryLocator.getInstance();
+ return ContextSingletonBeanFactoryLocator.getInstance();
}
}
diff --git a/voila-runtime-hibernate/src/main/java/it/mice/voila/runtime/hibernate/dao/impl/DaoHbmGeneric.java b/voila-runtime-hibernate/src/main/java/it/mice/voila/runtime/hibernate/dao/impl/DaoHbmGeneric_old.java
similarity index 96%
rename from voila-runtime-hibernate/src/main/java/it/mice/voila/runtime/hibernate/dao/impl/DaoHbmGeneric.java
rename to voila-runtime-hibernate/src/main/java/it/mice/voila/runtime/hibernate/dao/impl/DaoHbmGeneric_old.java
index dff3108384894cc20a4b03d52a25506016e2eaa1..c7871fd2e7b325adf74bcc9619be84b5aa1bb199 100644
--- a/voila-runtime-hibernate/src/main/java/it/mice/voila/runtime/hibernate/dao/impl/DaoHbmGeneric.java
+++ b/voila-runtime-hibernate/src/main/java/it/mice/voila/runtime/hibernate/dao/impl/DaoHbmGeneric_old.java
@@ -48,7 +48,7 @@ import it.mice.voila.runtime.util.UserMessage;
* Created by IntelliJ IDEA. User: zzy9v4 Date: 2-feb-2007 Time: 23.53.04 To
* change this template use File | Settings | File Templates.
*/
-public abstract class DaoHbmGenericgetResources
method with this
+ * name will be combined to create a definition, which is just a BeanFactory.
+ * @return the corresponding BeanFactoryLocator instance
+ * @throws BeansException in case of factory loading failure
+ */
+ public static BeanFactoryLocator getInstance() throws BeansException {
+ return getInstance(null);
+ }
+
+ /**
+ * Returns an instance which uses the the specified selector, as the name of the
+ * definition file(s). In the case of a name with a Spring "classpath*:" prefix,
+ * or with no prefix, which is treated the same, the current thread's context class
+ * loader's getResources
method will be called with this value to get
+ * all resources having that name. These resources will then be combined to form a
+ * definition. In the case where the name uses a Spring "classpath:" prefix, or
+ * a standard URL prefix, then only one resource file will be loaded as the
+ * definition.
+ * @param selector the location of the resource(s) which will be read and
+ * combined to form the definition for the BeanFactoryLocator instance.
+ * Any such files must form a valid ApplicationContext definition.
+ * @return the corresponding BeanFactoryLocator instance
+ * @throws BeansException in case of factory loading failure
+ */
+ public static BeanFactoryLocator getInstance(String selector) throws BeansException {
+ String resourceLocation = selector;
+ if (resourceLocation == null) {
+ resourceLocation = DEFAULT_RESOURCE_LOCATION;
+ }
+
+ // For backwards compatibility, we prepend "classpath*:" to the selector name if there
+ // is no other prefix (i.e. "classpath*:", "classpath:", or some URL prefix).
+ if (!ResourcePatternUtils.isUrl(resourceLocation)) {
+ resourceLocation = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resourceLocation;
+ }
+
+ synchronized (instances) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("ContextSingletonBeanFactoryLocator.getInstance(): instances.hashCode=" +
+ instances.hashCode() + ", instances=" + instances);
+ }
+ BeanFactoryLocator bfl = instances.get(resourceLocation);
+ if (bfl == null) {
+ bfl = new ContextSingletonBeanFactoryLocator(resourceLocation);
+ instances.put(resourceLocation, bfl);
+ }
+ return bfl;
+ }
+ }
+
+
+ /**
+ * Constructor which uses the the specified name as the resource name
+ * of the definition file(s).
+ * @param resourceLocation the Spring resource location to use
+ * (either a URL or a "classpath:" / "classpath*:" pseudo URL)
+ */
+ protected ContextSingletonBeanFactoryLocator(String resourceLocation) {
+ super(resourceLocation);
+ }
+
+ /**
+ * Overrides the default method to create definition object as an ApplicationContext
+ * instead of the default BeanFactory. This does not affect what can actually
+ * be loaded by that definition.
+ *