Embodiment
The invention will be further described below in conjunction with accompanying drawing.Following examples only are used for technical scheme of the present invention more clearly is described, and can not limit protection scope of the present invention with this.
The present invention adopts the thinking of model-driven, realize the behavior of business object is controlled by the state machine dynamic modeling, but set up running state conversion model and the Dynamic behavior model of business object by graphical configuration, it is characterized in that: comprise following concrete settlement steps to deal:
1) mode employing XML(extend markup language), by graphical tools, the state machine model file of definition and generation specific transactions object;
2) drive engine, the state machine model file of dynamic load specific transactions object by state machine model;
3) state machine model drives engine according to the state machine model of specific transactions object, and state conversion process and the dynamic behaviour of business object are controlled.
1. step 1 explanation:
The groundwork of step 1 is definition status machine model, be convenient definition with carrying out intuitively state machine model, adopt the C# development language to develop patterned defining tool, establishment is based on the state machine model file of Xml, the reimbursement application state machine object model instance of graphical tools definition as shown in Figure 1:
The concrete form of model file is as follows:
The model of whole state machine is included in " statemachine " node, and this node comprises two child nodes, is respectively " model " node and " view " node.
The model node is the node at state machine model information place, has wherein comprised the state conversion regime of specific transactions object;
The view node is the node at the pictorial information place of state machine, when wherein having comprised user's tool using and having defined, and the displaing coordinate of every kind of graphic element on screen, this part content of view is not the emphasis of this paper, does not launch to describe.The below describes the design of model node in detail:
According to the regulation of extend markup language (XML), the flow node is made of attribute and child node.The attribute of model node is as follows:
1.1.Model the attribute of node
-Id: unique indications of state machine model, numeric type;
-Name: the name of state machine model, the user understands and identification with helping, for example: " state machine of reimbursement object ";
-description: the detailed description information of state machine model, be used for the information such as effect of description status machine, help the user to understand more clearly and the concrete effect of status recognition machine model;
-version: the version of state machine model, because the variation of a business demand, the state machine of same business object needs constantly to adjust during the course, the new demand that proposes to satisfy the user, therefore need to help state machine engine control and distinguish new and old state machine by version, guarantee the normal operation of business object;
-starttime, endtime: the effective time of state machine, certain in particular cases, need the interim state machine that creates, only come into force in specific time range, the effect of these two attributes just is this, starttime has defined the entry-into-force time of state machine, endtime has defined the out-of-service time of state machine, when entry-into-force time and out-of-service time when all being empty, represents this state machine continuously effective; The state machine model priority that has defined startime and endtime time is higher than the state machine that does not define these two attributes;
-orgid: organizational structure's coding that state machine model is corresponding when state machine is used for the infosystem of group's level, is used for distinguishing the different conditions machine model of unified business object under different organizational structures;
-bizid: the business object type id that state machine model is corresponding is used for describing this state machine and is used for controlling which kind of business object.
1.2.Model the child node of node
Above attribute to the model node is described, and the below is described the child node of model node, and the child node of model node comprises:
1.2.1.Lookups node
How the attribute that this node is used for defining enumeration type in the business object converts the literal that the user can understand to, for example: when computing machine saved as " 0 " and " 1 " to sex " sex " property value, state machine should convert thereof into " woman " and " man " is shown to the final user.The Lookups attribute can have a plurality of " lookup " child node, and its structure is as follows:
The attribute that will change in the field attribute representation business object among the Lookup, code represents the value of Computer Storage, name represents the actual value of seeing of user, like this when the user needs to increase " type(educational background type) " or revises the literal that the user sees, as long as revise the model definition of state machine, do not need again to write code.
1.2.2.blocks node
The blocks node is used for defining the property control zone of business object, business object has a lot of attributes, usually these attributes are not can both be for the business personnel accessed or revised, therefore in the state machine definition, need to be defined in the attribute access authority that the business personnel can have under each state, can only revise the amount of money (price) attribute of reimbursement application object such as the financial staff, but can not revise other information such as claimer, when the attribute of business object is many especially, in order to simplify the configuration of state machine, reduce the workload of definition, the attribute of business object can be sorted out, attribute with identical access rights is defined within the attribute block (block), concentrates the access control configuration of carrying out authority.Its feature structure is as follows:
Id among the block is unique sign of property control piece, and attrs is concrete attribute list.The concrete use-pattern of block is described in the bizright node in the back.
1.2.3.Startconditions node
The entry condition node of state machine, this node definition the state machine entry condition of concrete business object, such as: after an expense report object is filled in and is finished, submit to examine application before, can only submit an expense account the expense that occurs then.This node can comprise one group of conditions condition node, has defined condition condition node in each conditions node, and concrete feature is as follows:
A) be the relation of "or" between the condition node in the conditions node;
B) between the conditions node be " with " relation;
Be exemplified below:
Illustrate: between above-mentioned " entry condition 1 " and " entry condition 2 " be " with " relation, the relation of "or" between " userid " and " price ", field has defined the attribute of business object in the condition node, the legal detection mode that type has defined this attribute is " field relatively ", value has defined fiducial value, symbol has defined relatively symbol, and datetype has defined field relatively and should compare according to which kind of data type.
Type attribute in the condition node has a plurality of values, is respectively " field, expression, action, storeproc, service ", and the specific features value implication of type attribute is as follows:
-field: represent that this condition is to compare according to the concrete value that defines in the field of business object and the model, draws " true and false ";
-expression: represent that this condition node is that the calculating that expression formula calculates to finish result " true and false " is carried out in requirement;
-action: expression need to draw " true and false " by calling certain concrete predefine class;
-storeproc: expression need to draw condition " true and false " by calling certain storing process;
-service: expression need to draw condition " true and false " by calling certain webservice;
1.2.4.states node
The state model node set of state machine model, this node is made of one group of state node, it is the core node of state machine model, each state node has defined a kind of intermediateness of business object in operational process, and the state node has three types: startstate node, state node, endstate node.
The Startstate node is the starter node of state machine, namely initiates a little;
The State node is general node;
The Endstate node is the end node of state machine, and namely terminating point says that from the angle of graph theory this node only has in-degree, does not have out-degree.
Above-mentioned three kinds of nodes do not have special difference from characterizing definition, come related by the transitions nodal community between the node; The state node comprises attribute and child node equally, and the below is described in detail:
The attribute of state node:
-Id: unique indications of state node;
-name: the Chinese of state node;
-description: the functional description of state node;
-colorremind: whether be that the object that state machine is controlled arranges special Show Color, when this attribute is true, the business datum that the user sees will present different colors according to the difference of state, help more clearly the user to find specific need to manage business;
-signaturetype: state manually examine type, value is that single(is single) or the counter(countersign);
The child node of state node
The basic structure of state node is as follows:
<state……>
<assignees/〉// definition this state the participant
<events/〉// event that definition relates in this state
<filters/〉// filtercondition that need to carry out of this state of definition
<buttonsright/〉// increase, the deletion of this state of definition, the access rights of modification button
<recover/〉// whether this state of definition allow condition and the event of recovering and recovering
<bizright/〉// the attribute access authority of business object of this state of definition
<transitions/〉// NextState id that the event that triggers when the definition out-degree (" out-degree " graph theory term) of this state and the conversion of generation state and needing activates
</state>
The detailed description of said structure:
A) assignees child node: define the participant of this state, the feature structure of this node is as follows:
<assignees>
<assignee name=" reimbursement applicant " type=" anonymous " andparentfilter=" true " value=" * " 〉
<leaveevents/〉// action behavior that definition need to trigger when this participant's executing state is changed
<filters/〉// when this participant of definition carries out the operation of business object, the filtercondition of system
</assignee>
<assignee〉// participant of another participant or another kind of type
……
</assignee>
</assignees>
An assignees node can have a plurality of assignee child nodes, and each assignee child node has defined the state participant of or a type.Assignee node diagnostic structure is as follows in the said structure:
The type attribute: this attribute definition participant's type, the type is an enumeration type, span is as follows:
-user: the user that certain is concrete;
-creator: founder or the startup person of state machine;
-anonymous: anonymous, namely all people that can access business object corresponding to this state machine model can operate;
-actor: the user who belongs to certain role;
-leader: Last status participant's leading body at a higher level, such as: the applicant is the office worker of engineering department, and the participant of this state is exactly the manager of engineering department so;
-group: the user who belongs to certain working group;
-assigneeAction: the participant who obtains this step by carrying out certain predefined class;
-subordinate: Last status participant's subordinate office worker;
-assigneeService: obtain the participant of this step by accessing certain web services, obtain the participant such as certain ldap directory service of access;
Andparentfilter attribute: compound father's condition whether, this attribute is to be used in when the participant is some special user, need to apply to the access of business object some special filterconditions, will carry out the filtercondition that defines in the filter child node of this node and the filter condition in the father node when property value is true " with " merge;
Value attribute: participant's concrete value;
Leaveevents node: the action behavior that definition need to trigger when this participant's executing state conversion
The filters node: when defining this participant and carrying out the operation of business object, the filtercondition of system, the back will be described in detail.
B) events child node: defined the behavior event that relates in the current state state node, comprised enterevents, leaveevents, humanevents three types:
Enterevents: the event that triggers when business object enters into current state;
Leaveevents: the event that triggers when business object is left current state;
Humanevents: the action event that business object can be carried out in current state;
Each event can trigger a plurality of actions in above-mentioned three kinds of events, is exemplified below:
Enterevents(enters event in the above-mentioned example) defined two actions in the node, " event 1 " made the status property value of business object into " general manager (GM) receives ", and " event 2 " made the price property value of business object into 5000; Two actions have been defined in humanevents (manual event) node, " operation 1 " will call the com.sac.patent.statusAction class status attribute of business object will be carried out assignment, and " operation 2 " will call the com.sac.patent.priceAction class price attribute of business object is carried out assignment;
Different is, the event that defines in two nodes of enterevents and leaveevents all is that system automatically performs, the time that carry out to occur is that business object is when entering into current state and leaving current state, each the event event that defines among the humanevents will appear in the tool bar of user interface as a button, in the above-mentioned example, after business object enters this state, can occur " operation 1 " and " operation 2 " two buttons in the toolbar when user opens the current operation interface, these two buttons will disappear automatically when leaving this state.
C) filters child node: the participant is when business object is in current state in definition, the filtercondition of system, and being consisted of by several filter child nodes of filters node, each filter child node is finished one group of filtercondition:
Filter inside has conditions condition child node to consist of, and finishes the definition work of actual conditions expression formula, and the constitutive characteristic of conditions condition node is identical with the feature of Startconditions node.The filters node can define business object when current state, and system is to the condition of business object retrieval.The final user is when the access system page, and the business object of seeing will be after the condition filter according to filter definition.
D) buttonsright child node: the access control right of definition business object when being in current state comprises the access rights of increases, deletion, modification button.In the default situation, comprised for the operation of a business object that the CRUD(additions and deletions change and looked into) four kinds of operations, the buttonsright child node in the state node changes three kinds of operations to additions and deletions to be controlled, and its feature structure is as follows:
Operating right " right=1 " expression that the participant of the right property control current operation in the right child node has has corresponding authority, and " right=0 " expression does not have corresponding authority;
E) recover child node: define this state and whether allow the precondition of recovering and recovering and recover to need the event that causes in the process, be in " pending " if the business object of state has defined recover information in state, and when business object has satisfied the condition that permission " recovers ", the business personnel of Last status (state) can carry out and recover operation, and state is transformed into Last status again.For example: the claimer has filled in reimbursement application and has submitted to leading body at a higher level and examine, catch sight of fill in have problem, before leading body at a higher level does not examine, system will allow it to recover reimbursement application and again processing so.The feature structure of Recover child node is as follows:
<recover allow=" true "〉// whether allow when defining this state to carry out to recover operation
<conditions/〉if // allow=true, defined then what the condition that allows to recover is, its structure is identical with the startconditions node
<events/〉// to carry out when recovering operation the system acting that triggers, the events child node of its structure and state is identical
</recover>
F) bizright child node: the attribute access authority that defines the business object of this state, the business personnel who namely is authorized to (participant who defines among the assignees) is under current state during the access service object, the property rights of the business object that can access, such as: reimbursement application object at state from the process that these several states of " application "-〉 " approval "-〉 " audit " are changed, the participant of " audit " link can revise " price " attribute of reimbursement object, but can not revise the claimer, other attributes such as reimbursement article, state machine is realized control to business object price attribute by definition bizright in the configuration information of " audit " state, and its feature is as follows:
<bizright default=" readonly "〉// arrange that business object all is read only attribute at all properties of current state in the default situation
<info id=" price " right=" modify " isblock=" false "/〉 // expression price attribute is in the current state operation of can making amendment
<infoid=" subject " right=" readonly " isblock=" true "/〉 // represent that all properties that defines in " subject " piece is all read-only
</biright>
Business object is in the attribute access authority of current state in the default situation of default setup of attribute of bizright, and readonly represents that all properties all is that read-only, modify represents that all properties can revise,
G) transitions child node: the event that triggers when out-degree (" out-degree " graph theory term) conversion of definition current state (state) and the conversion of generation state and the NextState id that needs to activate.Its feature structure is schematically as follows:
Among the above-mentioned transition:
-name attribute: defined the button name that finally appears in the user interface tool hurdle;
-icon attribute: the icon id(icon resource that has defined button is deposited in the resource file of system, does not give unnecessary details);
-destination attribute: defined when carrying out this conversion (transition), the dbjective state id(of state transition defines in the id of state node attribute)
-silence attribute: defined whether need participant's (defining among the assignees) typing remark information of be correlated with when carrying out conversion, such as: suggestions made after examination etc., " 0 " expression does not need, and " 1 " expression need to.
-counter attribute: defined whether need the number of conutersigning when carrying out this conversion, " 1 " is as long as expression has the individual consent (or disagreeing with) just can transition status, " * " represents that all meet the people who defines in the assignees node and all will agree (or disagreeing with) ability transition status, and other digital watch are shown with concrete How many people and agree that (or disagreeing with) just can carry out transition status.
-showconditions child node: defined the condition that shows switching button at the interface tool bar, shown when satisfying condition, otherwise do not show.Can only check business object such as some people but can not carry out when examining action.
-assignees child node: defined the participant that can carry out this conversion, this participant's priority is higher than the participant (assignees that defines among the state) who defines in the state node, if the content of this child node is empty, adopt the participant who defines among the state.
2. step 2 explanation:
Can save as an XML file after state machine model definition is finished is kept in the file of hard disk appointment and (is defaulted as " model " file under the graphical state machine model defining tool installation directory, the expansion of model file is called " .sm "), can adopt simultaneously the mode of blob field that the XML character string in this document is uploaded in the database, list structure is as follows:
State machine model what upload and load employing is the mode of webservice, the graphical state machine model defining tool of client communicates by mode and the server end of access webservice, and webservice provides the state machine model between SyncModel Interface realization client, server memory, the database three synchronous;
Before the new state machine model issue, need carry out first the checking of correctness, the method of checking is by state machine model being loaded in the content of application server end, setting up the buffer memory of state machine model at internal memory, will verifying the correctness of state machine model in this process.
The flow process that state machine model loads as shown in Figure 2.
Before state machine model is brought into use, state machine model drives the loading that engine can call the method completion status machine model of a loadAllStateMachines by name, the exemplary flow that loads is as implied above: at first from database the state machine model file that is using (that is: status=acitive) is checked out, be saved in the tabulation (List), then whether the state machine model quantity in the judgement tabulation is more than or equal to 1, if more than or equal to 1 state machine model that just will travel through wherein, and be attached in the internal memory, construct the memory object of state machine model.
In the process if there is unusually, the definition information that shows this state machine model has problem, the problematic place of meeting prompting in error handling processing (such as: the organizational structure that defines in the state machine model does not exist, business object does not exist, the user does not exist or the predefine class of wherein appointment does not exist etc.), thereby realize the checking of state machine model correctness, and abandon the structure of this state machine model memory object, carry out next one circulation, make up other state machine model memory object, finish until all state machine model memory objects all make up.
In fact the memory object building process of state machine model is exactly the process of analyzing XML file, because the xml file more complicated of state machine model, and therefore also relative complex in the process that memory object makes up.The method that this patent has adopted the common completion status machine of a plurality of classes model memory object to make up realizes the loading of state machine model, and concrete kind is as follows:
Above-mentioned these class functions have been finished memory object (StateMachineSchema) function of state machine model, finally build one group of StateMachineSchema object, each StateMachineSchema object represents the state machine model of a class business object, this group StateMachineSchema object is stored among the core buffer object StateMachineSchemaBuffer with the hashmap organization definition, convenient in the operation system operational process, locate fast and operate.
The mode of employing class is finished the parsing work to the xml document, the benefit of bringing for the performance of system is self-evident, the StateMachineSchema object has been arranged, and operation system is in operation just can adopt OO mode of operation Access status machine model, fast and stable.Use the Id attribute to distinguish between the StateMachineSchema object, adopt the StateMachineVersion attributes object to distinguish between the StateMachineSchema object of identical name attribute.
The basic procedure that StateMachineSchema makes up is as shown in Figure 3:
(dom4j is the java version of DOM Document Object Model at first to create an org.dom4j.Document object, be used in java, accessing the object structure that the XML document mode is stored), the state machine model information that the XML structure that obtains in the database is preserved is loaded in the org.dom4j.Document object, is convenient to like this in internal memory the accessing operation to the xml document information.
Then, state machine model drives engine will create the object instance of a StateMachineSchema type, and the loadXmlDefine method loading of calling example is kept at the model data in the Document object.
The process that the loadXmlDefine method is carried out:
-load the attribute information of Model node, comprise Id, version, name
-create BlockSchema list object (BlockList), the child node among the circulation blocks, and for each child node creates a BlockSchema subobject, finish the loading work to control of authority zone (blocks) information;
-create Lookup list object (LookupList), the child node of circulation Lookups, and for each child node creates a Lookup subobject, finish the loading of lookups nodal information;
-establishment Condition list object (ConditionList), circulation Conditions(or startconditions) child node, and for each child node creates a Condition subobject, finish Conditions(or startconditions) loading of nodal information;
-create state list object (StateList), the child node of circulation states, and be that each state child node creates a stateschema object, finish the loading of states nodal information;
Because the content relative complex of stateschema object, also need to create the assigneeschema list object in the loading procedure, event list object, transition list object, condition list object, filter list object, bizright list object, buttonright list object are used for loading the corresponding configuration information in the state node;
The state machine model file is complete to be loaded in the internal memory and to finish after document object (dom) makes up to the java object with StateMachineSchema, and the model of state machine model has just been realized setting up and buffer memory in internal memory.
The inner logical relation of a state machine model (StateMachineSchema) finally builds the state transition graph of a business object, this figure is a digraph, the node definition of figure each process status of business object, each out-degree of figure and in-degree have defined event in once conversion, switch condition and the transfer process of business object, thus finishing service Dynamic behavior of object feature.End-state machine model-driven engine is exactly to finish dynamic behaviour control work to business object according to the state transition graph of business object.
3. step 3 explanation:
State machine model is driven engine by state machine model and is loaded in the internal memory and after the form instantiation with object, will carry out the dynamic behaviour control of business object example under state machine model drives the assistance of engine.State machine model drives establishment and the driving process that engine is responsible for state machine instance, and driving method as shown in Figure 4.
State machine model driving engine is divided into following feature to the dynamic behaviour control of business object example:
Business object is defined as " entering ", " pending ", " in the processing ", " processing ", " leaving " five kinds of little states in a state conversion process, namely comprised above-mentioned five little states in state:
-entering (enter): the expression business object is transformed into transition state the process of another state from a state, state machine model drives engine and can enter some initial work before this state to business object in this state, and concrete work just is defined in the enterevents node.
-pending (wait): the expression business object has been passed through the state that is in after the transition state of " entering ", business object is placed in the task queue under this state, be in the state that the latency services personnel process, be in the business object of this state, if having defined recover(in the state node recovers) information, can be recovered a upper state state node.In case this business object is chosen by the business personnel and is retrieved, just will enter into " processing " state from " pending " state from task queue.
In-the processing (process): the expression business object has been left " pending " state, is begun to process by business personnel (participant who defines among the assignees).The business personnel can carry out various operations to this business object under this state in the scope that authority allows.When being in " in the processing " state, can not being performed recover(and recovering) operation;
-to process (completed): the expression business object is disposed, and waits for the next state that enters.The user can not make amendment to the information of business object again under this state.
-to leave (leave): the transition state of business object when leaving current state, this state descend and trigger the event that defines in the leaveevents node.
Above-mentioned five little states are that business object experiences during another state from a state transition in operational process.Different according to business demand and business operation behavior have one's own state machine instance, that is: a StateMachineInstance for each business object.
Service condition machine model (StateMachineSchema) has been described the dynamic behaviour feature of a class business object, and state machine instance (StateMachineInstance) has been described the dynamic behaviour of concrete certain business object, and state machine instance is the specific product of state machine model thus.
The above only is preferred implementation of the present invention; should be pointed out that for those skilled in the art, under the prerequisite that does not break away from the technology of the present invention principle; can also make some improvement and distortion, these improvement and distortion also should be considered as protection scope of the present invention.