GWT:Rebind结果必须是一个类

时间:2015-11-09 13:50:40

标签: java gwt

我编写了一个生成器类,为我们的DTO创建了一个简单的适配器。基本上,所有生成的代码都是查看DTO的所有方法来查找getter,并创建一个getProperty(String)方法来根据其属性名称检索属性。

在编译器尝试编译GWT.create()语句之前,一切似乎都没问题,然后我得到"必须是一个类"错误。

感激不尽的任何帮助。

下面的大量内容解释问题。

谢谢,

这是我的.gwt.xml部分:

<generate-with class="com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactoryGenerator" >
    <when-type-is class="com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactory"/>
</generate-with> 

这是控制台输出的一部分,显示正在运行的生成器:

[INFO] Computing all possible rebind results for 'com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactory'
[INFO]       Rebinding com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactory
[INFO]          Checking rule <generate-with class='com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactoryGenerator'/>
[INFO]             Checking if all subconditions are true (<all>)
[INFO]                <when-type-is class='com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactory'/>
[INFO]                   Yes, the requested type was an exact match
[INFO]                Yes: All subconditions were true
[INFO]          Rule was a match and will be used
[INFO]          Invoking generator com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactoryGenerator
[INFO]             Generator returned type 'com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactoryImpl; mode USE_ALL_NEW_WITH_NO_CACHING; in 162 ms
[INFO]          Rebind result was com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactoryImpl
[INFO]       Rebinding com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactory
[INFO]          Checking rule <generate-with class='com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactoryGenerator'/>
[INFO]             Checking if all subconditions are true (<all>)
[INFO]                <when-type-is class='com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactory'/>
[INFO]                   Yes, the requested type was an exact match
[INFO]                Yes: All subconditions were true
[INFO]          Rule was a match and will be used
[INFO]          Invoking generator com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactoryGenerator
[INFO]             Generator returned type 'com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactory; mode USE_EXISTING; in 48 ms
[INFO]          Rebind result was com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactory
[INFO]       Rebinding com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactory
[INFO]          Checking rule <generate-with class='com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactoryGenerator'/>
[INFO]             Checking if all subconditions are true (<all>)
[INFO]                <when-type-is class='com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactory'/>
[INFO]                   Yes, the requested type was an exact match
[INFO]                Yes: All subconditions were true
[INFO]          Rule was a match and will be used
[INFO]          Invoking generator com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactoryGenerator
[INFO]             Generator returned type 'com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactory; mode USE_EXISTING; in 53 ms
[INFO]          Rebind result was com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactory

这是导致构建失败的日志的后一部分:

[INFO]    [ERROR] Errors in 'com/kn/tls/acsuk/mobile/client/dataaccess/DataAccess.java'
[INFO]       [ERROR] Line 172: Rebind result 'com.kn.tls.acsuk.mobile.generator.ModelAdaptorFactory' must be a class

这是我的生成器生成的代码:

package com.kn.tls.acsuk.mobile.generator;

import com.kn.tls.acsuk.mobile.generator.ModelAdaptor;
import com.kn.tls.acsuk.mobile.dto.BaseMobileDTO;
import com.kn.tls.acsuk.mobile.dto.MobileAuditDetailDTO;
import com.kn.tls.acsuk.mobile.dto.MobileAuditHeaderDTO;
import com.kn.tls.acsuk.mobile.dto.MobileUserDTO;
import com.kn.tls.acsuk.mobile.dto.MobileAuditHeaderCommentDTO;

public class ModelAdaptorFactoryImpl implements ModelAdaptorFactory {
  class MobileAuditDetailDTOModelAdaptor implements ModelAdaptor
  {
    private MobileAuditDetailDTO wrapped;

    @Override
    public String getProperty(String propertyName)
    {
      switch (propertyName.toUpperCase())
      {
        case "TOTALASSETQUANTITY":
          return wrapped.getTotalAssetQuantity().toString();

        case "ONDISPLAYQUANTITY":
          return wrapped.getOnDisplayQuantity().toString();

        case "OFFSITEASSETQUANTITY":
          return wrapped.getOffsiteAssetQuantity().toString();

        case "OUTBOUNDTRANSITQUANTITY":
          return wrapped.getOutboundTransitQuantity().toString();

        case "INBOUNDTRANSITQUANTITY":
          return wrapped.getInboundTransitQuantity().toString();

        case "INACCESSIBLEASSETQUANTITY":
          return wrapped.getInaccessibleAssetQuantity().toString();

        case "DAMAGEDASSETQUANTITY":
          return wrapped.getDamagedAssetQuantity().toString();

        case "PACKEDASSETQUANTITY":
          return wrapped.getPackedAssetQuantity().toString();

        case "EMPTYASSETQUANTITY":
          return wrapped.getEmptyAssetQuantity().toString();

        case "ASSETAUDITHEADER":
          return wrapped.getAssetAuditHeader().toString();

        case "STOREFULLQUANTITY":
          return wrapped.getStoreFullQuantity().toString();

        case "STOREEMPTYQUANTITY":
          return wrapped.getStoreEmptyQuantity().toString();

        case "STOREOTHERQUANTITY":
          return wrapped.getStoreOtherQuantity().toString();

        case "EMPTYCLEANQUANTITY":
          return wrapped.getEmptyCleanQuantity().toString();

        case "EMPTYDIRTYQUANTITY":
          return wrapped.getEmptyDirtyQuantity().toString();

        case "ASSETTYPE":
          return wrapped.getAssetType().toString();

        case "ID":
          return wrapped.getId().toString();

        case "CLASS":
          return wrapped.getClass().toString();

      }
      return "";
    }

