使用事物

    在XWorker使用事物,可以把它当作对象来看待。

1. 获取事物

import org.xmeta.World;
import org.xmeta.Thing;

//世界是管理事物的容器
World world = World.getInstance();

//根据路径获取事物,类似于ClassLoader装载类的规则
Thing thing = world.getThing("HelloWorld");

2. 操作事物的属性和子事物

//获取和设置属性
Object value = thing.get("xxx");

//Xxx xxxValue = thing.getXxx("xxx");
Int intValue = thing.getInt("xxx");

//设置属性
thing.set("xxx", xxx);

//获取子节点
List<Thing> childs = thing.getChilds();

//添加子节点
thing.addChild(childThing);

3. 执行事物的行为

//执行事物的xxx行为,其中actionContext是变量上下文
thing.doAction("xxx", actionContext);

//也可以转化为动作来执行,和行为的差别是没有self(相当于this)变量
org.xmeta.Action action = thing.getAction();
action.run(actionContext);

 

Copyright ©  2007-2014 XWorker.org  版权所有

沪ICP备08000575号