1 package org.opendaylight.yangtools.sal.binding.generator.util;
5 import org.opendaylight.yangtools.yang.common.QName;
6 import org.opendaylight.yangtools.yang.model.api.*;
8 import com.google.common.base.Preconditions;
10 public class YangSchemaUtils {
12 public static final String AUGMENT_IDENTIFIER = "augment-identifier";
15 public YangSchemaUtils() {
16 throw new UnsupportedOperationException("Helper class. Instantiation is prohibited");
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) {
26 for(DataSchemaNode child : augmentation.getChildNodes()) {
27 // FIXME: Return true name
28 return QName.create(child.getQName(), "foo_augment");
30 // FIXME: Allways return a qname with module namespace.
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();
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) {
52 Preconditions.checkArgument(arguments.size() == 1);
53 for (QName qName : arguments) {
54 //previous.getDataChildByName(qName);
56 for(TypeDefinition<?> typedef : previous.getTypeDefinitions()) {
57 if(typedef.getQName().equals(typeQName)) {