blob: f5bd860d68189123b74ec7292100fba600ae1666 [file] [log] [blame]
lishuai2ddc4692015-07-31 15:15:16 +08001/*
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.ovsdb.rfc.table;
17
18import org.onosproject.ovsdb.rfc.notation.Row;
19import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
20
21/**
22 * Table generator.
23 */
24public final class TableGenerator {
25
26 /**
27 * Constructs a TableGenerator object. Utility classes should not have a
28 * public or default constructor, otherwise it will compile failed. This
29 * class should not be instantiated.
30 */
31 private TableGenerator() {
32 }
33
34 /**
35 * Create table.
36 * @param dbSchema DatabaseSchema entity
37 * @param tableName table name
38 * @return Object table entity
39 */
andreaed976a42015-10-05 14:38:25 -070040 //FIXME change the name, it creates a row object, such as a controller.
lishuai2ddc4692015-07-31 15:15:16 +080041 public static Object createTable(DatabaseSchema dbSchema,
42 OvsdbTable tableName) {
43 Row row = new Row();
44 return generateTable(dbSchema, row, tableName);
45 }
46
47 /**
48 * Get table from Row.
49 * @param dbSchema DatabaseSchema entity
50 * @param row Row entity
51 * @param tableName table name
52 * @return Object table entity
53 */
54 public static Object getTable(DatabaseSchema dbSchema, Row row,
55 OvsdbTable tableName) {
56 return generateTable(dbSchema, row, tableName);
57 }
58
59 /**
60 * Generate the table by table name.
61 * @param dbSchema DatabaseSchema entity
62 * @param row Row entity
63 * @param tableName table name
64 * @return Object Table entity
65 */
66 private static Object generateTable(DatabaseSchema dbSchema, Row row,
67 OvsdbTable tableName) {
68 switch (tableName) {
69 case INTERFACE:
70 return new Interface(dbSchema, row);
71 case BRIDGE:
72 return new Bridge(dbSchema, row);
73 case CONTROLLER:
74 return new Controller(dbSchema, row);
75 case OPENVSWITCH:
76 return new OpenVSwitch(dbSchema, row);
77 case PORT:
78 return new Port(dbSchema, row);
lishuai050145c2015-08-05 11:12:39 +080079 case FLWTABLE:
80 return new FlowTable(dbSchema, row);
81 case QOS:
82 return new Qos(dbSchema, row);
83 case QUEUE:
84 return new Queue(dbSchema, row);
85 case MIRROR:
86 return new Mirror(dbSchema, row);
87 case MANAGER:
88 return new Manager(dbSchema, row);
89 case NETFLOW:
90 return new Netflow(dbSchema, row);
91 case SSL:
92 return new Ssl(dbSchema, row);
93 case SFLOW:
94 return new Sflow(dbSchema, row);
95 case IPFIX:
96 return new Ipfix(dbSchema, row);
97 case FLOWSAMPLECOLLECTORSET:
98 return new FlowSampleCollectorSet(dbSchema, row);
lishuai2ddc4692015-07-31 15:15:16 +080099 default:
100 return null;
101 }
102 }
103}