/* (non-Javadoc) * @see woolfel.engine.rete.Function#executeFunction(woolfel.engine.Creshendo.Util.Rete.Rete, woolfel.engine.rete.Parameter[]) */ public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { if (engine != null && params_Renamed != null && params_Renamed.Length == 3) { BoundParam bp = (BoundParam)params_Renamed[0]; StringParam slot = (StringParam)params_Renamed[1]; ValueParam val = (ValueParam)params_Renamed[2]; Object instance = bp.ObjectRef; Defclass dc = engine.findDefclass(instance); // we check to make sure the Defclass exists if (dc != null) { MethodInfo setm = dc.getWriteMethod(slot.StringValue); try { setm.Invoke(instance, (Object[])new Object[] { val }); } catch (UnauthorizedAccessException e) { } catch (TargetInvocationException e) { } } } return(new DefaultReturnVector()); }
/* (non-Javadoc) * @see woolfel.engine.rete.Function#executeFunction(woolfel.engine.Creshendo.Util.Rete.Rete, woolfel.engine.rete.Parameter[]) */ public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed) { Object rtn = null; DefaultReturnVector drv = new DefaultReturnVector(); if (engine != null && params_Renamed != null && params_Renamed.Length == 3) { BoundParam bp = (BoundParam)params_Renamed[0]; StringParam slot = (StringParam)params_Renamed[1]; ValueParam val = (ValueParam)params_Renamed[2]; Object instance = bp.ObjectRef; Defclass dc = engine.findDefclass(instance); // we check to make sure the Defclass exists if (dc != null) { MethodInfo getm = dc.getWriteMethod(slot.StringValue); try { rtn = getm.Invoke(instance, (Object[])new Object[] { val }); int rtype = getMethodReturnType(getm); DefaultReturnValue rvalue = new DefaultReturnValue(rtype, rtn); drv.addReturnValue(rvalue); } catch (UnauthorizedAccessException e) { // TODO we should handle error, for now not implemented } catch (TargetInvocationException e) { // TODO we should handle error, for now not implemented } } } return(drv); }
/// <summary> The method uses Defclass, Class, Deftemplate and Rete to create a new /// instance of the java object. Once the instance is created, the method /// uses Defclass to look up the write method and calls it with the /// appropriate value. /// </summary> /// <param name="">cond /// </param> /// <param name="">templ /// </param> /// <param name="">engine /// </param> /// <returns> /// /// </returns> public static Object generateJavaFacts(ObjectCondition cond, Deftemplate templ, Rete.Rete engine) { try { Type theclz = Type.GetType(templ.ClassName); Defclass dfc = engine.findDefclass(theclz); Object data = CreateNewInstance(theclz); IConstraint[] cnstr = cond.Constraints; for (int idx = 0; idx < cnstr.Length; idx++) { IConstraint cn = cnstr[idx]; if (cn is LiteralConstraint) { MethodInfo meth = dfc.getWriteMethod(cn.Name); meth.Invoke(data, (Object[])new Object[] { cn.Value }); } } // for now the method doesn't inspect the bindings // later on it needs to be added return(data); } catch (UnauthorizedAccessException e) { return(null); } catch (ArgumentException e) { return(null); } catch (TargetInvocationException e) { return(null); } catch (Exception e) { return(null); } }