Tool for generate CODE.

Discussion in 'Java' started by FWE, Dec 27, 2005.

  1. FWE

    FWE Guest

    I work with eclipse. I must generate java code in relation to some
    variables . I want create java class that reflect table in mysql data
    base with function of read,update,insert,delete. EMF can help me to do
    this? Reading documentation about EMF i have understood that from UML,
    XMI and from java class it generate code but if i customize function?
    >From stupid person i have created this java class:

    i've created a "SalvaVita" class giving the information about variables
    number that i must use.
    In "Load" function i insert into two vectors the type of variables and
    the name of variables.(In future "Load" will get information from file
    or other..)
    After i have created many function but i have cited only one
    "generateConstructor()" that return a string that represents a
    constructor function.

    Anyone can help me?

    public class SalvaVita {

    private int numeroCampi;
    private String nomeTabella;
    private String[] nomeCampi;
    private String[] tipiCampi;

    public SalvaVita(int numeroCampi) {
    this.numeroCampi = numeroCampi;
    nomeCampi = new String[numeroCampi];
    tipiCampi = new String[numeroCampi];
    }

    public void Load(){

    nomeTabella="Azienda";

    nomeCampi[0]="ID";
    // ...

    tipiCampi[0]="int";
    // ...

    }

    public String generateConstructor(){
    String resultBegin,resultEnd;
    resultBegin = " public " + nomeTabella+"(";
    int i;

    for(i=0;i<(numeroCampi-1);i++){
    resultBegin+=tipiCampi+" "+nomeCampi+",";
    }
    resultBegin+=tipiCampi+" "+nomeCampi+"){\n";

    for(i=0;i<(numeroCampi);i++){
    resultBegin+=" this."+nomeCampi+" = "+nomeCampi+";\n";
    }
    resultEnd =" }\n";
    return resultBegin + resultEnd;
    }
    }
    FWE, Dec 27, 2005
    #1
    1. Advertising

  2. FWE wrote:
    > I work with eclipse. I must generate java code in relation to some
    > variables . I want create java class that reflect table in mysql data
    > base with function of read,update,insert,delete. EMF can help me to do
    > this? Reading documentation about EMF i have understood that from UML,
    > XMI and from java class it generate code but if i customize function?
    >>From stupid person i have created this java class:

    > i've created a "SalvaVita" class giving the information about variables
    > number that i must use.
    > In "Load" function i insert into two vectors the type of variables and
    > the name of variables.(In future "Load" will get information from file
    > or other..)
    > After i have created many function but i have cited only one
    > "generateConstructor()" that return a string that represents a
    > constructor function.
    >
    > Anyone can help me?
    >


    Best practice in this case is to have classes that extend the generated
    classes and specialize those. Then re-generating the generated classes
    will not affect the specializations.

    For example, generate a SalvaVistaBase class via the tool. Then create
    a SalvaVista extending SalvaVistaBase. Add the specialized code to
    SalvaVista. Only use the SalvaVista class in your application. When
    the schema changes, re-generate SalvaVistaBase.

    HTH,
    Ray

    --
    XML is the programmer's duct tape.
    Raymond DeCampo, Jan 1, 2006
    #2
    1. Advertising

  3. FWE

    Oliver Wong Guest

    "FWE" <> wrote in message
    news:...
    >I work with eclipse. I must generate java code in relation to some
    > variables . I want create java class that reflect table in mysql data
    > base with function of read,update,insert,delete. EMF can help me to do
    > this? Reading documentation about EMF i have understood that from UML,
    > XMI and from java class it generate code but if i customize function?


    It sounds like you want to generate code which you will them immediately
    use in your application (as opposed to, for example, giving your client a
    program which will generate .class files for them). If that's the case, you
    might want to try JET.

    JET code looks like JSP or PHP code, in that it's code that is embedded
    into arbitrary text streams. The JET plugin for Eclipse provides a builder
    so that as part of the build process, the JET code is executed, generating
    the Java code, which in turn gets compiled all in the background and
    automatically.

    http://www.eclipse.org/articles/Article-JET/jet_tutorial1.html

    - Oliver
    Oliver Wong, Jan 9, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Weng Tianxiang
    Replies:
    5
    Views:
    1,300
    Christophe
    Feb 16, 2006
  2. david ullua
    Replies:
    9
    Views:
    1,409
    Stefan Ram
    Feb 5, 2007
  3. Replies:
    3
    Views:
    399
    red floyd
    Apr 7, 2006
  4. Baron Samedi
    Replies:
    0
    Views:
    376
    Baron Samedi
    May 15, 2007
  5. Replies:
    2
    Views:
    474
    Bill Davy
    Dec 12, 2012
Loading...

Share This Page