Summary of the invention
In view of this, fundamental purpose of the present invention is to provide a kind of model-driven software development method based on template, to realize based on template model file being converted into the physics workpiece.
For above-mentioned technical matters, the present invention solves like this.Model-driven software development method based on template comprises:
B, select target platform also read model file;
C, according to the target platform of selecting and the classification of described model file, read corresponding template;
D, convert model file to the physics workpiece according to the template that is read.
As seen from the above, utilize details on the template, will transform into the physics workpiece that on target platform, can carry out via above-mentioned steps with model file.Utilize the reusability of template, can change all such model files under the same target platform.Thereby the degree that the automatic conversion that has improved the non-functional requirement of enterprise software generates.Reduced the workload of software development.
Preferably, described step D comprises:
D1, analytic model file generation model element;
D2, for model file loads the template read, have the instruction that the transformation model element is the physics workpiece on the described template;
D3, model element is converted to the physics workpiece according to the described instruction on the template.
As seen from the above, comprised a large amount of business information in the model file, i.e. model element.For each model element, the mode of its processing is different.For model element is effectively changed into the physics workpiece, then need model file is resolved to model element, with the instruction on the template model element is changed into executable physics workpiece on the target platform again.
One of below preferably, described instruction comprises at least:
Text instruction, branch instruction, recursion instruction and assignment directive.
As seen from the above, each physics workpiece comprises what all software all was made up of four kinds of the most basic statements, i.e. order statement, branch statement, loop statement and assignment statement.Corresponding, the processing to model element on the template just comprises: text instruction, branch instruction, recursion instruction and assignment directive.Can effectively model element be converted to the physics workpiece based on these four instructions.
Preferably, also comprise before the described step B:
A1, importing solution;
Solution generation model file directory that A2, parsing are imported and corresponding model file;
Reading model file among the step B is: read corresponding model file according to described model file catalogue;
Also comprise the physics workpiece that compiling generates behind the described step D.
As seen from the above, as a rule, the single model file corresponding with domain model is not sufficient to whole all information desiring to develop software of complete description, needs a plurality of different model files to be combined into solution mutually.Can realize of the conversion of whole solution by above-mentioned steps to the physics workpiece.
One of below preferably, described model file comprises at least:
Be used for describing each Business Entity Business Entity class model file, be used for describing business operation business operation class model file, be used for the service of describing service item class model file, be used for describing user interface class model file to the shown interface information of user, be used for describing the business processing process operation flow class model file, be used for describing the bordereaux class model file of report capability.
As seen from the above, the business information that comprises of the previous software of order mainly can be described by the domain model of one or more above-mentioned six class model file correspondences.
The present invention also provides a kind of model-driven software development system based on template, it is characterized in that, comprising:
Template base 808 is used for storing template, has the instruction that the transformation model element is the physics workpiece on the described template;
Platform selecting module 806 is used for the select target platform;
Maker 810, the classification that is used for the target platform selected according toplatform selecting module 806 and model file read the corresponding template oftemplate base 808, and according to the instruction on the template that reads model file are converted into the physics workpiece.
As seen from the above, utilize this system to load corresponding template, thereby be converted to the physics workpiece for the model file that reads.
Preferably, describedmaker 810 comprises:
Model file read module 81002 is used to read model file;
Template read module 81004 is used for the model file that the target platform selected according toplatform selecting module 806 and model file read module 81002 read, and reads the template of the correspondence in thetemplate base 808;
Model file parsing module 81006 is used for analytic model file generation model element;
Instruction module 81008 is used for converting model element to the physics workpiece according to the instruction on the described template;
By on model file can be resolved to model element, with the instruction on the template model element is changed into executable physics workpiece on the target platform again.
Preferably, describedinstruction module 81008 comprises,
Text module 810082 is used for the text instruction on the processing template, converts model element to the physics workpiece according to text instruction; Branch'smodule 810084 is used for the branch instruction on the processing template, converts model element to the physics workpiece according to branch instruction;Assignment module 810086 is used for the assignment directive on the processing template, converts model element to the physics workpiece according to assignment directive;Circulation module 810088 is used for the recursion instruction on the processing template, converts model element to the physics workpiece according to recursion instruction.Four instruction modules that comprised by thisinstruction module 81008 can effectively convert model element to the physics workpiece.
Preferably, also comprise,
Solution imports module 802, is used to import solution;
Solution parsing module 804 is used to resolve solution generation model file and model file catalogue;
Collector 814 is used to compile the physics workpiece that is generated.
Modifiedmodule 812 is used to revise the physics workpiece that is generated.
By on can realize importing solution, realize that whole solution is to the conversion of physics workpiece.
One of below wherein,template base 808 comprises at least: BusinessEntity class template 80802, businessoperation class template 80804, serviceitem class template 80806, userinterface class template 80808, operationflow class template 80810,bordereaux class template 80812.
By last, the business information that software comprises can be described by the domain model of one or more above-mentioned six class template correspondences.
Embodiment
At the different physics workpiece that domain model need produce, the set of independent template and template need be provided, template provides the instruction that how element of domain model is converted to relevant physics workpiece element.Below in conjunction with accompanying drawing the model-driven software development method based on template is described in detail.
Be illustrated in figure 1 as process flow diagram, may further comprise the steps based on the model-driven software development method of template:
Step 102 imports solution.
Solution is that the developer sets up at the system that will develop, constitute synoptic diagram referring to the solution shown in Fig. 2, solution is made up of a class or a few class in the following six class model files usually: Business Entity class model file, business operation class model file, service item class model file, user interface class model file, operation flow class model file and bordereaux class model file.Every class model file has comprised one or more model files.
Wherein, Business Entity class model file is used for describing each Business Entity.Business operation class model file is used for describing business operation.Service item class model file is used for describing service.Service definition is one section independently logical program, when a plurality of Services Combination can be finished dissimilar business demands together the time.User interface class model file is used for describing the shown interface information to the user.Operation flow class model file is used for describing the business processing process.For example order processing workflow component may be finished the workflow of order processing in conjunction with Business Entity objects such as client, orders.Bordereaux class model file is used for describing report capability.
The model file that solution comprised is that domain model designed when setting up solution generates.Wherein, described domain model is meant the structuring of corporate model and abstract, technology is realized being separated with the field business, and the technology that the behavior of object model and data are merged mutually.For according to domain model generation model file, promptly set up the step of solution and will sketch referring to Fig. 7 later.
With " online electronic emporium " is example, below solution is given an example, and in this example, solution adopts is that the XML language encapsulates and transmits:
<?xml?version=”1.0”?>
<Solution Name=" online electronic emporium "
<BEPro?ject?File=”Ecommerce.beprj”/>
<BPProject?File=”Ecommerce.bpprj”/>
<ServicePro?ject?File=”Ecommerce.svcprj”/>
<UIProject?File=”Ecommerce.uiprj”/>
<WorkflowProject?File=”Ecommerce.flowprj”/>
</Solution>
Therefore, in this exemplary solution at " online electronic emporium ", comprised a Business Entity model file Ecommerce.beprj, a business operation model file Ecommerce.bpprj, a service model file Ecommerce.svcprj, a subscriber interface model file Ecommerce.uiprj, and a business process model file Ecommerce.flowprj.
For the particular content of each model file, generate by domain model, and the deviser can for example can pass through the visual programming interface, while these model files of edit-modify in a integration environment.Can be referring to the schematic flow sheet of as shown in figure 14 design field model.
Step 104 is resolved solution, generation model file directory and model file.
Usually for all kinds of model files under the solution, every class model file is made up of one or more model files.Relation between these model files is specified by the developer.Corresponding, solution can be formed generation model file directory and model file according to it when resolving solution.Be illustrated in figure 3 as solution and resolve the model file catalogue of back generation and the synoptic diagram of model file.
Be example still, give an example to resolving the model file that generates below with " online electronic emporium ".The program code of listing at first below is for resolving the example of the Business Entity model file Ecommerce.beprj that generates:
<?xml?version=”1.0”?>
<BEProject Name=" online electronic emporium "
<Class Name=" order "
<Reference Name=" client "/
<Field Name=" place an order the time " Type=" DateTime "/
</Class>
<Class Name=" client "
<Field Name=" surname " Type=" String "/
<Field Name=" name " Type=" String "/
</Class>
</BEProject>
In this example, resolve Business Entity model file that solution generates comprising two Business Entities, order Business Entity and client traffic entity.The order Business Entity comprises attributes such as order number, the client who places an order, the time that places an order.Client entity comprises customer number, client's attributes such as name.Wherein, the information with professional meaning that is similar to these attributes that comprises in the model file is called model element.
The program code of listing below is for resolving the example of the business operation model file Ecommerce.bpprj that generates:
BP Project file:
<?xml?version=”1.0”?>
<BPProject Name=" online electronic emporium "
<Operation Name=" the submission order "
<Param Name=" customer name " Type=" String "/
<Param Name=" document number " Type=" String "/
</Operation>
</BPProject>
Resolve the business operation model file of solution generation and described business operation, in this example, the business operation that has comprised a key, it is the business operation that the user submits order to, this business operation described the user put submit the order button to after system what should be done, for example check the user legitimacy, check product have not in stock, how many days can shipment, how to valuate etc.
The program code of listing below is for resolving the example of the subscriber interface model file Ecommerce.uiprj that generates:
The UIProject file:
<?xml?version=”1.0”?>
<UIMLProject Name=" online electronic emporium "
<UIML Name=" products browse "
<Panel>
<TextBox?Name=”search”Text=”Search!”/>
<Grid>
<Column Name=" ProductName "/
<Column Name=" unit price "/
</Grid>
</Panel>
</UIML>
<UIML Name=" shopping cart "
<Panel>
<Button Name=" the submission order "/
</Panel>
</UIML>
</UIMLProject>
Resolve subscriber interface model file description that solution generates with user's interface, i.e. interface information.Subscriber interface model file in this example has comprised two interfaces, and one is products catalogue and tabulation, on this interface, show to comprise ProductName, every kind of product briefly introduce information such as quotation; Another is the shopping cart management, shows to comprise the product of purchasing total price, information such as discount, submission order on this interface.Wherein, information such as the employed control in each interface, position, arrangement mode, font and color also are described in model file.
Several model files that the back generates of resolving have below only been enumerated.At the solution of different business, resolve described solution and generate different model files, by these model files miscellaneous service content, i.e. model element have been described.
Step 106, the select target platform.
The target platform of the physics workpiece that selection will generate.For example C#, Java or C++ etc.
Be example still, below the target platform file of C# given an example with " online electronic emporium ":
BE:Order.cs
using?System;
using?System.Collections;
namespace?ADIFU.Ecommerce
{
public?class?Order
{
private?Customer?customer;
private?DateTime?orderDate;
public?Customer?Customer
{
get
{
return?customer;
}
set
{
customer=value;
}
}
public?DateTime?OrderDate
{
get
{
return?orderD?ate;
}
set
{
orderDate=value;
}
}
}
}
Step 108 is selected the template of corresponding classification according to the classification of model file.
Template provides the instruction that model element is converted to relevant physics workpiece.Be illustrated in figure 9 as the structural representation of template.Described physics workpiece can be a code segment or an executable program etc.
Be example still, below to giving an example corresponding to the template of entity class model file with " online electronic emporium ".BE in its template name " BE.cs.tpl " is promptly corresponding to the entity class model file:
BE.cs.tpl:
using?System;
using?System.Collections;
namespace#{namespace}
{
public?class#{be.Name}
{
<!foreach?field?in?be.Fields>
private#{filed.Type}#{lower(field.Name)};
</!foreach>
<!foreach?field?in?be.Fields>
public#{filed.Type}#{field.Name}
{
get
{
return#{lower(field.Name)};
}
set
{
#{lower(field.Name)}=value;
}
}
</!foreach>
}
}
Wherein, each target platform correspondence a series of template.Template that every class model file under the same target platform is corresponding usually.Thereby for the template of newly-built solution before can be multiplexing, to effectively reduce the development amount.
Step 110 converts model file to the physics workpiece according to the template that is read.
Template provides the instruction that model element is converted into the physics workpiece.Add behind the back(ing) board the at first one or more model elements of the resolved one-tenth of model file.The instruction that provides according to template again, corresponding physics workpiece that model element is changed into.
If the corresponding physics workpiece that generates of model file is a lot, can also relation between the physics workpiece be described with the code file catalogue.The Business Entity class model file 1 that is illustrated in figure 4 as in the solution " online electronic emporium " is resolved the code file catalogue of back generation and the synoptic diagram of model element.The code file catalogue is the same with the model file catalogue, also can be specified when setting up solution by the developer.
The most work of deviser is to use the IDE modeling, IDE implicit expression constantly sets up model file catalogue and model file in the process of visual modeling, and code directory is after the deviser clicks " generation " button, by maker disposable foundation in a generative process.
Be illustrated in figure 5 as the process flow diagram of setting up code file catalogue and product science and engineering part.Hereinafter to being described in detail step 110 in the explanation of Fig. 5.
Step 112 is revised the physics workpiece in the protected location.
For the domain model of each details of failing to define complete software product, can be by in the physics workpiece that produces, programming, thus finish undefined part.A kind of protection zone mechanism is provided in the present embodiment, and in protected district, the developer can directly write protected and program code that avoid changing.The modification of the manual input code in the protected location is independent of the change of domain model.Even so model evolution iteratively, the code in the protected location is still stayed in the identical logical place.Be illustrated in figure 6 as the example of in the protected location, revising.
Step 114, the physics workpiece that compiling generates.For example can in Visual Studio2005 platform, compile, can in the JDK platform, compile for Java for C#.
So far, finished whole process, as shown in figure 15 synoptic diagram for developing by solution product science and engineering part.According to the solution that the developer sets up, only the multiplexing template of needs can obtain the physics workpiece on the target platform.Thereby improved efficiency of software greatly.
The process of step 110 being set up code file catalogue and product science and engineering part below in conjunction with Fig. 5 is elaborated, and may further comprise the steps:
Step 502 reads model file.For example can read model file successively according to model file catalogue shown in Figure 3 for " online electronic emporium ".
Step 504, the analytic model file obtains model element.As shown in Figure 4, the business information in the analytic model file generates corresponding model element.The example that is exemplified as with the Business Entity class model file of " online electronic emporium " in the step 104.It is resolved the back and generates 2 model elements, i.e. order Business Entity and client traffic entity.
Step 506 adds back(ing) board.Load the template of corresponding classification respectively according to the classification of model file.What the model file of same classification loaded is same template.Comprise 2 Business Entity class model files in the solution for example shown in Figure 3 " online electronic emporium ".They are the Business Entity class templates shown in the step 108 corresponding to the loading of C# target platform.
Step 508 is set up the code file catalogue.The Business Entity class model file 1 that is illustrated in figure 4 as in the solution " online electronic emporium " is resolved the code file catalogue of back generation and the synoptic diagram of model element.
Step 510, product science and engineering part.Convert model element to the physics workpiece according to the instruction on the template.
Business Entity class template (BP) with " the online electronic emporium " shown in the step 108 is an example.When loading this section template, judge according to text instruction, do not have #{} and<! 〉</! Special instruction character all be considered as plain text, intact output; Export this value according to assignment directive then for the variate-value that #{} then obtains the inside; For<! Relevant steering order, if, carrying out branch then according to branch instruction, if else statement judges, be that genuine branch continues the template processing logic to evaluation then, if the foreach statement is then according to recursion instruction its inner template processing logic that circulates.
Step 512, output science and engineering part.
Finished the step that model file converts the physics workpiece to thus.
For the solution that step 102 is described, be prior art promptly according to domain model generation model file, the process flow diagram referring to solution shown in Figure 7 generates to only sketching for the step of setting up solution, may further comprise the steps:
Step 702, solution of redetermination.Be example still with " online electronic emporium ", the solution of redetermination one " online electronic emporium " by name.
Step 704, at least one class domain model of redetermination.For the solution that is called " online electronic emporium " defines all kinds of domain models.For example be called the Business Entity class domain model of " order business " etc.
Step 706, corresponding domain model are drawn the corresponding model element of input.For example the model element of input " client " in Business Entity class domain model comprises " customer name " etc.
Step 708, the generation model file.In the present embodiment, employing be the XML language.Be understood that the encapsulation that also can adopt other similar language to carry out model file also is fine.
Step 710 is combined into the generation solution with a plurality of model files.
So far just finished the generative process of solution.
Below in conjunction with accompanying drawing the system that develops based on the model-driven software of template is described in detail.
Be illustrated in figure 8 as the structural representation of thesystem 800 that develops based on the model-driven software of template, comprise:
Solution imports module 802, is used to import solution.Be illustrated in figure 2 as solution and constitute synoptic diagram, no longer be repeated in this description herein.
Solution parsing module 804 is used to resolve solution, generation model file and model file catalogue.Hereinafter can be described in detail in conjunction with Figure 11.
Template base 808 is used for storing template, has the instruction that the transformation model element is the physics workpiece on the described template.As Fig. 9 is the formwork structure 900 of each template in the template base, comprises 908 4 kinds of text instruction 902, branch instruction 904, recursion instruction 906 and assignment directives.Each template has one or more instructions in these four kinds of instructions.
In the present embodiment, corresponding to each target platform, a cover template is arranged respectively respectively in the template base.Every cover template is usually corresponding to different template kinds, for example Figure 10 described template base has comprised six class templates commonly used, for: the BusinessEntity class template 80802 of the entity class model file that is used for managing business, the businessoperation class template 80804 of class of operation model file is used for managing business, be used for handling the serviceitem class template 80806 of service item class model file, be used for the userinterface class template 80808 of process user interface class model file, the manage businessbordereaux class template 80812 of form class model file of the operationflow class template 80810 and being used for of flow process class model file of being used for managing business.
Platform selecting module 806 is used for the select target platform.For example C#, Java or C++ etc.
Maker 810, the classification that is used for the target platform selected according toplatform selecting module 806 and model file read the corresponding template oftemplate base 808, and according to the instruction on the template that reads model file are converted into physics workpiece and code file catalogue.Hereinafter can be elaborated tomaker 810 in conjunction with Figure 12.
Modified module 812 is used for revising the physics workpiece that generates in the protected location.
Collector 814, the physics workpiece that is used for generating carries out process of compilation.
Utilize thesystem 800 that develops based on the model-driven software of template just the solution that imports can be generated as the physics workpiece thus.
Below in conjunction with Figure 11 the solution parsing module is elaborated.Solution parsing module 804 comprises as shown in figure 11: modelfile generation module 8042 is used for the generation model file; Model filecatalogue generation module 8044 is used for the generation model file directory.As Fig. 3 is that solution " online electronic emporium " is resolved the model file catalogue of back generation and the synoptic diagram of model file.
Model file and model file catalogue thus solution have been resolved to.
Below in conjunction with Figure 12maker 810 iselaborated.Maker 810 comprises as shown in figure 12:
Model file read module 81002 is used to read model file.
Template read module 81004 is used for the model file that the target platform selected according toplatform selecting module 806 and model file read module 81002 read, and reads the template of the correspondence in thetemplate base 808; For example for target platform is a Business Entityclass model file 2002 in thesolution 200 of C#, what read is Business Entity class template in thetemplate base 808.
Model file parsing module 81006 is used for the analytic model file, the generation model element.The Business Entity class model file 1 that is illustrated in figure 4 as in the solution " online electronic emporium " is resolved the code file catalogue of back generation and the synoptic diagram of model element.
Instruction module 81008, the instruction that is used for having according to template converts model element to the physics workpiece; As shown in figure 13, it comprises:
Text module 810082 is used to handle text instruction; According to the text instruction in the template content in the model element is exported as plain text, and then converted to the physics workpiece.
Branch'smodule 810084 is used to handle branch instruction; According to the branch instruction in the template content in the model element is carried out branch and judge, be that genuine branch continues the template processing logic to evaluation then, and then convert the physics workpiece to.
Assignment module 810086 is used to handle assignment directive; According to the assignment directive in the template with the variate-value value of model element the inside after this value of output, and then convert the physics workpiece to.
Circulation module 810088 is used for the cycle of treatment instruction.According to the recursion instruction circular treatment model element in the template, and then convert the physics workpiece to.
Code file catalogue generation module 81010 is used to generate code file catalogue as shown in Figure 4.
Physics workpiece output module 81012 is used to export the physics workpiece of generation.
As seen from the above,, just can model file be converted into the physics workpiece, realize logical model is changed into the physics workpiece that satisfies non-functional requirement based on template by the present invention.
The above only is preferred embodiment of the present invention, and is in order to restriction the present invention, within the spirit and principles in the present invention not all, any modification of being done, is equal to replacement, improvement etc., all should be included within protection scope of the present invention.