【问题标题】:Intgrating acceleo with jboss errai and gwt将 acceleo 与 jboss erai 和 gwt 集成
【发布时间】:2013-03-30 07:46:57
【问题描述】:

我必须使用 GWT 在 jboss erai 中创建一个项目,但我想使用 eclipse 建模框架 .ecore 模型使用 acceleo 生成我的模型代码。我做过这些事情。

  1. 使用命令创建 maven 项目

mvn archetype:generate -DarchetypeGroupId=org.jboss.errai.archetypes -DarchetypeArtifactId=cdi-quickstart -DarchetypeVersion=2.2.0.Final

  1. 将项目导入 Eclipse 作为现有的 maven 项目。

  2. 转到 Acceleo->将项目转换为 Acceleo Generator 项目但一无所获。

  3. 然后我转到 Acceleo->Convert to Acceleo MTL Projects 并创建了一个新的 acceleo 项目并使用 .ecore 模型为我以前的项目生成了模型,但是当我在 String 处获取 EString 时在模型类中出现错误 和其他也作为电子数据类型,请建议解决方案如何在我的 jboss errai maven 项目中使用加速功能。

我的模板文件如下:

[comment encoding = UTF-8 /]
[module main('http://www.eclipse.org/emf/2002/Ecore')  ]



[template public generateElement(anEClass : EClass)]
[comment @main /]
[file (anEClass.name.concat('.java'), false, 'UTF-8')]
    public class [anEClass.name.toUpperFirst()/]{
[ for (p:EAttribute|anEClass.eAttributes) separator('\n')]
private [p.eAttributeType.name/] [p.name/];
[/for]

[ for (p:EAttribute|anEClass.eAttributes)  separator('\n')]
public  [p.eAttributeType.name/]  get[p.name.toUpperFirst()/]()
{

    return this.[p.name/];


}
[/for]

[ for (p:EAttribute|anEClass.eAttributes) separator('\n')]
public  void set[p.name.toUpperFirst()/]([p.eAttributeType.name/] [p.name/])
{
 this.[p.name/]=[p.name/];
}
[/for]


[protected ('protected')]

[/protected]

}



[/file]
[/template]

从.ecore模型生成的模型之一是

public class UserRegistration {
    private EString strFirstName;
    private EString strSurName;
    private EString strOccupation;
    private EString strQualificaion;
    private EString strFotherName;
    private EString strMotherName;
    private EEList chMaritalStatus;
    private EDouble dblAnnualIncome;
    private EDate dtDOB;
    private EString strAbout;
    private EJavaClass objAcceleo;

    public EString getStrFirstName() {
        return this.strFirstName;
    }

    public EString getStrSurName() {
        return this.strSurName;
    }

    public EString getStrOccupation() {
        return this.strOccupation;
    }

    public EString getStrQualificaion() {
        return this.strQualificaion;
    }

    public EString getStrFotherName() {
        return this.strFotherName;
    }

    public EString getStrMotherName() {
        return this.strMotherName;
    }

    public EEList getChMaritalStatus() {
        return this.chMaritalStatus;
    }

    public EDouble getDblAnnualIncome() {
        return this.dblAnnualIncome;
    }

    public EDate getDtDOB() {
        return this.dtDOB;
    }

    public EString getStrAbout() {
        return this.strAbout;
    }

    public EJavaClass getObjAcceleo() {
        return this.objAcceleo;
    }

    public void setStrFirstName(EString strFirstName) {
        this.strFirstName = strFirstName;
    }

    public void setStrSurName(EString strSurName) {
        this.strSurName = strSurName;
    }

    public void setStrOccupation(EString strOccupation) {
        this.strOccupation = strOccupation;
    }

    public void setStrQualificaion(EString strQualificaion) {
        this.strQualificaion = strQualificaion;
    }

    public void setStrFotherName(EString strFotherName) {
        this.strFotherName = strFotherName;
    }

    public void setStrMotherName(EString strMotherName) {
        this.strMotherName = strMotherName;
    }

    public void setChMaritalStatus(EEList chMaritalStatus) {
        this.chMaritalStatus = chMaritalStatus;
    }

    public void setDblAnnualIncome(EDouble dblAnnualIncome) {
        this.dblAnnualIncome = dblAnnualIncome;
    }

    public void setDtDOB(EDate dtDOB) {
        this.dtDOB = dtDOB;
    }

    public void setStrAbout(EString strAbout) {
        this.strAbout = strAbout;
    }

    public void setObjAcceleo(EJavaClass objAcceleo) {
        this.objAcceleo = objAcceleo;
    }

    //Start of user code protected
    //End of user code
}

这里我用 EString 代替 String 和其他原始数据类型作为 E-Data 类型。

请提出解决方案我怎样才能获得相同的java数据和其他处理器

【问题讨论】:

    标签: gwt jboss emf acceleo errai


    【解决方案1】:

    其实我得到了我刚刚在我的mtl文件中修改的问题的核心答案

    [comment encoding = UTF-8 /]
    [module main('http://www.eclipse.org/emf/2002/Ecore')/]  
    [template public generateElement(anEClass : EClass)]
    [comment @main /]
    [file (anEClass.name.concat('.java'), false, 'UTF-8')]
    package com.garvityWeb.main.migrated.models;
    @Portable
    public class [anEClass.name.toUpperFirst()/]
    {
    [ for (p:EAttribute|anEClass.eAttributes) separator('\n')]
    @Inject
    @DataField
    private [p.eAttributeType.instanceClassName/] [p.name/];
    [/for]
    
    [ for (p:EAttribute|anEClass.eAttributes)  separator('\n')]
    public  [p.eAttributeType.instanceClassName/]  get[p.name.toUpperFirst()/]()
    {
        return this.[p.name/];
    }
    [/for]
    [ for (p:EAttribute|anEClass.eAttributes) separator('\n')]
    public  void set[p.name.toUpperFirst()/]([p.eAttributeType.instanceClassName/] [p.name/])
    {
     this.[p.name/]=[p.name/];
    }
    [/for]
    }
    [/file]
    [/template]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-26
      • 1970-01-01
      • 1970-01-01
      • 2013-05-29
      • 1970-01-01
      • 2011-03-29
      相关资源
      最近更新 更多