    @Override
    public void setWrapped(BaseMobileDTO model)
    {
      this.wrapped = (MobileAuditDetailDTO) model;
    }
  }
  class MobileAuditHeaderDTOModelAdaptor implements ModelAdaptor
  {
    private MobileAuditHeaderDTO wrapped;

    @Override
    public String getProperty(String propertyName)
    {
      switch (propertyName.toUpperCase())
      {
        case "LOCATION":
          return wrapped.getLocation().toString();

        case "SCHEDULEDASSETAUDITDATE":
          return wrapped.getScheduledAssetAuditDate().toString();

        case "SCHEDULEDASSETAUDITOR":
          return wrapped.getScheduledAssetAuditor().toString();

        case "ACTUALASSETAUDITDATE":
          return wrapped.getActualAssetAuditDate().toString();

        case "ACTUALASSETAUDITOR":
          return wrapped.getActualAssetAuditor().toString();

        case "ASSETAUDITSTATUS":
          return wrapped.getAssetAuditStatus().toString();

        case "ASSETAUDITTYPE":
          return wrapped.getAssetAuditType().toString();

        case "FIRSTCOMMUNICATIONSENTDATE":
          return wrapped.getFirstCommunicationSentDate().toString();

        case "FINALCOMMUNICATIONSENTDATE":
          return wrapped.getFinalCommunicationSentDate().toString();

        case "SECONDCOMMUNICATIONSENTDATE":
          return wrapped.getSecondCommunicationSentDate().toString();

        case "COMMENTS":
          return wrapped.getComments().toString();

        case "DETAILS":
          return wrapped.getDetails().toString();

        case "ID":
          return wrapped.getId().toString();

        case "CLASS":
          return wrapped.getClass().toString();

      }
      return "";
    }

    @Override
    public void setWrapped(BaseMobileDTO model)
    {
      this.wrapped = (MobileAuditHeaderDTO) model;
    }
  }
  class MobileUserDTOModelAdaptor implements ModelAdaptor
  {
    private MobileUserDTO wrapped;

    @Override
    public String getProperty(String propertyName)
    {
      switch (propertyName.toUpperCase())
      {
        case "NAME":
          return wrapped.getName().toString();

        case "CODE":
          return wrapped.getCode().toString();

        case "ID":
          return wrapped.getId().toString();

        case "CLASS":
          return wrapped.getClass().toString();

      }
      return "";
    }

    @Override
    public void setWrapped(BaseMobileDTO model)
    {
      this.wrapped = (MobileUserDTO) model;
    }
  }
  class MobileAuditHeaderCommentDTOModelAdaptor implements ModelAdaptor
  {
    private MobileAuditHeaderCommentDTO wrapped;

    @Override
    public String getProperty(String propertyName)
    {
      switch (propertyName.toUpperCase())
      {
        case "COMMENT":
          return wrapped.getComment().toString();

        case "ASSETAUDITHEADER":
          return wrapped.getAssetAuditHeader().toString();

        case "ID":
          return wrapped.getId().toString();

        case "CLASS":
          return wrapped.getClass().toString();

      }
      return "";
    }

    @Override
    public void setWrapped(BaseMobileDTO model)
    {
      this.wrapped = (MobileAuditHeaderCommentDTO) model;
    }
  }

  public ModelAdaptor createAdaptor(BaseMobileDTO dto)
  {
    ModelAdaptor adaptor = null;
    switch (dto.getClass().getSimpleName().toUpperCase())
    {
      case "MOBILEAUDITDETAILDTO":
        adaptor = new MobileAuditDetailDTOModelAdaptor();
        adaptor.setWrapped(dto);
        break;
      case "MOBILEAUDITHEADERDTO":
        adaptor = new MobileAuditHeaderDTOModelAdaptor();
        adaptor.setWrapped(dto);
        break;
      case "MOBILEUSERDTO":
        adaptor = new MobileUserDTOModelAdaptor();
        adaptor.setWrapped(dto);
        break;
      case "MOBILEAUDITHEADERCOMMENTDTO":
        adaptor = new MobileAuditHeaderCommentDTOModelAdaptor();
        adaptor.setWrapped(dto);
        break;
    }
    return adaptor;
  }
}

1 个答案:

答案 0 :(得分:2)

在创建RebindResult类时,您应该使用生成的类的限定源名称而不是接口。

我期待这样的事情:

return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING,
                        packageName + "." + generatedClassName);

其中generatedClassName是生成的类的名称。

看起来你正在使用界面的名称。