blob: 8cf3843c26108781a0d687aade048bb170ed61a6 [file] [log] [blame]
Thomas Vachuska96d55b12015-05-11 08:52:03 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska96d55b12015-05-11 08:52:03 -07003 *
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 Vachuska96d55b12015-05-11 08:52:03 -070017
18
19import 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
28public abstract class SubjectFactory<S> {
29
30 private final Class<S> subjectClass;
Thomas Vachuskaea5adc62015-10-07 11:52:30 -070031 private final String subjectClassKey;
Thomas Vachuska96d55b12015-05-11 08:52:03 -070032
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 Vachuskaea5adc62015-10-07 11:52:30 -070039 * @param subjectClass subject class
40 * @param subjectClassKey subject class key
Thomas Vachuska96d55b12015-05-11 08:52:03 -070041 */
Thomas Vachuskaea5adc62015-10-07 11:52:30 -070042 protected SubjectFactory(Class<S> subjectClass, String subjectClassKey) {
Thomas Vachuska96d55b12015-05-11 08:52:03 -070043 this.subjectClass = subjectClass;
Thomas Vachuskaea5adc62015-10-07 11:52:30 -070044 this.subjectClassKey = subjectClassKey;
Thomas Vachuska96d55b12015-05-11 08:52:03 -070045 }
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 Vachuskaea5adc62015-10-07 11:52:30 -070063 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 Vachuska96d55b12015-05-11 08:52:03 -070077 }
78
79 /**
80 * Creates a configuration subject from its key image.
81 *
Thomas Vachuskad894b5d2015-07-30 11:59:07 -070082 * @param subjectKey subject class key
Thomas Vachuska96d55b12015-05-11 08:52:03 -070083 * @return configuration subject
84 */
Thomas Vachuskad894b5d2015-07-30 11:59:07 -070085 public abstract S createSubject(String subjectKey);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070086
87}