use of org.opendaylight.yangtools.yang.common.XMLNamespace in project netconf by opendaylight.
the class RuntimeRpc method canHandle.
@Override
protected HandlingPriority canHandle(final String netconfOperationName, final String namespace) {
final XMLNamespace namespaceURI = createNsUri(namespace);
final Optional<? extends Module> module = getModule(namespaceURI);
if (module.isEmpty()) {
LOG.debug("Cannot handle rpc: {}, {}", netconfOperationName, namespace);
return HandlingPriority.CANNOT_HANDLE;
}
getRpcDefinitionFromModule(module.get(), namespaceURI, netconfOperationName);
return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY;
}
use of org.opendaylight.yangtools.yang.common.XMLNamespace in project netconf by opendaylight.
the class FilterContentValidator method validate.
/**
* Validates filter content against this validator schema context. If the filter is valid,
* method returns {@link YangInstanceIdentifier} of node which can be used as root for data selection.
*
* @param filterContent filter content
* @return YangInstanceIdentifier
* @throws DocumentedException if filter content validation failed
*/
public YangInstanceIdentifier validate(final XmlElement filterContent) throws DocumentedException {
final XMLNamespace namespace;
try {
namespace = XMLNamespace.of(filterContent.getNamespace());
} catch (final IllegalArgumentException e) {
throw new RuntimeException("Wrong namespace in element + " + filterContent.toString(), e);
}
try {
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 ValidationException e) {
LOG.debug("Filter content isn't valid", e);
throw new DocumentedException("Validation failed. Cause: " + e.getMessage(), e, ErrorType.APPLICATION, ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
}
}
use of org.opendaylight.yangtools.yang.common.XMLNamespace in project netconf by opendaylight.
the class AbstractEdit method getSchemaNodeFromNamespace.
final SchemaTreeInference getSchemaNodeFromNamespace(final String namespace, final XmlElement element) throws DocumentedException {
final XMLNamespace ns;
try {
ns = XMLNamespace.of(namespace);
} catch (final IllegalArgumentException e) {
throw new NetconfDocumentedException("Unable to create URI for namespace : " + namespace, e, ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
}
// Returns module with newest revision since findModuleByNamespace returns a set of modules and we only
// need the newest one
final EffectiveModelContext ctx = schemaContext.getCurrentContext();
final Iterator<? extends @NonNull Module> it = ctx.findModules(ns).iterator();
if (!it.hasNext()) {
// No module is present with this namespace
throw new NetconfDocumentedException("Unable to find module by namespace: " + namespace, ErrorType.APPLICATION, ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
}
final Module module = it.next();
final SchemaInferenceStack stack = SchemaInferenceStack.of(ctx);
final String elementName = element.getName();
try {
// FIXME: This is a bit suspect. The element is formed using XML encoding, hence it corresponds to
// enterDataTree(). But then we use the result of this method to create a NormalizedNode tree,
// which contains ChoiceNode. This needs to be tested with something like to following:
//
// module mod {
// choice foo {
// case bar {
// leaf baz {
// type string;
// }
// }
// }
// }
stack.enterSchemaTree(QName.create(module.getQNameModule(), elementName));
} catch (IllegalArgumentException e) {
throw new DocumentedException("Unable to find node " + elementName + " with namespace: " + namespace + " in module: " + module, e, ErrorType.APPLICATION, ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
}
return stack.toSchemaTreeInference();
}
use of org.opendaylight.yangtools.yang.common.XMLNamespace in project netconf by opendaylight.
the class RestCodec method getModuleByNamespace.
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "https://github.com/spotbugs/spotbugs/issues/811")
private static Module getModuleByNamespace(final String namespace, final DOMMountPoint mountPoint, final SchemaContext schemaContext) {
final XMLNamespace validNamespace = resolveValidNamespace(namespace, mountPoint, schemaContext);
Module module = null;
if (mountPoint != null) {
module = modelContext(mountPoint).findModules(validNamespace).iterator().next();
} else {
module = schemaContext.findModules(validNamespace).iterator().next();
}
if (module == null) {
LOG.info("Module for namespace {} was not found.", validNamespace);
return null;
}
return module;
}
use of org.opendaylight.yangtools.yang.common.XMLNamespace in project netconf by opendaylight.
the class RestconfImpl method invokeSalRemoteRpcNotifiStrRPC.
/**
* Prepare stream for notification.
*
* @param payload
* contains list of qnames of notifications
* @return - checked future object
*/
private ListenableFuture<DOMRpcResult> invokeSalRemoteRpcNotifiStrRPC(final NormalizedNodeContext payload) {
final ContainerNode data = (ContainerNode) payload.getData();
LeafSetNode leafSet = null;
String outputType = "XML";
for (final DataContainerChild dataChild : data.body()) {
if (dataChild instanceof LeafSetNode) {
leafSet = (LeafSetNode) dataChild;
} else if (dataChild instanceof AugmentationNode) {
outputType = (String) ((AugmentationNode) dataChild).body().iterator().next().body();
}
}
final Collection<LeafSetEntryNode<?>> entryNodes = leafSet.body();
final List<SchemaPath> paths = new ArrayList<>();
String streamName = CREATE_NOTIFICATION_STREAM + "/";
StringBuilder streamNameBuilder = new StringBuilder(streamName);
final Iterator<LeafSetEntryNode<?>> iterator = entryNodes.iterator();
while (iterator.hasNext()) {
final QName valueQName = QName.create((String) iterator.next().body());
final XMLNamespace namespace = valueQName.getModule().getNamespace();
final Module module = controllerContext.findModuleByNamespace(namespace);
checkNotNull(module, "Module for namespace %s does not exist", namespace);
NotificationDefinition notifiDef = null;
for (final NotificationDefinition notification : module.getNotifications()) {
if (notification.getQName().equals(valueQName)) {
notifiDef = notification;
break;
}
}
final String moduleName = module.getName();
checkNotNull(notifiDef, "Notification %s does not exist in module %s", valueQName, moduleName);
paths.add(SchemaPath.of(Absolute.of(notifiDef.getQName())));
streamNameBuilder.append(moduleName).append(':').append(valueQName.getLocalName());
if (iterator.hasNext()) {
streamNameBuilder.append(',');
}
}
streamName = streamNameBuilder.toString();
final QName rpcQName = payload.getInstanceIdentifierContext().getSchemaNode().getQName();
final QName outputQname = QName.create(rpcQName, "output");
final QName streamNameQname = QName.create(rpcQName, "notification-stream-identifier");
final ContainerNode output = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(outputQname)).withChild(ImmutableNodes.leafNode(streamNameQname, streamName)).build();
if (!Notificator.existNotificationListenerFor(streamName)) {
Notificator.createNotificationListener(paths, streamName, outputType, controllerContext);
}
return Futures.immediateFuture(new DefaultDOMRpcResult(output));
}
Aggregations