chengfan | c58d4be | 2016-09-20 10:33:12 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.protocol.restconf.server.utils.parser.api; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.node.JsonNodeType; |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | |
| 21 | import java.util.Set; |
| 22 | |
| 23 | /** |
| 24 | * Abstraction of an entity which provides interfaces to build and obtain JSON |
| 25 | * data tree. |
| 26 | */ |
| 27 | public interface JsonBuilder { |
| 28 | |
| 29 | /** |
| 30 | * Adds a to half (a left brace/bracket and the field name) of a JSON |
| 31 | * object/array to the JSON tree. This method is used by protocols which |
| 32 | * knows the nature (object/array) of node. |
| 33 | * |
| 34 | * @param fieldName name of child to be added |
| 35 | * @param nodeType the type of the child |
| 36 | */ |
| 37 | void addNodeTopHalf(String fieldName, JsonNodeType nodeType); |
| 38 | |
| 39 | /** |
| 40 | * Adds a child with value and a comma to the JSON tree. |
| 41 | * Protocols unaware of nature of node (single/multiple) will use it to add |
| 42 | * both single instance and multi instance node. Protocols aware of nature |
| 43 | * of node will use it for single instance value node addition. |
| 44 | * |
| 45 | * @param fieldName name of child to be added |
| 46 | * @param value the type of the child |
| 47 | */ |
| 48 | void addNodeWithValueTopHalf(String fieldName, String value); |
| 49 | |
| 50 | /** |
| 51 | * Adds a child with list of values to JSON data tree. This method is |
| 52 | * used by protocols which knows the nature (object/array) of node for |
| 53 | * ArrayNode addition. |
| 54 | * |
| 55 | * @param fieldName name of child to be added |
| 56 | * @param sets the value list of the child |
| 57 | */ |
| 58 | void addNodeWithSetTopHalf(String fieldName, Set<String> sets); |
| 59 | |
| 60 | /** |
| 61 | * Adds the bottom half(a right brace/bracket) of a JSON object/array to |
| 62 | * the JSON tree. for the text, a comma should be taken out. |
| 63 | * |
| 64 | * @param nodeType the type of the child |
| 65 | */ |
| 66 | void addNodeBottomHalf(JsonNodeType nodeType); |
| 67 | |
| 68 | /** |
| 69 | * Returns the JSON tree after build operations in the format of string. |
| 70 | * |
| 71 | * @return the final string JSON tree after build operations |
| 72 | */ |
| 73 | String getTreeString(); |
| 74 | |
| 75 | /** |
| 76 | * Returns the JSON tree after build operations in the format of ObjectNode. |
| 77 | * |
| 78 | * @return the final ObjectNode JSON tree after build operations |
| 79 | */ |
| 80 | ObjectNode getTreeNode(); |
| 81 | } |