2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.yang.model.parser.builder.impl;
\r
10 import java.util.ArrayList;
\r
11 import java.util.Collections;
\r
12 import java.util.HashSet;
\r
13 import java.util.List;
\r
14 import java.util.Map;
\r
15 import java.util.Set;
\r
17 import org.opendaylight.controller.yang.common.QName;
\r
18 import org.opendaylight.controller.yang.model.api.AugmentationSchema;
\r
19 import org.opendaylight.controller.yang.model.api.SchemaNode;
\r
20 import org.opendaylight.controller.yang.model.api.SchemaPath;
\r
21 import org.opendaylight.controller.yang.model.api.UsesNode;
\r
22 import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder;
\r
23 import org.opendaylight.controller.yang.model.parser.builder.api.Builder;
\r
24 import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder;
\r
26 public class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder {
\r
28 private final UsesNodeImpl instance;
\r
29 private final Set<AugmentationSchemaBuilder> addedAugments = new HashSet<AugmentationSchemaBuilder>();
\r
31 UsesNodeBuilderImpl(String groupingPathStr) {
\r
32 SchemaPath groupingPath = parseUsesPath(groupingPathStr);
\r
33 instance = new UsesNodeImpl(groupingPath);
\r
37 public UsesNode build() {
\r
39 final Set<AugmentationSchema> augments = new HashSet<AugmentationSchema>();
\r
40 for (AugmentationSchemaBuilder builder : addedAugments) {
\r
41 augments.add(builder.build());
\r
43 instance.setAugmentations(augments);
\r
49 public void addAugment(AugmentationSchemaBuilder augmentBuilder) {
\r
50 addedAugments.add(augmentBuilder);
\r
54 public void setAugmenting(boolean augmenting) {
\r
55 instance.setAugmenting(augmenting);
\r
58 private SchemaPath parseUsesPath(String augmentPath) {
\r
59 String[] splittedPath = augmentPath.split("/");
\r
60 List<QName> path = new ArrayList<QName>();
\r
62 for (String pathElement : splittedPath) {
\r
63 String[] splittedElement = pathElement.split(":");
\r
64 if (splittedElement.length == 1) {
\r
65 name = new QName(null, null, null, splittedElement[0]);
\r
67 name = new QName(null, null, splittedElement[0],
\r
68 splittedElement[1]);
\r
72 final boolean absolute = augmentPath.startsWith("/");
\r
73 return new SchemaPath(path, absolute);
\r
76 private static class UsesNodeImpl implements UsesNode {
\r
78 private final SchemaPath groupingPath;
\r
79 private Set<AugmentationSchema> augmentations = Collections.emptySet();
\r
80 private boolean augmenting;
\r
82 private UsesNodeImpl(SchemaPath groupingPath) {
\r
83 this.groupingPath = groupingPath;
\r
87 public SchemaPath getGroupingPath() {
\r
88 return groupingPath;
\r
92 public Set<AugmentationSchema> getAugmentations() {
\r
93 return augmentations;
\r
96 private void setAugmentations(Set<AugmentationSchema> augmentations) {
\r
97 if (augmentations != null) {
\r
98 this.augmentations = augmentations;
\r
103 public boolean isAugmenting() {
\r
107 private void setAugmenting(boolean augmenting) {
\r
108 this.augmenting = augmenting;
\r
113 public Map<SchemaPath, SchemaNode> getRefines() {
\r
114 // TODO Auto-generated method stub
\r
119 public int hashCode() {
\r
120 final int prime = 31;
\r
122 result = prime * result + ((groupingPath == null) ? 0 : groupingPath.hashCode());
\r
123 result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode());
\r
124 result = prime * result + (augmenting ? 1231 : 1237);
\r
129 public boolean equals(Object obj) {
\r
136 if (getClass() != obj.getClass()) {
\r
139 UsesNodeImpl other = (UsesNodeImpl) obj;
\r
140 if (groupingPath == null) {
\r
141 if (other.groupingPath != null) {
\r
144 } else if (!groupingPath.equals(other.groupingPath)) {
\r
147 if (augmentations == null) {
\r
148 if (other.augmentations != null) {
\r
151 } else if (!augmentations.equals(other.augmentations)) {
\r
154 if (augmenting != other.augmenting) {
\r
161 public String toString() {
\r
162 StringBuilder sb = new StringBuilder(
\r
163 UsesNodeImpl.class.getSimpleName());
\r
164 sb.append("[groupingPath=" + groupingPath +"]");
\r
165 return sb.toString();
\r