use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.
the class ModifyCommand method execute.
public Object execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
EntryPoint wmep = ksession.getEntryPoint(factHandle.getEntryPointId());
Object object = wmep.getObject(this.factHandle);
MVELSafeHelper.getEvaluator().eval(getMvelExpr(), object);
wmep.update(factHandle, object);
return object;
}
use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.
the class InsertObjectInEntryPointCommand method execute.
public FactHandle execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
EntryPoint ep = ksession.getEntryPoint(entryPoint);
FactHandle factHandle = ep.insert(object);
DefaultFactHandle disconnectedHandle = ((DefaultFactHandle) factHandle).clone();
disconnectedHandle.disconnect();
if (outIdentifier != null) {
if (this.returnObject) {
((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, object);
}
((RegistryContext) context).lookup(ExecutionResultImpl.class).getFactHandles().put(this.outIdentifier, disconnectedHandle);
}
return disconnectedHandle;
}
use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.
the class ExecuteCommand method execute.
public ExecutionResults execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
ExecutionResults kresults = null;
if (ksession instanceof StatefulKnowledgeSessionImpl) {
kresults = ksession.execute(this.command);
} else {
// Graceful failure
kresults = ksession.execute(this.command);
}
if (this.outIdentifier != null) {
((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, kresults);
}
if (disconnected) {
ExecutionResultImpl disconnectedResults = new ExecutionResultImpl();
HashMap<String, Object> disconnectedHandles = new HashMap<String, Object>();
for (String key : kresults.getIdentifiers()) {
FactHandle handle = (FactHandle) kresults.getFactHandle(key);
if (handle != null) {
DefaultFactHandle disconnectedHandle = ((DefaultFactHandle) handle).clone();
disconnectedHandle.disconnect();
disconnectedHandles.put(key, disconnectedHandle);
}
}
disconnectedResults.setFactHandles(disconnectedHandles);
disconnectedResults.setResults((HashMap) ((ExecutionResultImpl) kresults).getResults());
return disconnectedResults;
}
return kresults;
}
use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.
the class GetKieContainerCommand method execute.
public KieContainer execute(Context context) {
// use the new API to retrieve the session by ID
KieServices kieServices = KieServices.Factory.get();
KieContainer kieContainer = kieServices.newKieContainer(releaseId);
((RegistryContext) context).register(KieContainer.class, kieContainer);
return kieContainer;
}
use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.
the class SetVariableCommandFromLastReturn method execute.
public Object execute(Context context) {
Context targetCtx;
if (this.contextName == null) {
targetCtx = context;
} else {
targetCtx = ((RegistryContext) context).getContextManager().getContext(this.contextName);
}
GetDefaultValue sim = (GetDefaultValue) context.get("simulator");
Object o = sim.getObject();
// for FactHandle's we store the handle on a map and the actual object as
if (o instanceof FactHandle) {
Map<String, FactHandle> handles = (Map<String, FactHandle>) targetCtx.get("h");
if (handles == null) {
handles = new HashMap<String, FactHandle>();
targetCtx.set("h", handles);
}
handles.put(identifier, (FactHandle) o);
o = ((InternalFactHandle) o).getObject();
}
targetCtx.set(identifier, o);
return o;
}
Aggregations