private void buildConfig(AnnotationType type, DocumentmanagerConfig.Annotationtype.Builder atb) { atb. id(type.getId()). name(type.getName()); if (type.getDataType() != null) { atb.datatype(type.getDataType().getId()); } if ( ! type.getInheritedTypes().isEmpty()) { for (AnnotationType inherited : type.getInheritedTypes()) { atb.inherits(new DocumentmanagerConfig.Annotationtype.Inherits.Builder().id(inherited.getId())); } } } private void buildConfig(Collection<AnnotationType> types, DocumentmanagerConfig.Builder builder) {
/** * Creates a new annotation type that can have values of the specified type. * * @param name the name of the new annotation type * @param dataType the data type of the annotation value */ public AnnotationType(String name, DataType dataType) { this.name = name; this.dataType = dataType; //always keep this as last statement in here: this.id = computeHash(); }
/** * Register a new annotation type. WARNING! Only to be used by the configuration system and in unit tests. Not to be used in production code. * * @param type the type to register * @throws IllegalArgumentException if a type is already registered with this name or this id, and it is non-equal to the argument. */ public void register(AnnotationType type) { if (idMap.containsKey(type.getId()) || nameMap.containsKey(type.getName())) { AnnotationType idType = idMap.get(type.getId()); AnnotationType nameType = nameMap.get(type.getName()); if (type.equals(idType) && type.equals(nameType)) { //it's the same one being re-registered, we're OK! return; } throw new IllegalArgumentException("A type is already registered with this name or this id."); } idMap.put(type.getId(), type); nameMap.put(type.getName(), type); }
/** * Unregisters the type given by the argument. WARNING! Only to be used by the configuration system and in unit tests. Not to be used in production code. * * @param type the AnnotationType to unregister. * @return true if the type was successfully unregistered, false otherwise (it was not present) * @throws IllegalArgumentException if the ID and name of this annotation type are present, but they do not belong together. */ public boolean unregister(AnnotationType type) { if (idMap.containsKey(type.getId()) && nameMap.containsKey(type.getName())) { AnnotationType idType = idMap.get(type.getId()); AnnotationType nameType = nameMap.get(type.getName()); if (idType == nameType) { //name and id belong together in our maps idMap.remove(type.getId()); nameMap.remove(type.getName()); } else { throw new IllegalArgumentException("The ID and name of this annotation type are present, but they do not belong together. Not removing type."); } return true; } //it's not there, but that's no problem return false; }
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()); StructDataType s = new StructDataType("annotation."+annotation.getName()); if (anyParentsHavePayLoad(sa, sdoc)) { annotation.setDataType(s); addType(dt, s); e.getKey().inherit(dt.getAnnotationType(e.getValue()));
public void write(Annotation annotation) { buf.putInt(annotation.getType().getId()); //name hash buf.putInt(annotation.getType().getDataType().getId()); annotation.getFieldValue().serialize(this);
/** * Creates an AnnotationReferenceDataType with a given id. * * @param aType the annotation type that AnnotationRefs shall refer to. * @param id the id to use */ public AnnotationReferenceDataType(AnnotationType aType, int id) { super("annotationreference<" + ((aType == null) ? "" : aType.getName()) + ">", id); this.aType = aType; }
/** * Sets the value of the annotation. * * @param fieldValue the value to set * @throws UnsupportedOperationException if the annotation type does not allow this annotation to have values. */ public void setFieldValue(FieldValue fieldValue) { if (fieldValue == null) { value = null; return; } DataType type = getType().getDataType(); if (type != null && type.isValueCompatible(fieldValue)) { this.value = fieldValue; } else { String typeName = (type == null) ? "null" : type.getValueClass().getName(); throw new IllegalArgumentException("Argument is of wrong type, must be of type " + typeName + ", was " + fieldValue.getClass().getName()); } }
/** * Unregisters the type given by the argument. WARNING! Only to be used by the configuration system and in unit tests. Not to be used in production code. * * @param name the name of the type to unregister. * @return true if the type was successfully unregistered, false otherwise (it was not present) */ public boolean unregister(String name) { AnnotationType oldType = nameMap.remove(name); if (oldType != null) { idMap.remove(oldType.getId()); return true; } return false; }
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 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); } } }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Annotation)) return false; Annotation that = (Annotation) o; if (!type.equals(that.type)) return false; if (spanNode != null ? !spanNode.equals(that.spanNode) : that.spanNode != null) return false; if (value != null ? !value.equals(that.value) : that.value != null) return false; return true; }
@Override public int compareTo(Annotation annotation) { int comp; if (spanNode == null) { comp = (annotation.spanNode == null) ? 0 : -1; } else { comp = (annotation.spanNode == null) ? 1 : spanNode.compareTo(annotation.spanNode); } if (comp != 0) { return comp; } comp = type.compareTo(annotation.type); if (comp != 0) { return comp; } //types are equal, too, compare values if (value == null) { comp = (annotation.value == null) ? 0 : -1; } else { comp = (annotation.value == null) ? 1 : value.compareTo(annotation.value); } return comp; } }
private static void setupAnnotationTypesWithoutPayloads(DocumentmanagerConfig config, DocumentTypeManager manager) { for (DocumentmanagerConfig.Annotationtype annType : config.annotationtype()) { AnnotationType annotationType = new AnnotationType(annType.name(), annType.id()); manager.getAnnotationTypeRegistry().register(annotationType); } }
public void write(Annotation annotation) { buf.putInt(annotation.getType().getId()); //name hash buf.putInt(annotation.getType().getDataType().getId()); annotation.getFieldValue().serialize(this);
/** * Unregisters the type given by the argument. WARNING! Only to be used by the configuration system and in unit tests. Not to be used in production code. * * @param id the id of the type to unregister. * @return true if the type was successfully unregistered, false otherwise (it was not present) */ public boolean unregister(int id) { AnnotationType oldType = idMap.remove(id); if (oldType != null) { nameMap.remove(oldType.getName()); return true; } return false; }
if (dataTypeId != type.getDataType().getId()) { FieldValue value = type.getDataType().createFieldValue(); value.deserialize(this); annotation.setFieldValue(value);
private void buildConfig(AnnotationReferenceDataType type, DocumenttypesConfig.Documenttype.Datatype.Builder dataTypeBuilder) { dataTypeBuilder. type(DocumenttypesConfig.Documenttype.Datatype.Type.Enum.ANNOTATIONREF). annotationref(new DocumenttypesConfig.Documenttype.Datatype.Annotationref.Builder(). annotation(new DocumenttypesConfig.Documenttype.Datatype.Annotationref.Annotation.Builder(). id(type.getAnnotationType().getId()))); }
private void buildConfig(AnnotationType annotation, DocumenttypesConfig.Documenttype.Annotationtype.Builder builder) { builder. id(annotation.getId()). name(annotation.getName()); DataType dt = annotation.getDataType(); if (dt != null) { builder.datatype(dt.getId()); } for (AnnotationType inherited : annotation.getInheritedTypes()) { builder.inherits(new DocumenttypesConfig.Documenttype.Annotationtype.Inherits.Builder().id(inherited.getId())); } }