Thomas Vachuska | f0e1fae | 2015-04-24 00:51:51 -0700 | [diff] [blame] | 1 | /* |
| 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 Milkey | a412236 | 2015-08-18 15:19:08 -0700 | [diff] [blame] | 16 | package org.onosproject.net.config; |
Thomas Vachuska | f0e1fae | 2015-04-24 00:51:51 -0700 | [diff] [blame] | 17 | |
| 18 | |
Thomas Vachuska | e2b7e7e | 2015-05-20 11:11:31 -0700 | [diff] [blame] | 19 | import com.google.common.annotations.Beta; |
| 20 | |
Thomas Vachuska | f0e1fae | 2015-04-24 00:51:51 -0700 | [diff] [blame] | 21 | /** |
| 22 | * Base abstract factory for creating configurations for the specified subject type. |
| 23 | * |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 24 | * @param <S> type of subject |
| 25 | * @param <C> type of configuration |
Thomas Vachuska | f0e1fae | 2015-04-24 00:51:51 -0700 | [diff] [blame] | 26 | */ |
Thomas Vachuska | e2b7e7e | 2015-05-20 11:11:31 -0700 | [diff] [blame] | 27 | @Beta |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 28 | public abstract class ConfigFactory<S, C extends Config<S>> { |
Thomas Vachuska | f0e1fae | 2015-04-24 00:51:51 -0700 | [diff] [blame] | 29 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 30 | private final SubjectFactory<S> subjectFactory; |
| 31 | private final Class<C> configClass; |
| 32 | private final String configKey; |
Thomas Vachuska | f0e1fae | 2015-04-24 00:51:51 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Creates a new configuration factory for the specified class of subjects |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 36 | * 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 Vachuska | f0e1fae | 2015-04-24 00:51:51 -0700 | [diff] [blame] | 39 | * |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 40 | * @param subjectFactory subject factory |
| 41 | * @param configClass configuration class |
| 42 | * @param configKey configuration class key |
Thomas Vachuska | f0e1fae | 2015-04-24 00:51:51 -0700 | [diff] [blame] | 43 | */ |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 44 | protected ConfigFactory(SubjectFactory<S> subjectFactory, |
| 45 | Class<C> configClass, String configKey) { |
| 46 | this.subjectFactory = subjectFactory; |
| 47 | this.configClass = configClass; |
| 48 | this.configKey = configKey; |
Thomas Vachuska | f0e1fae | 2015-04-24 00:51:51 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns the class of the subject to which this factory applies. |
| 53 | * |
| 54 | * @return subject type |
| 55 | */ |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 56 | public SubjectFactory<S> subjectFactory() { |
| 57 | return subjectFactory; |
Thomas Vachuska | f0e1fae | 2015-04-24 00:51:51 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /** |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 61 | * Returns the class of the configuration which this factory generates. |
Thomas Vachuska | f0e1fae | 2015-04-24 00:51:51 -0700 | [diff] [blame] | 62 | * |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 63 | * @return configuration type |
Thomas Vachuska | f0e1fae | 2015-04-24 00:51:51 -0700 | [diff] [blame] | 64 | */ |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 65 | 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 Vachuska | f0e1fae | 2015-04-24 00:51:51 -0700 | [diff] [blame] | 78 | } |
| 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 Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 86 | public abstract C createConfig(); |
Thomas Vachuska | f0e1fae | 2015-04-24 00:51:51 -0700 | [diff] [blame] | 87 | |
| 88 | } |