Feature uses features-parent as parent
[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  * Class that provides Managed Object metadata. The {@link PolicyClassInfo} object contains metadata
20  * about
21  * the Managed Object, while the {@link PolicyPropertyInfo} list
22  * contained by this object provides the metadata about the
23  * Managed Object properties.
24  * This data must be kept consistent with the agents.
25  *
26  * @author tbachman
27  */
28 public interface PolicyClassInfo {
29
30     static public enum PolicyClassType {
31         POLICY("policy"), REMOTE_ENDPOINT("remote_endpoint"), LOCAL_ENDPOINT("local_endpoint"), OBSERVABLE("observable"), LOCAL_ONLY(
32                 "local_only"), RESOLVER("resolver"), RELATIONSHIP("relationship"), REVERSE_RELATIONSHIP(
33                 "reverse_relationship");
34
35         private final String type;
36
37         PolicyClassType(String type) {
38             this.type = type;
39         }
40
41         @Override
42         public String toString() {
43             return this.type;
44         }
45     }
46
47     /**
48      * Get the ID for the class
49      *
50      * @return
51      */
52     public int getClassId();
53
54     /**
55      * Get the type for the class
56      *
57      * @return
58      */
59     public PolicyClassType getPolicyType();
60
61     /**
62      * Get the name for the class
63      *
64      * @return
65      */
66     public String getClassName();
67
68     /**
69      * Get a {@link PolicyPropertyInfo} object by name
70      * from the class.
71      *
72      * @param name
73      * @return
74      */
75     public PolicyPropertyInfo getProperty(String name);
76
77     /**
78      * Return the entire list of {@link PolicyPropertyInfo} objects for this class.
79      *
80      * @return
81      */
82     public List<PolicyPropertyInfo> getProperties();
83
84     /**
85      * Get a list of {@link PolicyPropertyId} objects,
86      * which are the keys to the {@link PolicyPropertyInfo} objects for this class.
87      *
88      * @return
89      */
90     public List<PolicyPropertyId> getKeys();
91
92     /**
93      * A builder class for create immutable instances of {@link PolicyClassInfo} objects.
94      *
95      * @author tbachman
96      */
97     public static class PolicyClassInfoBuilder {
98
99         private int classId;
100         private PolicyClassType policyType;
101         private String className;
102         private final Map<String, PolicyPropertyInfo> properties = new HashMap<>();
103         private final List<PolicyPropertyId> keys = new ArrayList<>();
104
105         public PolicyClassInfoBuilder() {
106         }
107
108         public int getClassId() {
109             return classId;
110         }
111
112         public PolicyClassInfoBuilder setClassId(int classId) {
113             this.classId = classId;
114             return this;
115         }
116
117         public PolicyClassType getPolicyType() {
118             return policyType;
119         }
120
121         public PolicyClassInfoBuilder setPolicyType(PolicyClassType policyType) {
122             this.policyType = policyType;
123             return this;
124         }
125
126         public String getClassName() {
127             return className;
128         }
129
130         public PolicyClassInfoBuilder setClassName(String className) {
131             this.className = className;
132             return this;
133         }
134
135         public PolicyClassInfoBuilder setProperty(List<PolicyPropertyInfo> ppil) {
136             for (PolicyPropertyInfo ppi : ppil) {
137                 this.properties.put(ppi.getPropName(), ppi);
138             }
139             return this;
140         }
141
142         public PolicyClassInfoBuilder setKey(List<PolicyPropertyId> pidl) {
143             this.keys.addAll(pidl);
144             return this;
145         }
146
147         public PolicyClassInfo build() {
148             return new PolicyClassInfoImpl(this);
149         }
150
151         private static final class PolicyClassInfoImpl implements PolicyClassInfo {
152
153             private final int classId;
154             private final PolicyClassType policyType;
155             private final String className;
156             private final Map<String, PolicyPropertyInfo> properties;
157             private final List<PolicyPropertyId> keys;
158
159             private PolicyClassInfoImpl(PolicyClassInfoBuilder builder) {
160                 this.classId = builder.classId;
161                 this.policyType = builder.policyType;
162                 this.className = builder.className;
163                 this.properties = builder.properties;
164                 this.keys = builder.keys;
165             }
166
167             @Override
168             public int getClassId() {
169                 return classId;
170             }
171
172             @Override
173             public PolicyClassType getPolicyType() {
174                 return policyType;
175             }
176
177             @Override
178             public String getClassName() {
179                 return className;
180             }
181
182             @Override
183             public PolicyPropertyInfo getProperty(String name) {
184                 return properties.get(name);
185             }
186
187             @Override
188             public List<PolicyPropertyInfo> getProperties() {
189                 return new ArrayList<PolicyPropertyInfo>(properties.values());
190             }
191
192             @Override
193             public List<PolicyPropertyId> getKeys() {
194                 return keys;
195             }
196         }
197     }
198
199 }