diff options
Diffstat (limited to 'POLICY-SDK-APP/src')
7 files changed, 4 insertions, 751 deletions
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java index de1c551fc..23392bdd2 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java @@ -21,7 +21,6 @@ package org.onap.policy.components; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.PrintWriter; @@ -42,7 +41,6 @@ import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.controller.PolicyController; import org.onap.policy.rest.jpa.FunctionDefinition; -import org.onap.policy.utils.XACMLPolicyWriterWithPapNotify; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.util.XACMLPolicyScanner; @@ -303,29 +301,6 @@ class HtmlProcessor extends SimpleCallback { super.onFinishScan(root); } - @SuppressWarnings("unused") - private void writeRawXACML() { - if (LOGGER.isTraceEnabled()) - LOGGER.trace("ENTER"); - - htmlOut.println("<hr>"); - htmlOut.println("<h3>Raw XACML:</h3>"); - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - if (rootPolicyObject instanceof PolicySetType) { - XACMLPolicyWriterWithPapNotify.writePolicyFile(bos, (PolicySetType) rootPolicyObject); - } else if (rootPolicyObject instanceof PolicyType) { - XACMLPolicyWriterWithPapNotify.writePolicyFile(bos, (PolicyType) rootPolicyObject); - } - - String xacml = bos.toString(); - xacml = xacml.replaceAll("<", "<"); - xacml = xacml.replaceAll(">", ">"); - htmlOut.println("<pre>"); - htmlOut.println(xacml); - htmlOut.println("</pre>"); - } - @Override public CallbackResult onPreVisitPolicySet(PolicySetType parent, PolicySetType policySet) { if (LOGGER.isTraceEnabled()) diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java index 64928f3f4..e5e868fd9 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java @@ -46,12 +46,12 @@ import org.json.JSONObject; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.model.PDPGroupContainer; -import org.onap.policy.model.PDPPolicyContainer; import org.onap.policy.model.Roles; import org.onap.policy.rest.adapter.AutoPushTabAdapter; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.PolicyEntity; import org.onap.policy.rest.jpa.PolicyVersion; +import org.onap.policy.rest.util.PDPPolicyContainer; import org.onap.policy.utils.PolicyUtils; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.api.pap.OnapPDPGroup; diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPGroupContainer.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPGroupContainer.java index d5767b46a..083565559 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPGroupContainer.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPGroupContainer.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,8 +31,8 @@ import java.util.Set; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; -import org.onap.policy.utils.PolicyContainer; -import org.onap.policy.utils.PolicyItemSetChangeNotifier; +import org.onap.policy.rest.util.PolicyContainer; +import org.onap.policy.rest.util.PolicyItemSetChangeNotifier; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.api.pap.OnapPDP; import org.onap.policy.xacml.api.pap.OnapPDPGroup; diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPPolicyContainer.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPPolicyContainer.java deleted file mode 100644 index e73adf84b..000000000 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPPolicyContainer.java +++ /dev/null @@ -1,346 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP Policy Engine - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.model; - - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import org.onap.policy.common.logging.flexlogger.FlexLogger; -import org.onap.policy.common.logging.flexlogger.Logger; -import org.onap.policy.utils.PolicyContainer; -import org.onap.policy.utils.PolicyItemSetChangeNotifier; -import org.onap.policy.xacml.api.XACMLErrorConstants; -import org.onap.policy.xacml.std.pap.StdPDPPolicy; - -import com.att.research.xacml.api.pap.PDP; -import com.att.research.xacml.api.pap.PDPGroup; -import com.att.research.xacml.api.pap.PDPPolicy; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class PDPPolicyContainer extends PolicyItemSetChangeNotifier implements PolicyContainer.Indexed { - private static final long serialVersionUID = 1L; - private static final Logger LOGGER = FlexLogger.getLogger(PDPPolicyContainer.class); - - /** - * String identifier of a file's "Id" property. - */ - private static final String PROPERTY_ID = "Id"; - - /** - * String identifier of a file's "name" property. - */ - private static final String PROPERTY_NAME = "Name"; - - /** - * String identifier of a file's "name" property. - */ - private static final String PROPERTY_VERSION = "Version"; - - /** - * String identifier of a file's "Description" property. - */ - private static final String PROPERTY_DESCRIPTION = "Description"; - - /** - * String identifier of a file's "IsRoot" property. - */ - private static final String PROPERTY_ISROOT = "Root"; - - /** - * List of the string identifiers for the available properties. - */ - private static Collection<String> pDPPolicyProperties; - - private final transient Object data; - private transient List<PDPPolicy> policies; - - @SuppressWarnings("unchecked") - public PDPPolicyContainer(Object data) { - super(); - this.data = data; - if (this.data instanceof PDPGroup) { - policies = new ArrayList<> (((PDPGroup) this.data).getPolicies()); - } - if (this.data instanceof PDP) { - policies = new ArrayList<> (((PDP) this.data).getPolicies()); - } - if (this.data instanceof Set) { - policies = new ArrayList<> ((Set<PDPPolicy>)data); - } - if (this.policies == null) { - LOGGER.info("NULL policies"); - throw new NullPointerException("PDPPolicyContainer created with unexpected Object type '" + data.getClass().getName() + "'"); - } - this.setContainer(this); - } - - @Override - public Object nextItemId(Object itemId) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("nextItemId: " + itemId); - } - int index = this.policies.indexOf(itemId); - if (index == -1 || ((index + 1) >= this.policies.size())) { - return null; - } - return new PDPPolicyItem(this.policies.get(index + 1)); - } - - @Override - public Object prevItemId(Object itemId) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("prevItemId: " + itemId); - } - int index = this.policies.indexOf(itemId); - if (index <= 0) { - return null; - } - return new PDPPolicyItem(this.policies.get(index - 1)); - } - - @Override - public Object firstItemId() { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("firstItemId: "); - } - if (this.policies.isEmpty()) { - return null; - } - return new PDPPolicyItem(this.policies.get(0)); - } - - @Override - public Object lastItemId() { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("lastItemid: "); - } - if (this.policies.isEmpty()) { - return null; - } - return new PDPPolicyItem(this.policies.get(this.policies.size() - 1)); - } - - @Override - public boolean isFirstId(Object itemId) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("isFirstId: " + itemId); - } - if (this.policies.isEmpty()) { - return false; - } - return itemId.equals(this.policies.get(0)); - } - - @Override - public boolean isLastId(Object itemId) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("isLastId: " + itemId); - } - if (this.policies.isEmpty()) { - return false; - } - return itemId.equals(this.policies.get(this.policies.size() - 1)); - } - - @Override - public Object addItemAfter(Object previousItemId) { - return null; - } - - @Override - public Collection<?> getContainerPropertyIds() { - return pDPPolicyProperties; - } - - @Override - public Collection<?> getItemIds() { - final Collection<Object> items = new ArrayList<>(); - items.addAll(this.policies); - return Collections.unmodifiableCollection(items); - } - - - @Override - public Class<?> getType(Object propertyId) { - if (propertyId.equals(PROPERTY_ID)) { - return String.class; - } - if (propertyId.equals(PROPERTY_NAME)) { - return String.class; - } - if (propertyId.equals(PROPERTY_VERSION)) { - return String.class; - } - if (propertyId.equals(PROPERTY_DESCRIPTION)) { - return String.class; - } - if (propertyId.equals(PROPERTY_ISROOT)) { - return Boolean.class; - } - return null; - } - - @Override - public int size() { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("size: " + this.policies.size()); - } - return this.policies.size(); - } - - @Override - public boolean containsId(Object itemId) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("containsId: " + itemId); - } - return this.policies.contains(itemId); - } - - @Override - public Object addItem() { - throw new UnsupportedOperationException("Cannot add an empty policy."); - } - - @Override - public boolean removeItem(Object itemId) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("removeItem: " + itemId); - } - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - StdPDPPolicy pdpPolicy = null; - try { - pdpPolicy = mapper.readValue(itemId.toString() , StdPDPPolicy.class); - for(int i = 0; i< policies.size(); i++){ - if(policies.get(i).getId().equalsIgnoreCase(pdpPolicy.getId())){ - return this.policies.remove(this.policies.get(i)); - } - } - } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Exception Occured While Mapping the Removing Policy from PDP Group to Std Policy"+e); - } - return this.policies.remove(itemId); - } - - @Override - public boolean addContainerProperty(Object propertyId, Class<?> type, - Object defaultValue) { - return false; - } - - @Override - public boolean removeContainerProperty(Object propertyId) { - return false; - } - - @Override - public boolean removeAllItems() { - return false; - } - - @Override - public int indexOfId(Object itemId) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("indexOfId: " + itemId); - } - return this.policies.indexOf(itemId); - } - - @Override - public Object getIdByIndex(int index) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("getIdByIndex: " + index); - } - return this.policies.get(index); - } - - @Override - public List<?> getItemIds(int startIndex, int numberOfItems) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("getItemIds: " + startIndex + " " + numberOfItems); - } - if (numberOfItems < 0) { - throw new IllegalArgumentException(); - } - return this.policies.subList(startIndex, startIndex + numberOfItems); - } - - @Override - public Object addItemAt(int index) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("addItemAt: " + index); - } - return null; - } - - public class PDPPolicyItem { - private final PDPPolicy policy; - - public PDPPolicyItem(PDPPolicy itemId) { - this.policy = itemId; - } - - public String getId() { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("getId: " + this.policy); - } - return this.policy.getId(); - } - - public String getName() { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("getName: " + this.policy); - } - return this.policy.getName(); - } - - public String getVersion() { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("getVersion: " + this.policy); - } - return this.policy.getVersion(); - } - - public String getDescription() { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("getDescription: " + this.policy); - } - return this.policy.getDescription(); - } - - public boolean getRoot() { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("isRoot: " + this.policy); - } - return this.policy.isRoot(); - } - - public void setRoot(Boolean root) { - ((StdPDPPolicy)this.policy).setRoot(root); - } - - } -}
\ No newline at end of file diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/utils/ConfigurableRESTUtils.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/utils/ConfigurableRESTUtils.java deleted file mode 100644 index 74576100a..000000000 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/utils/ConfigurableRESTUtils.java +++ /dev/null @@ -1,162 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP Policy Engine - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.utils; - - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStreamWriter; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Map; -import java.util.Map.Entry; - -import org.onap.policy.common.logging.flexlogger.FlexLogger; -import org.onap.policy.common.logging.flexlogger.Logger; - - -public class ConfigurableRESTUtils { - - protected Logger LOGGER = FlexLogger.getLogger(this.getClass()); - - // - // How the value is returned from the RESTful server - // httpResponseCode means the result is simply the HTTP Response code (e.g. 200, 505, etc.) - // other values identify the encoding used for the string in the body of the HTTP response - // - public enum REST_RESPONSE_FORMAT {httpResponseCode, json } - public enum RESQUEST_METHOD { - GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE; - } - - private String ERROR_RECEIVED = "ERROR - Unexpected HTTP response: "; - - public ConfigurableRESTUtils() { - //Default Constructor - } - - - /** - * Call the RESTful API and return a string containing the result. The string may be either a httpResponseCode or json body - * - * @param fullURI - * @param hardCodedHeaders - * @param httpResponseCodes - * @param responseFormat - * @param jsonBody - * @param requestMethod - * @return String - */ - public String sendRESTRequest(String fullURI, Map<String, String> hardCodedHeaderMap, - Map<Integer,String> httpResponseCodeMap, - REST_RESPONSE_FORMAT responseFormat, - String jsonBody, - RESQUEST_METHOD requestMethod ){ - - String responseString = null; - HttpURLConnection connection = null; - try { - - URL url = new URL(fullURI); - - // - // Open up the connection - // - connection = (HttpURLConnection)url.openConnection(); - // - // Setup our method and headers - // - connection.setRequestMethod(requestMethod.toString()); - - connection.setUseCaches(false); - - // add hard-coded headers - for (Entry<String, String> entry : hardCodedHeaderMap.entrySet()) { - connection.addRequestProperty(entry.getKey(), entry.getValue()); - } - - if (jsonBody != null){ - connection.setDoInput(true); - connection.setDoOutput(true); - OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream()); - out.write(jsonBody); - out.flush(); - out.close(); - } else{ - connection.connect(); - } - - int responseCode = connection.getResponseCode(); - - // check that the response is one we expected (and get the associated value at the same time) - responseString = httpResponseCodeMap.get(responseCode); - if (responseString == null) { - // the response was not configured, meaning it is unexpected and therefore an error - LOGGER.error("Unexpected HTTP response code '" + responseCode + "' from RESTful Server"); - return ERROR_RECEIVED + " code" + responseCode + " from RESTful Server"; - } - - // if the response is contained only in the http code we are done. Otherwise we need to read the body - if (responseFormat == REST_RESPONSE_FORMAT.httpResponseCode) { - return responseString; - } - - // Need to read the body and return that as the responseString. - - responseString = null; - // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file) - java.util.Scanner scanner = new java.util.Scanner(connection.getInputStream()); - scanner.useDelimiter("\\A"); - responseString = scanner.hasNext() ? scanner.next() : ""; - scanner.close(); - LOGGER.debug("RESTful body: " + responseString); - return responseString; - - } catch (Exception e) { - LOGGER.error("HTTP Request/Response from RESTFUL server: " + e); - responseString = ERROR_RECEIVED + e; - } finally { - // cleanup the connection - if (connection != null) { - try { - // For some reason trying to get the inputStream from the connection - // throws an exception rather than returning null when the InputStream does not exist. - InputStream is = null; - try { - is = connection.getInputStream(); - } catch (Exception e1) { - LOGGER.error("Exception Occured"+e1); - } - if (is != null) { - is.close(); - } - - } catch (IOException ex) { - LOGGER.error("Failed to close connection: " + ex, ex); - } - connection.disconnect(); - } - } - return responseString; - - } - -} diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/utils/PolicyContainer.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/utils/PolicyContainer.java deleted file mode 100644 index 08f477f38..000000000 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/utils/PolicyContainer.java +++ /dev/null @@ -1,118 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP Policy Engine - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.utils; - -import java.io.Serializable; -import java.util.Collection; -import java.util.List; - - -public interface PolicyContainer extends Serializable{ - - public Collection<?> getContainerPropertyIds(); - - public Collection<?> getItemIds(); - - public Class<?> getType(Object propertyId); - - public int size(); - - public boolean containsId(Object itemId); - - public Object addItem(); - - public boolean removeItem(Object itemId); - - public boolean addContainerProperty(Object propertyId, Class<?> type, - Object defaultValue); - - public boolean removeContainerProperty(Object propertyId); - - public boolean removeAllItems(); - - public interface Ordered extends PolicyContainer { - - public Object nextItemId(Object itemId); - - public Object prevItemId(Object itemId); - - public Object firstItemId(); - - public Object lastItemId(); - - public boolean isFirstId(Object itemId); - - public boolean isLastId(Object itemId); - - public Object addItemAfter(Object previousItemId); - - } - - - public interface Indexed extends Ordered { - - public int indexOfId(Object itemId); - - public Object getIdByIndex(int index); - - public List<?> getItemIds(int startIndex, int numberOfItems); - - public Object addItemAt(int index); - - public interface ItemAddEvent extends ItemSetChangeEvent { - - public Object getFirstItemId(); - - public int getFirstIndex(); - - public int getAddedItemsCount(); - } - - - public interface ItemRemoveEvent extends ItemSetChangeEvent { - - public Object getFirstItemId(); - - public int getFirstIndex(); - - public int getRemovedItemsCount(); - } - } - - public interface ItemSetChangeEvent extends Serializable { - - public PolicyContainer getContainer(); - } - - public interface ItemSetChangeListener extends Serializable { - - public void containerItemSetChange(PolicyContainer.ItemSetChangeEvent event); - } - - public interface ItemSetChangeNotifier extends Serializable { - - public void addItemSetChangeListener( - PolicyContainer.ItemSetChangeListener listener); - - public void removeItemSetChangeListener( - PolicyContainer.ItemSetChangeListener listener); - } -} diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/utils/PolicyItemSetChangeNotifier.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/utils/PolicyItemSetChangeNotifier.java deleted file mode 100644 index 61b51cc92..000000000 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/utils/PolicyItemSetChangeNotifier.java +++ /dev/null @@ -1,96 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP Policy Engine - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.utils; - - -import java.io.Serializable; -import java.util.Collection; -import java.util.EventObject; -import java.util.LinkedList; - -import org.onap.policy.utils.PolicyContainer.ItemSetChangeEvent; -import org.onap.policy.utils.PolicyContainer.ItemSetChangeListener; - - - -public class PolicyItemSetChangeNotifier implements PolicyContainer.ItemSetChangeNotifier { - private static final long serialVersionUID = 1L; - private Collection<PolicyContainer.ItemSetChangeListener> itemSetChangeListeners = null; - private PolicyContainer container = null; - - public PolicyItemSetChangeNotifier() { - // Empty constructor - } - - protected void setContainer(PolicyContainer c) { - this.container = c; - } - - @Override - public void addItemSetChangeListener(ItemSetChangeListener listener) { - if (getItemSetChangeListeners() == null) { - setItemSetChangeListeners(new LinkedList<PolicyContainer.ItemSetChangeListener>()); - } - getItemSetChangeListeners().add(listener); } - - @Override - public void removeItemSetChangeListener(ItemSetChangeListener listener) { - if (getItemSetChangeListeners() != null) { - getItemSetChangeListeners().remove(listener); - } - } - - protected static class BaseItemSetChangeEvent extends EventObject implements - PolicyContainer.ItemSetChangeEvent, Serializable { - private static final long serialVersionUID = 1L; - - protected BaseItemSetChangeEvent(PolicyContainer source) { - super(source); - } - - @Override - public PolicyContainer getContainer() { - return (PolicyContainer) getSource(); - } - } - - protected void setItemSetChangeListeners( - Collection<PolicyContainer.ItemSetChangeListener> itemSetChangeListeners) { - this.itemSetChangeListeners = itemSetChangeListeners; - } - protected Collection<PolicyContainer.ItemSetChangeListener> getItemSetChangeListeners() { - return itemSetChangeListeners; - } - - protected void fireItemSetChange() { - fireItemSetChange(new BaseItemSetChangeEvent(this.container)); - } - - protected void fireItemSetChange(ItemSetChangeEvent event) { - if (getItemSetChangeListeners() != null) { - final Object[] l = getItemSetChangeListeners().toArray(); - for (int i = 0; i < l.length; i++) { - ((PolicyContainer.ItemSetChangeListener) l[i]) - .containerItemSetChange(event); - } - } - } -} |