blob: 494ad4243bca94db858c81c9de3065c0da3e647e [file] [log] [blame]
Thomas Vachuskae586b792015-03-26 13:59:38 -07001/*
2 * Copyright 2015 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 */
16package org.onosproject.ui.impl;
17
18import com.fasterxml.jackson.databind.node.ArrayNode;
19import org.onosproject.ui.UiMessageHandler;
20
21import java.util.Set;
22
23/**
24 * Base message handler for tabular views.
25 */
26public abstract class AbstractTabularViewMessageHandler extends UiMessageHandler {
27
28 /**
29 * Creates a new tabular view message handler.
30 *
31 * @param messageTypes set of message types
32 */
33 protected AbstractTabularViewMessageHandler(Set<String> messageTypes) {
34 super(messageTypes);
35 }
36
37 /**
38 * Produces JSON from the specified array of rows.
39 *
40 * @param rows table rows
41 * @return JSON array
42 */
43 protected ArrayNode generateArrayNode(TableRow[] rows) {
44 ArrayNode array = mapper.createArrayNode();
45 for (TableRow r : rows) {
46 array.add(r.toJsonNode());
47 }
48 return array;
49 }
50
51 // TODO: possibly convert this into just a toolbox class
52 // TODO: extract and generalize other table constructs
53}