Added getParent() method to DataSchemaNode and DataNodeContainer. Fixed Bugs.
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / api / AbstractSchemaNodeBuilder.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\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
7  */\r
8 package org.opendaylight.yangtools.yang.parser.builder.api;\r
9 \r
10 import java.util.List;\r
11 \r
12 import org.opendaylight.yangtools.yang.common.QName;\r
13 import org.opendaylight.yangtools.yang.model.api.SchemaPath;\r
14 import org.opendaylight.yangtools.yang.model.api.Status;\r
15 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;\r
16 \r
17 /**\r
18  * Basic implementation of SchemaNodeBuilder.\r
19  */\r
20 public abstract class AbstractSchemaNodeBuilder extends AbstractBuilder implements SchemaNodeBuilder {\r
21     protected QName qname;\r
22     protected SchemaPath schemaPath;\r
23     protected String description;\r
24     protected String reference;\r
25     protected Status status = Status.CURRENT;\r
26 \r
27     protected AbstractSchemaNodeBuilder(final String moduleName, final int line, final QName qname) {\r
28         super(moduleName, line);\r
29         this.qname = qname;\r
30     }\r
31 \r
32     @Override\r
33     public int hashCode() {\r
34         final int prime = 31;\r
35         int result = super.hashCode();\r
36         result = prime * result + ((parentBuilder == null) ? 0 : parentBuilder.hashCode());\r
37         result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());\r
38         return result;\r
39     }\r
40 \r
41     @Override\r
42     public boolean equals(Object obj) {\r
43         if (this == obj) {\r
44             return true;\r
45         }\r
46         if (obj == null) {\r
47             return false;\r
48         }\r
49         if (getClass() != obj.getClass()) {\r
50             return false;\r
51         }\r
52         if (!super.equals(obj)) {\r
53             return false;\r
54         }\r
55         AbstractSchemaNodeBuilder other = (AbstractSchemaNodeBuilder) obj;\r
56         if (parentBuilder == null) {\r
57             if (other.parentBuilder != null) {\r
58                 return false;\r
59             }\r
60         } else if (!parentBuilder.equals(other.parentBuilder)) {\r
61             return false;\r
62         }\r
63         if (schemaPath == null) {\r
64             if (other.schemaPath != null) {\r
65                 return false;\r
66             }\r
67         } else if (!schemaPath.equals(other.schemaPath)) {\r
68             return false;\r
69         }\r
70         return true;\r
71     }\r
72 \r
73     public QName getQName() {\r
74         return qname;\r
75     }\r
76 \r
77     @Override\r
78     public SchemaPath getPath() {\r
79         return schemaPath;\r
80     }\r
81 \r
82     @Override\r
83     public void setPath(SchemaPath schemaPath) {\r
84         this.schemaPath = schemaPath;\r
85     }\r
86 \r
87     @Override\r
88     public String getDescription() {\r
89         return description;\r
90     }\r
91 \r
92     @Override\r
93     public void setDescription(String description) {\r
94         this.description = description;\r
95     }\r
96 \r
97     @Override\r
98     public String getReference() {\r
99         return reference;\r
100     }\r
101 \r
102     @Override\r
103     public void setReference(String reference) {\r
104         this.reference = reference;\r
105     }\r
106 \r
107     @Override\r
108     public Status getStatus() {\r
109         return status;\r
110     }\r
111 \r
112     @Override\r
113     public void setStatus(Status status) {\r
114         if (status != null) {\r
115             this.status = status;\r
116         }\r
117     }\r
118 \r
119     public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {\r
120         this.unknownNodes = unknownNodes;\r
121     }\r
122 \r
123 }\r