@SuppressWarnings({"rawtypes","unchecked"}) public static Iterable<TypeDefinition> getTypes(final UnionTypeDefinition definition) { return (List) definition.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 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); } }
Preconditions.checkNotNull(basePackageName, "Base Package Name cannot be NULL!"); Preconditions.checkNotNull(typedef, "Type Definition cannot be NULL!"); Preconditions.checkNotNull(typedef.getQName(), "Type definition QName cannot be NULL!"); final List<TypeDefinition<?>> unionTypes = typedef.getTypes(); final Module module = findParentModule(schemaContext, parentNode); final String typeName = BindingMapping.getClassName(typeDefName); unionGenTOBuilder = new GeneratedTOBuilderImpl(basePackageName, typeName); unionGenTOBuilder.setDescription(typedef.getDescription()); unionGenTOBuilder.setReference(typedef.getReference()); unionGenTOBuilder.setSchemaPath(typedef.getPath().getPathFromRoot()); unionGenTOBuilder.setModuleName(module.getName()); } else {
final UnionTypeDefinition typedef, final SchemaNode parentNode) { Preconditions.checkNotNull(typedef, "Type Definition cannot be NULL!"); Preconditions.checkNotNull(typedef.getQName(), "Type definition QName cannot be NULL!"); final List<TypeDefinition<?>> unionTypes = typedef.getTypes(); final Module module = findParentModule(schemaContext, parentNode); unionGenTOBuilder.setSchemaPath(typedef.getPath()); unionGenTOBuilder.setModuleName(module.getName()); addCodegenInformation(unionGenTOBuilder, typedef);
private Type createReturnTypeForUnion(final GeneratedTOBuilder genTOBuilder, final UnionTypeDefinition typeDef, final GeneratedTypeBuilder typeBuilder, final Module parentModule) { final GeneratedTOBuilder returnTypeBuilder = typeProvider.newGeneratedTOBuilder(genTOBuilder.getIdentifier()); returnTypeBuilder.setIsUnion(true); addCodegenInformation(returnTypeBuilder, parentModule, typeDef); returnTypeBuilder.setSchemaPath(typeDef.getPath()); returnTypeBuilder.setModuleName(parentModule.getName()); final GeneratedTransferObject returnType = returnTypeBuilder.build(); genTOBuilder.setTypedef(true); genTOBuilder.setIsUnion(true); AbstractTypeProvider.addUnitsToGenTO(genTOBuilder, typeDef.getUnits().orElse(null)); createUnionBuilder(genTOBuilder, typeBuilder, returnType, parentModule); return returnType; }
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 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; }
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 getBaseType().getTypes(); }
@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(); }
@Override @SuppressWarnings("checkstyle:illegalCatch") public final String serialize(final Object data) { for (final TypeDefinition<?> type : typeDefinition.getTypes()) { Codec<String, Object> codec = codecFor(type); if (codec == null) { LOG.debug("no codec found for {}", type); continue; } try { return codec.serialize(data); } catch (final Exception e) { LOG.debug("Data {} did not match for {}", data, type, e); // invalid - try the next union type. } } throw new IllegalArgumentException("Invalid data \"" + data + "\" for union type."); }
@Override @SuppressWarnings("checkstyle:illegalCatch") public final String serialize(final Object data) { for (final TypeDefinition<?> type : typeDefinition.getTypes()) { Codec<String, Object> codec = codecFor(type); if (codec == null) { LOG.debug("no codec found for {}", type); continue; } try { return codec.serialize(data); } catch (final Exception e) { LOG.debug("Data {} did not match for {}", data, type, e); // invalid - try the next union type. } } throw new IllegalArgumentException("Invalid data \"" + data + "\" for union type."); }