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 static com.google.common.base.Preconditions.checkArgument;
11 import static com.google.common.base.Preconditions.checkNotNull;
12 import static com.google.common.base.Preconditions.checkState;
15 import java.util.Date;
16 import java.util.List;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
20 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
21 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.NamespaceRevisionAware;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
25 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
26 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
28 public class YangSchemaUtils {
30 public static final String AUGMENT_IDENTIFIER = "augment-identifier";
33 public YangSchemaUtils() {
34 throw new UnsupportedOperationException("Helper class. Instantiation is prohibited");
38 public static QName getAugmentationQName(AugmentationSchema augmentation) {
39 checkNotNull(augmentation, "Augmentation must not be null.");
40 QName identifier = getAugmentationIdentifier(augmentation);
41 if(identifier != null) {
46 if(augmentation instanceof NamespaceRevisionAware) {
47 namespace = ((NamespaceRevisionAware) augmentation).getNamespace();
48 revision = ((NamespaceRevisionAware) augmentation).getRevision();
50 if(namespace == null || revision == null)
51 for(DataSchemaNode child : augmentation.getChildNodes()) {
52 // Derive QName from child nodes
53 if(!child.isAugmenting()) {
54 namespace = child.getQName().getNamespace();
55 revision = child.getQName().getRevision();
59 checkState(namespace != null, "Augmentation namespace must not be null");
60 checkState(revision != null, "Augmentation revision must not be null");
61 // FIXME: Allways return a qname with module namespace.
62 return QName.create(namespace,revision, "foo_augment");
65 public static QName getAugmentationIdentifier(AugmentationSchema augmentation) {
66 for(UnknownSchemaNode extension : augmentation.getUnknownSchemaNodes()) {
67 if(AUGMENT_IDENTIFIER.equals(extension.getNodeType().getLocalName())) {
68 return extension.getQName();
75 public static TypeDefinition<?> findTypeDefinition(SchemaContext context, SchemaPath path) {
76 List<QName> arguments = path.getPath();
77 QName first = arguments.get(0);
78 QName typeQName = arguments.get(arguments.size() -1);
79 DataNodeContainer previous = context.findModuleByNamespaceAndRevision(first.getNamespace(), first.getRevision());
80 if(previous == null) {
83 checkArgument(arguments.size() == 1);
84 for (QName qName : arguments) {
85 //previous.getDataChildByName(qName);
87 for(TypeDefinition<?> typedef : previous.getTypeDefinitions()) {
88 if(typedef.getQName().equals(typeQName)) {