View Javadoc

1   package at.ac.tuwien.infosys.sm4all.copal.rest.model;
2   
3   import at.ac.tuwien.infosys.sm4all.copal.api.ContextPublisher;
4   import at.ac.tuwien.infosys.sm4all.copal.api.MalformedDocumentException;
5   import at.ac.tuwien.infosys.sm4all.copal.api.event.xml.XMLContextEventType;
6   import at.ac.tuwien.infosys.sm4all.copal.api.helpers.AbstractXMLPublisher;
7   
8   /**
9    * {@link ContextPublisher} that is used by REST service to publish
10   * {@link Event}s.
11   * 
12   * @author sanjin
13   */
14  public class RESTPublisher extends AbstractXMLPublisher {
15  
16      /**
17       * Creates an instance of {@link RESTPublisher} that publishes {@link Event}
18       * s of specified type and using specified source ID.
19       * 
20       * @param sourceID the source ID.
21       * @param type the type of published {@link Event}s.
22       */
23      public RESTPublisher(final String sourceID, final String type) {
24          super(sourceID, type);
25      }
26  
27      @Override
28      protected boolean start(final XMLContextEventType type) {
29          return true;
30      }
31  
32      @Override
33      protected void stop(final XMLContextEventType type) {/* do nothing */}
34  
35      /**
36       * Publish specified {@link Event}.
37       * 
38       * @param event the {@link Event}.
39       * @throws MalformedDocumentException if specified {@link Event} is not
40       *         valid for specified type of published {@link Event}s.
41       */
42      public void publish(final Event event) throws MalformedDocumentException {
43          publish(event.toDocument());
44      }
45  }