@SuppressWarnings({"rawtypes","unchecked"}) public static Iterable<TypeDefinition> getTypes(final UnionTypeDefinition definition) { return (List) definition.getTypes(); } }
private static boolean isSimpleUnion(final UnionTypeDefinition union) { for (TypeDefinition<?> t : union.getTypes()) { if (t instanceof IdentityrefTypeDefinition || t instanceof LeafrefTypeDefinition || t instanceof UnionTypeDefinition && !isSimpleUnion((UnionTypeDefinition) t)) { LOG.debug("Type {} has non-simple subtype", t); return false; } } LOG.debug("Type {} is simple", union); return true; }
@Override public List<TypeDefinition<?>> getTypes() { return getBaseType().getTypes(); }
private static void processUnionType(final UnionTypeDefinition unionType, final JSONObject property) throws JSONException { StringBuilder type = new StringBuilder(); for (TypeDefinition<?> typeDef : unionType.getTypes()) { if (type.length() > 0) { type.append(" or "); } type.append(jsonTypeFor(typeDef)); } property.put(TYPE_KEY, type); }
@Override public List<TypeDefinition<?>> getTypes() { return baseType().getTypes(); }
private static boolean isSimpleUnion(final UnionTypeDefinition union) { for (TypeDefinition<?> t : union.getTypes()) { if (t instanceof IdentityrefTypeDefinition || t instanceof LeafrefTypeDefinition || t instanceof UnionTypeDefinition && !isSimpleUnion((UnionTypeDefinition) t)) { LOG.debug("Type {} has non-simple subtype", t); return false; } } LOG.debug("Type {} is simple", union); return true; }
@Override public List<TypeDefinition<?>> getTypes() { return baseType().getTypes(); }
static String toString(final UnionTypeDefinition type) { return TypeDefinitions.toStringHelper(type).add("types", type.getTypes()).toString(); } }
static String toString(final UnionTypeDefinition type) { return TypeDefinitions.toStringHelper(type).add("types", type.getTypes()).toString(); } }
@Override public List<TypeDefinition<?>> getTypes() { return getBaseType().getTypes(); }
private void emitUnionSpecification(final UnionTypeDefinition typeDefinition) { for (final TypeDefinition<?> subtype : typeDefinition.getTypes()) { // FIXME: BUG-2444: What if we have locally modified types here? // is solution to look-up in schema path? emitTypeNode(typeDefinition.getPath(), subtype); } }
private T createSimpleUnion(final UnionTypeDefinition union) { final List<TypeDefinition<?>> types = union.getTypes(); final List<T> codecs = new ArrayList<>(types.size()); for (TypeDefinition<?> type : types) { T codec = cache.lookupSimple(type); if (codec == null) { codec = verifyNotNull(getSimpleCodecFor(type), "Type %s did not resolve to a simple codec", type); } codecs.add(codec); } return unionCodec(union, codecs); }
private T createSimpleUnion(final UnionTypeDefinition union) { final List<TypeDefinition<?>> types = union.getTypes(); final List<T> codecs = new ArrayList<>(types.size()); for (TypeDefinition<?> type : types) { T codec = cache.lookupSimple(type); if (codec == null) { codec = verifyNotNull(getSimpleCodecFor(type), "Type %s did not resolve to a simple codec", type); } codecs.add(codec); } return unionCodec(union, codecs); }
static int hashCode(final UnionTypeDefinition type) { return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getTypes()); }
static int hashCode(final UnionTypeDefinition type) { return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getTypes()); }
private T createComplexUnion(final TypedDataSchemaNode schema, final UnionTypeDefinition union) { final List<TypeDefinition<?>> types = union.getTypes(); final List<T> codecs = new ArrayList<>(types.size()); for (TypeDefinition<?> type : types) { T codec = cache.lookupSimple(type); if (codec == null) { codec = getSimpleCodecFor(type); if (codec == null) { codec = createComplexCodecFor(schema, type); } } codecs.add(verifyNotNull(codec, "Schema %s subtype %s has no codec", schema, type)); } return unionCodec(union, codecs); } }
private T createComplexUnion(final TypedDataSchemaNode schema, final UnionTypeDefinition union) { final List<TypeDefinition<?>> types = union.getTypes(); final List<T> codecs = new ArrayList<>(types.size()); for (TypeDefinition<?> type : types) { T codec = cache.lookupSimple(type); if (codec == null) { codec = getSimpleCodecFor(type); if (codec == null) { codec = createComplexCodecFor(schema, type); } } codecs.add(verifyNotNull(codec, "Schema %s subtype %s has no codec", schema, type)); } return unionCodec(union, codecs); } }
static Callable<UnionTypeCodec> loader(final Class<?> unionCls, final UnionTypeDefinition unionType, final BindingCodecContext bindingCodecContext) { return () -> { final Set<UnionValueOptionContext> values = new LinkedHashSet<>(); for (final TypeDefinition<?> subtype : unionType.getTypes()) { if (subtype instanceof LeafrefTypeDefinition) { addLeafrefValueCodec(unionCls, unionType, bindingCodecContext, values, subtype); } else { final Method valueGetter = unionCls.getMethod(BindingMapping.GETTER_PREFIX + BindingMapping.getClassName(subtype.getQName())); final Class<?> valueType = valueGetter.getReturnType(); final Codec<Object, Object> valueCodec = bindingCodecContext.getCodec(valueType, subtype); values.add(new UnionValueOptionContext(unionCls, valueType, valueGetter, valueCodec)); } } return new UnionTypeCodec(unionCls, values); }; }