public static DocumentTypeManager configureNewManager(DocumentmanagerConfig config) { DocumentTypeManager manager = new DocumentTypeManager(); if (config == null) { return manager; } configureNewManager(config, manager); return manager; }
private static void registerArrayType(DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Arraytype array) { DataType nestedType = manager.getDataType(array.datatype(), ""); ArrayDataType type = new ArrayDataType(nestedType, id); manager.register(type); }
/** * Called by the configuration system to register document types based on documentmanager.cfg. * * @param config the instance representing config in documentmanager.cfg. */ @Override public void configure(DocumentmanagerConfig config) { DocumentTypeManager manager = configureNewManager(config); int defaultTypeCount = new DocumentTypeManager().getDataTypes().size(); if (this.managerToConfigure.getDataTypes().size() != defaultTypeCount) { log.log(LogLevel.DEBUG, "Live document config overwritten with new config."); } managerToConfigure.assign(manager); }
DataType getDataTypeAndReturnTemporary(int code, String detailedType) { if (hasDataType(code)) { return getDataType(code, detailedType); } return new TemporaryDataType(code, detailedType); }
public SDDocumentTypeOrderer(List<SDDocumentType> sdTypes, DeployLogger deployLogger) { this.deployLogger = deployLogger; for (SDDocumentType type : sdTypes) { createdSDTypes.put(type.getDocumentName(), type); } DocumentTypeManager dtm = new DocumentTypeManager(); for (DataType type : dtm.getDataTypes()) { seenTypes.add(type.getId()); } }
@SuppressWarnings("deprecation") private static void registerDocumentType(DocumentTypeManager manager, DocumentmanagerConfig.Datatype.Documenttype doc) { StructDataType header = (StructDataType) manager.getDataType(doc.headerstruct(), ""); StructDataType body = (StructDataType) manager.getDataType(doc.bodystruct(), ""); for (Field field : body.getFields()) { field.setHeader(false); } DocumentType type = new DocumentType(doc.name(), header, body); for (Object j : doc.inherits()) { DocumentmanagerConfig.Datatype.Documenttype.Inherits parent = (DocumentmanagerConfig.Datatype.Documenttype.Inherits) j; DataTypeName name = new DataTypeName(parent.name()); DocumentType parentType = manager.getDocumentType(name); if (parentType == null) { throw new IllegalArgumentException("Could not find document type '" + name.toString() + "'."); } type.inherit(parentType); } manager.register(type); }
private static void registerReferenceType(DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Referencetype refType) { ReferenceDataType referenceType; if (manager.hasDataType(refType.target_type_id())) { DocumentType targetDocType = (DocumentType)manager.getDataType(refType.target_type_id()); referenceType = new ReferenceDataType(targetDocType, id); } else { TemporaryStructuredDataType temporaryTargetType = TemporaryStructuredDataType.createById(refType.target_type_id()); referenceType = new ReferenceDataType(temporaryTargetType, id); } // Note: can't combine the above new-statements, as they call different constructors. manager.register(referenceType); }
@SuppressWarnings("deprecation") private void replaceTemporaryTypesInStruct(StructDataType structDataType, List<DataType> seenStructs) { seenStructs.add(structDataType); for (Field field : structDataType.getFieldsThisTypeOnly()) { DataType fieldType = field.getDataType(); if (fieldType instanceof TemporaryDataType) { field.setDataType(getDataType(fieldType.getCode(), ((TemporaryDataType)fieldType).getDetailedType())); } else { if (!seenStructs.contains(fieldType)) { replaceTemporaryTypes(fieldType, seenStructs); } } } }
private static void registerStructType(DocumentmanagerConfig config, DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Structtype struct) { StructDataType type = new StructDataType(id, struct.name()); if (config.enablecompression()) { CompressionConfig comp = makeCompressionConfig(struct); type.setCompressionConfig(comp); } for (Object j : struct.field()) { DocumentmanagerConfig.Datatype.Structtype.Field field = (DocumentmanagerConfig.Datatype.Structtype.Field) j; DataType fieldType = (field.datatype() == id) ? manager.getDataTypeAndReturnTemporary(field.datatype(), field.detailedtype()) : manager.getDataType(field.datatype(), field.detailedtype()); if (field.id().size() == 1) { type.addField(new Field(field.name(), field.id().get(0).id(), fieldType, true)); } else { type.addField(new Field(field.name(), fieldType, true)); } } manager.register(type); }
private static DocumentType getDocumentTypeFromString(String docTypeString, DocumentTypeManager typeManager) { final DocumentType docType = typeManager.getDocumentType(docTypeString); if (docType == null) { throw new IllegalArgumentException(String.format("Document type %s does not exist", docTypeString)); } return docType; }
private static void addAnnotationTypePayloads(DocumentmanagerConfig config, DocumentTypeManager manager) { for (DocumentmanagerConfig.Annotationtype annType : config.annotationtype()) { AnnotationType annotationType = manager.getAnnotationTypeRegistry().getType(annType.id()); DataType payload = manager.getDataType(annType.datatype(), ""); if (!payload.equals(DataType.NONE)) { annotationType.setDataType(payload); } } }
private static void setupAnnotationRefTypes(DocumentmanagerConfig config, DocumentTypeManager manager) { for (int i = 0; i < config.datatype().size(); i++) { DocumentmanagerConfig.Datatype thisDataType = config.datatype(i); int id = thisDataType.id(); for (Object o : thisDataType.annotationreftype()) { DocumentmanagerConfig.Datatype.Annotationreftype annRefType = (DocumentmanagerConfig.Datatype.Annotationreftype) o; AnnotationType annotationType = manager.getAnnotationTypeRegistry().getType(annRefType.annotation()); if (annotationType == null) { throw new IllegalArgumentException("Found reference to " + annRefType.annotation() + ", which does not exist!"); } AnnotationReferenceDataType type = new AnnotationReferenceDataType(annotationType, id); manager.register(type); } } }
public Map<String, AnnotationType> getAnnotationTypes() { return handler.getDocumentTypeManager().getAnnotationTypeRegistry().getTypes(); }
public DataType getDataType(int code) { return getDataType(code, ""); }
/** * Adds a document that can be mapped to this search. * @param source A document that can be mapped to this search. * @return Itself for chaining. */ public SearchDef add(DataType source) { sources.register(source); return this; }
private void replaceTemporaryTypesInMap(MapDataType mapDataType, List<DataType> seenStructs) { if (mapDataType.getValueType() instanceof TemporaryDataType) { mapDataType.setValueType(getDataType(mapDataType.getValueType().getCode(), "")); } else { replaceTemporaryTypes(mapDataType.getValueType(), seenStructs); } if (mapDataType.getKeyType() instanceof TemporaryDataType) { mapDataType.setKeyType(getDataType(mapDataType.getKeyType().getCode(), "")); } else { replaceTemporaryTypes(mapDataType.getKeyType(), seenStructs); } }
FieldSet parseFieldCollection(DocumentTypeManager docMan, String docType, String fieldNames) { DocumentType type = docMan.getDocumentType(docType); if (type == null) { throw new IllegalArgumentException("Unknown document type " + docType); } StringTokenizer tokenizer = new StringTokenizer(fieldNames, ","); FieldCollection collection = new FieldCollection(type); for (; tokenizer.hasMoreTokens(); ) { String token = tokenizer.nextToken(); Field f = type.getField(token); if (f == null) { throw new IllegalArgumentException("No such field " + token); } collection.add(f); } return collection; }
private static void addAnnotationTypeInheritance(DocumentmanagerConfig config, DocumentTypeManager manager) { for (DocumentmanagerConfig.Annotationtype annType : config.annotationtype()) { if (annType.inherits().size() > 0) { AnnotationType inheritedType = manager.getAnnotationTypeRegistry().getType(annType.inherits(0).id()); AnnotationType type = manager.getAnnotationTypeRegistry().getType(annType.id()); type.inherit(inheritedType); } } }
private static void addStructInheritance(DocumentmanagerConfig config, DocumentTypeManager manager) { for (int i = 0; i < config.datatype().size(); i++) { DocumentmanagerConfig.Datatype thisDataType = config.datatype(i); int id = thisDataType.id(); for (Object o : thisDataType.structtype()) { DocumentmanagerConfig.Datatype.Structtype struct = (DocumentmanagerConfig.Datatype.Structtype) o; StructDataType thisStruct = (StructDataType) manager.getDataType(id, ""); for (DocumentmanagerConfig.Datatype.Structtype.Inherits parent : struct.inherits()) { StructDataType parentStruct = (StructDataType) manager.getDataType(parent.name()); thisStruct.inherit(parentStruct); } } } } }
/** * Registers a document type. Typically called by someone * importing the document types from the common Vespa repository. * * @param docType The document type to register. * @return the previously registered type, or null if none was registered */ public DocumentType registerDocumentType(DocumentType docType) { register(docType); return docType; }