*/
package org.opendaylight.mdsal.binding.yang.types;
-import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
import static org.opendaylight.mdsal.binding.model.util.BindingTypes.TYPE_OBJECT;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNode;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import java.math.BigDecimal;
-import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collection;
import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.PathExpression;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.yangtools.yang.model.util.ModuleDependencySort;
-import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
+import org.opendaylight.yangtools.yang.model.util.PathExpressionImpl;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
import org.opendaylight.yangtools.yang.model.util.type.CompatUtils;
}
private boolean isLeafRefSelfReference(final LeafrefTypeDefinition leafref, final SchemaNode parentNode) {
- final SchemaNode leafRefValueNode;
- final RevisionAwareXPath leafRefXPath = leafref.getPathStatement();
- final RevisionAwareXPath leafRefStrippedXPath = new RevisionAwareXPathImpl(
- GROUPS_PATTERN.matcher(leafRefXPath.toString()).replaceAll(""), leafRefXPath.isAbsolute());
-
- ///// skip leafrefs in augments - they're checked once augments are resolved
- final Iterator<QName> iterator = parentNode.getPath().getPathFromRoot().iterator();
- boolean isAugmenting = false;
+ /*
+ * First check if the leafref is an augment. If that is the case, skip it as it will be checked once augments
+ * are resolved.
+ */
DataNodeContainer current = null;
DataSchemaNode dataChildByName;
-
- while (iterator.hasNext() && !isAugmenting) {
- final QName next = iterator.next();
+ for (QName next : parentNode.getPath().getPathFromRoot()) {
if (current == null) {
dataChildByName = schemaContext.getDataChildByName(next);
} else {
dataChildByName = current.getDataChildByName(next);
}
- if (dataChildByName != null) {
- isAugmenting = dataChildByName.isAugmenting();
- } else {
+ if (dataChildByName == null) {
+ return false;
+ }
+ if (dataChildByName.isAugmenting()) {
return false;
}
if (dataChildByName instanceof DataNodeContainer) {
current = (DataNodeContainer) dataChildByName;
}
}
- if (isAugmenting) {
- return false;
- }
- /////
+ // Then try to look up the expression.
+ final PathExpression leafRefXPath = leafref.getPathStatement();
+ final PathExpression leafRefStrippedXPath = new PathExpressionImpl(
+ GROUPS_PATTERN.matcher(leafRefXPath.getOriginalString()).replaceAll(""), leafRefXPath.isAbsolute());
final Module parentModule = getParentModule(parentNode);
+ final SchemaNode leafRefValueNode;
if (!leafRefStrippedXPath.isAbsolute()) {
leafRefValueNode = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(schemaContext, parentModule,
parentNode, leafRefStrippedXPath);
final boolean inGrouping) {
Preconditions.checkArgument(leafrefType != null, "Leafref Type Definition reference cannot be NULL!");
- final RevisionAwareXPath xpath = leafrefType.getPathStatement();
+ final PathExpression xpath = leafrefType.getPathStatement();
Preconditions.checkArgument(xpath != null, "The Path Statement for Leafref Type Definition cannot be NULL!");
- final String strXPath = verifyNotNull(xpath.toString());
+ final String strXPath = xpath.getOriginalString();
if (strXPath.indexOf('[') != -1) {
// XXX: why are we special-casing this?
return Types.objectType();
private static boolean leafContainsEnumDefinition(final SchemaNode dataNode) {
if (dataNode instanceof LeafSchemaNode) {
final LeafSchemaNode leaf = (LeafSchemaNode) dataNode;
- return CompatUtils.compatLeafType(leaf) instanceof EnumTypeDefinition;
+ return CompatUtils.compatType(leaf) instanceof EnumTypeDefinition;
}
return false;
}
if (dataNode != null) {
if (dataNode instanceof LeafSchemaNode) {
final LeafSchemaNode leaf = (LeafSchemaNode) dataNode;
- final TypeDefinition<?> type = CompatUtils.compatLeafType(leaf);
+ final TypeDefinition<?> type = CompatUtils.compatType(leaf);
returnType = javaTypeForSchemaDefinitionType(type, leaf);
} else if (dataNode instanceof LeafListSchemaNode) {
final LeafListSchemaNode leafList = (LeafListSchemaNode) dataNode;
}
public String getTypeDefaultConstruction(final LeafSchemaNode node, final String defaultValue) {
- final TypeDefinition<?> type = CompatUtils.compatLeafType(node);
+ final TypeDefinition<?> type = CompatUtils.compatType(node);
final QName typeQName = type.getQName();
final TypeDefinition<?> base = baseTypeDefForExtendedType(type);
requireNonNull(type, () -> "Cannot provide default construction for null type of " + node);
} else if (base instanceof StringTypeDefinition) {
result = "\"" + defaultValue + "\"";
} else if (BaseTypes.isUint8(base)) {
- result = typeToValueOfDef(Short.class, defaultValue);
+ result = typeToValueOfDef(Uint8.class, defaultValue);
} else if (BaseTypes.isUint16(base)) {
- result = typeToValueOfDef(Integer.class, defaultValue);
+ result = typeToValueOfDef(Uint16.class, defaultValue);
} else if (BaseTypes.isUint32(base)) {
- result = typeToValueOfDef(Long.class, defaultValue);
+ result = typeToValueOfDef(Uint32.class, defaultValue);
} else if (BaseTypes.isUint64(base)) {
- switch (defaultValue) {
- case "0":
- result = "java.math.BigInteger.ZERO";
- break;
- case "1":
- result = "java.math.BigInteger.ONE";
- break;
- case "10":
- result = "java.math.BigInteger.TEN";
- break;
- default:
- result = typeToDef(BigInteger.class, defaultValue);
- }
+ result = typeToValueOfDef(Uint64.class, defaultValue);
} else if (base instanceof UnionTypeDefinition) {
result = unionToDef(node);
} else {
Preconditions.checkArgument(leafrefType.getPathStatement() != null,
"The Path Statement for Leafref Type Definition cannot be NULL!");
- final RevisionAwareXPath xpath = leafrefType.getPathStatement();
- final String strXPath = xpath.toString();
+ final PathExpression xpath = leafrefType.getPathStatement();
+ final String strXPath = xpath.getOriginalString();
if (strXPath != null) {
if (strXPath.indexOf('[') == -1) {
}
private String unionToDef(final LeafSchemaNode node) {
- final TypeDefinition<?> type = CompatUtils.compatLeafType(node);
+ final TypeDefinition<?> type = CompatUtils.compatType(node);
String parentName;
String className;