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=========================================================
21 package org.onap.policy.utils;
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.utils.PolicyContainer.ItemSetChangeEvent;
30 import org.onap.policy.utils.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() {
42 protected void setContainer(PolicyContainer c) {
47 public void addItemSetChangeListener(ItemSetChangeListener listener) {
48 if (getItemSetChangeListeners() == null) {
49 setItemSetChangeListeners(new LinkedList<PolicyContainer.ItemSetChangeListener>());
51 getItemSetChangeListeners().add(listener); }
54 public void removeItemSetChangeListener(ItemSetChangeListener listener) {
55 if (getItemSetChangeListeners() != null) {
56 getItemSetChangeListeners().remove(listener);
60 protected static class BaseItemSetChangeEvent extends EventObject implements
61 PolicyContainer.ItemSetChangeEvent, Serializable {
62 private static final long serialVersionUID = 1L;
64 protected BaseItemSetChangeEvent(PolicyContainer source) {
69 public PolicyContainer getContainer() {
70 return (PolicyContainer) getSource();
74 protected void setItemSetChangeListeners(
75 Collection<PolicyContainer.ItemSetChangeListener> itemSetChangeListeners) {
76 this.itemSetChangeListeners = itemSetChangeListeners;
78 protected Collection<PolicyContainer.ItemSetChangeListener> getItemSetChangeListeners() {
79 return itemSetChangeListeners;
82 protected void fireItemSetChange() {
83 fireItemSetChange(new BaseItemSetChangeEvent(this.container));
86 protected void fireItemSetChange(ItemSetChangeEvent event) {
87 if (getItemSetChangeListeners() != null) {
88 final Object[] l = getItemSetChangeListeners().toArray();
89 for (int i = 0; i < l.length; i++) {
90 ((PolicyContainer.ItemSetChangeListener) l[i])
91 .containerItemSetChange(event);