import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import javax.ws.rs.core.Response.Status;
import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
import org.opendaylight.yangtools.concepts.Codec;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
onGlobalContextUpdated(schemas);
}
- public InstanceIdentifierContext toInstanceIdentifier(final String restconfInstance) {
+ public InstanceIdentifierContext<?> toInstanceIdentifier(final String restconfInstance) {
return toIdentifier(restconfInstance, false);
}
return globalSchema;
}
- public InstanceIdentifierContext toMountPointIdentifier(final String restconfInstance) {
+ public InstanceIdentifierContext<?> toMountPointIdentifier(final String restconfInstance) {
return toIdentifier(restconfInstance, true);
}
- private InstanceIdentifierContext toIdentifier(final String restconfInstance, final boolean toMountPointIdentifier) {
+ private InstanceIdentifierContext<?> toIdentifier(final String restconfInstance, final boolean toMountPointIdentifier) {
checkPreconditions();
if(restconfInstance == null) {
final InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder();
final Module latestModule = globalSchema.findModuleByName(startModule, null);
- final InstanceIdentifierContext iiWithSchemaNode = collectPathArguments(builder, pathArgs, latestModule, null,
+
+ if (latestModule == null) {
+ throw new RestconfDocumentedException("The module named '" + startModule + "' does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
+ }
+
+ final InstanceIdentifierContext<?> iiWithSchemaNode = collectPathArguments(builder, pathArgs, latestModule, null,
toMountPointIdentifier);
if (iiWithSchemaNode == null) {
return null;
}
- private static DataSchemaNode childByQName(final ChoiceNode container, final QName name) {
+ private static DataSchemaNode childByQName(final ChoiceSchemaNode container, final QName name) {
for (final ChoiceCaseNode caze : container.getCases()) {
final DataSchemaNode ret = ControllerContext.childByQName(caze, name);
if (ret != null) {
final DataSchemaNode ret = container.getDataChildByName(name);
if (ret == null) {
for (final DataSchemaNode node : container.getChildNodes()) {
- if ((node instanceof ChoiceNode)) {
- final ChoiceNode choiceNode = ((ChoiceNode) node);
+ if ((node instanceof ChoiceSchemaNode)) {
+ final ChoiceSchemaNode choiceNode = ((ChoiceSchemaNode) node);
final DataSchemaNode childByQName = ControllerContext.childByQName(choiceNode, name);
if (childByQName != null) {
return childByQName;
return object == null ? "" : URLEncoder.encode(codec.serialize(object).toString(), ControllerContext.URI_ENCODING_CHAR_SET);
}
- private InstanceIdentifierContext collectPathArguments(final InstanceIdentifierBuilder builder,
+ private InstanceIdentifierContext<?> collectPathArguments(final InstanceIdentifierBuilder builder,
final List<String> strings, final DataNodeContainer parentNode, final DOMMountPoint mountPoint,
final boolean returnJustMountPoint) {
Preconditions.<List<String>> checkNotNull(strings);
if (returnJustMountPoint || strings.size() == 1) {
final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance();
- return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema);
+ return new InstanceIdentifierContext<>(instance, mountPointSchema, mount,mountPointSchema);
}
final String moduleNameBehindMountPoint = toModuleName(strings.get(1));
return createContext(builder.build(), targetNode, mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema);
}
- private InstanceIdentifierContext createContext(final YangInstanceIdentifier instance, final DataSchemaNode dataSchemaNode,
+ private InstanceIdentifierContext<?> createContext(final YangInstanceIdentifier instance, final DataSchemaNode dataSchemaNode,
final DOMMountPoint mountPoint, final SchemaContext schemaContext) {
final YangInstanceIdentifier instanceIdentifier = new DataNormalizer(schemaContext).toNormalized(instance);
- return new InstanceIdentifierContext(instanceIdentifier, dataSchemaNode, mountPoint,schemaContext);
+ return new InstanceIdentifierContext<>(instanceIdentifier, dataSchemaNode, mountPoint,schemaContext);
}
public static DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container, final String name,
return instantiatedDataNodeContainers;
}
- private static final Function<ChoiceNode, Set<ChoiceCaseNode>> CHOICE_FUNCTION = new Function<ChoiceNode, Set<ChoiceCaseNode>>() {
+ private static final Function<ChoiceSchemaNode, Set<ChoiceCaseNode>> CHOICE_FUNCTION = new Function<ChoiceSchemaNode, Set<ChoiceCaseNode>>() {
@Override
- public Set<ChoiceCaseNode> apply(final ChoiceNode node) {
+ public Set<ChoiceCaseNode> apply(final ChoiceSchemaNode node) {
return node.getCases();
}
};
}
}
- final Iterable<ChoiceNode> choiceNodes = Iterables.filter(container.getChildNodes(), ChoiceNode.class);
+ final Iterable<ChoiceSchemaNode> choiceNodes = Iterables.filter(container.getChildNodes(), ChoiceSchemaNode.class);
final Iterable<Set<ChoiceCaseNode>> map = Iterables.transform(choiceNodes, CHOICE_FUNCTION);
final Iterable<ChoiceCaseNode> allCases = Iterables.<ChoiceCaseNode> concat(map);
private static DataSchemaNode childByQName(final Object container, final QName name) {
if (container instanceof ChoiceCaseNode) {
return childByQName((ChoiceCaseNode) container, name);
- } else if (container instanceof ChoiceNode) {
- return childByQName((ChoiceNode) container, name);
+ } else if (container instanceof ChoiceSchemaNode) {
+ return childByQName((ChoiceSchemaNode) container, name);
} else if (container instanceof ContainerSchemaNode) {
return childByQName((ContainerSchemaNode) container, name);
} else if (container instanceof ListSchemaNode) {
}
}
- public Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> toNormalized(final YangInstanceIdentifier legacy,
- final CompositeNode compositeNode) {
- try {
- return dataNormalizer.toNormalized(legacy, compositeNode);
- } catch (final NullPointerException e) {
- throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e);
- }
- }
-
public YangInstanceIdentifier toNormalized(final YangInstanceIdentifier legacy) {
try {
return dataNormalizer.toNormalized(legacy);
}
}
- public CompositeNode toLegacy(final YangInstanceIdentifier instanceIdentifier,
- final NormalizedNode<?,?> normalizedNode) {
- try {
- return dataNormalizer.toLegacy(instanceIdentifier, normalizedNode);
- } catch (final NullPointerException e) {
- throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e);
- }
- }
-
public YangInstanceIdentifier toXpathRepresentation(final YangInstanceIdentifier instanceIdentifier) {
try {
return dataNormalizer.toLegacy(instanceIdentifier);