@Override public int compareTo(final PathArgument arg) { return type.getCanonicalName().compareTo(arg.getType().getCanonicalName()); } }
@Nonnull @Override public Optional<? extends DataObject> read(@Nonnull final InstanceIdentifier<? extends DataObject> id, @Nonnull final ReadContext ctx) throws ReadFailedException { final InstanceIdentifier.PathArgument first = checkNotNull( Iterables.getFirst(id.getPathArguments(), null), "Empty id"); final Reader<? extends DataObject, ? extends Builder<?>> reader = rootReaders.get(first.getType()); checkNotNull(reader, "Read failed. Missing reader for %s. Current readers for: %s", id, rootReaders.keySet()); LOG.debug("Reading from delegate: {}", reader); return reader.read(id, ctx); }
private boolean isPathEqual(@Nonnull final InstanceIdentifier<?> iid, final InstanceIdentifier<?> childIiD) { // Verifying path because the same type can be used in several places. Iterator<InstanceIdentifier.PathArgument> pathArguments = iid.getPathArguments().iterator(); for (final InstanceIdentifier.PathArgument pathArgument : childIiD.getPathArguments()) { if (!pathArguments.hasNext() || !pathArgument.getType().equals(pathArguments.next().getType())) { return false; } } return true; }
private boolean isAdditionalScope(final InstanceIdentifier.PathArgument pathArgument) { return additionalKeyTypes.contains(pathArgument.getType()); }
SubtreeReader(final Reader<D, B> delegate, Set<InstanceIdentifier<?>> handledTypes) { this.delegate = delegate; for (InstanceIdentifier<?> handledType : handledTypes) { // Iid has to start with Reader's handled root type checkArgument(delegate.getManagedDataObjectType().getTargetType().equals( handledType.getPathArguments().iterator().next().getType()), "Handled node from subtree has to be identified by an instance identifier starting from: %s." + "Instance identifier was: %s", getManagedDataObjectType().getTargetType(), handledType); checkArgument(Iterables.size(handledType.getPathArguments()) > 1, "Handled node from subtree identifier too short: %s", handledType); handledChildTypes.add(InstanceIdentifier.create(Iterables.concat( getManagedDataObjectType().getPathArguments(), Iterables.skip(handledType.getPathArguments(), 1)))); } }
private boolean shouldDelegateToChild(@Nonnull final InstanceIdentifier<? extends DataObject> id) { return childReaders.containsKey(RWUtils.getNextId(id, getManagedDataObjectType()).getType()); }
@SuppressWarnings({ "unchecked", "rawtypes" }) static <N extends DataObject> InstanceIdentifier<N> trustedCreate(final PathArgument arg, final Iterable<PathArgument> pathArguments, final int hash, boolean wildcarded) { if (Identifiable.class.isAssignableFrom(arg.getType()) && !wildcarded) { Identifier<?> key = null; if (arg instanceof IdentifiableItem) { key = ((IdentifiableItem<?, ?>)arg).getKey(); } else { wildcarded = true; } return new KeyedInstanceIdentifier(arg.getType(), pathArguments, wildcarded, hash, key); } return new InstanceIdentifier(arg.getType(), pathArguments, wildcarded, hash); }
@SuppressWarnings("rawtypes") @Override public Map<InstanceIdentifier, DataContainer> readUsingPathArgument(final DataContainer parent, final PathArgument childArgument, final InstanceIdentifier builder) { checkArgument(childArgument instanceof Item<?>, "Path Argument must be Item without keys"); DataContainer aug = read(parent, childArgument.getType()); if (aug != null) { @SuppressWarnings("unchecked") final InstanceIdentifier childPath = builder.child(childArgument.getType()); return Collections.singletonMap(childPath, aug); } else { return Collections.emptyMap(); } }
private static DataObject filterSingle(final DataObject parent, final InstanceIdentifier.PathArgument nextId, final Method method) { return nextId.getType().cast(invoke(method, nextId, parent)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) static InstanceIdentifier<?> trustedCreate(final PathArgument arg, final Iterable<PathArgument> pathArguments, final int hash, boolean wildcarded) { if (Identifiable.class.isAssignableFrom(arg.getType()) && !(wildcarded)) { Identifier<?> key = null; if (arg instanceof IdentifiableItem<?, ?>) { key = ((IdentifiableItem<?, ?>)arg).key; } else { wildcarded = true; } return new KeyedInstanceIdentifier(arg.getType(), pathArguments, wildcarded, hash, key); } else { return new InstanceIdentifier(arg.getType(), pathArguments, wildcarded, hash); } }
@Override public QName apply(final PathArgument input) { return BindingReflections.findQName(input.getType()); }
@Override public final int compareTo(final PathArgument arg) { final int cmp = compareClasses(type, arg.getType()); if (cmp != 0) { return cmp; } final Optional<? extends Class<?>> caseType = getCaseType(); if (!caseType.isPresent()) { return arg.getCaseType().isPresent() ? -1 : 1; } final Optional<? extends Class<?>> argCaseType = getCaseType(); return argCaseType.isPresent() ? compareClasses(caseType.get(), argCaseType.get()) : 1; }
/** * Find next item in ID after provided type. */ @Nonnull public static InstanceIdentifier.PathArgument getNextId(@Nonnull final InstanceIdentifier<? extends DataObject> id, @Nonnull final InstanceIdentifier<? extends DataObject> type) { final Iterable<InstanceIdentifier.PathArgument> pathArguments = id.getPathArguments(); final int i = Iterables.indexOf(pathArguments, input -> input.getType().isAssignableFrom(type.getTargetType())); Preconditions.checkArgument(i >= 0, "Unable to find %s type in %s", type.getTargetType(), id); return Iterables.get(pathArguments, i + 1); }
@SuppressWarnings("rawtypes") private static final Map<InstanceIdentifier, DataContainer> readData(final DataContainer parent, final InstanceIdentifier parentPath, final PathArgument child) { checkArgument(parent != null, "Object should not be null."); checkArgument(child != null, "Child argument should not be null"); Class<? extends DataContainer> parentClass = parent.getImplementedInterface(); return resolveReadStrategy(parentClass, child.getType()).readUsingPathArgument(parent, child, parentPath); }
private static InstanceIdentifier.PathArgument cleanPathArgumentFromKeys(final InstanceIdentifier.PathArgument pathArgument) { return pathArgument instanceof InstanceIdentifier.IdentifiableItem<?, ?> ? new InstanceIdentifier.Item<>(pathArgument.getType()) : pathArgument; } }
/** * Trim InstanceIdentifier at indexOf(type). */ @SuppressWarnings("unchecked") @Nonnull public static <D extends DataObject> InstanceIdentifier<D> cutId(@Nonnull final InstanceIdentifier<? extends DataObject> id, @Nonnull final InstanceIdentifier<D> type) { final Iterable<InstanceIdentifier.PathArgument> pathArguments = id.getPathArguments(); final int i = Iterables.indexOf(pathArguments, input -> input.getType().equals(type.getTargetType())); Preconditions.checkArgument(i >= 0, "ID %s does not contain %s", id, type); return (InstanceIdentifier<D>) InstanceIdentifier.create(Iterables.limit(pathArguments, i + 1)); }
private Optional<? extends DataObject> readSubtree(final InstanceIdentifier<? extends DataObject> id, final ReadContext ctx) throws ReadFailedException { final InstanceIdentifier.PathArgument nextId = RWUtils.getNextId(id, getManagedDataObjectType()); final Reader<?, ? extends Builder<?>> nextReader = childReaders.get(nextId.getType()); checkArgument(nextReader != null, "Unable to read: %s. No delegate present, available readers at next level: %s", id, childReaders.keySet()); return nextReader.read(id, ctx); }
@Override public Map<InstanceIdentifier, DataContainer> readUsingPathArgument(final DataContainer parent, final PathArgument childArgument, final InstanceIdentifier parentPath) { final DataContainer result = read(parent, childArgument.getType()); if (result != null) { @SuppressWarnings("unchecked") InstanceIdentifier childPath = parentPath.child(childArgument.getType()); return Collections.singletonMap(childPath, result); } return Collections.emptyMap(); }
private static Collection<Class<?>> decompose(final InstanceIdentifier<?> path) { final Set<Class<?>> clazzes = new HashSet<>(); for(final InstanceIdentifier.PathArgument arg : path.getPathArguments()) { clazzes.add(arg.getType()); } return clazzes; }
<N extends DataObject> InstanceIdentifierBuilderImpl<N> addWildNode(final PathArgument newArg) { if (Identifiable.class.isAssignableFrom(newArg.getType())) { wildcard = true; } return addNode(newArg); }