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;
27 * @deprecated Pre-Beryllium implementation, scheduled for removal.
30 public final class NotificationBuilder extends AbstractDocumentedDataNodeContainerBuilder implements SchemaNodeBuilder,
31 AugmentationTargetBuilder {
32 private NotificationDefinitionImpl instance;
34 private SchemaPath schemaPath;
35 // AugmentationTarget args
36 private final List<AugmentationSchema> augmentations = new ArrayList<>();
37 private final List<AugmentationSchemaBuilder> augmentationBuilders = new ArrayList<>();
39 NotificationBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path) {
40 super(moduleName, line, qname);
41 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
44 NotificationBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path,
45 final NotificationDefinition base) {
46 super(moduleName, line, qname, path, base);
47 this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
49 addedUnknownNodes.addAll(BuilderUtils.wrapUnknownNodes(moduleName, line, base.getUnknownSchemaNodes(), path,
51 augmentations.addAll(base.getAvailableAugmentations());
56 public NotificationDefinition build() {
57 if (!(getParent() instanceof ModuleBuilder)) {
58 throw new YangParseException(getModuleName(), getLine(),
59 "Notification can be defined only under module (was " + getParent() + ")");
61 if (instance != null) {
66 instance = new NotificationDefinitionImpl(qname, schemaPath, this);
69 for (AugmentationSchemaBuilder builder : augmentationBuilders) {
70 augmentations.add(builder.build());
72 instance.augmentations = ImmutableSet.copyOf(augmentations);
75 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
76 unknownNodes.add(b.build());
78 instance.unknownNodes = ImmutableList.copyOf(unknownNodes);
84 public SchemaPath getPath() {
89 public void setPath(final SchemaPath path) {
90 this.schemaPath = path;
94 public void addAugmentation(final AugmentationSchemaBuilder augment) {
95 augmentationBuilders.add(augment);
99 public String toString() {
100 return "notification " + getQName().getLocalName();
104 protected String getStatementName() {
105 return "notification";