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