模型
模型的开发文档
重要
在处理器维度中模型用于数据在节点流转中的序列化以及数据映射,而在触发器里模型用于流程入参和出参的约定。
类别
DalaranModelSchema
- ModelField 是所有模型的元数据类,Mule的所有模型都是继承DalaranModelSchema。
@Datapublic class DalaranModelSchema {
private static final Map<String, Class<? extends DalaranModelSchema>> modelSchemaMapping = new HashMap<>();
private Map<String, ModelField> fields = new HashMap<>();
public void setRootField(ModelField rootField) { fields.put(MODEL_ROOT, rootField); }
public static void addModelSchema(String modelTypeName, Class<? extends DalaranModelSchema> modelSchemaClass) { modelSchemaMapping.put(modelTypeName, modelSchemaClass); }
public static Class<? extends DalaranModelSchema> getModelSchemaClass(String modelTypeName) { return modelSchemaMapping.get(modelTypeName); }}- ModelField类
ModelField是对模型的元数据的建模类,也是目前Mule系统所有模型的父类。
public class ModelField {
private FieldType type;
private FieldType subType;
private boolean nullable;
private String description;
Map<String, ModelField> fields = new HashMap<>();
public void addField(String name, ModelField field) { fields.put(name, field); }}示例
@ModelFieldInfo
@ModelFieldInfo 配置除模型元数据信息以外特定的属性,
@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.FIELD})public @interface ModelFieldInfo {
String defaultValue() default "";
String example() default "";
String label() default "";
boolean required() default true;
boolean readonly() default false;
String inputType() default FieldInputType.Auto;}对于CSV模型我配置了字段顺序,数据解析分隔符,数据拼接分隔符,模型类型,保留行结束符,保留换行符,便于生成CSV文件和解析CSV文件的特定属性。
@Data@Model(value = "CSV")public class CsvModelSchema extends DalaranModelSchema { @ModelFieldInfo(label = "字段顺序", inputType = FieldInputType.String, required = false) private String columnSequence;
@ModelFieldInfo(label = "数据解析分隔符", inputType = FieldInputType.String, required = false) private String columnDelimiter;
@ModelFieldInfo(label = "数据拼接分隔符", inputType = FieldInputType.String, required = false) private String dataDelimiter;
@ModelFieldInfo(label = "模型类型", inputType = FieldInputType.Select, defaultValue = "COMMON") private CSVModelType type = CSVModelType.COMMON;
@ModelFieldInfo(label = "保留行结束符", inputType = FieldInputType.Switch, required = false, defaultValue = "false") private boolean remainEOF = false;
@ModelFieldInfo(label = "保留换行符", inputType = FieldInputType.Switch, required = false, defaultValue = "false") private boolean remainNewLine = false;}