View Javadoc

1   /*
2    ORDI - Ontology Repository and Data Integration
3   
4    Copyright (c) 2004-2007, OntoText Lab. / SIRMA
5   
6    This library is free software; you can redistribute it and/or modify it under
7    the terms of the GNU Lesser General Public License as published by the Free
8    Software Foundation; either version 2.1 of the License, or (at your option)
9    any later version.
10   This library is distributed in the hope that it will be useful, but WITHOUT
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13   details.
14   You should have received a copy of the GNU Lesser General Public License along
15   with this library; if not, write to the Free Software Foundation, Inc.,
16   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17   */
18  package com.ontotext.ordi.tripleset.impl;
19  
20  import java.util.ArrayList;
21  import java.util.Iterator;
22  import java.util.List;
23  
24  import com.ontotext.ordi.tripleset.Listener;
25  import com.ontotext.ordi.tripleset.TStatement;
26  
27  public class CallMultiplexor implements Listener {
28  
29      protected final List<Listener> listeners;
30  
31      public void addListener(Listener listener) {
32          if (listener != null) {
33              listeners.add(listener);
34          }
35      }
36  
37      public void removeListener(Listener listener) {
38          listeners.remove(listener);
39      }
40  
41      public List<Listener> listListeners() {
42          return new ArrayList<Listener>(listeners);
43      }
44  
45      public CallMultiplexor() {
46          listeners = new ArrayList<Listener>();
47      }
48  
49      public CallMultiplexor(List<Listener> listeners) {
50          if (listeners == null) {
51              throw new IllegalArgumentException();
52          }
53          this.listeners = listeners;
54      }
55  
56      public void onClose() {
57          for (Iterator<Listener> i = listeners.iterator(); i.hasNext();) {
58              i.next().onClose();
59          }
60      }
61  
62      public void onCommit() {
63          for (Iterator<Listener> i = listeners.iterator(); i.hasNext();) {
64              i.next().onCommit();
65          }
66      }
67  
68      public void onRollback() {
69          for (Iterator<Listener> i = listeners.iterator(); i.hasNext();) {
70              i.next().onRollback();
71          }
72      }
73  
74      public void statementAdded(TStatement statement) {
75          for (Iterator<Listener> i = listeners.iterator(); i.hasNext();) {
76              i.next().statementAdded(statement);
77          }
78      }
79  
80      public void statementInferred(TStatement statement) {
81          for (Iterator<Listener> i = listeners.iterator(); i.hasNext();) {
82              i.next().statementInferred(statement);
83          }
84      }
85  
86      public void statementAssociated(TStatement statement) {
87          for (Iterator<Listener> i = listeners.iterator(); i.hasNext();) {
88              i.next().statementAssociated(statement);
89          }
90      }
91  
92      public void statementDeassociated(TStatement statement) {
93          for (Iterator<Listener> i = listeners.iterator(); i.hasNext();) {
94              i.next().statementDeassociated(statement);
95          }
96      }
97  
98      public void statementRemoved(TStatement statement) {
99          for (Iterator<Listener> i = listeners.iterator(); i.hasNext();) {
100             i.next().statementRemoved(statement);
101         }
102     }
103 }