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

com.github.dynamicextensionsalfresco.osgi.spring.AbstractFrameworkFactoryBean 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 java.util.Map;

import com.github.dynamicextensionsalfresco.osgi.FrameworkConfiguration;

import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
import org.springframework.beans.factory.FactoryBean;

/**
 * Abstract base class for FactoryBeans that create {@link Framework}s. Subclasses must provide the
 * implementation-specific {@link FrameworkFactory} used to instantiate the Framework.
 * 
 * @author Laurens Fridael
 * 
 */
public abstract class AbstractFrameworkFactoryBean implements FactoryBean {

	private FrameworkConfiguration frameworkConfiguration;

	private Framework framework;

	public void setFrameworkConfiguration(final FrameworkConfiguration configuration) {
		this.frameworkConfiguration = configuration;
	}

	/**
	 * Provides the Framework configuration settings as a Map suitable for use with
	 * FrameworkFactory#newFramework(Map).
	 * 
	 * @return The Framework configuration or null if none has been specified.
	 * @see FrameworkConfiguration#toMap()
	 */
	protected Map getFrameworkConfigurationMap() {
		if (frameworkConfiguration != null) {
			return frameworkConfiguration.toMap();
		} else {
			return null;
		}
	}

	@Override
	public Class getObjectType() {
		return Framework.class;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}

	@Override
	public final Framework getObject() {
		if (framework == null) {
			framework = createFramework();
		}
		return framework;
	}

	protected Framework createFramework() {
		final Map configuration = getFrameworkConfigurationMap();
		return getFrameworkFactory().newFramework(configuration);
	}

	/**
	 * Obtains the FrameworkFactory that will be used to create the Framework.
	 * 
	 * @return The FrameworkFactory.
	 */
	protected abstract FrameworkFactory getFrameworkFactory();

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy