Similar to instantiate(instantiationTarget,TypeClass classToInstantiate, String instanceName, boolean instantiateExtensions), but a reusable context can be added. This is useful when multiple instantiations are processed within a script in order to achieve optimal performance.
It is important to strictly follow the application of pattern in the example, otherwise may not be saved.
instantiate(instantiationTarget, MechatronicObjectClass classToInstantiate, String instanceName, boolean instantiateExtensions, IMechatronicInstantiationContext context) throws NoMatchingPlaceholderException | |||
---|---|---|---|
Argument | instantiationTarget | A mechatronic component or mechatronic root, under which the new object is placed | |
MechatronicObjectClass | classToInstantiate | The class to instantiate | |
String | instanceName | The name of the object. If null is returned, the object gets the name of the class. | |
Boolean | instantiateExtensions | If the return value is true, internal extension points are calculated while instantiation, if the return value is false no calculation is done. | |
IMechatronicInstantiationContext | context | A reusable context for instantiation. | |
Return value | Component | The instantiated object |
import com.mind8.mechatronic.skill.api.IMechatronicInstantiationAPI;
import com.mind8.mechatronic.skill.api.NoMatchingPlaceholderException;
import com.mind8.mechatronic.skill.eos.TypeClass;
import java.util.ArrayList;
instantiationTarget = obj; // Argument in Command
classToInstantiate = TypeClass.findType(self.getUnitOfWork(), "Pfuderer_Baukasten.Mechatronik.Stationen.Einsetzen.Einsetzen");
context = IMechatronicInstantiationAPI.DEFAULT.createInstantiationContext(instantiationTarget);
aList = new ArrayList();
try
{
instance = IMechatronicInstantiationAPI.DEFAULT.instantiate(instantiationTarget, classToInstantiate, "Einsetzen", true, context);
aList.add(instance);
instance = IMechatronicInstantiationAPI.DEFAULT.instantiate(instantiationTarget, classToInstantiate, "Einsetzen2", true, context);
aList.add(instance);
}
catch (NoMatchingPlaceholderException nmpe)
{
// error handling
}
finally
{
context.deleteUnusedInstances();
}
return aList;