Beispiel #1
0
  private Optional<DataSchemaNode> getCurrentNode(DataSchemaNode parent, final String buffer) {
    for (final String part : buffer.split(SEPARATOR)) {
      if (IOUtil.isQName(part) == false) {
        return Optional.of(parent);
      }

      final QName qName;
      try {
        qName = IOUtil.qNameFromKeyString(part, mappedModules);
      } catch (final ReadingException e) {
        return Optional.of(parent);
      }
      if (parent instanceof DataNodeContainer) {
        parent = ((DataNodeContainer) parent).getDataChildByName(qName);
      } else {
        // This should check if we are at the end of buffer ?
        return Optional.of(parent);
      }
    }
    return Optional.of(parent);
  }
Beispiel #2
0
  @Override
  protected List<NormalizedNode<?, ?>> readWithContext(final DataSchemaNode schemaNode)
      throws IOException, ReadingException {
    console.writeLn("Config " + schemaNode.getQName().getLocalName());
    console.writeLn("Submit path of the data to edit. Use TAB for autocomplete");

    final String rawValue = console.read();

    // FIXME isSkip check should be somewhere in abstractReader
    if (isSkipInput(rawValue) || Strings.isNullOrEmpty(rawValue)) {
      return Collections.emptyList();
    }

    final List<QName> filterPartsQNames = Lists.newArrayList();

    for (final String part : rawValue.split(SEPARATOR)) {
      final QName qName = IOUtil.qNameFromKeyString(part, mappedModules);
      filterPartsQNames.add(qName);
    }

    List<? extends NormalizedNode<?, ?>> previous = readInnerNode(rawValue);

    for (final QName qName :
        Lists.reverse(filterPartsQNames).subList(1, filterPartsQNames.size())) {
      previous =
          Collections.<NormalizedNode<?, ?>>singletonList(
              ImmutableContainerNodeBuilder.create()
                  .withNodeIdentifier(new NodeIdentifier(qName))
                  .withValue(
                      previous == null
                          ? Collections.<DataContainerChild<?, ?>>emptyList()
                          : (Collection) previous)
                  .build());
    }

    if (previous == null) {
      return Collections.singletonList(null);
    }

    final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> builder =
        ImmutableContainerNodeBuilder.create();
    builder.withNodeIdentifier(new NodeIdentifier(schemaNode.getQName()));
    builder.withValue((Collection<DataContainerChild<?, ?>>) previous);

    return Collections.<NormalizedNode<?, ?>>singletonList(builder.build());
  }