brooklyn.entity.basic.ClosureEntityFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of brooklyn-core Show documentation
Show all versions of brooklyn-core Show documentation
Entity implementation classes, events, and other core elements
package brooklyn.entity.basic;
import brooklyn.entity.Entity;
import groovy.lang.Closure;
import java.util.HashMap;
import java.util.Map;
public class ClosureEntityFactory extends AbstractConfigurableEntityFactory {
private final Closure closure;
public ClosureEntityFactory(Closure closure){
this(new HashMap(),closure);
}
public ClosureEntityFactory(Map flags, Closure closure) {
super(flags);
this.closure = closure;
}
public T newEntity2(Map flags, Entity parent) {
if (closure.getMaximumNumberOfParameters()>1)
return closure.call(flags, parent);
else {
//leaving out the parent is discouraged
T entity = closure.call(flags);
if(parent!=null && entity.getParent()==null){
entity.setParent(parent);
}
return entity;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy