1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.onemind.commons.java.xml.digest;
22
23 import java.util.EventObject;
24 import org.onemind.commons.java.event.*;
25 import org.onemind.commons.java.event.EventFirer;
26 import org.onemind.commons.java.event.EventListenerList;
27 import org.xml.sax.Attributes;
28 import org.xml.sax.SAXException;
29 /***
30 * The abstract implementation of ElementCreatorDigester. The element creator will fire an event
31 * at the end of digestion
32 * @author TiongHiang Lee (thlee@onemindsoft.org)
33 */
34 public abstract class AbstractElementCreatorDigester extends DefaultDigester implements ElementCreatorDigester
35 {
36 /*** the listener list **/
37 private final EventListenerList _listeners = new EventListenerList();
38
39 /*** the created object **/
40 private Object _created;
41
42 /*** event firer for element event **/
43 private static final EventFirer _FIRER = new EventFirer()
44 {
45
46 /***
47 * {@inheritDoc}
48 */
49 public void fireEvent(EventListener listener, EventObject evt)
50 {
51 ((ElementListener) listener).objectCreated(((ElementEvent) evt).getElement());
52 }
53 };
54
55 /***
56 * Constructor
57 * @param name the element name
58 */
59 public AbstractElementCreatorDigester(String name)
60 {
61 super(name);
62 }
63
64 /***
65 * {@inheritDoc}
66 */
67 public final void addListener(ElementListener l)
68 {
69 _listeners.addListener(l);
70 }
71
72 /***
73 * {@inheritDoc}
74 */
75 public final void removeListener(ElementListener l)
76 {
77 _listeners.removeListener(l);
78 }
79
80 /***
81 * {@inheritDoc}
82 */
83 public void endDigest(SaxDigesterHandler handler) throws SAXException
84 {
85 _listeners.fireEvent(_FIRER, new ElementEvent(this, getCreatedElement()));
86 }
87
88 /***
89 * Set the created element
90 * @param obj the object
91 */
92 protected final void setCreatedElement(Object obj)
93 {
94 _created = obj;
95 }
96
97 /***
98 * {@inheritDoc}
99 */
100 public final Object getCreatedElement()
101 {
102 return _created;
103 }
104 }