/** * Create an instance identifier for a very specific object type. This method * implements {@link #create(Iterable)} semantics, except it is used by internal * callers, which have assured that the argument is an immutable Iterable. * * * @param pathArguments The path to a specific node in the data tree * @return InstanceIdentifier instance * @throws IllegalArgumentException if pathArguments is empty or * contains a null element. */ private static InstanceIdentifier<?> internalCreate(final Iterable<PathArgument> pathArguments) { final Iterator<? extends PathArgument> it = Preconditions.checkNotNull(pathArguments, "pathArguments may not be null").iterator(); final HashCodeBuilder<PathArgument> hashBuilder = new HashCodeBuilder<>(); boolean wildcard = false; PathArgument a = null; while (it.hasNext()) { a = it.next(); Preconditions.checkArgument(a != null, "pathArguments may not contain null elements"); // TODO: sanity check ChildOf<>; hashBuilder.addArgument(a); if (Identifiable.class.isAssignableFrom(a.getType()) && !(a instanceof IdentifiableItem<?, ?>)) { wildcard = true; } } Preconditions.checkArgument(a != null, "pathArguments may not be empty"); return trustedCreate(a, pathArguments, hashBuilder.build(), wildcard); }
@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; }
PathArgument currentArg = pathArguments.next(); Preconditions.checkArgument(currentArg != null); QName currentQName = BindingReflections.findQName(currentArg.getType()); if (BindingReflections.isNotification(currentArg.getType())) { currentContainer = findNotification(ctx, currentQName); } else if (BindingReflections.isRpcType(currentArg.getType())) { currentContainer = findFirstDataNodeContainerInRpc(ctx, currentArg.getType()); if (currentQName == null && currentContainer.isPresent()) { currentQName = ((DataSchemaNode) currentContainer.get()).getQName(); if (Augmentation.class.isAssignableFrom(currentArg.getType())) { currentQName = BindingReflections.findQName(currentArg.getType()); if (pathArguments.hasNext()) { currentArg = pathArguments.next(); if (ChildOf.class.isAssignableFrom(currentArg.getType()) && BindingReflections.isAugmentationChild(currentArg.getType())) { currentQName = BindingReflections.findQName(currentArg.getType()); } else { currentQName = BindingReflections.findQName(currentArg.getType()).withModule(currentQName.getModule());
PathArgument currentArg = pathArguments.next(); Preconditions.checkArgument(currentArg != null); QName currentQName = BindingReflections.findQName(currentArg.getType()); if (BindingReflections.isNotification(currentArg.getType())) { currentContainer = findNotification(ctx, currentQName); } else if (BindingReflections.isRpcType(currentArg.getType())) { currentContainer = findFirstDataNodeContainerInRpc(ctx, currentArg.getType()); if(currentQName == null && currentContainer.isPresent()) { currentQName = ((DataSchemaNode) currentContainer.get()).getQName(); if (Augmentation.class.isAssignableFrom(currentArg.getType())) { currentQName = BindingReflections.findQName(currentArg.getType()); if(pathArguments.hasNext()) { currentArg = pathArguments.next(); if(ChildOf.class.isAssignableFrom(currentArg.getType()) && BindingReflections.isAugmentationChild(currentArg.getType())) { currentQName = BindingReflections.findQName(currentArg.getType()); } else { currentQName = QName.create(currentQName, BindingReflections.findQName(currentArg.getType()).getLocalName());
try { for (PathArgument arg: path.getPathArguments()) { Class<?> type = arg.getType();
int count = 1; for (final PathArgument a : pathArguments) { if (type.equals(a.getType())) { @SuppressWarnings("unchecked") final InstanceIdentifier<I> ret = (InstanceIdentifier<I>) internalCreate(
/** * Finds all modified subnodes of given type in {@link Neutron} node. * * @param <T> * @param iid path to data in root node * @param rootNode modified data of {@link Neutron} node * @return {@link List} of modified subnodes */ private <T extends DataObject> List<DataObjectModification<T>> findModifiedData(InstanceIdentifier<T> iid, DataObjectModification<Neutron> rootNode) { List<DataObjectModification<T>> modDtos = new ArrayList<>(); PeekingIterator<PathArgument> pathArgs = Iterators.peekingIterator(iid.getPathArguments().iterator()); DataObjectModification<? extends DataObject> modifDto = rootNode; while (pathArgs.hasNext()) { pathArgs.next(); for (DataObjectModification<? extends DataObject> childDto : modifDto.getModifiedChildren()) { if (pathArgs.hasNext() && childDto.getDataType().equals(pathArgs.peek().getType())) { if (childDto.getDataType().equals(iid.getTargetType())) { modDtos.add((DataObjectModification<T>) childDto); } else { modifDto = childDto; break; } } } } return modDtos; }
int i = 1; for (final PathArgument a : pathArguments) { if (type.equals(a.getType())) { @SuppressWarnings("unchecked") final InstanceIdentifier<I> ret = (InstanceIdentifier<I>) internalCreate(Iterables.limit(pathArguments, i));
/** * Create an instance identifier for a very specific object type. This method implements {@link #create(Iterable)} * semantics, except it is used by internal callers, which have assured that the argument is an immutable Iterable. * * @param pathArguments The path to a specific node in the data tree * @return InstanceIdentifier instance * @throws IllegalArgumentException if pathArguments is empty or contains a null element. * @throws NullPointerException if {@code pathArguments} is null */ private static InstanceIdentifier<?> internalCreate(final Iterable<PathArgument> pathArguments) { final Iterator<? extends PathArgument> it = requireNonNull(pathArguments, "pathArguments may not be null") .iterator(); final HashCodeBuilder<PathArgument> hashBuilder = new HashCodeBuilder<>(); boolean wildcard = false; PathArgument arg = null; while (it.hasNext()) { arg = it.next(); checkArgument(arg != null, "pathArguments may not contain null elements"); // TODO: sanity check ChildOf<>; hashBuilder.addArgument(arg); if (Identifiable.class.isAssignableFrom(arg.getType()) && !(arg instanceof IdentifiableItem<?, ?>)) { wildcard = true; } } checkArgument(arg != null, "pathArguments may not be empty"); return trustedCreate(arg, pathArguments, hashBuilder.build(), wildcard); }
@Override public DataContainerCodecContext<?,?> bindingPathArgumentChild(final InstanceIdentifier.PathArgument arg, final List<YangInstanceIdentifier.PathArgument> builder) { final Class<? extends DataObject> argType = arg.getType(); DataContainerCodecPrototype<?> ctxProto = byBindingArgClass.get(argType); if (ctxProto == null && Augmentation.class.isAssignableFrom(argType)) { ctxProto = augmentationByClass(argType); } final DataContainerCodecContext<?, ?> context = childNonNull(ctxProto, argType, "Class %s is not valid child of %s", argType, getBindingClass()).get(); if (context instanceof ChoiceNodeCodecContext) { final ChoiceNodeCodecContext<?> choice = (ChoiceNodeCodecContext<?>) context; choice.addYangPathArgument(arg, builder); final Optional<? extends Class<? extends DataObject>> caseType = arg.getCaseType(); final Class<? extends DataObject> type = arg.getType(); final DataContainerCodecContext<?, ?> caze; if (caseType.isPresent()) { // Non-ambiguous addressing this should not pose any problems caze = choice.streamChild(caseType.get()); } else { caze = choice.getCaseByChildClass(type); } caze.addYangPathArgument(arg, builder); return caze.bindingPathArgumentChild(arg, builder); } context.addYangPathArgument(arg, builder); return context; }
/** * Check whether this instance identifier contains the other identifier after wildcard expansion. This is similar * to {@link #contains(InstanceIdentifier)}, with the exception that a wildcards are assumed to match the their * non-wildcarded PathArgument counterpart. * * @param other Identifier which should be checked for inclusion. * @return true if this identifier contains the other object */ public final boolean containsWildcarded(final InstanceIdentifier<?> other) { requireNonNull(other, "other should not be null"); final Iterator<PathArgument> lit = pathArguments.iterator(); final Iterator<PathArgument> oit = other.pathArguments.iterator(); while (lit.hasNext()) { if (!oit.hasNext()) { return false; } final PathArgument la = lit.next(); final PathArgument oa = oit.next(); if (!la.getType().equals(oa.getType())) { return false; } if (la instanceof IdentifiableItem<?, ?> && oa instanceof IdentifiableItem<?, ?> && !la.equals(oa)) { return false; } } return true; }
/** * Check whether this instance identifier contains the other identifier after wildcard expansion. This is similar * to {@link #contains(InstanceIdentifier)}, with the exception that a wildcards are assumed to match the their * non-wildcarded PathArgument counterpart. * * @param other Identifier which should be checked for inclusion. * @return true if this identifier contains the other object */ public final boolean containsWildcarded(final InstanceIdentifier<?> other) { Preconditions.checkNotNull(other, "other should not be null"); final Iterator<PathArgument> lit = pathArguments.iterator(); final Iterator<PathArgument> oit = other.pathArguments.iterator(); while (lit.hasNext()) { if (!oit.hasNext()) { return false; } final PathArgument la = lit.next(); final PathArgument oa = oit.next(); if (!la.getType().equals(oa.getType())) { return false; } if (la instanceof IdentifiableItem<?, ?> && oa instanceof IdentifiableItem<?, ?> && !la.equals(oa)) { return false; } } return true; }
private static Optional<? extends DataObject> findNextParent(@Nonnull final DataObject parent, @Nonnull final InstanceIdentifier.PathArgument nextId, @Nonnull final Class<?> managedType) { Optional<Method> method = ReflectionUtils.findMethodReflex(managedType, "get", Collections.emptyList(), nextId.getType()); if (method.isPresent()) { return Optional.fromNullable(filterSingle(parent, nextId, method.get())); } else { // List child nodes method = ReflectionUtils.findMethodReflex(managedType, "get" + nextId.getType().getSimpleName(), Collections.emptyList(), List.class); if (method.isPresent()) { return filterList(parent, nextId, method.get()); } else { throw new IllegalStateException( "Unable to filter " + nextId + " from " + parent + " getters not found using reflexion"); } } }
/** * Return the key associated with the first component of specified type in * an identifier. * * @param listItem component type * @param listKey component key type * @return key associated with the component, or null if the component type * is not present. */ public final <N extends Identifiable<K> & DataObject, K extends Identifier<N>> K firstKeyOf(final Class<N> listItem, final Class<K> listKey) { for (final PathArgument i : pathArguments) { if (listItem.equals(i.getType())) { @SuppressWarnings("unchecked") final K ret = ((IdentifiableItem<N, K>)i).getKey(); return ret; } } return null; }
/** * Return the key associated with the first component of specified type in * an identifier. * * @param listItem component type * @return key associated with the component, or null if the component type * is not present. */ public final <N extends Identifiable<K> & DataObject, K extends Identifier<N>> K firstKeyOf( final Class<N> listItem) { for (final PathArgument i : pathArguments) { if (listItem.equals(i.getType())) { @SuppressWarnings("unchecked") final K ret = ((IdentifiableItem<N, K>)i).getKey(); return ret; } } return null; }
/** * Returns nested node context using supplied Binding Instance Identifier * and adds YANG instance identifiers to supplied list. * * @param arg Binding Instance Identifier Argument * @return Context of child or null if supplied {@code arg} does not represent valid child. * @throws IllegalArgumentException If supplied argument does not represent valid child. */ @Override public DataContainerCodecContext<?, ?> bindingPathArgumentChild(final PathArgument arg, final List<YangInstanceIdentifier.PathArgument> builder) { final DataContainerCodecContext<?,?> child = streamChild(arg.getType()); if (builder != null) { child.addYangPathArgument(arg,builder); } return child; }
/** * @param identifier InstanceIdentifier that will be checked * @param datastoreType Datastore type where datastore will be checked * @param <T> Any type extending DataObject * @return If All parents of provided path exists */ private <T extends DataObject> boolean checkParentExist(final InstanceIdentifier<T> identifier, final LogicalDatastoreType datastoreType) { final InstanceIdentifier.PathArgument[] arguments = Iterables.toArray(identifier.getPathArguments(), InstanceIdentifier.PathArgument.class); if (arguments.length < 2) return true; return readSynchronous(identifier.firstIdentifierOf(arguments[arguments.length - 2].getType()), datastoreType) != null; }
/** * Determine whether the flow filter list specified by the given instance * identifier is output filter or not. * * @param path Path to the virtual node in the flow filter list. * @return {@code true} only if the specified flow filter list is output * filter. */ public static final boolean isOutput(InstanceIdentifier<?> path) { for (PathArgument arg: path.getPathArguments()) { if (OUTPUT_FILTERS.contains(arg.getType())) { return true; } } return false; }
@Nonnull private static Optional<? extends DataObject> filterSubtree(@Nonnull final DataObject parent, @Nonnull final InstanceIdentifier<? extends DataObject> absolutPath, @Nonnull final Class<?> managedType) { final InstanceIdentifier.PathArgument nextId = RWUtils.getNextId(absolutPath, InstanceIdentifier.create(parent.getClass())); final Optional<? extends DataObject> nextParent = findNextParent(parent, nextId, managedType); if (Iterables.getLast(absolutPath.getPathArguments()).equals(nextId)) { return nextParent; // we found the dataObject identified by absolutePath } else if (nextParent.isPresent()) { return filterSubtree(nextParent.get(), absolutPath, nextId.getType()); } else { return nextParent; // we can't go further, return Optional.absent() } }
@Override public DataContainerCodecContext<?, ?> bindingPathArgumentChild(final InstanceIdentifier.PathArgument arg, final List<PathArgument> builder) { final Optional<? extends Class<? extends DataObject>> caseType = arg.getCaseType(); if (caseType.isPresent()) { // XXX: we use two caseType.get()s because of https://bugs.openjdk.java.net/browse/JDK-8144185, // which makes JaCoCo blow up if we try using @NonNull on the local variable. final ChoiceNodeCodecContext<?> choice = choicesByClass.getUnchecked(caseType.get()); choice.addYangPathArgument(arg, builder); final DataContainerCodecContext<?, ?> caze = choice.streamChild(caseType.get()); caze.addYangPathArgument(arg, builder); return caze.bindingPathArgumentChild(arg, builder); } return super.bindingPathArgumentChild(arg, builder); }