2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.dom.adapter.query;
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.mdsal.binding.api.query.DescendantQueryBuilder;
12 import org.opendaylight.mdsal.binding.api.query.MatchBuilderPath;
13 import org.opendaylight.mdsal.binding.api.query.QueryExpression;
14 import org.opendaylight.yangtools.yang.binding.ChildOf;
15 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.opendaylight.yangtools.yang.binding.Key;
19 import org.opendaylight.yangtools.yang.binding.KeyAware;
21 final class DefaultDescendantQueryBuilder<R extends DataObject, T extends DataObject>
22 implements DescendantQueryBuilder<T> {
23 private final InstanceIdentifier.Builder<T> childPath;
24 private final QueryBuilderState builder;
26 DefaultDescendantQueryBuilder(final DefaultQueryFactory factory, final InstanceIdentifier<T> rootPath) {
27 builder = new QueryBuilderState(factory, rootPath);
28 childPath = rootPath.builder();
32 @SuppressWarnings("unchecked")
33 public <N extends ChildOf<? super T>> DescendantQueryBuilder<N> extractChild(final Class<N> childClass) {
34 childPath.child(childClass);
35 return (DefaultDescendantQueryBuilder<R, N>) this;
39 @SuppressWarnings("unchecked")
40 public <C extends ChoiceIn<? super T> & DataObject, N extends ChildOf<? super C>>
41 DescendantQueryBuilder<N> extractChild(final Class<C> caseClass, final Class<N> childClass) {
42 childPath.child(caseClass, childClass);
43 return (DefaultDescendantQueryBuilder<R, N>) this;
47 @SuppressWarnings("unchecked")
48 public <N extends KeyAware<K> & ChildOf<? super T>, K extends Key<N>> DescendantQueryBuilder<N> extractChild(
49 final Class<@NonNull N> listItem, final K listKey) {
50 childPath.child(listItem, listKey);
51 return (DefaultDescendantQueryBuilder<R, N>) this;
55 public MatchBuilderPath<T, T> matching() {
56 final InstanceIdentifier<T> selectPath = childPath.build();
57 builder.setSelectPath(selectPath);
58 return new DefaultMatchBuilderPath<>(builder, selectPath, childPath);
62 public QueryExpression<T> build() {
63 builder.setSelectPath(childPath.build());
64 return builder.buildQuery();