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

com.github.dynamicextensionsalfresco.policy.ProxyPolicyComponentFactoryBean 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.policy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

import org.alfresco.repo.policy.PolicyComponent;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Required;

/**
 * {@link FactoryBean} for creating proxy {@link PolicyComponent}s.
 * 
 * @author Laurens Fridael
 * 
 */
public class ProxyPolicyComponentFactoryBean implements FactoryBean {

	/* Dependencies */

	private PolicyComponent policyComponent;

	private BehaviourProxyFactory behaviourProxyFactory;

	/* State */

	private PolicyComponent proxyPolicyComponent;

	/* Operations */

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

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

	@Override
	public PolicyComponent getObject() {
		if (proxyPolicyComponent == null) {
			proxyPolicyComponent = createProxyPolicyComponent();
		}
		return proxyPolicyComponent;
	}

	/* Utility operations */

	protected PolicyComponent createProxyPolicyComponent() {
		final InvocationHandler handler = new ProxyPolicyComponentInvocationHandler(getPolicyComponent(),
				getBehaviourProxyFactory());
		return (PolicyComponent) Proxy.newProxyInstance(getClass().getClassLoader(),
				new Class[] { PolicyComponent.class }, handler);
	}

	/* Dependencies */

	@Required
	public void setPolicyComponent(final PolicyComponent policyComponent) {
		this.policyComponent = policyComponent;
	}

	protected PolicyComponent getPolicyComponent() {
		return policyComponent;
	}

	@Required
	public void setBehaviourProxyFactory(final BehaviourProxyFactory behaviourProxyFactory) {
		this.behaviourProxyFactory = behaviourProxyFactory;
	}

	protected BehaviourProxyFactory getBehaviourProxyFactory() {
		return behaviourProxyFactory;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy