Added range type to subject-feature-definition/parameter
[groupbasedpolicy.git] / renderers / opflex / src / main / java / org / opendaylight / groupbasedpolicy / renderer / opflex / mit / PolicyClassInfo.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.groupbasedpolicy.renderer.opflex.mit;
10
11 import java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
14 import java.util.Map;
15
16 import org.opendaylight.groupbasedpolicy.renderer.opflex.mit.PolicyPropertyInfo.PolicyPropertyId;
17
18
19
20 /**
21  * Class that provides Managed Object metadata. The
22  * {@link PolicyClassInfo} object contains metadata about
23  * the Managed Object, while the {@link PropertyInfo} list
24  * contained by this object provides the metadata about the
25  * Managed Object properties.
26  *
27  * This data must be kept consistent with the agents.
28  *
29  * @author tbachman
30  *
31  */
32 public interface PolicyClassInfo {
33
34         static public enum PolicyClassType {
35                 POLICY("policy"),
36                 REMOTE_ENDPOINT("remote_endpoint"),
37                 LOCAL_ENDPOINT("local_endpoint"),
38                 OBSERVABLE("observable"),
39                 LOCAL_ONLY("local_only"),
40                 RESOLVER("resolver"),
41                 RELATIONSHIP("relationship"),
42                 REVERSE_RELATIONSHIP("reverse_relationship");
43
44                 private final String type;
45
46                 PolicyClassType(String type) {
47                         this.type = type;
48                 }
49
50                 @Override
51                 public String toString() {
52                         return this.type;
53                 }
54         }
55
56         /**
57          * Get the ID for the class
58          *
59          * @return
60          */
61         public int getClassId() ;
62
63         /**
64          * Get the type for the class
65          *
66          * @return
67          */
68         public PolicyClassType getPolicyType();
69
70         /**
71          * Get the name for the class
72          *
73          * @return
74          */
75         public String getClassName();
76
77         /**
78          * Get a {@link PolicyPropertyInfo} object by name
79          * from the class.
80          *
81          * @param name
82          * @return
83          */
84         public PolicyPropertyInfo getProperty(String name);
85
86         /**
87          * Return the entire list of {@link PolicyPropertyInfo}
88          * objects for this class.
89          *
90          * @return
91          */
92         public List<PolicyPropertyInfo> getProperties();
93
94         /**
95          * Get a list of {@link PolicyPropertyId} objects,
96          * which are the keys to the {@link PolicyPropertyInfo}
97          * objects for this class.
98          *
99          * @return
100          */
101         public List<PolicyPropertyId> getKeys();
102
103         /**
104          * A builder class for create immutable instances of
105          * {@link PolicyClassInfo} objects.
106          *
107          * @author tbachman
108          *
109          */
110         public static class PolicyClassInfoBuilder {
111                 private int classId;
112                 private PolicyClassType policyType;
113                 private String className;
114                 private Map<String, PolicyPropertyInfo> properties;
115                 private List<PolicyPropertyId> keys;
116
117                 public PolicyClassInfoBuilder() {
118                         this.properties = new HashMap<String, PolicyPropertyInfo>();
119                         this.keys = new ArrayList<PolicyPropertyId>();
120                 }
121
122                 public int getClassId() {
123                         return classId;
124                 }
125
126                 public PolicyClassInfoBuilder setClassId(int classId) {
127                         this.classId = classId;
128                         return this;
129                 }
130
131                 public PolicyClassType getPolicyType() {
132                         return policyType;
133                 }
134
135                 public PolicyClassInfoBuilder setPolicyType(PolicyClassType policyType) {
136                         this.policyType = policyType;
137                         return this;
138                 }
139
140                 public String getClassName() {
141                         return className;
142                 }
143
144                 public PolicyClassInfoBuilder setClassName(String className) {
145                         this.className = className;
146                         return this;
147                 }
148
149                 public PolicyClassInfoBuilder setProperty(List<PolicyPropertyInfo> ppil) {
150                         for (PolicyPropertyInfo ppi: ppil) {
151                                 this.properties.put(ppi.getPropName(),ppi);
152                         }
153                         return this;
154                 }
155
156                 public PolicyClassInfoBuilder setKey(List<PolicyPropertyId> pidl) {
157                         this.keys.addAll(pidl);
158                         return this;
159                 }
160
161                 public PolicyClassInfo build() {
162                         return new PolicyClassInfoImpl(this);
163                 }
164
165                 private static final class PolicyClassInfoImpl implements PolicyClassInfo {
166
167                         private final int classId;
168                         private final PolicyClassType policyType;
169                         private final String className;
170                         private final Map<String, PolicyPropertyInfo> properties;
171                         private List<PolicyPropertyId> keys;
172
173                         private PolicyClassInfoImpl(PolicyClassInfoBuilder builder) {
174                                 this.classId = builder.classId;
175                                 this.policyType = builder.policyType;
176                                 this.className = builder.className;
177                                 this.properties = builder.properties;
178                                 this.keys = builder.keys;
179                         }
180                         @Override
181                         public int getClassId() {
182                                 return classId;
183                         }
184
185                         @Override
186                         public PolicyClassType getPolicyType() {
187                                 return policyType;
188                         }
189
190                         @Override
191                         public String getClassName() {
192                                 return className;
193                         }
194
195                         @Override
196                         public PolicyPropertyInfo getProperty(String name) {
197                                 return properties.get(name);
198                         }
199
200                         @Override
201                         public List<PolicyPropertyInfo> getProperties() {
202                                 return new ArrayList<PolicyPropertyInfo>(properties.values());
203                         }
204
205                         @Override
206                         public List<PolicyPropertyId> getKeys() {
207                                 return keys;
208                         }
209                 }
210         }
211
212 }