public MetaData getMuleTypeMetaData(String key) {

    DynamicObjectBuilder dynamicObject = new DefaultMetaDataBuilder().createDynamicObject(key);
    String targetDocType = key;
    buildMuleDocTypeMetaDataModel(targetDocType, dynamicObject);
    MetaDataModel model = dynamicObject.build();

    return new DefaultMetaData(model);
  }
 protected void buildMuleDocTypeMetaDataModel(String docType, DynamicObjectBuilder dynamicObject) {
   dynamicObject.addSimpleField(
       DataSenseHelper.getDataSenseFieldName("ecm", "path"), getDataType("string"));
   dynamicObject.addSimpleField(
       DataSenseHelper.getDataSenseFieldName("ecm", "state"), getDataType("string"));
   dynamicObject.addSimpleField(
       DataSenseHelper.getDataSenseFieldName("ecm", "repository"), getDataType("string"));
   dynamicObject.addSimpleField(
       DataSenseHelper.getDataSenseFieldName("ecm", "id"), getDataType("string"));
   dynamicObject.addSimpleField(
       DataSenseHelper.getDataSenseFieldName("ecm", "type"), getDataType("string"));
   buildMuleDataModelMetaDataModel(docType, dynamicObject);
 }
  protected void addField(
      String prefix, String name, JsonNode fieldNode, DynamicObjectBuilder dynamicObject) {

    String type = fieldNode.getTextValue();
    JsonNode subFields = null;

    if (type == null && !fieldNode.isTextual()) {
      type = fieldNode.get("type").getTextValue();
      subFields = fieldNode.get("fields");
    }
    boolean multiValued = false;
    if (type.endsWith("[]")) {
      multiValued = true;
      type = type.substring(0, type.length() - 2);
    }
    if ("blob".equals(type)) {
      DynamicObjectBuilder blobField =
          dynamicObject.addDynamicObjectField(DataSenseHelper.getDataSenseFieldName(prefix, name));
      blobField.addSimpleField("encoding", DataType.STRING);
      blobField.addSimpleField("mime-type", DataType.STRING);
      blobField.addSimpleField("name", DataType.STRING);
      blobField.addSimpleField("length", DataType.LONG);
      blobField.addSimpleField("digest", DataType.STRING);
      blobField.addSimpleField("data", DataType.STRING);
      return;
    }

    if (subFields != null) {
      DynamicObjectBuilder cplxField = null;
      if (multiValued) {
        cplxField =
            dynamicObject
                .addListOfDynamicObjectField(DataSenseHelper.getDataSenseFieldName(prefix, name))
                .addDynamicObjectField("item");
      } else {
        cplxField =
            dynamicObject.addDynamicObjectField(
                DataSenseHelper.getDataSenseFieldName(prefix, name));
      }
      Iterator<String> fnames = subFields.getFieldNames();
      while (fnames.hasNext()) {
        String subFieldName = fnames.next();
        JsonNode subfield = subFields.get(subFieldName);
        addField(prefix, subFieldName, subfield, cplxField);
        // addField(prefix, name + "/" + subFieldName, subfield, cplxField);
      }
    } else {
      if (multiValued) {
        dynamicObject
            .addListOfDynamicObjectField(DataSenseHelper.getDataSenseFieldName(prefix, name))
            .addSimpleField("item", getDataType(type));
      } else {
        dynamicObject.addSimpleField(
            DataSenseHelper.getDataSenseFieldName(prefix, name), getDataType(type));
      }
    }
  }