/** * Checks if <code>dataNode</code> is <code>LeafSchemaNode</code> and if it * so then checks if it is of type <code>EnumTypeDefinition</code>. * * @param dataNode * data schema node for which is checked if it is leaf and if it * is of enum type * @return boolean value * <ul> * <li>true - if <code>dataNode</code> is leaf of type enumeration</li> * <li>false - other cases</li> * </ul> */ private static boolean leafContainsEnumDefinition(final SchemaNode dataNode) { if (dataNode instanceof LeafSchemaNode) { final LeafSchemaNode leaf = (LeafSchemaNode) dataNode; if (leaf.getType() instanceof EnumTypeDefinition) { return true; } } return false; }
private String toUriString(final Object object, final LeafSchemaNode leafNode, final DOMMountPoint mount) throws UnsupportedEncodingException { final Codec<Object, Object> codec = RestCodec.from(leafNode.getType(), mount); return object == null ? "" : URLEncoder.encode(codec.serialize(object).toString(), ControllerContext.URI_ENCODING_CHAR_SET); }
@Override public String getTypeDefaultConstruction(final LeafSchemaNode node) { return getTypeDefaultConstruction(node, (String) node.getType().getDefaultValue().orElse(null)); }
/** * Return a {@link LeafInterner} for a particular schema. Interner instances must not be reused for leaves of * different types, otherwise they may produce unexpected results. * * @param schema The leaf node's schema * @return An interner instance */ @NonNull public static <T extends LeafNode<?>> Interner<T> forSchema(final @Nullable LeafSchemaNode schema) { if (schema != null && isLowCardinality(schema.getType())) { return LeafInterner::intern; } return Objects::requireNonNull; }
/** * Return a {@link LeafInterner} for a particular schema. Interner instances must not be reused for leaves of * different types, otherwise they may produce unexpected results. * * @param schema The leaf node's schema * @return An interner instance */ @NonNull public static <T extends LeafNode<?>> Interner<T> forSchema(final @Nullable LeafSchemaNode schema) { if (schema != null && isLowCardinality(schema.getType())) { return LeafInterner::intern; } return Objects::requireNonNull; }
/** * Extracts the base type of leaf schema node until it reach concrete type of TypeDefinition. * * @param node * a node representing LeafSchemaNode * @return concrete type definition of node value */ private static TypeDefinition<?> typeDefinition(final LeafSchemaNode node) { TypeDefinition<?> baseType = node.getType(); while (baseType.getBaseType() != null) { baseType = baseType.getBaseType(); } return baseType; }
/** * Extracts the base type of leaf schema node until it reach concrete type of TypeDefinition. * * @param node * a node representing LeafSchemaNode * @return concrete type definition of node value */ private static TypeDefinition<?> typeDefinition(final LeafSchemaNode node) { TypeDefinition<?> baseType = node.getType(); while (baseType.getBaseType() != null) { baseType = baseType.getBaseType(); } return baseType; }
private JSONObject processLeafNode(final LeafSchemaNode leafNode) throws JSONException { JSONObject property = new JSONObject(); String leafDescription = leafNode.getDescription(); property.put(DESCRIPTION_KEY, leafDescription); processConstraints(leafNode.getConstraints(), property); processTypeDef(leafNode.getType(), property); return property; }
private static Object createDefaultObject(final DataSchemaNode schema, final Codec<Object, Object> codec, final SchemaContext schemaContext) { if (schema instanceof LeafSchemaNode) { Optional<? extends Object> defaultValue = ((LeafSchemaNode) schema).getType().getDefaultValue(); TypeDefinition<?> type = ((LeafSchemaNode) schema).getType(); if (defaultValue.isPresent()) { if (type instanceof IdentityrefTypeDefinition) { return qnameDomValueFromString(codec, schema, (String) defaultValue.get(), schemaContext); } return domValueFromString(codec, type, defaultValue.get()); } while (type.getBaseType() != null && !type.getDefaultValue().isPresent()) { type = type.getBaseType(); } defaultValue = type.getDefaultValue(); if (defaultValue.isPresent()) { if (type instanceof IdentityrefTypeDefinition) { return qnameDomValueFromString(codec, schema, (String) defaultValue.get(), schemaContext); } return domValueFromString(codec, type, defaultValue); } } return null; }
private Object getValue(QName key, String value){ if(listSchemaNode != null){ for(DataSchemaNode node : listSchemaNode.getChildNodes()){ if(node instanceof LeafSchemaNode && node.getQName().equals(key)){ return TypeDefinitionAwareCodec.from(LeafSchemaNode.class.cast(node).getType()).deserialize(value); } } } return value; } }
private void emitRefineLeafNodes(final LeafSchemaNode value) { final LeafSchemaNode original = getOriginalChecked(value); // emitMustNodes(child.getConstraints().getMustConstraints()); if (Objects.deepEquals(original.getType().getDefaultValue(), value.getType().getDefaultValue())) { emitDefaultNode(value.getType().getDefaultValue()); } if (Objects.deepEquals(original.isConfiguration(), value.isConfiguration())) { emitConfigNode(value.isConfiguration()); } emitDocumentedNodeRefine(original, value); if (Objects.deepEquals(original.isMandatory(), value.isMandatory())) { emitMandatoryNode(value.isMandatory()); } }
private void emitLeaf(final LeafSchemaNode child) { super.writer.startLeafNode(child.getQName()); child.getWhenCondition().ifPresent(this::emitWhen); // FIXME: BUG-2444: *(ifFeatureNode ) emitTypeNode(child.getPath(), child.getType()); child.getType().getUnits().ifPresent(this::emitUnitsNode); child.getMustConstraints().forEach(this::emitMust); child.getType().getDefaultValue().ifPresent(this::emitDefaultNode); emitConfigNode(child.isConfiguration()); emitMandatoryNode(child.isMandatory()); emitDocumentedNode(child); emitUnknownStatementNodes(child.getUnknownSchemaNodes()); super.writer.endNode(); }
/** * Converts <code>dataNode</code> to JAVA <code>Type</code>. * * @param dataNode * contains information about YANG type * @return JAVA <code>Type</code> representation of <code>dataNode</code> */ private Type resolveTypeFromDataSchemaNode(final SchemaNode dataNode) { Type returnType = null; if (dataNode != null) { if (dataNode instanceof LeafSchemaNode) { final LeafSchemaNode leaf = (LeafSchemaNode) dataNode; returnType = javaTypeForSchemaDefinitionType(leaf.getType(), leaf); } else if (dataNode instanceof LeafListSchemaNode) { final LeafListSchemaNode leafList = (LeafListSchemaNode) dataNode; returnType = javaTypeForSchemaDefinitionType(leafList.getType(), leafList); } } return returnType; }
private static Object createDefaultObject(final DataSchemaNode schema, final Codec<Object, Object> codec, final SchemaContext schemaContext) { if (schema instanceof LeafSchemaNode) { TypeDefinition<?> type = ((LeafSchemaNode) schema).getType(); Optional<? extends Object> defaultValue = type.getDefaultValue(); if (defaultValue.isPresent()) { if (type instanceof IdentityrefTypeDefinition) { return qnameDomValueFromString(codec, schema, (String) defaultValue.get(), schemaContext); } return domValueFromString(codec, type, defaultValue.get()); } while (type.getBaseType() != null && !type.getDefaultValue().isPresent()) { type = type.getBaseType(); } defaultValue = type.getDefaultValue(); if (defaultValue.isPresent()) { if (type instanceof IdentityrefTypeDefinition) { return qnameDomValueFromString(codec, schema, (String) defaultValue.get(), schemaContext); } return domValueFromString(codec, type, defaultValue.get()); } } return null; }
private void addKeyValue(final HashMap<QName, Object> map, final DataSchemaNode node, final String uriValue, final DOMMountPoint mountPoint) { Preconditions.checkNotNull(uriValue); Preconditions.checkArgument((node instanceof LeafSchemaNode)); final String urlDecoded = urlPathArgDecode(uriValue); TypeDefinition<?> typedef = ((LeafSchemaNode) node).getType(); final TypeDefinition<?> baseType = RestUtil.resolveBaseTypeFrom(typedef); if (baseType instanceof LeafrefTypeDefinition) { typedef = SchemaContextUtil.getBaseTypeForLeafRef((LeafrefTypeDefinition) baseType, globalSchema, node); } Codec<Object, Object> codec = RestCodec.from(typedef, mountPoint); Object decoded = codec.deserialize(urlDecoded); String additionalInfo = ""; if (decoded == null) { if ((baseType instanceof IdentityrefTypeDefinition)) { decoded = toQName(urlDecoded, null); additionalInfo = "For key which is of type identityref it should be in format module_name:identity_name."; } } if (decoded == null) { throw new RestconfDocumentedException(uriValue + " from URI can't be resolved. " + additionalInfo, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); } map.put(node.getQName(), decoded); }
return union(className, (String) node.getType().getDefaultValue().orElse(null), node);
TypeDefinition type; if (schemaNode instanceof LeafSchemaNode) { type = ((LeafSchemaNode) schemaNode).getType(); } else { type = ((LeafListSchemaNode) schemaNode).getType();
final TypeDefinition<?> typeDef = leaf.getType(); if (typeDef instanceof UnionTypeDefinition) { final Module enumModule = schemaContext.findModuleByNamespaceAndRevision(qname.getNamespace(), qname.getRevision()); returnType = genCtx.get(enumModule).getInnerType(originalLeaf.getType().getPath()); } else { returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
private boolean resolveLeafSchemaNodeAsProperty(final GeneratedTOBuilder toBuilder, final LeafSchemaNode leaf, final boolean isReadOnly) { if (leaf != null && toBuilder != null) { Type returnType; final TypeDefinition<?> typeDef = CompatUtils.compatLeafType(leaf); if (typeDef instanceof UnionTypeDefinition) { // GeneratedType for this type definition should have be already created final ModuleContext mc = moduleContext(typeDef.getQName().getModule()); returnType = mc.getTypedefs().get(typeDef.getPath()); if (returnType == null) { // This may still be an inner type, try to find it returnType = mc.getInnerType(typeDef.getPath()); } } else if (typeDef instanceof EnumTypeDefinition && typeDef.getBaseType() == null) { // Annonymous enumeration (already generated, since it is inherited via uses). LeafSchemaNode originalLeaf = (LeafSchemaNode) SchemaNodeUtils.getRootOriginalIfPossible(leaf); QName qname = originalLeaf.getQName(); returnType = moduleContext(qname.getModule()).getInnerType(originalLeaf.getType().getPath()); } else { returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf); } return resolveLeafSchemaNodeAsProperty(toBuilder, leaf, returnType, isReadOnly); } return false; }
public static CharSequence writeLeafSchemaNode(final LeafSchemaNode leafSchemaNode) { StringConcatenation _builder = new StringConcatenation(); _builder.append("leaf "); QName _qName = leafSchemaNode.getQName(); String _localName = _qName.getLocalName(); _builder.append(_localName, ""); _builder.append(" {"); _builder.newLineIfNotEmpty(); _builder.append(" "); _builder.append("type "); TypeDefinition<?> _type = leafSchemaNode.getType(); QName _qName_1 = _type.getQName(); String _localName_1 = _qName_1.getLocalName(); _builder.append(_localName_1, " "); _builder.append(";"); _builder.newLineIfNotEmpty(); _builder.append("}"); _builder.newLine(); return _builder; }