2 * Copyright (c) 2014, 2015 EBay Software Foundation and others. All rights reserved.
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
8 package org.opendaylight.ovsdb.lib.schema;
10 import com.fasterxml.jackson.databind.JsonNode;
11 import java.util.HashMap;
12 import java.util.Iterator;
14 import org.opendaylight.ovsdb.lib.error.BadSchemaException;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 public class GenericTableSchema extends TableSchema<GenericTableSchema> {
19 private static final Logger LOG = LoggerFactory.getLogger(GenericTableSchema.class);
21 public GenericTableSchema(final String name) {
25 public GenericTableSchema(final String name, final Map<String, ColumnSchema> columns) {
29 public GenericTableSchema(final TableSchema tableSchema) {
30 super(tableSchema.getName(), tableSchema.getColumnSchemas());
33 public static GenericTableSchema fromJson(final String tableName, final JsonNode json) {
34 if (!json.isObject() || !json.has("columns")) {
35 throw new BadSchemaException("bad tableschema root, expected \"columns\" as child");
38 Map<String, ColumnSchema> columns = new HashMap<>();
39 for (Iterator<Map.Entry<String, JsonNode>> iter = json.get("columns").fields(); iter.hasNext(); ) {
40 Map.Entry<String, JsonNode> column = iter.next();
41 LOG.trace("fromJson() table/column = {}:{}", tableName, column.getKey());
42 columns.put(column.getKey(), ColumnSchema.fromJson(column.getKey(), column.getValue()));
45 return new GenericTableSchema(tableName, columns);