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

brooklyn.entity.basic.ClosureEntityFactory Maven / Gradle / Ivy

There is a newer version: 0.7.0-M1
Show newest version
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