1
15
16
17 package gate.jape;
18
19 import java.io.Serializable;
20 import java.net.URL;
21 import java.util.Vector;
22
23 import gate.AnnotationSet;
24 import gate.Document;
25 import gate.creole.ExecutionException;
26 import gate.creole.ontology.Ontology;
27 import gate.event.ProgressListener;
28 import gate.event.StatusListener;
29
30
31
34 public abstract class Transducer implements Serializable
35 {
36
37 private static final boolean DEBUG = false;
38
39
40 protected String name;
41
42 protected Ontology ontology = null;
43
44
45 public String getName() { return name; }
46
47
48 public abstract void transduce(Document doc, AnnotationSet inputAS,
49 AnnotationSet outputAS)
50 throws JapeException, ExecutionException;
51
52
55 public abstract void finish();
56
57
58 public abstract void cleanUp();
59
60
61 public abstract String toString(String pad);
62
63
64
68 public synchronized boolean isInterrupted(){
69 return interrupted;
70 }
71
72
75 public synchronized void interrupt(){
76 interrupted = true;
77 }
78
79 protected boolean interrupted = false;
80
81
82 public void setBaseURL(java.net.URL newBaseURL) {
83 baseURL = newBaseURL;
84 }
85 public java.net.URL getBaseURL() {
86 return baseURL;
87 }
88 public synchronized void removeProgressListener(ProgressListener l) {
89 if (progressListeners != null && progressListeners.contains(l)) {
90 Vector v = (Vector) progressListeners.clone();
91 v.removeElement(l);
92 progressListeners = v;
93 }
94 }
95 public synchronized void addProgressListener(ProgressListener l) {
96 Vector v = progressListeners == null ? new Vector(2) : (Vector) progressListeners.clone();
97 if (!v.contains(l)) {
98 v.addElement(l);
99 progressListeners = v;
100 }
101 }
102
103 public void setDebugMode(boolean debugMode) {
104 this.debugMode = debugMode;
105 }
106 public boolean isDebugMode() {
107 return debugMode;
108 }
109
110
113 private boolean debugMode = false;
114
115 public void setMatchGroupMode(boolean mode) {
116 matchGroupMode = mode;
117 }
118
119 public boolean isMatchGroupMode() {
120 return matchGroupMode;
121 }
122
123
125 private boolean matchGroupMode = false;
126
127 private URL baseURL;
128
129 private transient Vector progressListeners;
130 private transient Vector statusListeners;
131
132
135 protected boolean enableDebugging;
136
137
142 protected void fireProgressChanged(int e) {
143 if (progressListeners != null && !progressListeners.isEmpty()) {
144 Vector listeners = progressListeners;
145 int count = listeners.size();
146 for (int i = 0; i < count; i++) {
147 ((ProgressListener) listeners.elementAt(i)).progressChanged(e);
148 }
149 }
150 }
151 protected void fireProcessFinished() {
152 if (progressListeners != null) {
153 Vector listeners = progressListeners;
154 int count = listeners.size();
155 for (int i = 0; i < count; i++) {
156 ((ProgressListener) listeners.elementAt(i)).processFinished();
157 }
158 }
159 }
160 public synchronized void removeStatusListener(StatusListener l) {
161 if (statusListeners != null && statusListeners.contains(l)) {
162 Vector v = (Vector) statusListeners.clone();
163 v.removeElement(l);
164 statusListeners = v;
165 }
166 }
167 public synchronized void addStatusListener(StatusListener l) {
168 Vector v = statusListeners == null ? new Vector(2) : (Vector) statusListeners.clone();
169 if (!v.contains(l)) {
170 v.addElement(l);
171 statusListeners = v;
172 }
173 }
174 protected void fireStatusChanged(String e) {
175 if (statusListeners != null) {
176 Vector listeners = statusListeners;
177 int count = listeners.size();
178 for (int i = 0; i < count; i++) {
179 ((StatusListener) listeners.elementAt(i)).statusChanged(e);
180 }
181 }
182 }
183
184
188 public Ontology getOntology() {
189 return ontology;
190 }
191
192
196 public void setOntology(Ontology ontology) {
197 this.ontology = ontology;
198 }
199
200 public boolean isEnableDebugging() {
201 return enableDebugging;
202 }
203
204 public void setEnableDebugging(boolean enableDebugging) {
205 this.enableDebugging = enableDebugging;
206 }
207
208
210 }
212
213
214