2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.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.openecomp.policy.xacml.api.pap.EcompPDP;
30 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
31 import org.openecomp.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 EcompPDP, 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 PDPStatus status = new StdPDPStatus();
50 private Set<PDPPolicy> policies = new HashSet<PDPPolicy>();
52 private Set<PDPPIPConfig> pipConfigs = new HashSet<PDPPIPConfig>();
58 public StdPDP(String id, Integer jmxport) {
59 this(id, null, null, jmxport);
62 public StdPDP(String id, String name, Integer jmxport) {
63 this(id, name, null, jmxport);
66 public StdPDP(String id, String name, String description, Integer jmxport) {
69 this.description = description;
71 this.jmxport = jmxport;
75 public StdPDP(String id, Properties properties) {
78 this.initialize(properties);
81 public void initialize(Properties properties) {
82 for (Object key : properties.keySet()) {
83 if (key.toString().startsWith(this.id + ".")) {
84 if (logger.isDebugEnabled()) {
85 logger.debug("Found: " + key);
87 if (key.toString().endsWith(".name")) {
88 this.name = properties.getProperty(key.toString());
89 } else if (key.toString().endsWith(".description")) {
90 this.description = properties.getProperty(key.toString());
91 }else if (key.toString().endsWith(".jmxport")) {
92 //todo fix this hackjob
93 if (properties.getProperty(key.toString()) != null && properties.getProperty(key.toString()).trim().length() > 0){
94 logger.debug("initialize before: " + this.jmxport);
95 this.jmxport = Integer.valueOf( properties.getProperty(key.toString()));
96 logger.debug("initialize after: " + this.jmxport);
106 public String getId() {
110 public void setId(String id) {
115 public String getName() {
120 public void setName(String name) {
122 this.firePDPChanged(this);
126 public String getDescription() {
127 return this.description;
131 public void setDescription(String description) {
132 this.description = description;
133 this.firePDPChanged(this);
137 public PDPStatus getStatus() {
141 public void setStatus(PDPStatus status) {
142 this.status = status;
146 public Set<PDPPolicy> getPolicies() {
147 return Collections.unmodifiableSet(this.policies);
150 public void setPolicies(Set<PDPPolicy> policies) {
151 this.policies = policies;
155 public Set<PDPPIPConfig> getPipConfigs() {
156 return Collections.unmodifiableSet(this.pipConfigs);
159 public void setPipConfigs(Set<PDPPIPConfig> pipConfigs) {
160 this.pipConfigs = pipConfigs;
162 public void setJmxPort(Integer jmxport) {
163 this.jmxport = jmxport;
166 public Integer getJmxPort() {
171 public int hashCode() {
172 final int prime = 31;
174 result = prime * result + ((id == null) ? 0 : id.hashCode());
179 public boolean equals(Object obj) {
184 if (getClass() != obj.getClass())
186 StdPDP other = (StdPDP) obj;
188 if (other.id != null)
190 } else if (!id.equals(other.id))
196 public String toString() {
197 return "StdPDP [id=" + id + ", name=" + name + ", description="
198 + description + ", jmxport=" + jmxport + ", status=" + status + ", policies=" + policies
199 + ", pipConfigs=" + pipConfigs + "]";
203 // Comparable interface
206 public int compareTo(StdPDP o) {
210 if ( ! (o instanceof StdPDP)) {
213 if (((StdPDP)o).name == null) {
219 return name.compareTo(((StdPDP)o).name);