Move RuntimeGeneratedMappingService from md-sal to yang-data-impl(codecs + apis)...
[yangtools.git] / code-generator / binding-generator-impl / src / main / java / org / opendaylight / yangtools / sal / binding / generator / util / YangSchemaUtils.java
1 package org.opendaylight.yangtools.sal.binding.generator.util;
2
3 import java.util.List;
4
5 import org.opendaylight.yangtools.yang.common.QName;
6 import org.opendaylight.yangtools.yang.model.api.*;
7
8 import com.google.common.base.Preconditions;
9
10 public class YangSchemaUtils {
11
12     public static final String AUGMENT_IDENTIFIER = "augment-identifier";
13
14
15     public YangSchemaUtils() {
16         throw new UnsupportedOperationException("Helper class. Instantiation is prohibited");
17     }
18
19
20     public static QName getAugmentationQName(AugmentationSchema augmentation) {
21         Preconditions.checkNotNull(augmentation, "Augmentation must not be null.");
22         QName identifier = getAugmentationIdentifier(augmentation);
23         if(identifier != null) {
24             return identifier;
25         }
26         for(DataSchemaNode child : augmentation.getChildNodes()) {
27             // FIXME: Return true name
28             return QName.create(child.getQName(), "foo_augment");
29         }
30         // FIXME: Allways return a qname with module namespace.
31         return null;
32     }
33
34     public static QName getAugmentationIdentifier(AugmentationSchema augmentation) {
35         for(UnknownSchemaNode extension : augmentation.getUnknownSchemaNodes()) {
36             if(AUGMENT_IDENTIFIER.equals(extension.getNodeType().getLocalName())) {
37                 return extension.getQName();
38             }
39         }
40         return null;
41     }
42
43
44     public static TypeDefinition<?> findTypeDefinition(SchemaContext context, SchemaPath path) {
45         List<QName> arguments = path.getPath();
46         QName first = arguments.get(0);
47         QName typeQName = arguments.get(arguments.size() -1);
48         DataNodeContainer previous = context.findModuleByNamespaceAndRevision(first.getNamespace(), first.getRevision());
49         if(previous == null) {
50             return null;
51         }
52         Preconditions.checkArgument(arguments.size() == 1);
53         for (QName qName : arguments) {
54             //previous.getDataChildByName(qName);
55         }
56         for(TypeDefinition<?> typedef : previous.getTypeDefinitions()) {
57             if(typedef.getQName().equals(typeQName)) {
58                 return typedef;
59             }
60         }
61         return null;
62     }
63 }