Summary of the invention
The present invention aims to provide a kind of code generating unit based on J2EE framework, and the exploitation that it can solve for software operation qualitative model takies the time that open personnel are a lot, causes the construction cycle of whole project long, the problem that development efficiency is low.
According to an aspect of the present invention, provide a kind of code generating unit based on J2EE framework, comprising:
Setup of attribute unit, arranges file attribute for the parameter according to receiving, and generates corresponding configuration file output;
Engine unit, for obtaining described configuration file and resolving, selects corresponding code module according to the described file attribute parsing, and generating code file.
Preferably, also comprise:
Input-output unit, for the parameter from user being sent to described setup of attribute unit, exports the code file that described engine unit generates.
Preferably, described setup of attribute unit comprises:
Name attribute module, for according to user's parameter, arranges the name variable rule in file name rule and file, generates corresponding expandable mark language XML configuration file output;
Page properties module, for receiving user's parameter, arranges the page shape, the control type on the page, control color and the control layout that are shown to user, generates corresponding CSS (cascading style sheet) CSS configuration file output;
Database module, for receiving user's parameter, arranges the list structure, field attribute, major key attribute, the index attributes that on the described page, show, generates corresponding XML configuration file output.
Preferably, described database module comprises:
Table name attribute submodule, for receiving user's parameter, arranges the naming rule of described table, generates corresponding XML configuration file output;
Field attribute submodule, for receiving user's parameter, arranges the interior data type of each field in table and shows rule, generates corresponding XML configuration file output;
Major key attribute submodule, for receiving user's parameter, arranges the create-rule of major key in table, generates corresponding XML configuration file output;
Index attributes submodule, for receiving user's parameter, arranges the index in table, generates corresponding XML configuration file output.
Preferably, also comprise:
Data basd link connection module, for XML configuration file stores that described database module is generated to database;
Described engine unit, for obtaining described XML configuration file by described database.
Preferably, described engine unit comprises:
Database component, for receiving user's parameter, arranges and connects described data base configuration file;
Resolve attribute assembly, for obtaining the XML configuration file of the XML configuration file of described database preservation, the generation of described name attribute module and the CSS configuration file of described page properties module generation and resolving;
Code formation component, for selecting corresponding code module according to the described file attribute parsing, and generating code file.
Preferably, described engine unit, also comprises:
Configuration file assembly, is configured to predefined file for the code file that code formation component is generated.
Device of the present invention adopts Componentized structure, and the parameter arranging by user, can generate corresponding code file automatically, by user, is configured to platform; By device of the present invention, saved the time of user's edit code file, improved user's work efficiency, reduce the construction cycle of whole project.
Embodiment
Below with reference to the accompanying drawings and in conjunction with the embodiments, describe the present invention in detail.
Device embodiment of the present invention adopts the design of object-oriented thought, and its structural drawing can, referring to Fig. 1, comprise:
Setup of attribute unit 11, arranges file attribute for the parameter according to receiving, and comprises the title of file and file content, type etc., generates corresponding configuration file output;
Engine unit 12, for obtaining described configuration file and resolving, selects corresponding code module generating code file according to described file attribute;
Input-output unit 13, for the parameter from user being sent to described setup of attribute unit, exports described code file.
User to setup of attribute unit input parameters, arranges the various attributes of file by peripheral hardware, comprising: name attribute, Database Properties, page properties etc.Modules in setup of attribute unit 11 is carried out corresponding setup of attribute according to parameter, comprises respectively:
Name attribute module 112, for receiving user's parameter-definition Naming conventions (definition of the definition of variable specifications, the definition of file, java bag) and arranging.
The variable naming of definition different types of data, data type comprises, integer, character type, date type, floating type (with radix point type).The main prefix of defining variable and the capital and small letter of initial, while being convenient to generating code by this regular naming variable.When configuration is complete, generate corresponding XML configuration file.
The name nominating rule of definition java class file and jsp file, each file name is fixed and is identical with the table name name of database 14, and initial capital and small letter defines from here.When configuration is complete, generate corresponding XML configuration file.
The name of definition java bag, each module can be in standard a corresponding java overall budget (for example, com.order.cc.app.user), under each overall budget, can have six attached bags, attached bag is without definition, and the attached bag under overall budget generates according to platform properties, relation between each class can be referring to Fig. 2, mainly comprise Form, action, Serivce, dao, idao, entity, each attached bag is responsible for the function that code is realized business separately, is described as follows:
Corresponding method entrance when action:jsp submits to.
The buffering of form:jsp and back-end data.
Entity: the entity file of related data object.
Dao: all database manipulations all will complete in this type of, forbidden data storehouse sq1 occurs in other classes.
The interface class of idao:dao.
Serivce: service logic realizes in this type of, links up with dao.
When generating certain module java class file, engine unit can generate corresponding class file under the attached bag of correspondence according to the overall budget of this module definition and platform properties under overall budget, and file generated is as follows:
Action class name form: the title+Action.java of module table
Form class name form: the title+Form.java of module table
Entity class name form: the title+Entity.java of module table
Dao class class name form: the title+DAO.java of module table
IDao class class name form: the title+DAO.java of I+ module table
Svc class class name form: the title+Serivce.java of module table
Database module 111, arranges the attribute of traffic table structure and data item and is kept at database 14 with the form of XML file for accepting user's parameter.Comprise table name attribute submodule 1101, field attribute submodule 1102, major key attribute submodule 1103, index attributes submodule 1104.
Table name attribute submodule 1101, for his-and-hers watches, name, definition table name naming rule, as subscriber's meter, can add corresponding name service word by prefix, prefix and the direct junction symbol of title implication word, these all need define at this, and for example Prefix Hierarchy Names is TB, and connector is combined into " _ ", business word title is UESER, and this table name is just defined as TB_USER.
Field attribute submodule 1102, for define field naming rule and title, field is mainly reflected in form class and entity class, jsp, the prefix of define field and junction symbol, prefix and junction symbol do not show in the file generating, mainly judge the label control that this field shows in the jsp page, prefix mainly comprises Txt (form with text box in the page embodies), com (form with combobox in the page embodies) date (form with time control in the page embodies) txtare (form with textview field in the page embodies).
Major key attribute submodule 1103, for receiving user's parameter, major key is set is automatically to generate or filled in by user, if automatically generated, the rule automatically generating, the mode of main sequence, the title of specified sequence.
Index attributes submodule 1104, arranges the file index of inquiry for receiving user's parameter, generate corresponding expandable mark language XML configuration file output, to improve search efficiency.
Page properties module 113, the structure of the page style sheet while feeding back to user for receiving user's parameter-definition, control type, control color, control layout etc., and be stored in database 14 with CSS (cascading style sheet) CSS document form with the definition standard of page style sheet.The file name of setting style sheet, is divided into two large classes, and query page and maintain pages can be specified respectively different style sheet, and style sheet also can directly be revised, and after modification, is directly saved under the path of the style sheet that platform is corresponding.The verifying function of script, for various field type, specifies different methods of calibration, and type comprises numeric type, date type, character type three major types, can associated corresponding method when generating jsp.
Also comprise, data basd link connection module 114, for connection data storehouse 14, the XML configuration file stores that database module in setup of attribute unit is generated is in database 14.
Describe the modules in setup of attribute unit 11 above in detail, the following describes modules and function in engine unit 12; Engine unit 12 comprises following each assembly and function:
1) database component 121, and for connection data storehouse 14, and reading database link module 114 is saved in the XML profile information of the traffic table in database 14.
To the database 14 that will use, can pass through interaction page, connection parameter is set, be saved in the XML file of appointment.In order to carry out the connection to this database in usage data storehouse.The database that can use by configuration, reads the traffic table information in this storehouse.
2) resolve attribute assembly 122, major function:
The XML configuration file that parsing is preserved in database, resolve the XML configuration file of described name attribute module generation and the CSS configuration file that described page properties module generates, after parsing, read and offer generating code assembly, generating code assembly generates corresponding code file according to the attribution rule of XML configuration file, CSS configuration definition.Resolution data storehouse configuration parameter, offers database and connects, and carries out the connection to database.
3) code formation component 123, major function:
To the traffic table of choosing, the standard rule parsing according to parsing attribute assembly generates corresponding code file, file mainly divides two classes, one class is corresponding java class file, another kind of is corresponding jsp pagefile, java file can be created under the src catalogue of platform automatically according to the bag name setting, and jsp file can be generated under the webroot catalogue under platform according to the title of overall budget.
4) configuration file assembly 124, major function:
Platform architecture adopts carries out programming development on the J2EE framework of SSH (Struts Spring Hibernate three's the combination) structure increase income, some configuration files that need on stream struts, Spring and hibernate, the java class that code formation component is generated and jsp file configuration are in these configuration files.
By device embodiment of the present invention, user is in the process of design software, first analyze business demand, determine and need to show which data, thereby the layout of the list structures such as corresponding file name, the field comprising, data type, page display content is set respectively by the modules in setup of attribute unit, set which field data need safeguard, in page display format, need operating function (increase, delete, change, look into) etc.;
After setting completes, setup of attribute unit can be saved in the parameter of setting in database with XML document form automatically, engine unit can pass through database component connection data storehouse, by resolving attribute assembly, read XML file and resolve, the standard being defined according to name attribute module by code formation component, the Java/Jsp code file of generation respective name; Finally by configuration file assembly, the code file of generation is configured in the file under corresponding platform.
Device of the present invention adopts Componentized structure, and the parameter arranging by user, can generate corresponding code file automatically, by user, is configured to platform; By device of the present invention, saved the time of user's edit code file, improved user's work efficiency, reduce the construction cycle of whole project.
Obviously, those skilled in the art should be understood that, above-mentioned each module of the present invention or each step can realize with general calculation element, they can concentrate on single calculation element, or be distributed on the network that a plurality of calculation elements form, alternatively, they can be realized with the executable program code of calculation element, thereby they can be stored in memory storage and be carried out by calculation element, or they are made into respectively to each integrated circuit modules, or a plurality of modules in them or step are made into single integrated circuit module to be realized.Like this, the present invention is not restricted to any specific hardware and software combination.
The foregoing is only the preferred embodiments of the present invention, be not limited to the present invention, for a person skilled in the art, the present invention can have various modifications and variations.Within the spirit and principles in the present invention all, any modification of doing, be equal to replacement, improvement etc., within all should being included in protection scope of the present invention.