View Javadoc

1   package at.ac.tuwien.infosys.sm4all.copal.api.listener.xml;
2   
3   import org.w3c.dom.Element;
4   import at.ac.tuwien.infosys.sm4all.copal.api.listener.ContextListener;
5   import at.ac.tuwien.infosys.sm4all.copal.api.processor.ContextProcessor;
6   import at.ac.tuwien.infosys.sm4all.copal.api.xml.Marshaller;
7   
8   /**
9    * Command that marshalls a {@link ContextListener} into an {@link Element}.
10   * 
11   * @author sanjin
12   */
13  public class XMLContextListener implements Marshaller<ContextListener> {
14  
15      private final Element element;
16  
17      /**
18       * Creates instance of {@link ContextListener} marshaller which uses
19       * specified {@link Element} to marshal the {@link ContextListener}.
20       * 
21       * @param element the {@link Element} used for marshalling.
22       * @throws NullPointerException if specified {@link Element} is
23       *         <code>null</code>.
24       */
25      public XMLContextListener(final Element element) {
26          super();
27  
28          if (element == null)
29              throw new NullPointerException("XML DOM element cannot be null.");
30  
31          this.element = element;
32      }
33  
34      /**
35       * Marshalls specified {@link ContextListener} into specified
36       * {@link Element}.
37       * 
38       * @param listener the {@link ContextListener}.
39       * @throws NullPointerException if specified {@link ContextProcessor} is
40       *         <code>null</code>.
41       */
42      @Override
43      public void marshal(final ContextListener listener) {
44          if (listener == null)
45              throw new NullPointerException("Listener cannot be null.");
46  
47          new Name(this.element).marshal(listener);
48      }
49  }