All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dynamicextensionsalfresco.osgi.spring.ChildApplicationContextFactoryBean Maven / Gradle / Ivy

Go to download

Adds an OSGi container to alfresco repository supporting dynamic code reloading, classpath isolation and a bunch of other useful features

There is a newer version: 3.1.0
Show newest version
package com.github.dynamicextensionsalfresco.osgi.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Spring {@link FactoryBean} for creating a child {@link ApplicationContext}.
 * 

* This class can operate in createSingletons or prototype mode. * * @author Laurens Fridael * */ public class ChildApplicationContextFactoryBean implements FactoryBean, ApplicationContextAware { /* Dependencies */ private ApplicationContext parentApplicationContext; /* Configuration */ private String[] configLocations; private boolean createSingletons = true; /* State */ private ClassPathXmlApplicationContext childApplicationContext; /* Main operations */ @Override public boolean isSingleton() { return createSingletons; } @Override public Class getObjectType() { return ClassPathXmlApplicationContext.class; } @Override public ClassPathXmlApplicationContext getObject() { if (isCreateSingletons()) { if (childApplicationContext == null) { childApplicationContext = createOsgiContainerApplicationContext(); } return childApplicationContext; } else { return createOsgiContainerApplicationContext(); } } public void destroy() { closeOsgiContainerApplicationContext(); } /* Dependencies */ protected ClassPathXmlApplicationContext createOsgiContainerApplicationContext() { return new ClassPathXmlApplicationContext(getConfigLocations(), getParentApplicationContext()); } protected void closeOsgiContainerApplicationContext() { if (childApplicationContext != null) { childApplicationContext.close(); } } /* Dependencies */ @Override public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException { this.parentApplicationContext = applicationContext; } protected ApplicationContext getParentApplicationContext() { return parentApplicationContext; } /* Configuration */ public void setConfigLocations(final String[] configLocations) { this.configLocations = configLocations; } protected String[] getConfigLocations() { return configLocations; } public void setCreateSingletons(final boolean createSingletons) { this.createSingletons = createSingletons; } public boolean isCreateSingletons() { return createSingletons; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy