2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.policy.xacml.std.pap;
22 import java.io.Serializable;
23 import java.util.Collections;
24 import java.util.HashSet;
25 import java.util.Properties;
28 import org.onap.policy.xacml.api.pap.OnapPDP;
30 import org.onap.policy.common.logging.flexlogger.FlexLogger;
31 import org.onap.policy.common.logging.flexlogger.Logger;
32 import com.att.research.xacml.api.pap.PDPPIPConfig;
33 import com.att.research.xacml.api.pap.PDPPolicy;
34 import com.att.research.xacml.api.pap.PDPStatus;
36 public class StdPDP extends StdPDPItemSetChangeNotifier implements OnapPDP, Comparable<StdPDP>, Serializable {
37 private static final long serialVersionUID = 1L;
38 private static Logger logger = FlexLogger.getLogger(StdPDP.class);
44 private String description;
46 private Integer jmxport = 0;
48 private transient PDPStatus status = new StdPDPStatus();
50 private transient Set<PDPPolicy> policies = new HashSet<>();
52 private transient Set<PDPPIPConfig> pipConfigs = new HashSet<>();
56 // Default constructor
60 public StdPDP(String id, Integer jmxport) {
61 this(id, null, null, jmxport);
64 public StdPDP(String id, String name, Integer jmxport) {
65 this(id, name, null, jmxport);
68 public StdPDP(String id, String name, String description, Integer jmxport) {
71 this.description = description;
73 this.jmxport = jmxport;
77 public StdPDP(String id, Properties properties) {
80 this.initialize(properties);
83 public void initialize(Properties properties) {
84 for (Object key : properties.keySet()) {
85 if (key.toString().startsWith(this.id + ".")) {
86 if (logger.isDebugEnabled()) {
87 logger.debug("Found: " + key);
89 if (key.toString().endsWith(".name")) {
90 this.name = properties.getProperty(key.toString());
91 } else if (key.toString().endsWith(".description")) {
92 this.description = properties.getProperty(key.toString());
93 }else if (key.toString().endsWith(".jmxport")) {
94 if (properties.getProperty(key.toString()) != null && properties.getProperty(key.toString()).trim().length() > 0){
95 logger.debug("initialize before: " + this.jmxport);
96 this.jmxport = Integer.valueOf( properties.getProperty(key.toString()));
97 logger.debug("initialize after: " + this.jmxport);
107 public String getId() {
111 public void setId(String id) {
116 public String getName() {
121 public void setName(String name) {
123 this.firePDPChanged(this);
127 public String getDescription() {
128 return this.description;
132 public void setDescription(String description) {
133 this.description = description;
134 this.firePDPChanged(this);
138 public PDPStatus getStatus() {
142 public void setStatus(PDPStatus status) {
143 this.status = status;
147 public Set<PDPPolicy> getPolicies() {
148 return Collections.unmodifiableSet(this.policies);
151 public void setPolicies(Set<PDPPolicy> policies) {
152 this.policies = policies;
156 public Set<PDPPIPConfig> getPipConfigs() {
157 return Collections.unmodifiableSet(this.pipConfigs);
160 public void setPipConfigs(Set<PDPPIPConfig> pipConfigs) {
161 this.pipConfigs = pipConfigs;
165 public void setJmxPort(Integer jmxport) {
166 this.jmxport = jmxport;
169 public Integer getJmxPort() {
174 public int hashCode() {
175 final int prime = 31;
177 result = prime * result + ((id == null) ? 0 : id.hashCode());
182 public boolean equals(Object obj) {
187 if (getClass() != obj.getClass())
189 StdPDP other = (StdPDP) obj;
191 if (other.id != null)
193 } else if (!id.equals(other.id))
199 public String toString() {
200 return "StdPDP [id=" + id + ", name=" + name + ", description="
201 + description + ", jmxport=" + jmxport + ", status=" + status + ", policies=" + policies
202 + ", pipConfigs=" + pipConfigs + "]";
206 // Comparable interface
209 public int compareTo(StdPDP o) {
213 if (o.name == null) {
219 return name.compareTo(o.name);