View Javadoc
1   package org.exolab.castor.xml.parsing;
2   
3   import org.castor.xml.UnmarshalListener;
4   import org.castor.xml.UnmarshalListenerAdapter;
5   import org.exolab.castor.xml.UnmarshalHandler;
6   
7   /**
8    * This class handles delegates methods call to {@link UnmarshalListener}. Even if
9    * {@link UnmarshalListener} is null, all of the delegating methods can be invoke.
10   * 
11   * @author <a href="mailto:philipp DOT erlacher AT gmail DOT com">Philipp Erlacher</a>
12   * 
13   * @since 1.3.2
14   */
15  public class UnmarshalListenerDelegate implements UnmarshalListener {
16  
17    /**
18     * The unmarshaller listener.
19     */
20    private org.castor.xml.UnmarshalListener _unmarshalListener = null;
21  
22    /**
23     * Sets an {@link org.castor.xml.UnmarshalListener}.
24     * 
25     * @param listener the {@link org.castor.xml.UnmarshalListener} to use with this instance of the
26     *        {@link UnmarshalHandler}.
27     */
28    public void setUnmarshalListener(org.castor.xml.UnmarshalListener listener) {
29      _unmarshalListener = listener;
30    }
31  
32    /**
33     * Sets an {@link org.exolab.castor.xml.UnmarshalListener}.
34     * 
35     * @param listener the {@link org.exolab.castor.xml.UnmarshalListener} to use with this instance
36     *        of the UnmarshalHandler.
37     * @deprecated please move to the new {@link org.castor.xml.UnmarshalListener} interface
38     */
39    public void setUnmarshalListener(org.exolab.castor.xml.UnmarshalListener listener) {
40      if (listener == null) {
41        listener = null;
42      } else {
43        UnmarshalListenerAdapter adapter = new UnmarshalListenerAdapter();
44        adapter.setOldListener(listener);
45        _unmarshalListener = adapter;
46      }
47    }
48  
49    /**
50     * @see org.castor.xml.UnmarshalListener.unmarshalled
51     * @param object
52     * @param parentObject
53     */
54    public void unmarshalled(Object object, Object parentObject) {
55      // -- We're finished processing the object, so notify the
56      // -- Listener (if any).
57      if (_unmarshalListener != null && object != null) {
58        _unmarshalListener.unmarshalled(object, parentObject);
59      }
60  
61    }
62  
63    /**
64     * @see org.castor.xml.UnmarshalListener.fieldAdded
65     * @param object
66     * @param parentObject
67     */
68    public void fieldAdded(String fieldName, Object stateObject, Object fieldStateObject) {
69      // If there is a parent for this object, pass along
70      // a notification that we've finished adding a child
71      if (_unmarshalListener != null) {
72        _unmarshalListener.fieldAdded(fieldName, stateObject, fieldStateObject);
73      }
74    }
75  
76    /**
77     * @see org.castor.xml.UnmarshalListener.initialized
78     * @param object
79     * @param parentObject
80     */
81    public void initialized(Object stateObject, Object parentObject) {
82      if (_unmarshalListener != null)
83        _unmarshalListener.initialized(stateObject, parentObject);
84    }
85  
86    /**
87     * @see org.castor.xml.UnmarshalListener.attributesProcessed
88     * @param object
89     * @param parentObject
90     */
91    public void attributesProcessed(Object stateObject, Object parentObject) {
92      if (_unmarshalListener != null)
93        _unmarshalListener.attributesProcessed(stateObject, parentObject);
94    }
95  }