public DataType getDataType(int code) { return getDataType(code, ""); }
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); }
DataType getDataTypeAndReturnTemporary(int code, String detailedType) { if (hasDataType(code)) { return getDataType(code, detailedType); } return new TemporaryDataType(code, detailedType); }
private static void registerMapType(DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Maptype map) { DataType keyType = manager.getDataType(map.keytype(), ""); DataType valType = manager.getDataType(map.valtype(), ""); MapDataType type = new MapDataType(keyType, valType, id); manager.register(type); }
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); }
@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 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); } } } } }
private void replaceTemporaryTypeInReference(ReferenceDataType referenceDataType) { if (referenceDataType.getTargetType() instanceof TemporaryStructuredDataType) { referenceDataType.setTargetType((DocumentType) getDataType(referenceDataType.getTargetType().getId())); } // TODO should we recursively invoke replaceTemporaryTypes for the target type? It should only ever be a doc type }
private static void registerWeightedSetType(DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Weightedsettype wset) { DataType nestedType = manager.getDataType(wset.datatype(), ""); WeightedSetDataType type = new WeightedSetDataType( nestedType, wset.createifnonexistant(), wset.removeifzero(), id); manager.register(type); }
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); } }
private void replaceTemporaryTypesInCollection(CollectionDataType collectionDataType, List<DataType> seenStructs) { if (collectionDataType.getNestedType() instanceof TemporaryDataType) { collectionDataType.setNestedType(getDataType(collectionDataType.getNestedType().getCode(), "")); } else { replaceTemporaryTypes(collectionDataType.getNestedType(), seenStructs); } }
private void replaceTemporaryTypesInWeightedSet(WeightedSetDataType weightedSetDataType, List<DataType> seenStructs) { if (weightedSetDataType.getNestedType() instanceof TemporaryDataType) { weightedSetDataType.setNestedType(getDataType(weightedSetDataType.getNestedType().getCode(), "")); } else { replaceTemporaryTypes(weightedSetDataType.getNestedType(), seenStructs); } }
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); } } }
@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); }
docMan.getDataType(name); throw new ParseException("Reserved name '" + name + "' can not be used to declare a struct."); } catch (IllegalArgumentException e) {