View Javadoc

1   package at.ac.tuwien.infosys.sm4all.copal.api.event.xml.publisher;
2   
3   import org.w3c.dom.Element;
4   import at.ac.tuwien.infosys.sm4all.copal.api.ContextProcessor;
5   import at.ac.tuwien.infosys.sm4all.copal.api.ContextPublisher;
6   import at.ac.tuwien.infosys.sm4all.copal.api.event.xml.Marshaller;
7   
8   /**
9    * Command that marshalls a {@link ContextPublisher} into an {@link Element}.
10   * 
11   * @author sanjin
12   */
13  public class XMLContextPublisher implements Marshaller<ContextPublisher> {
14  
15      private final Element element;
16  
17      /**
18       * Creates instance of {@link ContextPublisher} marshaller which uses
19       * specified {@link Element} to marshal the {@link ContextPublisher}.
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 XMLContextPublisher(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 ContextPublisher} into specified
36       * {@link Element}.
37       * 
38       * @param publisher the {@link ContextPublisher}.
39       * @throws NullPointerException if specified {@link ContextProcessor} is
40       *         <code>null</code>.
41       */
42      @Override
43      public void marshal(final ContextPublisher publisher) {
44          if (publisher == null)
45              throw new NullPointerException("Publisher cannot be null.");
46  
47          new SourceID(this.element).marshal(publisher);
48          new Event(this.element).marshal(publisher);
49      }
50  }