/** * Returns the type discriminator value for given Frames model class, extracted from the @TypeValue annotation. */ public static String getTypeValue(Class<? extends WindupFrame> clazz) { TypeValue typeValueAnnotation = clazz.getAnnotation(TypeValue.class); if (typeValueAnnotation == null) throw new IllegalArgumentException("Class " + clazz.getCanonicalName() + " lacks a @TypeValue annotation"); return typeValueAnnotation.value(); }
/** * Returns the type discriminator value for given Frames model class, extracted from the @TypeValue annotation. */ public static String getTypeValue(Class<? extends WindupFrame> clazz) { TypeValue typeValueAnnotation = clazz.getAnnotation(TypeValue.class); if (typeValueAnnotation == null) throw new IllegalArgumentException("Class " + clazz.getCanonicalName() + " lacks a @TypeValue annotation"); return typeValueAnnotation.value(); }
public String getFrameDiscriminator() { if (frameType.getAnnotation(TypeValue.class) == null) { throw new IllegalStateException("Missing @" + TypeValue.class.getSimpleName() + ": " + frameType.getName()); } return frameType.getAnnotation(TypeValue.class).value(); }
public static boolean hasType(Class<? extends WindupVertexFrame> type, Vertex v) { TypeValue typeValueAnnotation = type.getAnnotation(TypeValue.class); if (typeValueAnnotation == null) { throw new IllegalArgumentException("Class " + type.getCanonicalName() + " lacks a @TypeValue annotation"); } // LOG.info("has type called for: " + type + " and vertex: " + v); Iterable<String> vertexTypes = getTypeProperties(v); for (String typeValue : vertexTypes) { if (typeValue.equals(typeValueAnnotation.value())) { return true; } } return false; }
public static boolean hasType(Class<? extends WindupVertexFrame> type, Vertex v) { TypeValue typeValueAnnotation = type.getAnnotation(TypeValue.class); if (typeValueAnnotation == null) { throw new IllegalArgumentException("Class " + type.getCanonicalName() + " lacks a @TypeValue annotation"); } // LOG.info("has type called for: " + type + " and vertex: " + v); Iterable<String> vertexTypes = getTypeProperties(v); for (String typeValue : vertexTypes) { if (typeValue.equals(typeValueAnnotation.value())) { return true; } } return false; }
private void addTypeToRegistry(Class<? extends WindupFrame<?>> frameType) { LOG.info(" Adding type to registry: " + frameType.getName()); TypeValue typeValueAnnotation = frameType.getAnnotation(TypeValue.class); // Do not attempt to add types without @TypeValue. We use // *Model types with no @TypeValue to function as essentially // "abstract" models that would never exist on their own (only as subclasses). if (typeValueAnnotation == null) { String msg = String.format("@%s is missing on type %s", TypeValue.class.getSimpleName(), frameType.getName()); LOG.warning(msg); return; } if (getRegisteredTypeMap().containsKey(typeValueAnnotation.value())) { throw new IllegalArgumentException("Type value for model '" + frameType.getCanonicalName() + "' is already registered with model " + getRegisteredTypeMap().get(typeValueAnnotation.value()).getName()); } getRegisteredTypeMap().put(typeValueAnnotation.value(), frameType); getTypeRegistry().add(frameType); }
@Override public List<ModelTypeInformation> getTypes() { return this.graphTypeManager.getRegisteredTypes().stream() .map(type -> { TypeValue typeValueAnnotation = type.getAnnotation(TypeValue.class); if (typeValueAnnotation == null) return null; return new ModelTypeInformation(typeValueAnnotation.value(), type.getSimpleName()); }) .filter(Objects::nonNull) .sorted((type1, type2) -> type1.getClassName().compareToIgnoreCase(type2.getClassName())) .collect(Collectors.toList()); }
private void addTypeToRegistry(Class<? extends WindupFrame<?>> frameType) { LOG.info(" Adding type to registry: " + frameType.getName()); TypeValue typeValueAnnotation = frameType.getAnnotation(TypeValue.class); // Do not attempt to add types without @TypeValue. We use // *Model types with no @TypeValue to function as essentially // "abstract" models that would never exist on their own (only as subclasses). if (typeValueAnnotation == null) { String msg = String.format("@%s is missing on type %s", TypeValue.class.getSimpleName(), frameType.getName()); LOG.warning(msg); return; } if (getRegisteredTypeMap().containsKey(typeValueAnnotation.value())) { throw new IllegalArgumentException("Type value for model '" + frameType.getCanonicalName() + "' is already registered with model " + getRegisteredTypeMap().get(typeValueAnnotation.value()).getName()); } getRegisteredTypeMap().put(typeValueAnnotation.value(), frameType); getTypeRegistry().add(frameType); }
/** * Remove the given type from the provided {@link Element}. */ public void removeTypeFromElement(Class<? extends WindupFrame<?>> kind, Element element) { TypeValue typeValueAnnotation = kind.getAnnotation(TypeValue.class); if (typeValueAnnotation == null) return; String typeValue = typeValueAnnotation.value(); List<String> newTypes = new ArrayList<>(); for (String existingType : getTypeProperties(element)) { if (!existingType.equals(typeValue)) { newTypes.add(typeValue); } } element.properties(WindupFrame.TYPE_PROP).forEachRemaining(Property::remove); for (String newType : newTypes) addProperty(element, WindupFrame.TYPE_PROP, newType); addSuperclassType(kind, element); }
/** * Remove the given type from the provided {@link Element}. */ public void removeTypeFromElement(Class<? extends WindupFrame<?>> kind, Element element) { TypeValue typeValueAnnotation = kind.getAnnotation(TypeValue.class); if (typeValueAnnotation == null) return; String typeValue = typeValueAnnotation.value(); List<String> newTypes = new ArrayList<>(); for (String existingType : getTypeProperties(element)) { if (!existingType.equals(typeValue)) { newTypes.add(typeValue); } } element.properties(WindupFrame.TYPE_PROP).forEachRemaining(Property::remove); for (String newType : newTypes) addProperty(element, WindupFrame.TYPE_PROP, newType); addSuperclassType(kind, element); }
/** * Adds the type value to the field denoting which type the element represents. */ public void addTypeToElement(Class<? extends WindupFrame<?>> kind, Element element) { TypeValue typeValueAnnotation = kind.getAnnotation(TypeValue.class); if (typeValueAnnotation == null) return; String typeValue = typeValueAnnotation.value(); Set<String> types = getTypeProperties(element); // LOG.info("Adding type to element: " + element + " type: " + kind + " property is already present? " + types); for (String typePropertyValue : types) { if (typePropertyValue.equals(typeValue)) { // this is already in the list, so just exit now return; } } addProperty(element, WindupFrame.TYPE_PROP, typeValue); addSuperclassType(kind, element); }
/** * Adds the type value to the field denoting which type the element represents. */ public void addTypeToElement(Class<? extends WindupFrame<?>> kind, Element element) { TypeValue typeValueAnnotation = kind.getAnnotation(TypeValue.class); if (typeValueAnnotation == null) return; String typeValue = typeValueAnnotation.value(); Set<String> types = getTypeProperties(element); // LOG.info("Adding type to element: " + element + " type: " + kind + " property is already present? " + types); for (String typePropertyValue : types) { if (typePropertyValue.equals(typeValue)) { // this is already in the list, so just exit now return; } } addProperty(element, WindupFrame.TYPE_PROP, typeValue); addSuperclassType(kind, element); }
modelDescriptor.discriminator = typeValueAnn.value();