package io.ebeanservice.docstore.api.mapping;
import io.ebean.annotation.DocMapping;
import io.ebean.core.type.DocPropertyType;
import java.util.ArrayList;
import java.util.List;
public class DocPropertyMapping {
private String name;
private DocPropertyType type;
private DocPropertyOptions options;
private List<DocPropertyMapping> children = new ArrayList<>();
public DocPropertyMapping() {
this.type = DocPropertyType.ROOT;
}
public DocPropertyMapping(String name, DocPropertyType type) {
this.type = type;
this.name = name;
this.options = new DocPropertyOptions();
}
public DocPropertyMapping(String name, DocPropertyType type, DocPropertyOptions options) {
this.name = name;
this.type = type;
this.options = options;
}
public void visit(DocPropertyVisitor visitor) {
switch (type) {
case ROOT:
visitor.visitBegin();
visitChildren(visitor);
visitor.visitEnd();
break;
case OBJECT:
visitor.visitBeginObject(this);
visitChildren(visitor);
visitor.visitEndObject(this);
break;
case LIST:
visitor.visitBeginList(this);
visitChildren(visitor);
visitor.visitEndList(this);
break;
default:
visitor.visitProperty(this);
}
}
private void visitChildren(DocPropertyVisitor visitor) {
for (DocPropertyMapping property : children) {
property.visit(visitor);
}
}
@Override
public String toString() {
return "name:" + name + " type:" + type + " options(" + options + ")";
}
public DocPropertyType getType() {
return type;
}
public void setType(DocPropertyType type) {
this.type = type;
}
public String getName() {
return name;
}
public DocPropertyOptions getOptions() {
return options;
}
public List<DocPropertyMapping> getChildren() {
return children;
}
public void addChild(DocPropertyMapping docMapping) {
children.add(docMapping);
}
public void apply(DocMapping docMapping) {
options.apply(docMapping);
}
}