Summary of the invention
The present invention aims to provide a kind of code generating unit based on the J2EE framework, and the exploitation that it can solve for the qualitative pattern of software operation takies a lot of time of open personnel, 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, comprising based on the J2EE framework:
Attribute is provided with the unit, is used for according to the parameter that receives file attribute being set, and generates corresponding configuration file and output;
Engine unit is used to obtain described configuration file and parsing, selects corresponding code module according to the described file attribute that parses, and the generating code file.
Preferably, also comprise:
Input-output unit is used for that the parameter from the user is sent to described attribute the unit is set, and exports the code file that described engine unit generates.
Preferably, described attribute is provided with the unit and comprises:
The name attribute module is used for the parameter according to the user, and the name variable rule in file name rule and the file is set, and generates corresponding expandable mark language XML configuration file and output;
The page properties module is used to receive user's parameter, and the page shape, the control type on the page, control color and the control layout that are shown to the user are set, and generates corresponding CSS (cascading style sheet) CSS configuration file and output;
Database module is used to receive user's parameter, and the list structure, field attribute, major key attribute, the index attributes that show on the described page are set, and generates corresponding XML configuration file and output.
Preferably, described database module comprises:
Table name attribute submodule is used to receive user's parameter, and the naming rule of described table is set, and generates corresponding XML configuration file and output;
The field attribute submodule is used to receive user's parameter, the interior data type of each field in the table is set and shows rule, generates corresponding XML configuration file and output;
Major key attribute submodule is used to receive user's parameter, and the create-rule of major key in the table is set, and generates corresponding XML configuration file and output;
The index attributes submodule is used to receive user's parameter, and the index in the table is set, and generates corresponding XML configuration file and output.
Preferably, also comprise:
The data basd link connection module, the XML configuration file stores that is used for described database module is generated is to database;
Described engine unit is used for obtaining described XML configuration file by described database.
Preferably, described engine unit comprises:
Database component is used to receive user's parameter, is provided with to connect described data base configuration file;
Resolve the attribute assembly, be used to obtain 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 also resolve;
The code formation component is used for selecting corresponding code module according to the described file attribute that parses, and the generating code file.
Preferably, described engine unit also comprises:
The configuration file assembly is used for the code file that the code formation component generates is configured to predefined file.
Device of the present invention adopts the Componentized structure, and the parameter by the user is provided with can generate corresponding code file automatically, is configured to platform by the user; 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 comprise referring to Fig. 1:
Attribute is provided with unit 11, is used for according to the parameter that receives file attribute being set, and comprises the title of file and file content, type etc., generates corresponding configuration file and output;
Engine unit 12 is used to obtain described configuration file and parsing, selects corresponding code module and generating code file according to described file attribute;
Input-output unit 13 is used for that the parameter from the user is sent to described attribute the unit is set, and exports described code file.
The user is provided with the unit input by peripheral hardware to attribute parameter is set, and the various attributes of file are set, and comprising: name attribute, Database Properties, page properties etc.Each module that attribute is provided with in the unit 11 is carried out corresponding attribute setting according to parameter, comprises respectively:
Name attribute module 112 is used to receive user's parameter-definition Naming conventions (definition of the definition of variable specifications, the definition of file, java bag) and setting.
The variable name of definition different types of data, data type comprise, integer, character type, date type, floating type (having the radix point type).The prefix of main defining variable and the capital and small letter of initial, when being convenient to generating code by this regular naming variable.When finishing, configuration generates corresponding XML configuration file.
The name nominating rule of definition java class file and jsp file, each file name are fixed and are identical with the table name name of database 14, and the initial capital and small letter defines from here.When finishing, configuration generates 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), six son bags all can be arranged under each overall budget, and the son bag need not definition, and the child bag under the 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 son bag is responsible for code separately and is realized professional function, is described as follows:
The method of correspondence inlet 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 be finished in this type of, and 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 according to the overall budget and the platform properties of this module definition under the child bag of correspondence under overall budget, and file generates 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, the parameter that is used for accepting the user are provided with the attribute of traffic table structure and data item and are kept at database 14 with the form of XML file.Comprise table name attribute submodule 1101, field attribute submodule 1102, major key attribute submodule 1103, index attributes submodule 1104.
Table name attribute submodule 1101, being used for his-and-hers watches names, definition table name naming rule as subscriber's meter, can add corresponding name service word with prefix, prefix and the direct junction symbol of title implication word, these all need to define at this, and for example Prefix Hierarchy Names is TB, and connector is combined into " _ ", professional word title is UESER, and this table name just is defined as TB_USER.
Field attribute submodule 1102, be used for define field naming rule and title, field is mainly reflected among form class and entity class, the jsp, the prefix of define field and junction symbol, prefix and junction symbol do not show in the file that generates, 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 the time control in the page embodies) txtare (form with textview field in the page embodies).
Major key attribute submodule 1103, it is to generate automatically or filled in by the user that the parameter that is used to receive the user is provided with major key, if generate automatically, the rule that generates automatically, the mode of main sequence, the title of specified sequence.
Index attributes submodule 1104, the parameter that is used to receive the user is provided with the file index of inquiry, generates corresponding expandable mark language XML configuration file and output, to improve search efficiency.
Page properties module 113, the structure of the page style sheet the when parameter-definition that is used to receive the user feeds back to the user, control type, control color, control layout etc., and be stored in the database 14 with CSS (cascading style sheet) CSS document form with the definition standard of page style sheet.Set the file name of style sheet, be divided into two big classes, query page can be specified different style sheet respectively with maintain pages, and style sheet also can directly be revised, and after modification finishes, directly is saved under the path of style sheet of platform correspondence.The verifying function of script at various field type, is specified different methods of calibration, and type comprises numeric type, date type, character type three major types, can related corresponding method when generating jsp.
Comprise that also data basd link connection module 114 is used to connect database 14, attribute is provided with the XML configuration file stores of database module generation in the unit in database 14.
Describe attribute above in detail each module in the unit 11 is set, the following describes each module and function in the engine unit 12; Comprise following each assembly and function in the engine unit 12:
1) database component 121, are used to connect database 14, and reading database link module 114 is saved in the XML profile information of the traffic table in the database 14.
To the database 14 that will use, can pass through interaction page, the connection parameter is set, be saved in the XML file of appointment.In order to when using database, carrying out connection to this database.Can read the traffic table information in this storehouse by the database of configuration use.
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, read and offer the generating code assembly after the parsing, the 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) the code formation component 123, major function:
To the traffic table of choosing, according to resolving the corresponding code file of standard rule generation that the attribute assembly parses, file mainly divides two classes, one class is corresponding java class file, another kind of is corresponding jsp pagefile, the java file can be created under the src catalogue of platform automatically according to the bag name that sets, and the jsp file can be generated to according to the title of overall budget under the webroot catalogue under the platform.
4) the 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 struts, Spring and hibernate on stream, java class that the code formation component is generated and jsp file configuration are in these configuration files.
By device embodiment of the present invention, the user is in the process of design software, at first analyze business demand, determine to need to show which data, thereby by attribute the layout that each module in the unit is provided with list structures such as corresponding file name, the field that is comprised, data type, page display content respectively is set, set which field data need safeguard, in page display format, need operating functions (increase, delete, change, look into) etc.;
After setting is finished, attribute is provided with the unit and can automatically the parameter that is provided be saved in the database with the XML document form, engine unit can connect database by database component, read XML file and parsing by resolving the attribute assembly, by the standard of code formation component, generate the Java/Jsp code file of respective name according to the definition of name attribute module; The code file that generates is configured in the file under the corresponding platform at last by the configuration file assembly.
Device of the present invention adopts the Componentized structure, and the parameter by the user is provided with can generate corresponding code file automatically, is configured to platform by the user; 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 the general calculation device, they can concentrate on the single calculation element, perhaps be distributed on the network that a plurality of calculation element forms, alternatively, they can be realized with the executable program code of calculation element, carry out by calculation element thereby they can be stored in the memory storage, perhaps they are made into each integrated circuit modules respectively, perhaps a plurality of modules in them or step are made into the single integrated circuit module and realize.Like this, the present invention is not restricted to any specific hardware and software combination.
The above is the preferred embodiments of the present invention only, is not limited to the present invention, and for a person skilled in the art, the present invention can have various changes and variation.Within the spirit and principles in the present invention all, any modification of being done, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.