+
+ private boolean isBoolean(String value) {
+ if (value.equals("true") || value.equals("false")) {
+ return true;
+ }
+ return false;
+ }
+
+ private void writeEmptyDataTypeToJson(JsonWriter writer) throws IOException {
+ writer.beginArray();
+ writer.nullValue();
+ writer.endArray();
+ }
+
+ private boolean isNumber(String value) {
+ try {
+ Double.valueOf(value);
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ return true;
+ }
+
+ private boolean containsType(UnionTypeDefinition unionType, Class<?>... searchedTypes) {
+ List<TypeDefinition<?>> allUnionSubtypes = resolveAllUnionSubtypesFrom(unionType);
+
+ for (TypeDefinition<?> unionSubtype : allUnionSubtypes) {
+ for (Class<?> searchedType : searchedTypes) {
+ if (searchedType.isInstance(unionSubtype)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private List<TypeDefinition<?>> resolveAllUnionSubtypesFrom(UnionTypeDefinition inputType) {
+ List<TypeDefinition<?>> result = new ArrayList<>();
+ for (TypeDefinition<?> subtype : inputType.getTypes()) {
+ TypeDefinition<?> resolvedSubtype = subtype;
+
+ resolvedSubtype = resolveBaseTypeFrom(subtype);
+
+ if (resolvedSubtype instanceof UnionTypeDefinition) {
+ List<TypeDefinition<?>> subtypesFromRecursion = resolveAllUnionSubtypesFrom((UnionTypeDefinition) resolvedSubtype);
+ result.addAll(subtypesFromRecursion);
+ } else {
+ result.add(resolvedSubtype);
+ }
+ }
+
+ return result;
+ }
+
+ private TypeDefinition<?> resolveBaseTypeFrom(TypeDefinition<?> type) {
+ return type.getBaseType() != null ? resolveBaseTypeFrom(type.getBaseType()) : type;
+ }
+
+ private void writeName(Node<?> node, DataSchemaNode schema, JsonWriter writer) throws IOException {
+ String nameForOutput = node.getNodeType().getLocalName();
+ if (schema.isAugmenting()) {
+ ControllerContext contContext = ControllerContext.getInstance();
+ CharSequence moduleName;
+ moduleName = contContext.toRestconfIdentifier(schema.getQName());
+ if (moduleName != null) {
+ nameForOutput = moduleName.toString();
+ }
+ }
+ writer.name(nameForOutput);
+ }
+