d7232374f8d862343f51c47f72b23435e71173f3
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / AugmentationModificationStrategy.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11
12 import java.util.HashSet;
13 import java.util.Set;
14 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
17 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
18 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAugmentationNodeBuilder;
19 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
21 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
22 import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema;
23
24 final class AugmentationModificationStrategy
25         extends AbstractDataNodeContainerModificationStrategy<AugmentationSchemaNode> {
26     AugmentationModificationStrategy(final AugmentationSchemaNode schema, final DataNodeContainer resolved,
27             final DataTreeConfiguration treeConfig) {
28         super(createAugmentProxy(schema,resolved), AugmentationNode.class, treeConfig);
29     }
30
31     @Override
32     @SuppressWarnings("rawtypes")
33     protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
34         checkArgument(original instanceof AugmentationNode);
35         return ImmutableAugmentationNodeBuilder.create((AugmentationNode) original);
36     }
37
38     @Override
39     protected NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) {
40         checkArgument(original instanceof AugmentationNode);
41         return ImmutableAugmentationNodeBuilder.create()
42                 .withNodeIdentifier(((AugmentationNode) original).getIdentifier()).build();
43     }
44
45     private static AugmentationSchemaNode createAugmentProxy(final AugmentationSchemaNode schema,
46             final DataNodeContainer resolved) {
47         final Set<DataSchemaNode> realChildSchemas = new HashSet<>();
48         for (final DataSchemaNode augChild : schema.getChildNodes()) {
49             realChildSchemas.add(resolved.getDataChildByName(augChild.getQName()));
50         }
51         return new EffectiveAugmentationSchema(schema, realChildSchemas);
52     }
53 }