View Javadoc

1   /*
2    * Copyright (C) 2004 TiongHiang Lee
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not,  write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   *
18   * Email: thlee@onemindsoft.org
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 }