Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 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 | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 17 | |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | |
| 21 | /** |
| 22 | * Base abstract factory for creating configuration subjects from their |
| 23 | * string key image. |
| 24 | * |
| 25 | * @param <S> subject class |
| 26 | */ |
| 27 | @Beta |
| 28 | public abstract class SubjectFactory<S> { |
| 29 | |
| 30 | private final Class<S> subjectClass; |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame] | 31 | private final String subjectClassKey; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Creates a new configuration factory for the specified class of subjects |
| 35 | * capable of generating the configurations of the specified class. The |
| 36 | * subject and configuration class keys are used merely as keys for use in |
| 37 | * composite JSON trees. |
| 38 | * |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame] | 39 | * @param subjectClass subject class |
| 40 | * @param subjectClassKey subject class key |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 41 | */ |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame] | 42 | protected SubjectFactory(Class<S> subjectClass, String subjectClassKey) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 43 | this.subjectClass = subjectClass; |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame] | 44 | this.subjectClassKey = subjectClassKey; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns the class of the subject to which this factory applies. |
| 49 | * |
| 50 | * @return subject type |
| 51 | */ |
| 52 | public Class<S> subjectClass() { |
| 53 | return subjectClass; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns the unique key of this configuration subject class. |
| 58 | * This is primarily aimed for use in composite JSON trees in external |
| 59 | * representations and has no bearing on the internal behaviours. |
| 60 | * |
| 61 | * @return configuration key |
| 62 | */ |
Thomas Vachuska | ea5adc6 | 2015-10-07 11:52:30 -0700 | [diff] [blame] | 63 | public String subjectClassKey() { |
| 64 | return subjectClassKey; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Returns the unique key of the specified configuration subject. |
| 69 | * This is primarily aimed for use in composite JSON trees in external |
| 70 | * representations and has no bearing on the internal behaviours. |
| 71 | * |
| 72 | * @param subject specific subject |
| 73 | * @return subject key |
| 74 | */ |
| 75 | public String subjectKey(S subject) { |
| 76 | return subject.toString(); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Creates a configuration subject from its key image. |
| 81 | * |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 82 | * @param subjectKey subject class key |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 83 | * @return configuration subject |
| 84 | */ |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 85 | public abstract S createSubject(String subjectKey); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 86 | |
| 87 | } |