com.github.lontime.extspring.impl.copper.SpringDependencyInjector Maven / Gradle / Ivy
package com.github.lontime.extspring.impl.copper;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.copperengine.core.AbstractDependencyInjector;
import org.copperengine.core.persistent.SavepointAware;
/**
* Connects SPRING to COPPER. Enables COPPER to inject dependencies into workflow instances using a spring
* container/context.
*
* @author austermann
* @since 1.0
*/
public class SpringDependencyInjector extends AbstractDependencyInjector implements ApplicationContextAware {
private ApplicationContext context;
public SpringDependencyInjector() {
}
public SpringDependencyInjector(ApplicationContext context) {
this.context = context;
}
@Override
public String getType() {
return "SPRING";
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
context = applicationContext;
}
@Override
protected Object getBean(String beanId) {
Object firsttry = context.getBean(beanId);
if (firsttry instanceof SavepointAware) {
Object secondtry = context.getBean(beanId);
if (firsttry == secondtry) {
throw new IllegalStateException(beanId + " scope is not prototype");
}
}
return firsttry;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy