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=========================================================
21 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;
34 public class PolicyItemSetChangeNotifier implements PolicyContainer.ItemSetChangeNotifier {
35 private static final long serialVersionUID = 1L;
36 private Collection<PolicyContainer.ItemSetChangeListener> itemSetChangeListeners = null;
37 private PolicyContainer container = null;
39 public PolicyItemSetChangeNotifier() {
43 protected void setContainer(PolicyContainer c) {
48 public void addItemSetChangeListener(ItemSetChangeListener listener) {
49 if (getItemSetChangeListeners() == null) {
50 setItemSetChangeListeners(new LinkedList<PolicyContainer.ItemSetChangeListener>());
52 getItemSetChangeListeners().add(listener); }
55 public void removeItemSetChangeListener(ItemSetChangeListener listener) {
56 if (getItemSetChangeListeners() != null) {
57 getItemSetChangeListeners().remove(listener);
61 protected static class BaseItemSetChangeEvent extends EventObject implements
62 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(
76 Collection<PolicyContainer.ItemSetChangeListener> itemSetChangeListeners) {
77 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])
92 .containerItemSetChange(event);