jadex.extension.envsupport.MEnvSpaceInstance Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-kernel-extension-envsupport Show documentation
Show all versions of jadex-kernel-extension-envsupport Show documentation
The Jadex kernel extension envsupport allows for using 2D spaces in concert with components.
package jadex.extension.envsupport;
import java.util.List;
import java.util.Map;
import jadex.application.IExtensionInfo;
import jadex.application.IExtensionInstance;
import jadex.bridge.IComponentStep;
import jadex.bridge.IExternalAccess;
import jadex.bridge.IInternalAccess;
import jadex.commons.IValueFetcher;
import jadex.commons.SReflect;
import jadex.commons.collection.MultiCollection;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.extension.envsupport.environment.AbstractEnvironmentSpace;
/**
* Configuration of an Env space.
*/
public class MEnvSpaceInstance implements IExtensionInfo
{
//-------- attributes --------
/** The space name. */
protected String name;
/** The space type name. */
protected String type;
/** The space type (resolved during loading). */
protected MEnvSpaceType spacetype;
/** The properties. */
protected MultiCollection properties;
//-------- IExtensionInfo interface --------
/**
* Instantiate the extension for a specific component instance.
* @param access The external access of the component.
* @param fetcher The value fetcher of the component to be used for evaluating dynamic expressions.
* @return The extension instance object.
*/
public IFuture createInstance(final IExternalAccess access, final IValueFetcher fetcher)
{
return access.scheduleStep(new IComponentStep()
{
public IFuture execute(IInternalAccess ia)
{
IFuture ret;
try
{
Class clazz = SReflect.findClass(spacetype.getClassName(), access.getModel().getAllImports(), ia.getClassLoader());
AbstractEnvironmentSpace space = clazz.newInstance();
space.setInitData(ia, MEnvSpaceInstance.this, fetcher);
ret = new Future(space);
}
catch(Exception e)
{
ret = new Future(e);
}
return ret;
}
});
}
//-------- methods --------
/**
* Add a property.
* @param key The key.
* @param value The value.
*/
public void addProperty(String key, Object value)
{
// System.out.println("addP: "+key+" "+value);
if(properties==null)
properties = new MultiCollection();
properties.add(key, value);
}
/**
* Get a property.
* @param key The key.
* @return The value.
*/
public List