2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.rest.util;
24 import java.io.Serializable;
25 import java.util.Collection;
26 import java.util.EventObject;
27 import java.util.LinkedList;
29 import org.onap.policy.rest.util.PolicyContainer.ItemSetChangeEvent;
30 import org.onap.policy.rest.util.PolicyContainer.ItemSetChangeListener;
32 public class PolicyItemSetChangeNotifier implements PolicyContainer.ItemSetChangeNotifier {
33 private static final long serialVersionUID = 1L;
35 private Collection<PolicyContainer.ItemSetChangeListener> itemSetChangeListeners = null;
36 private PolicyContainer container = null;
38 public PolicyItemSetChangeNotifier() {
42 protected void setContainer(PolicyContainer container) {
43 this.container = container;
47 public void addItemSetChangeListener(ItemSetChangeListener listener) {
48 if (getItemSetChangeListeners() == null) {
49 setItemSetChangeListeners(new LinkedList<PolicyContainer.ItemSetChangeListener>());
51 getItemSetChangeListeners().add(listener);
55 public void removeItemSetChangeListener(ItemSetChangeListener listener) {
56 if (getItemSetChangeListeners() != null) {
57 getItemSetChangeListeners().remove(listener);
61 protected static class BaseItemSetChangeEvent extends EventObject
62 implements PolicyContainer.ItemSetChangeEvent, Serializable {
63 private static final long serialVersionUID = 1L;
65 protected BaseItemSetChangeEvent(PolicyContainer source) {
70 public PolicyContainer getContainer() {
71 return (PolicyContainer) getSource();
75 protected void setItemSetChangeListeners(Collection<PolicyContainer.ItemSetChangeListener> itemSetChangeListeners) {
76 this.itemSetChangeListeners = itemSetChangeListeners;
79 protected Collection<PolicyContainer.ItemSetChangeListener> getItemSetChangeListeners() {
80 return itemSetChangeListeners;
83 protected void fireItemSetChange() {
84 fireItemSetChange(new BaseItemSetChangeEvent(this.container));
87 protected void fireItemSetChange(ItemSetChangeEvent event) {
88 if (getItemSetChangeListeners() != null) {
89 final Object[] l = getItemSetChangeListeners().toArray();
90 for (int i = 0; i < l.length; i++) {
91 ((PolicyContainer.ItemSetChangeListener) l[i]).containerItemSetChange(event);