MCPcopy Create free account
hub / github.com/GateNLP/gate-core / AbstractResource

Class AbstractResource

src/main/java/gate/creole/AbstractResource.java:45–510  ·  view source on GitHub ↗

A convenience implementation of Resource with some default code.

Source from the content-addressed store, hash-verified

43/** A convenience implementation of Resource with some default code.
44 */
45abstract public class AbstractResource
46extends AbstractFeatureBearer implements Resource
47{
48 static final long serialVersionUID = -9196293927841163321L;
49
50 /** Initialise this resource, and return it. */
51 @Override
52 public Resource init() throws ResourceInstantiationException {
53 return this;
54 } // init()
55
56 /** Sets the name of this resource*/
57 @Override
58 public void setName(String name){
59 this.name = name;
60 }
61
62 /** Returns the name of this resource*/
63 @Override
64 public String getName(){
65 return name;
66 }
67
68 protected String name;
69 /**
70 * releases the memory allocated to this resource
71 */
72 @Override
73 public void cleanup(){
74 }
75
76 //Parameters utility methods
77 /**
78 * Gets the value of a parameter for a resource.
79 * @param resource the resource from which the parameter value will be
80 * obtained
81 * @param paramaterName the name of the parameter
82 * @return the current value of the parameter
83 */
84 public static Object getParameterValue(Resource resource,
85 String paramaterName)
86 throws ResourceInstantiationException{
87 // get the beaninfo for the resource bean, excluding data about Object
88 BeanInfo resBeanInf = null;
89 try {
90 resBeanInf = getBeanInfo(resource.getClass());
91 } catch(Exception e) {
92 throw new ResourceInstantiationException(
93 "Couldn't get bean info for resource " + resource.getClass().getName()
94 + Strings.getNl() + "Introspector exception was: " + e
95 );
96 }
97 PropertyDescriptor[] properties = resBeanInf.getPropertyDescriptors();
98
99 //find the property we're interested on
100 if(properties == null){
101 throw new ResourceInstantiationException(
102 "Couldn't get properties info for resource " +

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected