| ResourceData.java |
1 /*
2 * ResourceData.java
3 *
4 * Copyright (c) 1998-2004, The University of Sheffield.
5 *
6 * This file is part of GATE (see http://gate.ac.uk/), and is free
7 * software, licenced under the GNU Library General Public License,
8 * Version 2, June 1991 (in the distribution as file licence.html,
9 * and also available at http://gate.ac.uk/gate/licence.html).
10 *
11 * Hamish Cunningham, 1/Sept/2000
12 *
13 * $Id: ResourceData.java,v 1.20 2004/11/09 12:54:23 valyt Exp $
14 */
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 /** Models an individual CREOLE resource metadata, plus configuration data,
27 * plus the instantiations of the resource current within the system.
28 * Some metadata elements are used by GATE to load resources, or index
29 * the members of the CREOLE register; some are used during resource
30 * parameterisation and initialisation.
31 * Metadata elements which are used by the CREOLE registration and loading
32 * mechanisms are properties of ResourceData implementations and have their
33 * own get/set methods. Other metadata elements are made features of the
34 * ResourceData. So, for example, if you add an element "FunkyElementThaing"
35 * to the metadata of a resource, this will be made a feature of that
36 * resource's ResourceData.
37 * @see CreoleRegister
38 */
39 public class ResourceData extends AbstractFeatureBearer implements Serializable
40 {
41
42 /** Debug flag */
43 protected static final boolean DEBUG = false;
44
45 /** Construction */
46 public ResourceData() { }// ResourceData
47
48 /** String representation */
49 public String toString() {
50 int noInst = (instantiationStack == null) ? 0: instantiationStack.size();
51 /*
52 int noSmallViews = (smallViews == null) ? 0: smallViews.size();
53 int noViews = (views == null) ? 0: views.size();
54 */
55 StringBuffer s = new StringBuffer(
56 "ResourceDataImpl, name=" + name + "; className=" + className +
57 "; jarFileName=" + jarFileName + "; jarFileUrl=" + jarFileUrl +
58 "; xmlFileName=" + xmlFileName + "; xmlFileUrl=" + xmlFileUrl +
59 "; isAutoLoading=" + autoLoading + "; numberInstances=" + noInst +
60 "; isPrivate=" + priv +"; isTool="+ tool +
61 "; validityMessage=" + validityMessage +
62 "; interfaceName=" + interfaceName +
63 "; guiType=" + guiType +
64 "; mainViewer=" + isMainView +
65 "; resourceDisplayed=" + resourceDisplayed +
66 "; annotationTypeDisplayed=" + annotationTypeDisplayed +
67 "; parameterList=" + parameterList +
68 "; features=" + features
69 );
70 return s.toString();
71 } // toString
72
73 /** Equality: two resource data objects are the same if they have the
74 * same name
75 */
76 public boolean equals(Object other) {
77 if(name.equals(((ResourceData) other).getName()))
78 return true;
79 return false;
80 } // equals
81
82 /** Hashing, based on the name field of the object */
83 public int hashCode() {
84 return name.hashCode();
85 } // hashCode
86
87 /** The name of the resource */
88 protected String name;
89
90 /** Set method for the resource name */
91 public void setName(String name) { this.name = name; }
92
93 /** Get method for the resource name */
94 public String getName() { return name; }
95
96 /** Location of an icon for the resource */
97 protected String icon;
98
99 /** Set method for the resource icon */
100 public void setIcon(String icon) { this.icon = icon; }
101
102 /** Get method for the resource icon */
103 public String getIcon() { return icon; }
104
105 /** The stack of instantiations */
106 protected WeakBumpyStack instantiationStack = new WeakBumpyStack();
107
108 /** This list contains all instances loaded from creole.xml with
109 * AUTOINSTANCE tag. The idea is that we don't want to loose them from the
110 * system, because of the WeakBumpyStack
111 */
112 protected List persistantInstantiationList = new ArrayList();
113
114 /** Get the list of instantiations of resources */
115 public WeakBumpyStack getInstantiations() {
116 return instantiationStack;
117 } // getInstantiations
118
119 /** Add an instantiation of the resource to the register of these */
120 public void addInstantiation(Resource resource) {
121 instantiationStack.push(resource);
122 } // addInstantiation
123
124 /** This method makes a certain resource persistent by adding it into a
125 * persistantInstantiationList. It is used especially with AUTOINSTANCE tag
126 * in creole xml.
127 */
128 public void makeInstantiationPersistant(Resource resource) {
129 persistantInstantiationList.add(resource);
130 } // makeInstantiationPersistant
131
132 /** Remove an instantiation of the resource from the register of these */
133 public void removeInstantiation(Resource resource) {
134 instantiationStack.remove(resource);
135 persistantInstantiationList.remove(resource);
136 } // removeInstantiation
137
138 /** Bump an instantiation to the top of the instantiation stack */
139 public void bumpInstantiation(Resource resource) {
140 instantiationStack.bump(resource);
141 } // bumpInstantiation
142
143 /** The class name of the resource */
144 protected String className;
145
146 /** Set method for the resource class name */
147 public void setClassName(String className) { this.className = className; }
148
149 /** Get method for the resource class name */
150 public String getClassName() { return className; }
151
152 /** The interface name of the resource */
153 protected String interfaceName;
154
155 /** Set method for the resource interface name */
156 public void setInterfaceName(String interfaceName) {
157 this.interfaceName = interfaceName;
158 } // setInterfaceName
159
160 /** Get method for the resource interface name */
161 public String getInterfaceName() { return interfaceName; }
162
163 /** The class of the resource */
164 protected Class resourceClass;
165
166 /** Set method for the resource class */
167 public void setResourceClass(Class resourceClass) {
168 this.resourceClass = resourceClass;
169 } // setResourceClass
170
171 /** Get method for the resource class. Asks the GATE class loader
172 * to load it, if it is not already present.
173 */
174 public Class getResourceClass() throws ClassNotFoundException {
175 if(resourceClass == null) {
176 GateClassLoader classLoader = Gate.getClassLoader();
177 resourceClass = classLoader.loadClass(className);
178 }
179
180 return resourceClass;
181 } // getResourceClass
182
183 /** The jar file name of the resource */
184 protected String jarFileName;
185
186 /** Set method for the resource jar file name */
187 public void setJarFileName(String jarFileName) {
188 this.jarFileName = jarFileName;
189 } // setJarFileName
190
191 /** Get method for the resource jar file name */
192 public String getJarFileName() { return jarFileName; }
193
194 /** The jar file URL of the resource */
195 protected URL jarFileUrl;
196
197 /** Set method for the resource jar file URL */
198 public void setJarFileUrl(URL jarFileUrl) { this.jarFileUrl = jarFileUrl; }
199
200 /** Get method for the resource jar file URL */
201 public URL getJarFileUrl() { return jarFileUrl; }
202
203 /** The xml file name of the resource */
204 protected String xmlFileName;
205
206 /** The xml file URL of the resource */
207 protected URL xmlFileUrl;
208
209 /** Set the URL to the creole.xml file that defines this resource */
210 public void setXmlFileUrl(URL xmlFileUrl) { this.xmlFileUrl = xmlFileUrl; }
211
212 /** Get the URL to the creole.xml file that defines this resource */
213 public URL getXmlFileUrl() { return xmlFileUrl; }
214
215 /** The comment string */
216 protected String comment;
217
218 /** Get method for the resource comment */
219 public String getComment() { return comment; }
220
221 /** Set method for the resource comment */
222 public void setComment(String comment) { this.comment = comment; }
223
224 /** The set of parameter lists */
225 protected ParameterList parameterList = new ParameterList();
226
227 /** Set the parameter list */
228 public void setParameterList(ParameterList parameterList) {
229 this.parameterList = parameterList;
230 } // addParameterList
231
232 /** Get the parameter list */
233 public ParameterList getParameterList() { return parameterList; }
234
235 /** Autoloading flag */
236 protected boolean autoLoading;
237
238 /** Set method for resource autoloading flag */
239 public void setAutoLoading(boolean autoLoading) {
240 this.autoLoading = autoLoading;
241 } // setAutoLoading
242
243 /** Is the resource autoloading? */
244 public boolean isAutoLoading() { return autoLoading; }
245
246 /** Private flag */
247 protected boolean priv = false;
248
249 /** Set method for resource private flag */
250 public void setPrivate(boolean priv) {
251 this.priv = priv;
252 } // setPrivate
253
254 /** Is the resource private? */
255 public boolean isPrivate() { return priv; }
256
257 /** Tool flag */
258 protected boolean tool = false;
259
260 /** Set method for resource tool flag */
261 public void setTool(boolean tool) {
262 this.tool = tool;
263 } // setTool
264
265 /** Is the resource a tool? */
266 public boolean isTool() { return tool; }
267 /** Is this a valid resource data configuration? If not, leave an
268 * error message that can be returned by <TT>getValidityMessage()</TT>.
269 */
270 public boolean isValid() {
271 boolean valid = true;
272 //******************************
273 // here should check that the resource has all mandatory elements,
274 // e.g. class name, and non-presence of runtime params on LRs and VRs etc.
275 //******************************
276 return valid;
277 } // isValid()
278
279 /** Status message set by isValid() */
280 protected String validityMessage = "";
281
282 /** Get validity statues message. */
283 public String getValidityMessage() { return validityMessage; }
284
285 /////////////////////////////////////////////////////
286 // Fields added for GUI element
287 /////////////////////////////////////////////////////
288 /** This type indicates that the resource is not a GUI */
289 public static final int NULL_GUI = 0;
290 /**This type indicates that the resource goes into the large area of GATE GUI*/
291 public static final int LARGE_GUI = 1;
292 /**This type indicates that the resource goes into the small area of GATE GUI*/
293 public static final int SMALL_GUI = 2;
294 /** A filed which can have one of the 3 predefined values. See above.*/
295 protected int guiType = NULL_GUI;
296 /** Whether or not this viewer will be the default one*/
297 protected boolean isMainView = false;
298 /** The full class name of the resource displayed by this viewer.*/
299 protected String resourceDisplayed = null;
300 /** The full type name of the annotation displayed by this viewer.*/
301 protected String annotationTypeDisplayed = null;
302 /** A simple mutator for guiType field*/
303 public void setGuiType(int aGuiType){guiType = aGuiType;}
304 /** A simple accessor for guiType field*/
305 public int getGuiType(){return guiType;}
306 /** A simple mutator for isMainView field*/
307 public void setIsMainView(boolean mainView){isMainView = mainView;}
308 /** A simple accessor for isMainView field*/
309 public boolean isMainView(){return isMainView;}
310 /** A simple mutator for resourceDisplayed field*/
311 public void setResourceDisplayed(String aResourceDisplayed){
312 resourceDisplayed = aResourceDisplayed;
313 }// setResourceDisplayed
314 /** A simple accessor for resourceDisplayed field*/
315 public String getResourceDisplayed(){return resourceDisplayed;}
316 /** A simple mutator for annotationTypeDisplayed field*/
317 public void setAnnotationTypeDisplayed(String anAnnotationTypeDisplayed){
318 annotationTypeDisplayed = anAnnotationTypeDisplayed;
319 }// setAnnotationTypeDisplayed
320 /** A simple accessor for annotationTypeDisplayed field*/
321 public String getAnnotationTypeDisplayed(){return annotationTypeDisplayed;}
322 } // ResourceData
323