Пример #1
0
  /*
   * for each avro field, search for nested schema.
   * if field is nested, create tree and recursive
   * else fetch field as a element
   */
  private static void fetchToTree(Field field, Tree parent) {
    //		System.out.println(" Field: " + field.name());
    if (field.schema().getType().toString().equalsIgnoreCase("RECORD")) {
      //			if(!multipleData)
      //				multipleData = true;
      //

      Tree child = new Tree(parent);
      child.setName(field.name());

      List<Field> list = field.schema().getFields();
      Iterator<Field> it = list.iterator();

      while (it.hasNext()) {
        Field fieldOfField = it.next();
        fetchToTree(fieldOfField, child);
      }
      parent.getTrees().add(child);
    } else if (field.schema().getType().getName().equalsIgnoreCase("ARRAY")) {
      if (field.schema().getElementType().getType().name().toString().equalsIgnoreCase("RECORD")) {
        if (!multipleData) multipleData = true;

        Schema arraySchema = field.schema().getElementType();
        Tree childParent = new Tree(parent);
        childParent.setName(field.name()); // employee
        //					parent.getTrees().add(childParent);
        //					Tree child = new Tree(childParent);
        //					child.setName(arraySchema.getName());//employeerecord
        List<Field> list = arraySchema.getFields();
        Iterator<Field> it = list.iterator();

        while (it.hasNext()) {
          Field fieldOfField = it.next();
          fetchToTree(fieldOfField, childParent);
        }
        parent.getTrees().add(childParent);
      }
    } else {
      Element elementNew = new Element(parent);
      elementNew.setName(field.name());
      parent.getElements().add(elementNew);
    }
    //		return parent;
  }
Пример #2
0
 /** @generated NOT */
 private void createElement(dataMapper.diagram.tree.model.Element element, TreeNode treeNode) {
   Element ele = DataMapperFactory.eINSTANCE.createElement();
   // ele.setName(element.getCount() + "," + element.getName());
   ele.setName(element.getName());
   ele.setLevel(element.getCount());
   if (element.getSchemaType() != null) {
     switch (element.getSchemaType()) {
       case ARRAY:
         ele.setSchemaDataType(SchemaDataType.ARRAY);
         break;
       case BOOLEAN:
         ele.setSchemaDataType(SchemaDataType.BOOLEAN);
         break;
       case BYTES:
         ele.setSchemaDataType(SchemaDataType.BYTES);
         break;
       case DOUBLE:
         ele.setSchemaDataType(SchemaDataType.DOUBLE);
         break;
       case ENUM:
         ele.setSchemaDataType(SchemaDataType.ENUM);
         break;
       case FIXED:
         ele.setSchemaDataType(SchemaDataType.FIXED);
         break;
       case FLOAT:
         ele.setSchemaDataType(SchemaDataType.FLOAT);
         break;
       case INT:
         ele.setSchemaDataType(SchemaDataType.INT);
         break;
       case LONG:
         ele.setSchemaDataType(SchemaDataType.LONG);
         break;
       case MAP:
         ele.setSchemaDataType(SchemaDataType.MAP);
         break;
       case NULL:
         ele.setSchemaDataType(SchemaDataType.NULL);
         break;
       case RECORD:
         ele.setSchemaDataType(SchemaDataType.RECORD);
         break;
       case STRING:
         ele.setSchemaDataType(SchemaDataType.STRING);
         break;
       case UNION:
         ele.setSchemaDataType(SchemaDataType.UNION);
         break;
       default:
         break;
     }
   }
   treeNode.getElement().add(ele);
   if (!(element.getAttribute().isEmpty())) {
     for (dataMapper.diagram.tree.model.Attribute attribute : element.getAttribute()) {
       createAttribute(attribute, treeNode);
     }
   }
 }