View Javadoc

1   /* This file is part of COPAL (COntext Provisioning for All).
2    *
3    * COPAL is a part of SM4All (Smart hoMes for All) project.
4    *
5    * COPAL is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU Lesser General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * COPAL is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public License
16   * along with COPAL. If not, see <http://www.gnu.org/licenses/>.
17   */
18  package at.ac.tuwien.infosys.sm4all.copal.api.processor.xml;
19  
20  import java.util.List;
21  import org.w3c.dom.Element;
22  import at.ac.tuwien.infosys.sm4all.copal.api.ContextException;
23  import at.ac.tuwien.infosys.sm4all.copal.api.processor.ProcessorAction;
24  import at.ac.tuwien.infosys.sm4all.copal.api.publisher.xml.Event;
25  import at.ac.tuwien.infosys.sm4all.copal.api.xml.ArrayElement;
26  import at.ac.tuwien.infosys.sm4all.copal.api.xml.Constants;
27  
28  /**
29   * Command that marshalls and unmarshalls output of a {@link ProcessorAction}
30   * into/from an {@link Element}.
31   * 
32   * @author sanjin
33   */
34  public class ProcessorActionOutput extends ArrayElement<String> {
35  
36      /**
37       * Creates instance of {@link ProcessorAction} output marshaller and
38       * unmarshaller which uses specified {@link Element} to marshal and/or
39       * unmarshal the output.
40       * 
41       * @param element the {@link Element} used for marshalling and
42       *        unmarshalling.
43       * @throws NullPointerException if specified {@link Element} is
44       *         <code>null</code>.
45       */
46      public ProcessorActionOutput(final Element element) {
47          super(element, Constants.COPAL_NAMESPACE_URI, Constants.COPAL_PREFIX,
48                  "Event");
49      }
50  
51      /**
52       * Returns the unmarshalled <code>Event</code> child {@link Element}s of
53       * specified {@link Element} using the {@link Event#unmarshal()} method.
54       * 
55       * @return the unmarshalled <code>Event</code> child {@link Element}s.
56       * @throws ContextException if unmarshalling of any <code>Event</code> child
57       *         {@link Element} fails.
58       */
59      @Override
60      public String[] unmarshal() throws ContextException {
61          final List<String> result = unmarshalList();
62  
63          return result.toArray(new String[result.size()]);
64      }
65  
66      @Override
67      protected String unmarshal(final Element element) throws ContextException {
68          return new Event(element).unmarshal();
69      }
70  
71      @Override
72      protected void marshal(final String publishedType, final Element element) {
73          new Event(element).marshal(publishedType);
74      }
75  }