public Object createObject(Map args) throws Exception { Map sourceview = (Map)args.get("sourceview"); IEnvironmentSpace space = (IEnvironmentSpace)args.get("space"); IDataView ret = (IDataView)((Class)getProperty(sourceview, "clazz")).newInstance(); Map props = null; List lprops = (List)sourceview.get("properties"); if(lprops!=null) { SimpleValueFetcher fetcher = new SimpleValueFetcher(); fetcher.setValue("$space", space); fetcher.setValue("$object", args.get("object")); fetcher.setValue("$view", args.get(ret)); props = convertProperties(lprops, fetcher); } ret.init(space, props); return ret; } }, new BeanAccessInfo(AccessInfo.THIS)))
/** * Add reason to fetcher. */ @Override public SimpleValueFetcher wrapFetcher(IValueFetcher fetcher) { SimpleValueFetcher ret = super.wrapFetcher(fetcher); if(reason instanceof RParameterElement) { ret.setValue(((RParameterElement)reason).getFetcherName(), reason); } return ret; }
/** * Get the value fetcher. * @return The fetcher. */ public SimpleValueFetcher getFetcher() { if(fetcher==null) { this.fetcher = new SimpleValueFetcher() { public Object fetchValue(String name) { Object ret = null; if(getPropertyNames().contains(name)) { ret = getProperty(name); } else { ret = super.fetchValue(name); } return ret; } }; fetcher.setValue("$space", this); } return this.fetcher; }
/** * Wrap the fetcher to include the element itself. */ public SimpleValueFetcher wrapFetcher(final IValueFetcher fetcher) { SimpleValueFetcher ret = new SimpleValueFetcher(fetcher); ret.setValue(getFetcherName(), this); return ret; }
fetcher.setValue("$object", this);
/** * Get the value fetcher. * @return The fetcher. */ public SimpleValueFetcher getFetcher() { if(fetcher==null) { this.fetcher = new SimpleValueFetcher(obscenter.getSpace().getFetcher()); fetcher.setValue("$perspective", this); } return this.fetcher; }
/** * Get the value fetcher. * * @return The fetcher. */ public SimpleValueFetcher getFetcher() { if(fetcher == null) { this.fetcher = new SimpleValueFetcher(obscenter.getSpace().getFetcher()); // fetcher.setValue("$space", obscenter.getSpace()); fetcher.setValue("$perspective", this); } return this.fetcher; }
/** * This method will be executed by the object before the process gets added * to the execution queue. * @param clock The clock. * @param space The space this process is running in. */ public void start(IClockService clock, IEnvironmentSpace space) { this.lasttick = clock.getTick(); this.lasttime = clock.getTime(); this.fetcher = new SimpleValueFetcher(); fetcher.setValue("$space", space); fetcher.setValue("$clock", clock); // Set back counters to trigger immediate object creation at startup. if(getProperty("tickrate")!=null) { this.lastrate = ((Number)getProperty("tickrate")).doubleValue(); lasttick -= lastrate; } else if(getProperty("timerate")!=null) { this.lastrate = ((Number)getProperty("timerate")).doubleValue(); lasttime -= lastrate; } }
/** * Set an injected field value. */ protected void setFieldValue(Object val, Field field, String convert) { if(val!=null || !SReflect.isBasicType(field.getType())) { try { Object agent = microagent instanceof IPojoMicroAgent? ((IPojoMicroAgent)microagent).getPojoAgent(): microagent; if(convert!=null) { SimpleValueFetcher fetcher = new SimpleValueFetcher(getFetcher()); fetcher.setValue("$value", val); val = SJavaParser.evaluateExpression(convert, getModel().getAllImports(), fetcher, getClassLoader()); } field.setAccessible(true); field.set(agent, val); } catch(Exception e) { throw new RuntimeException(e); } } }
/** * Prepares the object for rendering to a Java2D viewport * * @param dc the DrawableCombiner drawing the object * @param primitive the primitive being drawn * @param obj the object being drawn * @param vp the viewport */ public void prepareAndExecuteDraw(DrawableCombiner dc, Primitive primitive, Object obj, ViewportJ2D vp) { IParsedExpression drawcondition = primitive.getDrawCondition(); boolean draw = drawcondition==null; if(!draw) { SimpleValueFetcher fetcher = new SimpleValueFetcher(vp.getPerspective().getObserverCenter().getSpace().getFetcher()); fetcher.setValue("$object", obj); fetcher.setValue("$perspective", vp.getPerspective()); draw = ((Boolean)drawcondition.getValue(fetcher)).booleanValue(); } if (draw) draw(dc, primitive, obj, vp); }
/** * Evaluate the condition. */ public IFuture<Tuple2<Boolean, Object>> evaluate(IEvent event) { IFuture<Tuple2<Boolean, Object>> ret = null; try { fetcher.setValue("$event", event); IParsedExpression exp = SJavaParser.parseExpression(expression, null, null); // todo: classloader? Object res = exp.getValue(fetcher); ret = CommandCondition.evaluateResult(res); } catch(Exception e) { ret = new Future<Tuple2<Boolean, Object>>(e); // throw new RuntimeException(e); } return ret; }
/** * Execute the query using a local parameter. * @param name The name of the local parameter. * @param value The value of the local parameter. * @return the result value of the query. */ public Object execute(String name, Object value) { SimpleValueFetcher fet = new SimpleValueFetcher(CapabilityWrapper.getFetcher(getAgent(), uexp.getLanguage())); fet.setValue(name, value); return getParsedExpression().getValue(fet); }
/** * Get the value fetcher. */ public IValueFetcher getFetcher() { assert !getComponentAdapter().isExternalThread(); if(fetcher==null) { SimpleValueFetcher fetcher = new SimpleValueFetcher(super.getFetcher()); if(microagent instanceof IPojoMicroAgent) { fetcher.setValue("$pojoagent", ((IPojoMicroAgent)microagent).getPojoAgent()); } this.fetcher = fetcher; } return fetcher; }
/** * Execute the query using local parameters. * @param names The names of parameters. * @param values The parameter values. * @return The return value. */ public Object execute(String[] names, Object[] values) { SimpleValueFetcher fet = new SimpleValueFetcher(CapabilityWrapper.getFetcher(getAgent(), uexp.getLanguage())); for(int i=0; i<names.length; i++) { fet.setValue(names[i], values[i]); } return getParsedExpression().getValue(fet); }
/** * Set an injected field value. */ protected void setFieldValue(Object val, Field field, String convert) { if(val!=null || !SReflect.isBasicType(field.getType())) { try { Object agent = getComponent().getComponentFeature(IPojoComponentFeature.class).getPojoAgent(); if(convert!=null) { SimpleValueFetcher fetcher = new SimpleValueFetcher(getComponent().getFetcher()); fetcher.setValue("$value", val); val = SJavaParser.evaluateExpression(convert, getComponent().getModel().getAllImports(), fetcher, getComponent().getClassLoader()); } field.setAccessible(true); field.set(agent, val); } catch(Exception e) { throw new RuntimeException(e); } } } }
/** * Get the name of components to start. * @return The name. */ protected String getName(ComponentInstanceInfo component, IModelInfo model, int cnt) { String ret = component.getName(); if(ret!=null) { SimpleValueFetcher fetcher = new SimpleValueFetcher(this.component.getFetcher()); fetcher.setValue("$n", Integer.valueOf(cnt)); try { ret = (String)SJavaParser.evaluateExpression(component.getName(), model.getAllImports(), fetcher, this.component.getClassLoader()); if(ret==null) ret = component.getName(); } catch(RuntimeException e) { } } return ret; }
fetcher.setValue("$value", val); val = SJavaParser.evaluateExpression(convback, getModel().getAllImports(), fetcher, getClassLoader());
/** * Get the name of components to start. * @return The name. */ public String getName(ComponentInstanceInfo component, IModelInfo model, int cnt) { assert !getComponentAdapter().isExternalThread(); String ret = component.getName(); if(ret!=null) { SimpleValueFetcher fetcher = new SimpleValueFetcher(getFetcher()); fetcher.setValue("$n", Integer.valueOf(cnt)); try { ret = (String)SJavaParser.evaluateExpression(component.getName(), model.getAllImports(), fetcher, getClassLoader()); if(ret==null) ret = component.getName(); } catch(RuntimeException e) { } } return ret; }