blob: f8b72dfc1fc862fca1ae7f82db7465e97993614a [file] [log] [blame]
Thomas Vachuskaf0e1fae2015-04-24 00:51:51 -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 */
Ray Milkeya4122362015-08-18 15:19:08 -070016package org.onosproject.net.config;
Thomas Vachuskaf0e1fae2015-04-24 00:51:51 -070017
18
Thomas Vachuskae2b7e7e2015-05-20 11:11:31 -070019import com.google.common.annotations.Beta;
20
Thomas Vachuskaf0e1fae2015-04-24 00:51:51 -070021/**
22 * Base abstract factory for creating configurations for the specified subject type.
23 *
Thomas Vachuska96d55b12015-05-11 08:52:03 -070024 * @param <S> type of subject
25 * @param <C> type of configuration
Thomas Vachuskaf0e1fae2015-04-24 00:51:51 -070026 */
Thomas Vachuskae2b7e7e2015-05-20 11:11:31 -070027@Beta
Thomas Vachuska96d55b12015-05-11 08:52:03 -070028public abstract class ConfigFactory<S, C extends Config<S>> {
Thomas Vachuskaf0e1fae2015-04-24 00:51:51 -070029
Thomas Vachuska96d55b12015-05-11 08:52:03 -070030 private final SubjectFactory<S> subjectFactory;
31 private final Class<C> configClass;
32 private final String configKey;
Thomas Vachuskaf0e1fae2015-04-24 00:51:51 -070033
34 /**
35 * Creates a new configuration factory for the specified class of subjects
Thomas Vachuska96d55b12015-05-11 08:52:03 -070036 * capable of generating the configurations of the specified class. The
37 * subject and configuration class keys are used merely as keys for use in
38 * composite JSON trees.
Thomas Vachuskaf0e1fae2015-04-24 00:51:51 -070039 *
Thomas Vachuska96d55b12015-05-11 08:52:03 -070040 * @param subjectFactory subject factory
41 * @param configClass configuration class
42 * @param configKey configuration class key
Thomas Vachuskaf0e1fae2015-04-24 00:51:51 -070043 */
Thomas Vachuska96d55b12015-05-11 08:52:03 -070044 protected ConfigFactory(SubjectFactory<S> subjectFactory,
45 Class<C> configClass, String configKey) {
46 this.subjectFactory = subjectFactory;
47 this.configClass = configClass;
48 this.configKey = configKey;
Thomas Vachuskaf0e1fae2015-04-24 00:51:51 -070049 }
50
51 /**
52 * Returns the class of the subject to which this factory applies.
53 *
54 * @return subject type
55 */
Thomas Vachuska96d55b12015-05-11 08:52:03 -070056 public SubjectFactory<S> subjectFactory() {
57 return subjectFactory;
Thomas Vachuskaf0e1fae2015-04-24 00:51:51 -070058 }
59
60 /**
Thomas Vachuska96d55b12015-05-11 08:52:03 -070061 * Returns the class of the configuration which this factory generates.
Thomas Vachuskaf0e1fae2015-04-24 00:51:51 -070062 *
Thomas Vachuska96d55b12015-05-11 08:52:03 -070063 * @return configuration type
Thomas Vachuskaf0e1fae2015-04-24 00:51:51 -070064 */
Thomas Vachuska96d55b12015-05-11 08:52:03 -070065 public Class<C> configClass() {
66 return configClass;
67 }
68
69 /**
70 * Returns the unique key (within subject class) of this configuration.
71 * This is primarily aimed for use in composite JSON trees in external
72 * representations and has no bearing on the internal behaviours.
73 *
74 * @return configuration key
75 */
76 public String configKey() {
77 return configKey;
Thomas Vachuskaf0e1fae2015-04-24 00:51:51 -070078 }
79
80 /**
81 * Creates a new but uninitialized configuration. Framework will initialize
82 * the configuration via {@link Config#init} method.
83 *
84 * @return new uninitialized configuration
85 */
Thomas Vachuska96d55b12015-05-11 08:52:03 -070086 public abstract C createConfig();
Thomas Vachuskaf0e1fae2015-04-24 00:51:51 -070087
88}