1
15
16 package gate.creole;
17
18 import java.io.Serializable;
19 import java.net.URL;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import gate.*;
24 import gate.util.*;
25
26
39 public class ResourceData extends AbstractFeatureBearer implements Serializable
40 {
41
42
43 protected static final boolean DEBUG = false;
44
45 protected static final String DEFAULT_LR_ICON = "lr.gif";
46 protected static final String DEFAULT_PR_ICON = "pr.gif";
47 protected static final String DEFAULT_OTHER_ICON = "controller.gif";
48
49 public ResourceData() { }
51
52 public String toString() {
53 int noInst = (instantiationStack == null) ? 0: instantiationStack.size();
54
58 StringBuffer s = new StringBuffer(
59 "ResourceDataImpl, name=" + name + "; className=" + className +
60 "; jarFileName=" + jarFileName + "; jarFileUrl=" + jarFileUrl +
61 "; xmlFileName=" + xmlFileName + "; xmlFileUrl=" + xmlFileUrl +
62 "; isAutoLoading=" + autoLoading + "; numberInstances=" + noInst +
63 "; isPrivate=" + priv +"; isTool="+ tool +
64 "; validityMessage=" + validityMessage +
65 "; interfaceName=" + interfaceName +
66 "; guiType=" + guiType +
67 "; mainViewer=" + isMainView +
68 "; resourceDisplayed=" + resourceDisplayed +
69 "; annotationTypeDisplayed=" + annotationTypeDisplayed +
70 "; parameterList=" + parameterList +
71 "; features=" + features
72 );
73 return s.toString();
74 }
76
79 public boolean equals(Object other) {
80 if(name.equals(((ResourceData) other).getName()))
81 return true;
82 return false;
83 }
85
86 public int hashCode() {
87 return name.hashCode();
88 }
90
91 protected String name;
92
93
94 public void setName(String name) { this.name = name; }
95
96
97 public String getName() { return name; }
98
99
100 protected String icon;
101
102
103 public void setIcon(String icon) { this.icon = icon; }
104
105
106 public String getIcon() {
107 if(icon == null){
109 icon = guessIcon();
110 }
111 return icon;
112 }
113
114
121 protected String guessIcon(){
122 if(className == null) return DEFAULT_OTHER_ICON;
124 if(resourceClass == null) return DEFAULT_OTHER_ICON;
125 if(LanguageResource.class.isAssignableFrom(resourceClass))
126 return DEFAULT_LR_ICON;
127 if(ProcessingResource.class.isAssignableFrom(resourceClass))
128 return DEFAULT_PR_ICON;
129 return DEFAULT_OTHER_ICON;
130 }
131
132
133 protected WeakBumpyStack instantiationStack = new WeakBumpyStack();
134
135
139 protected List persistantInstantiationList = new ArrayList();
140
141
142 public WeakBumpyStack getInstantiations() {
143 return instantiationStack;
144 }
146
147 public void addInstantiation(Resource resource) {
148 instantiationStack.push(resource);
149 }
151
155 public void makeInstantiationPersistant(Resource resource) {
156 persistantInstantiationList.add(resource);
157 }
159
160 public void removeInstantiation(Resource resource) {
161 instantiationStack.remove(resource);
162 persistantInstantiationList.remove(resource);
163 }
165
166 public void bumpInstantiation(Resource resource) {
167 instantiationStack.bump(resource);
168 }
170
171 protected String className;
172
173
174 public void setClassName(String className) { this.className = className; }
175
176
177 public String getClassName() { return className; }
178
179
180 protected String interfaceName;
181
182
183 public void setInterfaceName(String interfaceName) {
184 this.interfaceName = interfaceName;
185 }
187
188 public String getInterfaceName() { return interfaceName; }
189
190
191 protected Class resourceClass;
192
193
194 public void setResourceClass(Class resourceClass) {
195 this.resourceClass = resourceClass;
196 }
198
201 public Class getResourceClass() throws ClassNotFoundException {
202 if(resourceClass == null) {
203 GateClassLoader classLoader = Gate.getClassLoader();
204 resourceClass = classLoader.loadClass(className);
205 }
206
207 return resourceClass;
208 }
210
211 protected String jarFileName;
212
213
214 public void setJarFileName(String jarFileName) {
215 this.jarFileName = jarFileName;
216 }
218
219 public String getJarFileName() { return jarFileName; }
220
221
222 protected URL jarFileUrl;
223
224
225 public void setJarFileUrl(URL jarFileUrl) { this.jarFileUrl = jarFileUrl; }
226
227
228 public URL getJarFileUrl() { return jarFileUrl; }
229
230
231 protected String xmlFileName;
232
233
234 protected URL xmlFileUrl;
235
236
237 public void setXmlFileUrl(URL xmlFileUrl) { this.xmlFileUrl = xmlFileUrl; }
238
239
240 public URL getXmlFileUrl() { return xmlFileUrl; }
241
242
243 protected String comment;
244
245
246 public String getComment() { return comment; }
247
248
249 public void setComment(String comment) { this.comment = comment; }
250
251
252 protected ParameterList parameterList = new ParameterList();
253
254
255 public void setParameterList(ParameterList parameterList) {
256 this.parameterList = parameterList;
257 }
259
260 public ParameterList getParameterList() { return parameterList; }
261
262
263 protected boolean autoLoading;
264
265
266 public void setAutoLoading(boolean autoLoading) {
267 this.autoLoading = autoLoading;
268 }
270
271 public boolean isAutoLoading() { return autoLoading; }
272
273
274 protected boolean priv = false;
275
276
277 public void setPrivate(boolean priv) {
278 this.priv = priv;
279 }
281
282 public boolean isPrivate() { return priv; }
283
284
285 protected boolean tool = false;
286
287
288 public void setTool(boolean tool) {
289 this.tool = tool;
290 }
292
293 public boolean isTool() { return tool; }
294
297 public boolean isValid() {
298 boolean valid = true;
299 return valid;
304 }
306
307 protected String validityMessage = "";
308
309
310 public String getValidityMessage() { return validityMessage; }
311
312
316 public static final int NULL_GUI = 0;
317
318 public static final int LARGE_GUI = 1;
319
320 public static final int SMALL_GUI = 2;
321
322 protected int guiType = NULL_GUI;
323
324 protected boolean isMainView = false;
325
326 protected String resourceDisplayed = null;
327
328 protected String annotationTypeDisplayed = null;
329
330 public void setGuiType(int aGuiType){guiType = aGuiType;}
331
332 public int getGuiType(){return guiType;}
333
334 public void setIsMainView(boolean mainView){isMainView = mainView;}
335
336 public boolean isMainView(){return isMainView;}
337
338 public void setResourceDisplayed(String aResourceDisplayed){
339 resourceDisplayed = aResourceDisplayed;
340 }
342 public String getResourceDisplayed(){return resourceDisplayed;}
343
344 public void setAnnotationTypeDisplayed(String anAnnotationTypeDisplayed){
345 annotationTypeDisplayed = anAnnotationTypeDisplayed;
346 }
348 public String getAnnotationTypeDisplayed(){return annotationTypeDisplayed;}
349 }