Implement conversion between vo an and the vo of ActionScript.

Source: Internet
Author: User

 

 

Like java, ActionScript is an object-oriented development program. There are many similarities between them.

 

Sometimes, after compiling the JavaBean, we need to create the corresponding as object. in the case of a small number, it may not be cumbersome. but if you have dozens or hundreds of JavaBean, do you want to automatically generate the as VO?

 

Here we will show you the code automatically generated between the time I wrote Java and ActionScript. since the program has just been written, it is not complete, so it is rough, please do not laugh. if any friend has a better conversion method, please email (eclipser@163.com) to send to me, I am very grateful here!

 

Package CN. vicky. utils; </P> <p> Import Java. io. file; <br/> Import Java. io. filewriter; <br/> Import Java. io. ioexception; <br/> Import Java. lang. reflect. field; <br/> Import Java. math. bigdecimal; <br/> Import Java. util. date; </P> <p>/** <br/> * @ author Vicky <br/> * @ emial eclipser@163.com <br/> */<br/> public class java2flex {<br/> // Java code directory <br/> Private Static string java_src_path = "G: /game project/game_webserve R/src "; </P> <p> // flex code directory <br/> Private Static string flex_src_path =" G:/game project/game_webserver/src "; </P> <p> // pojo package path <br/> Private Static string java_package = "CN. vicky. pojo "; </P> <p> // path of the AS value object package to be generated <br/> Private Static string flex_package =" CN. vicky. pojo "; </P> <p> Private Static string example =" example "; </P> <p> Public java2flex () {<br/>}</P> <p> @ suppresswarnings ("static-access") <br/> pub LIC java2flex (string java_src_path, string flex_src_path, <br/> string java_package, string flex_package) {<br/> This. java_src_path = java_src_path; <br/> This. flex_src_path = flex_src_path; <br/> This. java_package = java_package; <br/> This. flex_package = flex_package; <br/>}</P> <p>/** <br/> * @ Param ARGs <br/> */<br/> Public static void main (string [] ARGs) {<br/> string srcpath = java_package.replac Eall ("//. ","/"); <br/> file dir = new file (java_src_path +" // "+ srcpath); <br/> file [] files = dir. listfiles (); </P> <p> string name = ""; <br/> for (File file: Files) {<br/> If (! File. isdirectory () & file. isfile () {<br/> name = file. getname (); </P> <p> If (name. lastindexof (example + ". java ") =-1) {</P> <p> name = Name. replaceall (". java "," "); <br/> try {<br/> class <?> Clazz = Class. forname (java_package + ". "<br/> + name); <br/> createfile (clazz); <br/>}catch (exception e) {<br/> E. printstacktrace (); <br/>}</P> <p> Private Static void createfile (class <?> Clz) throws ioexception {<br/> string flexsrcpath = flex_package.replaceall ("//. ","/"); </P> <p> string filename = clz. getsimplename (); // user <br/> file dir = new file (flex_src_path + "//" + flexsrcpath); <br/> If (! Dir. exists () {<br/> dir. mkdirs (); <br/>}< br/> file F = new file (Dir, filename + ". as "); // user. as <br/> If (F. exists () {<br/> F. delete (); <br/>}< br/> F. createnewfile (); </P> <p> filewriter fw = new filewriter (f); <br/> FW. write ("package" + flex_package + "{/N"); <br/> // FW. write ("/T [Bindable]/n"); // [Bindable] <br/> FW. write ("/tpublic class" + filename + "{/N"); // public class user {<br/> FW. write ("/T/tpublic function" + filename + "() {}/N"); <br/> // system. out. println (filename + ":" + clz. getdeclaredfields (). length); <br/> for (field FD: clz. getdeclaredfields () {<br/> FW. write (createfield (FD); // create attributes <br/>}</P> <p> FW. write ("/t}/n}"); <br/> FW. close (); </P> <p >}</P> <p> Private Static string createfield (field FD) {<br/> string r = "/T/tpublic Var"; <br/> class <?> Type = FD. getType (); <br/> string name = FD. getname (); <br/> If (name. equals ("serialversionuid") {<br/> return ""; <br/>}</P> <p> system. out. println ("type:" + type); <br/> system. out. println ("type. getname (): "+ type. getname (); <br/> If (type. equals (Long. class) | type. equals ("long") <br/> | type. equals (double. class) | type. equals ("double") <br/> | type. equals (integer. class) | type. equals ("int") <Br/> | type. equals (short. class) | type. equals (bigdecimal. class) {<br/> r = R + name + ": Number;"; <br/>} else if (type. equals (string. class) {<br/> r = R + name + ": string;"; <br/>} else if (type. equals (date. class) {<br/> r = R + name + ": date;"; <br/>} else if (type. getname (). equals ("Java. lang. object ") {<br/> r = R + name +": object; "; <br/>} else if (type. getname (). equals ("Java. util. list ") <Br/> | type. getname (). equals ("Java. util. set ") <br/> | type. getname (). equals ("Java. util. vector ") {<br/> r = R + name +": array = new array (); "; <br/>} else if (type. getname ()! = NULL &&! Type. getname (). equals ("") {<br/> r = R + name + ":" + getfiletype (type. getname () + ";"; <br/>}else {<br/> system. out. println (type. getname (); <br/>}< br/> return r + "/N "; <br/>}</P> <p> Public static string getfiletype (string type) {<br/> If (type. contains (". ") {<br/> type = type. substring (type. lastindexof (". ") + 1, type. length (); <br/>}< br/> return type; <br/>}</P> <p >}< br/>

 

Compile the test JavaBean

** <Br/> * player table <br/> * @ author Vicky <br/> */<br/> @ entity <br/> @ table (name = "lesogo_user ") <br/> public class user implements serializable {</P> <p> Private Static final long serialversionuid = 1l; </P> <p> @ ID <br/> @ generatedvalue (Strategy = generationtype. auto) <br/> private integer ID; </P> <p> @ column (length = 20, unique = true, nullable = false) <br/> private string user_name; </P> <p> @ column (length = 32, nullable = false) <br/> private string user_password; </P> <p> @ column (length = 2, nullable = false) <br/> private integer user_rank = 1; </P> <p> @ column (length = 5, nullable = false) <br/> private integer user_experience = 0; </P> <p> @ column (length = 10, nullable = false) <br/> private integer user_money = 0; </P> <p> @ column (length = 5, nullable = false) <br/> private integer user_charm = 0; </P> <p> @ column (length = 3, nullable = false) <br/> private integer user_skills = 1; </P> <p> @ column (length = 20, nullable = false) <br/> private string user_trbal; </P> <p> @ manytoone (cascade = {cascadetype. refresh}, optional = true, fetch = fetchtype. lazy) <br/> @ joincolumn (name = "user_village_id") <br/> private ages user_village_id; </P> <p> @ temporal (temporaltype. timestamp) <br/> @ column (nullable = false) <br/> private date user_create_time = new date (); </P> <p> @ column (length = 19) <br/> private string user_login_time; </P> <p> @ column (length = 1, nullable = false) <br/> private integer user_islogin = 0; </P> <p> @ onetoworkflow (cascade = {cascadetype. all}, fetch = fetchtype. lazy, mappedby = "friendships_owner") <br/> private set <friendships> userid = new hashset <friendships> (); </P> <p> @ onetoworkflow (cascade = {cascadetype. refresh}, fetch = fetchtype. lazy, mappedby = "friendships_friend") <br/> private set <friendships> friendid = new hashset <friendships> (); </P> <p> @ onetoone (cascade = {cascadetype. all}, fetch = fetchtype. lazy) <br/> @ joincolumn (name = "user_forbidden_id") <br/> private forbidden user_forbidden_id; </P> <p> // getter & setter

Generate ActionScript

Package CN. vicky. pojo {<br/> public class user {<br/> Public Function user () {}< br/> Public var ID: Number; <br/> Public var user_name: string; <br/> Public var user_password: string; <br/> Public var user_rank: Number; <br/> Public var user_experience: Number; <br/> Public var user_money: number; <br/> Public var user_charm: Number; <br/> Public var user_skills: Number; <br/> Public var user_trbal: string; <br/> Public var user_1_age_id: ages; <br/> Public var user_create_time: date; <br/> Public var user_login_time: string; <br/>... <br/>}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.