BUG 1440 - json stream to normalized node stream writer
[yangtools.git] / yang / yang-data-codec-gson / src / main / java / org / opendaylight / yangtools / yang / data / codec / gson / AbstractNodeDataWithSchema.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.codec.gson;
9
10 import java.io.IOException;
11
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
14 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
15
16 abstract class AbstractNodeDataWithSchema {
17
18     private final DataSchemaNode schema;
19
20     public AbstractNodeDataWithSchema(final DataSchemaNode schema) {
21         this.schema = schema;
22     }
23
24     public final DataSchemaNode getSchema() {
25         return schema;
26     }
27
28     protected abstract void writeToStream(final NormalizedNodeStreamWriter nnStreamWriter) throws IOException;
29
30     protected NodeIdentifier provideNodeIdentifier() {
31         return new NodeIdentifier(schema.getQName());
32     }
33
34     @Override
35     public int hashCode() {
36         final int prime = 31;
37         int result = 1;
38         result = prime * result + ((schema == null) ? 0 : schema.hashCode());
39         return result;
40     }
41
42     @Override
43     public boolean equals(final Object obj) {
44         if (this == obj) {
45             return true;
46         }
47         if (obj == null) {
48             return false;
49         }
50         if (getClass() != obj.getClass()) {
51             return false;
52         }
53         AbstractNodeDataWithSchema other = (AbstractNodeDataWithSchema) obj;
54         if (schema == null) {
55             if (other.schema != null) {
56                 return false;
57             }
58         } else if (!schema.equals(other.schema)) {
59             return false;
60         }
61
62         return true;
63     }
64
65 }