2 * Copyright (c) 2013 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.yang.parser.builder.impl;
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableList;
12 import com.google.common.collect.ImmutableSet;
13 import java.util.ArrayList;
14 import java.util.List;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
17 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
20 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationTargetBuilder;
21 import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
22 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
23 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
24 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
26 public final class NotificationBuilder extends AbstractDocumentedDataNodeContainerBuilder implements SchemaNodeBuilder,
27 AugmentationTargetBuilder {
28 private NotificationDefinitionImpl instance;
30 private SchemaPath schemaPath;
31 // AugmentationTarget args
32 private final List<AugmentationSchema> augmentations = new ArrayList<>();
33 private final List<AugmentationSchemaBuilder> augmentationBuilders = new ArrayList<>();
35 NotificationBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path) {
36 super(moduleName, line, qname);
37 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
40 NotificationBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path,
41 final NotificationDefinition base) {
42 super(moduleName, line, qname, path, base);
43 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
45 addedUnknownNodes.addAll(BuilderUtils.wrapUnknownNodes(moduleName, line, base.getUnknownSchemaNodes(), path,
47 augmentations.addAll(base.getAvailableAugmentations());
52 public NotificationDefinition build() {
53 if (!(getParent() instanceof ModuleBuilder)) {
54 throw new YangParseException(getModuleName(), getLine(),
55 "Notification can be defined only under module (was " + getParent() + ")");
57 if (instance != null) {
62 instance = new NotificationDefinitionImpl(qname, schemaPath, this);
65 for (AugmentationSchemaBuilder builder : augmentationBuilders) {
66 augmentations.add(builder.build());
68 instance.augmentations = ImmutableSet.copyOf(augmentations);
71 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
72 unknownNodes.add(b.build());
74 instance.unknownNodes = ImmutableList.copyOf(unknownNodes);
80 public SchemaPath getPath() {
85 public void setPath(final SchemaPath path) {
86 this.schemaPath = path;
90 public void addAugmentation(final AugmentationSchemaBuilder augment) {
91 augmentationBuilders.add(augment);
95 public String toString() {
96 return "notification " + getQName().getLocalName();
100 protected String getStatementName() {
101 return "notification";