2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.sal.binding.generator.util;
10 import java.util.List;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.*;
15 import com.google.common.base.Preconditions;
17 public class YangSchemaUtils {
19 public static final String AUGMENT_IDENTIFIER = "augment-identifier";
22 public YangSchemaUtils() {
23 throw new UnsupportedOperationException("Helper class. Instantiation is prohibited");
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) {
33 for(DataSchemaNode child : augmentation.getChildNodes()) {
34 // FIXME: Return true name
35 return QName.create(child.getQName(), "foo_augment");
37 // FIXME: Allways return a qname with module namespace.
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();
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) {
59 Preconditions.checkArgument(arguments.size() == 1);
60 for (QName qName : arguments) {
61 //previous.getDataChildByName(qName);
63 for(TypeDefinition<?> typedef : previous.getTypeDefinitions()) {
64 if(typedef.getQName().equals(typeQName)) {