01 /*
02 * Copyright (c) 1995-2010, The University of Sheffield. See the file
03 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
04 *
05 * This file is part of GATE (see http://gate.ac.uk/), and is free
06 * software, licenced under the GNU Library General Public License,
07 * Version 2, June 1991 (in the distribution as file licence.html,
08 * and also available at http://gate.ac.uk/gate/licence.html).
09 *
10 * Eric Sword, 09/03/08
11 *
12 * $Id$
13 */
14
15 package gate.jape.constraint;
16
17 import gate.AnnotationSet;
18 import gate.Document;
19
20 import org.apache.log4j.Logger;
21
22 /**
23 * Accessor which returns a particular property or meta-property of an
24 * annotation, such as length or string.
25 *
26 * @version $Revision$
27 * @author esword
28 */
29 public abstract class MetaPropertyAccessor implements AnnotationAccessor {
30 protected static final Logger log = Logger.getLogger(MetaPropertyAccessor.class);
31
32 public MetaPropertyAccessor() {
33 super();
34 }
35
36 @Override
37 public int hashCode() {
38 return this.getClass().hashCode();
39 }
40
41 @Override
42 public boolean equals(Object obj) {
43 if(obj == null) return false;
44 if(obj == this) return true;
45 if(!(this.getClass().equals(obj.getClass()))) return false;
46
47 return true;
48 }
49
50 @Override
51 public String toString() {
52 return this.getClass().getSimpleName();
53 }
54
55 public void setKey(Object key) {
56 if(key != null && !key.equals(""))
57 log.warn(this.getClass().getName() + " doesn't use key values. Key was: " + key);
58 }
59
60 /**
61 * Sub-classes should return the name of the meta-property which they implement.
62 */
63 public abstract Object getKey();
64 }
|