The invention relates to a UML (
Unified Modeling Language) model-oriented event-driven behavior code automatic generation method and
system. The method comprises the following steps: exporting an XMI file containing class, activity and state machines from a UML (
Unified Modeling Language) modeling tool, constructing a
document tree through DOM (
Document Object Model) analysis, and extracting meta-model elements and relationships thereof; and generating attributes and methods of the main class and the associated class and
Java source codes of the main method according to an analysis result, taking the main method of the main class as a
simulation / operation entry, and calling the main method of the associated class during operation. Aiming at the
behavior type of the classifier: when the
behavior type is Activity, traversing an identification sequence, branching / merging, parallelizing /
synchronizing and circulating from an InitialNode, constructing a
behavior control flow diagram, decomposing the behavior into SimpleTask and LoopTask, and generating a
Java code containing an Execute method and a scheduling statement; and when the state conversion diagram is the StateMach, reconstructing the state conversion diagram and generating a state
machine instance and a StateMach Runner operation management type instance code, thereby realizing migration execution driven by a
signal event and a time event and mixed triggering of the
signal event and the time event and the activity. The method is suitable for the field with high requirements for model consistency and rapid
verification.