*/
public boolean setState(
Trace trace,
TraceNode position) throws RulesException {
DTState ds = trace.session.getState();
// Found our position. We are Done!
if(position == this) return true;
// Keep track of where we actually execute a table. This will happen even
// if we don't actually end up executing a column.
if(name.equals("execute_table")){
trace.execute_table = this;
}
// We are an entitypush. Find that entity and push it.
if(name.equals("entitypush")){
ds.entitypush(getEntity(trace));
}
// We are an entitypop. Pop an entity!
if(name.equals("entitypop")){
ds.entitypop();
}
// If we are setting an attribute
if(name.equals("def")){
IRObject v;
String name = attributes.get("name");
if(body.length()==0){
v = RNull.getRNull();
}else{
trace.session.execute(body);
v = ds.datapop();
}
IREntity e = getEntity(trace);
RName rn = RName.getRName(name);
e.put(trace.session, rn, v);
Change c = new Change(e, rn, trace.execute_table);
trace.changes.put(c, c); // Keep a hash lookup of my change object.
}
// Creating an array
if(name.equals("newarray")){
int id = Integer.parseInt(attributes.get("arrayId"));
if(!trace.arraytable.containsKey(id)){
trace.arraytable.put(id, RArray.newArrayTraceInterface(id, true, false));
}
}
// Adding to an array
if(name.equals("addto")){
int id = Integer.parseInt(attributes.get("arrayId"));
RArray ar = trace.arraytable.get(id);
if(ar==null){ // Now this shouldn't happen, but if it does, create the array
ar = RArray.newArrayTraceInterface(id, true, false);
trace.arraytable.put(id, ar);
}
IRObject v;
if(body.length()==0){
v = RNull.getRNull();
}else{
trace.session.execute(body);
v = ds.datapop();
}
ar.add(v);
}
// Remove a value from an array
if(name.equals("remove")){
int id = Integer.parseInt(attributes.get("arrayId"));
RArray ar = trace.arraytable.get(id);
if(ar==null){ // Now this shouldn't happen, but if it does, create the array
ar = RArray.newArrayTraceInterface(id, true, false);
trace.arraytable.put(id, ar);
}
IRObject v;
if(body.length()==0){
v = RNull.getRNull();
}else{
trace.session.execute(body);
v = ds.datapop();
}
ds.datapush(ar);
ds.datapush(v);
ds.getSession().execute("remove");
ds.datapop();
}
// Remove a value from an array at a location
if(name.equals("remove")){
int id = Integer.parseInt(attributes.get("arrayId"));
RArray ar = trace.arraytable.get(id);
if(ar==null){ // Now this shouldn't happen, but if it does, create the array
ar = RArray.newArrayTraceInterface(id, true, false);
trace.arraytable.put(id, ar);
}
trace.session.execute(body);
IRObject i = ds.datapop();
ds.datapush(ar);
ds.datapush(i);
ds.getSession().execute("removeat");
ds.datapop();
}
for(TraceNode child : children){
if(child.setState(trace, position)){