Descriptor (class)

1.Descriptor (class)

    For some historical reasons, the dynamic model refers to classes as descriptors.  

    In a dynamic model an object can use any object as its own descriptor, inheriting the behavior of the descriptor.

2.descriptors property

    A model's descriptors attribute is used to mark its descriptors.

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

<Person name="ZhangSan" descriptors="Person">
    <Child name="XiaoMing"/>

    As in the above XML, descriptors="Person" means that it uses the model whose path is Person as its descriptor (class), so the above XML also inherits the behavior of Person.

3. Multiple Descriptors

    If a model has multiple descriptors, the descriptor paths are separated by commas.

    For example: descriptors="Person,Employee".

4. The descriptor can describe the behavior of the object

    The descriptor has the ability to describe the behavior of the object because the object inherits the behavior of the descriptor, so the behavior of the descriptor is equivalent to the behavior of the object.

5. The descriptor can describe the structure of the object

    Descriptor's child node<attriubte name="xxx" .../>Attributes for object, Descriptor's child node<thing name="xxx" ... /> is used to describe the child nodes of the object.

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

<thing name="Person" _xmeta_id_="379" descriptors="xworker.lang.MetaDescriptor3">
    <attribute name="name"/>
    <attribute name="age" _xmeta_id_="652"/>
    <attribute name="sex" _xmeta_id_="653" inputtype="select">
        <value name="male" _xmeta_id_="654" value="male"/>
        <value name="female" _xmeta_id_="655" value="female"/>
    <attribute name="birthDay" _xmeta_id_="656" inputtype="datePick"/>
    <attribute name="memo" _xmeta_id_="657" inputtype="html"/>
        <GroovyAction name="sayHello" descriptors="xworker.groovy.GroovyAction" code="println self.get(&quot;name&quot;) + &quot; say hello world!&quot; ;"/>
    <thing name="Child" extends="_transient.p379"/>

    When a model uses the above XML as its own descriptor, then the model should have attributes such as name, age, sex, birthDay and memo, and can add <Child .../> byte point.

    For example, the following model is described by the above model.

<Person name="ZhangSan" descriptors="Person">
    <Child name="XiaoMing"/>

6. Model serialization only saves attributes defined by the descriptor

    When a model is serialized for storage, only the attributes defined by the descriptor are usually saved.


Copyright ©  2007-2019  版权所有  沪ICP备08000575号