2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.groupbasedpolicy.renderer.opflex.mit;
11 import java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
16 import org.opendaylight.groupbasedpolicy.renderer.opflex.mit.PolicyPropertyInfo.PolicyPropertyId;
19 * Class that provides Managed Object metadata. The {@link PolicyClassInfo} object contains metadata
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.
28 public interface PolicyClassInfo {
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");
35 private final String type;
37 PolicyClassType(String type) {
42 public String toString() {
48 * Get the ID for the class
52 public int getClassId();
55 * Get the type for the class
59 public PolicyClassType getPolicyType();
62 * Get the name for the class
66 public String getClassName();
69 * Get a {@link PolicyPropertyInfo} object by name
75 public PolicyPropertyInfo getProperty(String name);
78 * Return the entire list of {@link PolicyPropertyInfo} objects for this class.
82 public List<PolicyPropertyInfo> getProperties();
85 * Get a list of {@link PolicyPropertyId} objects,
86 * which are the keys to the {@link PolicyPropertyInfo} objects for this class.
90 public List<PolicyPropertyId> getKeys();
93 * A builder class for create immutable instances of {@link PolicyClassInfo} objects.
97 public static class PolicyClassInfoBuilder {
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<>();
105 public PolicyClassInfoBuilder() {
108 public int getClassId() {
112 public PolicyClassInfoBuilder setClassId(int classId) {
113 this.classId = classId;
117 public PolicyClassType getPolicyType() {
121 public PolicyClassInfoBuilder setPolicyType(PolicyClassType policyType) {
122 this.policyType = policyType;
126 public String getClassName() {
130 public PolicyClassInfoBuilder setClassName(String className) {
131 this.className = className;
135 public PolicyClassInfoBuilder setProperty(List<PolicyPropertyInfo> ppil) {
136 for (PolicyPropertyInfo ppi : ppil) {
137 this.properties.put(ppi.getPropName(), ppi);
142 public PolicyClassInfoBuilder setKey(List<PolicyPropertyId> pidl) {
143 this.keys.addAll(pidl);
147 public PolicyClassInfo build() {
148 return new PolicyClassInfoImpl(this);
151 private static final class PolicyClassInfoImpl implements PolicyClassInfo {
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;
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;
168 public int getClassId() {
173 public PolicyClassType getPolicyType() {
178 public String getClassName() {
183 public PolicyPropertyInfo getProperty(String name) {
184 return properties.get(name);
188 public List<PolicyPropertyInfo> getProperties() {
189 return new ArrayList<PolicyPropertyInfo>(properties.values());
193 public List<PolicyPropertyId> getKeys() {