예제 #1
0
 /**
  * 替换宏
  *
  * @param element
  * @param macroId
  * @return 仅当成功的进行宏替换后返回真
  */
 private boolean doReplaceMacros(Element element, String macroId) {
   if (!StringUtils.isEmpty(macroId)) {
     if (!macros.containsKey(macroId)) {
       logger.error("消息配置错误,不存在这样的宏定义:" + macroId);
       return false;
     }
     // 防止子macro被重复替换
     if (element.getChildren().size() > 0) {
       return false;
     }
     Element macro = macros.get(macroId);
     Element macroClone = (Element) macro.clone();
     element.addContent(macroClone.removeContent());
     return true;
   }
   return false;
 }
예제 #2
0
  /**
   * @param field
   * @param subFieldElements
   */
  private void setSubFields(FieldObject field, List<Element> subFieldElements) {
    List<FieldObject> subFields = new ArrayList<FieldObject>();
    fields.put(field.getType(), subFields);
    for (Element subElement : subFieldElements) {
      FieldObject subField = new FieldObject();
      subField.setType(subElement.getAttributeValue("type"));
      subField.setClientType(subElement.getAttributeValue("clientType"));
      if (StringUtils.isEmpty(subField.getClientType())) {
        subField.setClientType(GeneratorHelper.getClientClassName(subField.getType()) + "Data");
      }
      subField.setSmallName(subElement.getAttributeValue("name"));
      subField.setComment(subElement.getAttributeValue("comment"));
      if (subElement.getAttributeValue("list") != null) {
        subField.setList(subElement.getAttributeValue("list").equals("true") ? true : false);
        field.setHasListField(true);
      }
      subFields.add(subField);
      List<Element> subsubFieldElements = subElement.getChildren("field", NAME_SPACE);
      if (subsubFieldElements.size() > 0) {
        this.setSubFields(subField, subsubFieldElements);
      }

      // 如果不是系统定义的类型则说明是子消息
      if (!new ArrayListWrapper(sysTypes).contains(subField.getType())) {
        subField.setIsNewType(true);
        if (subField.getType().indexOf("_") > 0) {
          subField.setType(GeneratorHelper.generateServerClassName(subField.getType()));
        }
      }
    }
    field.setSubFields(subFields);
    // 如果配置了子节点,而且类型中不存在包名,则说明是新定义的类型
    if (field.getType().indexOf(".") == -1) {
      field.setNeedCreateType(true);
    }
  }
예제 #3
0
  /**
   * 设置消息对象的字段
   *
   * @param msgObj
   * @param msgElement
   */
  private void setMsgObjFields(
      MessageObject msgObj, List fElements, boolean isClient, boolean isCppClient) {
    for (Iterator j = fElements.iterator(); j.hasNext(); ) {
      Element fElement = (Element) j.next();
      FieldObject field = new FieldObject();
      field.setType(fElement.getAttributeValue("type"));
      field.setClientType(fElement.getAttributeValue("clientType"));
      if (StringUtils.isEmpty(field.getClientType())) {
        field.setClientType(GeneratorHelper.getClientClassName(field.getType()) + "Data");
      }
      field.setSmallName(fElement.getAttributeValue("name"));
      field.setComment(fElement.getAttributeValue("comment"));

      if (fElement.getAttribute("defaultValue") != null) {
        String defaultValue = fElement.getAttributeValue("defaultValue");
        if (StringUtils.isEmpty(defaultValue)) {
          if (!TYPE_STRING.equals(field.getType())) {
            defaultValue = "0";
          } else {
            defaultValue = "";
          }
        }
        if (TYPE_STRING.equals(field.getType())) {
          defaultValue = "\"" + defaultValue + "\"";
        }
        field.setDefaultValue("=" + defaultValue);
      } else {
        field.setDefaultValue("");
      }

      List<Element> subFieldElements = fElement.getChildren("field", NAME_SPACE);
      if (fElement.getAttributeValue("bytes") != null) {
        field.setBytes(fElement.getAttributeValue("bytes").equals("true") ? true : false);
      }
      if (fElement.getAttributeValue("list") != null) {
        field.setList(fElement.getAttributeValue("list").equals("true") ? true : false);
        msgObj.setHasListField(true);
      }

      boolean isSubMsg = "true".equalsIgnoreCase(fElement.getAttributeValue("subMsg"));
      field.setSubMsg(isSubMsg);
      if (isSubMsg) {
        field.setSubMsgType(GeneratorHelper.generateServerClassName(field.getType()));
        msgObj.setListMsg(true);
        if (isCppClient) {
          field.setList(true);
          msgObj.setHasListField(true);
          field.setType("_LZOBEX_" + field.getType());
        }
      }

      // 如果不是系统定义的类型则说明是子消息
      if (!new ArrayListWrapper(sysTypes).contains(field.getType())) {
        if (!isCppClient || !field.isSubMsg()) {
          field.setIsNewType(true);
          if (!isClient && field.getType().indexOf("_") > 0) {
            field.setType(GeneratorHelper.generateServerClassName(field.getType()));
          }
        }
      }

      if (subFieldElements.size() > 0) {
        this.setSubFields(field, subFieldElements);
      } else {
        if (isClient && field.getIsNewType()) { // 客户端生成消息的时候要为其补全
          field.setSubFields(fields.get(field.getType()));
        }
        if (!isClient && field.getList() && field.getIsNewType()) {
          String type = field.getType();
          field.setSubFields(msgs.get(type).getFields());
        }
      }
      if (field.isSubMsg() && !isCppClient) {
        msgObj.addSubMsg(field);
      } else {
        msgObj.addField(field);
      }
    }
  }