726c40c02ca56343d79d498b3529bdd4240d22e0
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / transform / base / AugmentationSchemaProxy.java
1 /*
2  * Copyright (c) 2013 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.transform.base;
9
10 import java.util.List;
11 import java.util.Map;
12 import java.util.Set;
13
14 import com.google.common.collect.Maps;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.*;
17
18 /**
19  * Proxy for AugmentationSchema. Child node schemas are replaced with actual schemas from parent.
20  */
21 public final class AugmentationSchemaProxy implements AugmentationSchema {
22     private final AugmentationSchema delegate;
23     private final Set<DataSchemaNode> realChildSchemas;
24     private final Map<QName, DataSchemaNode> mappedChildSchemas;
25
26     public AugmentationSchemaProxy(AugmentationSchema augmentSchema, Set<DataSchemaNode> realChildSchemas) {
27         this.delegate = augmentSchema;
28         this.realChildSchemas = realChildSchemas;
29
30         this.mappedChildSchemas = Maps.newHashMap();
31         for (DataSchemaNode realChildSchema : realChildSchemas) {
32             mappedChildSchemas.put(realChildSchema.getQName(), realChildSchema);
33         }
34     }
35
36     @Override
37     public RevisionAwareXPath getWhenCondition() {
38         return delegate.getWhenCondition();
39     }
40
41     @Override
42     public String getDescription() {
43         return delegate.getDescription();
44     }
45
46     @Override
47     public String getReference() {
48         return delegate.getReference();
49     }
50
51     @Override
52     public Status getStatus() {
53         return delegate.getStatus();
54     }
55
56     @Override
57     public SchemaPath getTargetPath() {
58         return delegate.getTargetPath();
59     }
60
61     @Override
62     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
63         return delegate.getUnknownSchemaNodes();
64     }
65
66     @Override
67     public Set<TypeDefinition<?>> getTypeDefinitions() {
68         return delegate.getTypeDefinitions();
69     }
70
71     @Override
72     public Set<DataSchemaNode> getChildNodes() {
73         return realChildSchemas;
74     }
75
76     @Override
77     public Set<GroupingDefinition> getGroupings() {
78         return delegate.getGroupings();
79     }
80
81     @Override
82     public DataSchemaNode getDataChildByName(QName name) {
83         if(mappedChildSchemas.containsKey(name)) {
84             return mappedChildSchemas.get(name);
85         }
86
87         throw new IllegalArgumentException("Unknown child: " + name + " in: " + delegate);
88     }
89
90     @Override
91     public DataSchemaNode getDataChildByName(String name) {
92         // Unused
93         throw new UnsupportedOperationException("Unable to retrieve child node by name");
94     }
95
96     @Override
97     public Set<UsesNode> getUses() {
98         return delegate.getUses();
99     }
100 }