use of com.yahoo.searchdefinition.document.annotation.SDAnnotationType in project vespa by vespa-engine.
the class DocumentModelBuilder method convert.
private NewDocumentType convert(SDDocumentType sdoc) {
Map<AnnotationType, String> annotationInheritance = new HashMap<>();
Map<StructDataType, String> structInheritance = new HashMap<>();
NewDocumentType dt = new NewDocumentType(new NewDocumentType.Name(sdoc.getName()), sdoc.getDocumentType().getHeaderType(), sdoc.getDocumentType().getBodyType(), sdoc.getFieldSets(), convertDocumentReferencesToNames(sdoc.getDocumentReferences()));
for (SDDocumentType n : sdoc.getInheritedTypes()) {
NewDocumentType.Name name = new NewDocumentType.Name(n.getName());
NewDocumentType inherited = model.getDocumentManager().getDocumentType(name);
if (inherited != null) {
dt.inherit(inherited);
}
}
for (SDDocumentType type : sdoc.getTypes()) {
if (type.isStruct()) {
handleStruct(dt, type);
} else {
throw new IllegalArgumentException("Data type '" + sdoc.getName() + "' is not a struct => tostring='" + sdoc.toString() + "'.");
}
}
for (AnnotationType annotation : sdoc.getAnnotations()) {
dt.add(annotation);
}
for (AnnotationType annotation : sdoc.getAnnotations()) {
SDAnnotationType sa = (SDAnnotationType) annotation;
if (annotation.getInheritedTypes().isEmpty() && (sa.getInherits() != null)) {
annotationInheritance.put(annotation, sa.getInherits());
}
if (annotation.getDataType() == null) {
if (sa.getSdDocType() != null) {
StructDataType s = handleStruct(dt, sa.getSdDocType());
annotation.setDataType(s);
if ((sa.getInherits() != null)) {
structInheritance.put(s, "annotation." + sa.getInherits());
}
} else if (sa.getInherits() != null) {
StructDataType s = new StructDataType("annotation." + annotation.getName());
if (anyParentsHavePayLoad(sa, sdoc)) {
annotation.setDataType(s);
addType(dt, s);
}
structInheritance.put(s, "annotation." + sa.getInherits());
}
}
}
for (Map.Entry<AnnotationType, String> e : annotationInheritance.entrySet()) {
e.getKey().inherit(dt.getAnnotationType(e.getValue()));
}
for (Map.Entry<StructDataType, String> e : structInheritance.entrySet()) {
StructDataType s = (StructDataType) dt.getDataType(e.getValue());
if (s != null) {
e.getKey().inherit(s);
}
}
handleStruct(dt, sdoc.getDocumentType().getHeaderType());
handleStruct(dt, sdoc.getDocumentType().getBodyType());
extractDataTypesFromFields(dt, sdoc.fieldSet());
return dt;
}
use of com.yahoo.searchdefinition.document.annotation.SDAnnotationType in project vespa by vespa-engine.
the class DocumentModelBuilder method anyParentsHavePayLoad.
private static boolean anyParentsHavePayLoad(SDAnnotationType sa, SDDocumentType sdoc) {
if (sa.getInherits() != null) {
AnnotationType tmp = sdoc.findAnnotation(sa.getInherits());
SDAnnotationType inherited = (SDAnnotationType) tmp;
return ((inherited.getSdDocType() != null) || anyParentsHavePayLoad(inherited, sdoc));
}
return false;
}
Aggregations