01: package uk.org.ponder.saxalizer;
02:
03: /* SAXAccessMethodHash provides a quick lookup of an XML tag name to a
04: * SAXAccessMethod object corresponding to the tag, for a particular
05: * SAXalizable class.
06: */
07: class SAXAccessMethodHash {
08: /** Class <code>SAXAccessMethodHash</code> stores a hashtable of
09: * <code>set</code> methods that have been
10: * discovered in a class to allow them to be easily invoked when
11: * an object of the type it accepts is at hand. */
12: public SAXAccessMethod[] methods;
13:
14: /*
15: * @param m The <code>SAXAccessMethodSpec</code> for the method to be added to the hash
16: * @param parentclazz A class object representing the class actually possessing the
17: * method.
18: */
19: /** @param tag The tag name (<code>Xxxx</code> stub) of the
20: * <code>AccessMethod</code> object that is required.
21: * @return The required <code>AccessMethod</code> */
22: public SAXAccessMethod get(String tag) {
23: if (methods == null)
24: return null;
25: for (int i = methods.length - 1; i >= 0; --i) {
26: if (methods[i].tagname.equals(tag)) {
27: return methods[i];
28: }
29: }
30: return null;
31: }
32:
33: public SAXAccessMethodHash(SAMSList samslist, Class parentclass) {
34: methods = new SAXAccessMethod[samslist.size()];
35: for (int i = 0; i < samslist.size(); ++i) {
36: this .methods[i] = new SAXAccessMethod(samslist.SAMSAt(i),
37: parentclass);
38: }
39: }
40:
41: /** An iterator for all gettable methods */
42: public class HashSAMIterator implements SAMIterator {
43: //int methodtype;
44: int currentindex = -1;
45:
46: public HashSAMIterator() {
47: stepAlong();
48: }
49:
50: private void stepAlong() {
51: while (++currentindex < methods.length) {
52: if (methods[currentindex].canGet())
53: break;
54: //if (methodtype == SAXAccessMethodSpec.SET_METHOD && methods[currentindex].setmethod != null) break;
55: }
56: }
57:
58: public boolean valid() {
59: return currentindex < methods.length;
60: }
61:
62: public void next() {
63: stepAlong();
64: }
65:
66: public SAXAccessMethod get() {
67: return methods[currentindex];
68: }
69: }
70:
71: public SAMIterator getGetEnumeration() {
72: return new HashSAMIterator();
73: }
74: }
|