/* (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(); }
/// <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; } }