@Override public void setAnnotationType(AnnotationType type) { super.setName("annotationreference<" + type.getName() + ">"); super.setAnnotationType(type); } }
@Override public boolean isValueCompatible(FieldValue value) { if (!(value instanceof AnnotationReference)) { return false; } AnnotationReference reference = (AnnotationReference) value; if (equals(reference.getDataType())) { return true; } return false; }
/** * Set an {@link Annotation} that this AnnotationReference shall refer to. * * @param reference an Annotation that this AnnotationReference shall refer to. * @throws IllegalArgumentException if the given annotation has a type that is not compatible with this reference */ public void setReference(Annotation reference) { if (reference == null) { this.reference = null; return; } AnnotationReferenceDataType type = getDataType(); if (type.getAnnotationType().isValueCompatible(reference) // The case if concrete annotation type || reference.getType() instanceof AnnotationType) { this.reference = reference; } else { throw new IllegalArgumentException("Cannot set reference, must be of type " + type + " (was of type " + reference.getType() + ")"); } }
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); } } }
/** * Creates an AnnotationReferenceDataType with a generated id. * * @param aType the annotation type that AnnotationRefs shall refer to. */ public AnnotationReferenceDataType(AnnotationType aType) { super("annotationreference<" + ((aType == null) ? "" : aType.getName()) + ">", 0); setAnnotationType(aType); }
private int createId() { //TODO: This should be Java's hashCode(), since all other data types use it, and using something else here will probably lead to collisions return getName().toLowerCase().hashCode(); }
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()))); }
"' does not exist."); dataType = new AnnotationReferenceDataType(target); addType(docType, dataType); return dataType;
builder.annotationreftype(new Datatype.Annotationreftype.Builder().annotation(annotationRef.getAnnotationType().getName())); } else if (type instanceof TensorDataType) {