Separating renderers into features.
[groupbasedpolicy.git] / renderers / opflex / src / main / java / org / opendaylight / groupbasedpolicy / renderer / opflex / mit / PolicyPropertyInfo.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
12 /**
13  * Class containing metadata used to describe
14  * properties contained by an OpFlex Managed Object
15  *
16  * @author tbachman
17  *
18  */
19 public interface PolicyPropertyInfo {
20         /**
21          * enum that represents possible Property types
22          *
23          * @author tbachman
24          *
25          */
26         static public enum PropertyType {
27                 COMPOSITE("composite"),
28                 REFERENCE("reference"),
29                 STRING("string"),
30                 S64("s64"),
31                 U64("u64"),
32                 MAC("mac"),
33                 ENUM8("enum8"),
34                 ENUM16("enum16"),
35                 ENUM32("enum32"),
36                 ENUM64("enum64");
37
38                 private final String type;
39
40                 PropertyType(String type) {
41                         this.type = type;
42                 }
43
44                 @Override
45                 public String toString() {
46                         return this.type;
47                 }
48         }
49
50         /**
51          * enum that represents the possible cardinalities of a Property
52          *
53          * @author tbachman
54          *
55          */
56         static public enum PropertyCardinality {
57                 SCALAR("scalar"),
58                 VECTOR("vector");
59
60                 private final String cardinality;
61
62                 PropertyCardinality(String cardinality) {
63                         this.cardinality = cardinality;
64                 }
65
66                 @Override
67                 public String toString() {
68                         return this.cardinality;
69                 }
70         }
71
72         /**
73          * The unique local ID assigned to this Property
74          *
75          * @author tbachman
76          *
77          */
78         static public class PolicyPropertyId {
79                 private final long propertyId;
80                 public PolicyPropertyId(long propertyId) {
81                         this.propertyId = propertyId;
82                 }
83                 public long getPropertyId() {
84                         return propertyId;
85                 }
86                 @Override
87                 public int hashCode() {
88                         final int prime = 31;
89                         int result = 1;
90                         result = prime * result + (int) (propertyId ^ (propertyId >>> 32));
91                         return result;
92                 }
93                 @Override
94                 public boolean equals(Object obj) {
95                         if (this == obj)
96                                 return true;
97                         if (obj == null)
98                                 return false;
99                         if (getClass() != obj.getClass())
100                                 return false;
101                         PolicyPropertyId other = (PolicyPropertyId) obj;
102                         if (propertyId != other.propertyId)
103                                 return false;
104                         return true;
105                 }
106
107         }
108
109         public static class PolicyPropertyInfoBuilder {
110                 private long classId;
111                 private PropertyType type;
112                 private PolicyPropertyId propId;
113                 private PropertyCardinality propCardinality;
114                 private String propName;
115                 private EnumInfo enumInfo;
116
117                 public PolicyPropertyInfoBuilder setClassId(long classId) {
118                         this.classId = classId;
119                         return this;
120                 }
121
122                 public PolicyPropertyInfoBuilder setType(PropertyType type) {
123                         this.type = type;
124                         return this;
125                 }
126
127                 public PolicyPropertyInfoBuilder setPropId(PolicyPropertyId propId) {
128                         this.propId = propId;
129                         return this;
130                 }
131
132                 public PolicyPropertyInfoBuilder setPropCardinality(PropertyCardinality propCardinality) {
133                         this.propCardinality = propCardinality;
134                         return this;
135                 }
136
137                 public PolicyPropertyInfoBuilder setPropName(String propName) {
138                         this.propName = propName;
139                         return this;
140                 }
141
142                 public PolicyPropertyInfoBuilder setEnumInfo(EnumInfo enumInfo) {
143                         this.enumInfo = enumInfo;
144                         return this;
145                 }
146
147                 public PolicyPropertyInfo build() {
148                         return new PolicyPropertyInfoImpl(this);
149                 }
150
151                 private static final class PolicyPropertyInfoImpl implements PolicyPropertyInfo {
152                         /*
153                          * The classId is only used in COMPOSITE properties
154                          */
155                         private final long classId;
156                         private final PropertyType type;
157                         private final PolicyPropertyId propId;
158                         private final PropertyCardinality propCardinality;
159                         private final String propName;
160                         private final EnumInfo enumInfo;
161
162                         public PolicyPropertyInfoImpl(PolicyPropertyInfoBuilder builder) {
163                                 this.classId = builder.classId;
164                                 this.type = builder.type;
165                                 this.propId = builder.propId;
166                                 this.propCardinality = builder.propCardinality;
167                                 this.propName = builder.propName;
168                                 this.enumInfo = builder.enumInfo;
169
170                         }
171                         @Override
172                         public long getClassId() {
173                                 return classId;
174                         }
175
176                         @Override
177                         public PropertyType getType() {
178                                 return type;
179                         }
180
181                         @Override
182                         public PolicyPropertyId getPropId() {
183                                 return propId;
184                         }
185
186                         @Override
187                         public PropertyCardinality getPropCardinality() {
188                                 return propCardinality;
189                         }
190
191                         @Override
192                         public String getPropName() {
193                                 return propName;
194                         }
195
196                         @Override
197                         public EnumInfo getEnumInfo() {
198                                 return enumInfo;
199                         }
200                 }
201
202         }
203
204         /**
205          * Get the class of the {@link PolicyPropertyInfo} object
206          *
207          * @return
208          */
209         public long getClassId();
210
211         /**
212          * Get the type of the {@link PolicyPropertyInfo} object
213          *
214          * @return
215          */
216         public PropertyType getType();
217
218         /**
219          * Get the ID of the {@link PolicyPropertyInfo} object
220          *
221          * @return
222          */
223         public PolicyPropertyId getPropId();
224
225         /**
226          * Get the cardinality of the {@link PolicyPropertyInfo} object
227          *
228          * @return
229          */
230         public PropertyCardinality getPropCardinality();
231
232         /**
233          * Get the name of the {@link PolicyPropertyInfo} object
234          *
235          * @return
236          */
237         public String getPropName();
238
239         /**
240          * Get the {@link EnumInfo} object for the {@link PolicyPropertyInfo}
241          * object, if present
242          *
243          * @return
244          */
245         public EnumInfo getEnumInfo();
246
247 }