定义框架

1.定义框架

    框架并不需要特别的定义,如果一个模型包含子模型,那么这个模型就可以当做一个框架了。

    比如XWorker的动作框架。

<?xml version="1.0" encoding="utf-8"?>

<ThingIndex name="Actions" descriptors="xworker.lang.util.ThingIndex" th_createIndex="true"
     th_registThing="child|xworker.lang.util.ThingIndex" group="actions" icon="icons/bullet_green.png"
     description="&lt;p&gt;各种动作的集合。&lt;/p&gt;">
    <thing name="Begin" _xmeta_id_="ActionGroup" descriptors="xworker.lang.MetaDescriptor3/@thing"
         extends="xworker.lang.actions.Begin" group="_actions.statement" inheritDescription="true"></thing>
    <thing name="Break" descriptors="xworker.lang.MetaDescriptor3/@thing" extends="xworker.lang.actions.Break"
         group="_actions.statement" inheritDescription="true"></thing>
    <thing name="Continue" descriptors="xworker.lang.MetaDescriptor3/@thing" extends="xworker.lang.actions.Continue"
         group="_actions.statement" inheritDescription="true"></thing>
    <thing name="Do" descriptors="xworker.lang.MetaDescriptor3/@thing" extends="xworker.lang.actions.Do"
         group="_actions.statement" inheritDescription="true"></thing>
    <thing name="GroovyAction" descriptors="xworker.lang.MetaDescriptor3/@thing" extends="xworker.lang.actions.GroovyAction"
         group="_actions.code" inheritDescription="true"></thing>
    <thing name="For" descriptors="xworker.lang.MetaDescriptor3/@thing" extends="xworker.lang.actions.For"
         group="_actions.statement" inheritDescription="true"></thing>
    <thing name="If" descriptors="xworker.lang.MetaDescriptor3/@thing" extends="xworker.lang.actions.If"
         group="_actions.statement" inheritDescription="true"></thing>
    ......
</ThingIndex>

    上面是XWorker中的xworker.lang.actions.Actions模型的代码片段,Actions是动作模型的集合,它包含了各种动作模型。

2.使用框架

2.1.继承框架模型

    框架模型通常作为描述者(类)模型使用,也可以让一个描述者模型继承框架模型,比如XWorker中的xworker.lang.MetaDescriptor3模型中的动作模型。

2.2.使用框架模型

     在使用描述者(类)创建模型时,就可以使用框架所包含的子模型了,比如用上面的xworker.lang.MetaDescriptor3模型的动作(actions)模型来编写模型的行为。

    可以看到这里有很多动作模型可以选择,这就是框架模型的作用。

 

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

沪ICP备08000575号