在com.opensymphony.workflow.loader包下,有许多形形色色的Descriptor,他们以AbstractDescriptor为根,遍地开花。
图1:
从上图可以看到AbstractDescriptor的子嗣不是一般的多啊,但不要被他们所吓倒!
窥一斑而知全豹
OSWorkflow把定义在XML中的流程,根据DTD文件中定义好的各种XML元素,抽象出了很多种Descriptor,因此我们才得以见到如此多的Descriptor,这里也包括我们之前提到的WorkflowDescriptor,他可是XML流程文件中的根节点,也是最复杂的Descriptor,我们就从他开始。
The main workflow element. A workflow includes a set of meta properties that are global, as well as global registers
and trigger functions. It also defines a set of initial actions that are available to kick off the workflow.
The global actions are actions that can be executed from any step. They are available to all steps.
common-actions are actions that can be reused in steps. They are specified here, and a step can optionally
refer to a common-action to make it available. Note that all actions id's must be globally unique.
A workflow consists of a number of steps, split definitions that determine the states to move to within a split,
and join definitions to determine the conditions and steps for a join.
这是workflow_2_8.dtd文件开头的一段话,workflow作为XML流程文件的根节点,他当中包含有许多全局的属性以及各种registers、actions、functions等等,让我们看他的定义:
<!ELEMENT workflow (meta*, registers?, trigger-functions?, global-conditions?, initial-actions, global-actions?, common-actions?, steps, splits?, joins?)>
从以上的元素定义可以看出,除了initial-actions、steps之外,其他的都不是必须的。
图2:
看WorkflowDescriptor的类型定义,基本上与DTD文件中的定义是一一对应的。其实所有AbstractDescriptor的子嗣都和WorkflowDescriptor一样,都是这样一种设计思路。AbstractDescriptor中的parent说明了任何一个AbstractDescriptor的子类,都可以通过getParent()方法获得他的父一级的AbstractDescriptor实例,而WorkflowDescriptor类的那些get*相关的方法,返回的也都是相关Descriptor对象的实例。
WorkflowDescriptor内部同时给出了Validatable接口和XMLizable接口的实现,前者是关于XML格式相关验证,后者则是以XML的形式通过PrintWriter给print出来。