示例 XML 代码
清单 1 给出一个示例 XML 文件,它代表一个资源(或用户)结构。下面列出示例 XML 代码中的几个属性:
Class:Java 类的名称
Extends:父 Java 类的名称
Abstract:表示在 Java 术语中这个类是否是抽象的
TestReady:表示代码生成器是否应该为这个类生成单元测试
Field name:字段的 Java 变量名
Field type:字段使用的 Java 类型
Field label:用户界面上特定字段使用的标签
Field min and max:字符串或数字值的最小和最大长度
Field default:在创建对象时,应用于一个字段的默认值
Field composite:表示字段是引用还是复合的关系
Field valid types:表示抽象对象数组中可以包含的有效类型
Field mandatory:表示在创建对象时这个字段是否是强制的
Field readable:表示用户是否可以读取这个字段
继承的字段覆盖
清单 1. 代表资源(或用户)结构的示例代码
<?xml version="1.0"?>
<object
class="sample.Resource"
abstract="false"
extends="sample.BaseObject"
testready="false"
documentation="A resource represents a user of the system.">
<rule
type="create"
documentation="To create a resource,
the user must have the administrator
security rights" />
<rule
type="update"
documentation="A resource has the right to modify
itself. Only administrators have the right to modify
resources otherwise." />
<rule
type="delete"
documentation="Administrators have the right
to delete a resouce." />
<field
name="active"
label="Active"
type="java.lang.Boolean"
default="true" />
<field
name="calendar"
label="Calendar"
type="sample.WorkCalendar"
composite="false" />
<field
name="contactGroupAssignments"
type="sample.ContactGroupAssignment[]"
composite="true">
<valid-type
class="sample.ContactGroupAssignment" />
</field>
<field
name="name"
label="Full Name"
type="java.lang.String"
mandatory="true"
max="35" />
<field
name="password"
label="Password"
type="java.lang.String"
min="3"
max="16"
readable="false" />
<!-- BaseObject -->
<inherited
name="parent"
mandatory="true">
<valid-type class="sample.ResourceFolder" />
<invalid-type class="sample.Project" />
</inherited>
</object>
<object
class="sample.Resource"
abstract="false"
extends="sample.BaseObject"
testready="false"
documentation="A resource represents a user of the system.">
<rule
type="create"
documentation="To create a resource,
the user must have the administrator
security rights" />
<rule
type="update"
documentation="A resource has the right to modify
itself. Only administrators have the right to modify
resources otherwise." />
<rule
type="delete"
documentation="Administrators have the right
to delete a resouce." />
<field
name="active"
label="Active"
type="java.lang.Boolean"
default="true" />
<field
name="calendar"
label="Calendar"
type="sample.WorkCalendar"
composite="false" />
<field
name="contactGroupAssignments"
type="sample.ContactGroupAssignment[]"
composite="true">
<valid-type
class="sample.ContactGroupAssignment" />
</field>
<field
name="name"
label="Full Name"
type="java.lang.String"
mandatory="true"
max="35" />
<field
name="password"
label="Password"
type="java.lang.String"
min="3"
max="16"
readable="false" />
<!-- BaseObject -->
<inherited
name="parent"
mandatory="true">
<valid-type class="sample.ResourceFolder" />
<invalid-type class="sample.Project" />
</inherited>
</object>