import static org.opendaylight.yangtools.yang.data.util.ParserStreamUtils.findSchemaNodeByNameAndNamespace;
-import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamWriter;
-import org.opendaylight.controller.config.util.xml.DocumentedException;
-import org.opendaylight.controller.config.util.xml.MissingNameSpaceException;
-import org.opendaylight.controller.config.util.xml.XmlElement;
+import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.xml.MissingNameSpaceException;
+import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.codec.xml.XmlCodecFactory;
import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
import org.opendaylight.yangtools.yang.data.util.codec.TypeAwareCodec;
-import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
public YangInstanceIdentifier validate(final XmlElement filterContent) throws DocumentedException {
try {
final URI namespace = new URI(filterContent.getNamespace());
- final Module module = schemaContext.getCurrentContext().findModuleByNamespaceAndRevision(namespace, null);
+ final Module module = schemaContext.getCurrentContext().findModules(namespace).iterator().next();
final DataSchemaNode schema = getRootDataSchemaNode(module, namespace, filterContent.getName());
final FilterTree filterTree = validateNode(
filterContent, schema, new FilterTree(schema.getQName(), Type.OTHER, schema));
return getFilterDataRoot(filterTree, filterContent, YangInstanceIdentifier.builder());
} catch (final URISyntaxException e) {
- throw new RuntimeException("Wrong namespace in element + " + filterContent.toString());
+ throw new RuntimeException("Wrong namespace in element + " + filterContent.toString(), e);
} catch (final ValidationException e) {
LOG.debug("Filter content isn't valid", e);
- throw new DocumentedException("Validation failed. Cause: " + e.getMessage(),
+ throw new DocumentedException("Validation failed. Cause: " + e.getMessage(), e,
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.UNKNOWN_NAMESPACE,
DocumentedException.ErrorSeverity.ERROR);
*/
private DataSchemaNode getRootDataSchemaNode(final Module module, final URI nameSpace, final String name)
throws DocumentedException {
- final Collection<DataSchemaNode> childNodes = module.getChildNodes();
- for (final DataSchemaNode childNode : childNodes) {
+ for (final DataSchemaNode childNode : module.getChildNodes()) {
final QName qName = childNode.getQName();
if (qName.getNamespace().equals(nameSpace) && qName.getLocalName().equals(name)) {
return childNode;
final DataSchemaNode childSchema = path.getLast();
validateNode(childElement, childSchema, subtree);
} catch (URISyntaxException | MissingNameSpaceException e) {
- throw new RuntimeException("Wrong namespace in element + " + childElement.toString());
+ throw new RuntimeException("Wrong namespace in element + " + childElement.toString(), e);
}
}
return tree;
if (listKey instanceof IdentityrefTypeDefinition) {
keys.put(qualifiedName, keyValue.get());
} else {
- if (listKey.getType() instanceof IdentityrefTypeDefinition) {
+ final TypeDefinition<? extends TypeDefinition<?>> keyType = listKey.getType();
+ if (keyType instanceof IdentityrefTypeDefinition || keyType instanceof LeafrefTypeDefinition) {
final Document document = filterContent.getDomElement().getOwnerDocument();
final NamespaceContext nsContext = new UniversalNamespaceContextImpl(document, false);
final XmlCodecFactory xmlCodecFactory =
XmlCodecFactory.create(schemaContext.getCurrentContext());
- final TypeAwareCodec<?, NamespaceContext, XMLStreamWriter> identityrefTypeCodec =
+ final TypeAwareCodec<?, NamespaceContext, XMLStreamWriter> typeCodec =
xmlCodecFactory.codecFor(listKey);
- final QName deserializedKey =
- (QName) identityrefTypeCodec.parseValue(nsContext, keyValue.get());
- keys.put(qualifiedName, deserializedKey);
+ final Object deserializedKeyValue = typeCodec.parseValue(nsContext, keyValue.get());
+ keys.put(qualifiedName, deserializedKeyValue);
} else {
- final Object deserializedKey = TypeDefinitionAwareCodec.from(listKey.getType())
+ final Object deserializedKey = TypeDefinitionAwareCodec.from(keyType)
.deserialize(keyValue.get());
keys.put(qualifiedName, deserializedKey);
}
}
FilterTree addChild(final DataSchemaNode data) {
- final Type type;
- if (data instanceof ChoiceCaseNode) {
- type = Type.CHOICE_CASE;
+ final Type childType;
+ if (data instanceof CaseSchemaNode) {
+ childType = Type.CHOICE_CASE;
} else if (data instanceof ListSchemaNode) {
- type = Type.LIST;
+ childType = Type.LIST;
} else {
- type = Type.OTHER;
+ childType = Type.OTHER;
}
- final QName name = data.getQName();
- FilterTree childTree = children.get(name);
+ final QName childName = data.getQName();
+ FilterTree childTree = children.get(childName);
if (childTree == null) {
- childTree = new FilterTree(name, type, data);
+ childTree = new FilterTree(childName, childType, data);
}
- children.put(name, childTree);
+ children.put(childName, childTree);
return childTree;
}