1 6 7 package com.hp.hpl.jena.graph.impl; 8 9 import java.util.*; 10 11 import com.hp.hpl.jena.graph.*; 12 import com.hp.hpl.jena.mem.TrackingTripleIterator; 13 import com.hp.hpl.jena.util.IteratorCollection; 14 import com.hp.hpl.jena.util.iterator.ExtendedIterator; 15 16 30 31 public class SimpleEventManager implements GraphEventManager 32 { 33 protected Graph graph; 34 protected List listeners; 35 36 SimpleEventManager( Graph graph ) 37 { 38 this.graph = graph; 39 this.listeners = new ArrayList(); 40 } 41 42 public GraphEventManager register( GraphListener listener ) 43 { 44 listeners.add( listener ); 45 return this; 46 } 47 48 public GraphEventManager unregister( GraphListener listener ) 49 { 50 listeners.remove( listener ); 51 return this; 52 } 53 54 public boolean listening() 55 { return listeners.size() > 0; } 56 57 public void notifyAddTriple( Graph g, Triple t ) 58 { 59 for (int i = 0; i < listeners.size(); i += 1) 60 ((GraphListener) listeners.get(i)).notifyAddTriple( g, t ); 61 } 62 63 public void notifyAddArray( Graph g, Triple [] ts ) 64 { 65 for (int i = 0; i < listeners.size(); i += 1) 66 ((GraphListener) listeners.get(i)).notifyAddArray( g, ts ); 67 } 68 69 public void notifyAddList( Graph g, List L ) 70 { 71 for (int i = 0; i < listeners.size(); i += 1) 72 ((GraphListener) listeners.get(i)).notifyAddList( g, L); 73 } 74 75 public void notifyAddIterator( Graph g, List it ) 76 { 77 for (int i = 0; i < listeners.size(); i += 1) 78 ((GraphListener) listeners.get(i)).notifyAddIterator( g, it.iterator() ); 79 } 80 81 public void notifyAddIterator( Graph g, Iterator it ) 82 { notifyAddIterator( g, IteratorCollection.iteratorToList( it ) ); } 83 84 public void notifyAddGraph( Graph g, Graph added ) 85 { 86 for (int i = 0; i < listeners.size(); i += 1) 87 ((GraphListener) listeners.get(i)).notifyAddGraph( g, added ); 88 } 89 90 public void notifyDeleteTriple( Graph g, Triple t ) 91 { 92 for (int i = 0; i < listeners.size(); i += 1) 93 ((GraphListener) listeners.get(i)).notifyDeleteTriple( g, t ); 94 } 95 96 public void notifyDeleteArray( Graph g, Triple [] ts ) 97 { 98 for (int i = 0; i < listeners.size(); i += 1) 99 ((GraphListener) listeners.get(i)).notifyDeleteArray( g, ts ); 100 } 101 102 public void notifyDeleteList( Graph g, List L ) 103 { 104 for (int i = 0; i < listeners.size(); i += 1) 105 ((GraphListener) listeners.get(i)).notifyDeleteList( g, L ); 106 } 107 108 public void notifyDeleteIterator( Graph g, List L ) 109 { 110 for (int i = 0; i < listeners.size(); i += 1) 111 ((GraphListener) listeners.get(i)).notifyDeleteIterator( g, L.iterator() ); 112 } 113 114 public void notifyDeleteIterator( Graph g, Iterator it ) 115 { notifyDeleteIterator( g, IteratorCollection.iteratorToList( it ) ); } 116 117 public void notifyDeleteGraph( Graph g, Graph removed ) 118 { 119 for (int i = 0; i < listeners.size(); i += 1) 120 ((GraphListener) listeners.get(i)).notifyDeleteGraph( g, removed ); 121 } 122 123 public void notifyEvent( Graph source, Object event ) 124 { 125 for (int i = 0; i < listeners.size(); i += 1) 126 ((GraphListener) listeners.get(i)).notifyEvent( source, event ); } 127 128 132 public static ExtendedIterator notifyingRemove( final Graph g, Iterator i ) 133 { 134 return new TrackingTripleIterator( i ) 135 { 136 protected final GraphEventManager gem = g.getEventManager(); 137 public void remove() 138 { 139 super.remove(); 140 gem.notifyDeleteTriple( g, current ); 141 } 142 }; 143 } 144 145 } 146 147 | Popular Tags |