blob: 3f7e6dccb893ff183dccd79a0a5c03297947d3de [file] [log] [blame]
Thomas Vachuska96d55b12015-05-11 08:52:03 -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 */
16package org.onosproject.incubator.net.config;
17
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;
31 private final String subjectKey;
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 *
39 * @param subjectClass subject class
40 * @param subjectKey subject class key
41 */
42 protected SubjectFactory(Class<S> subjectClass, String subjectKey) {
43 this.subjectClass = subjectClass;
44 this.subjectKey = subjectKey;
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 */
63 public String subjectKey() {
64 return subjectKey;
65 }
66
67 /**
68 * Creates a configuration subject from its key image.
69 *
70 * @return configuration subject
71 */
72 public abstract S createSubject(String key);
73
74}