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.publisher.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.publisher.ContextPublisher;
24  import at.ac.tuwien.infosys.sm4all.copal.api.xml.ArrayElement;
25  import at.ac.tuwien.infosys.sm4all.copal.api.xml.Constants;
26  
27  /**
28   * Command that marshalls and unmarshalls published types of a
29   * {@link ContextPublisher} into/from an {@link Element}.
30   * 
31   * @author sanjin
32   */
33  public class Events extends ArrayElement<String> {
34  
35      /**
36       * Creates instance of {@link ContextPublisher} published types marshaller
37       * and unmarshaller which uses specified {@link Element} to marshal and/or
38       * unmarshal the published types.
39       * 
40       * @param element the {@link Element} used for marshalling and
41       *        unmarshalling.
42       * @throws NullPointerException if specified {@link Element} is
43       *         <code>null</code>.
44       */
45      public Events(final Element element) {
46          super(element, Constants.COPAL_NAMESPACE_URI, Constants.COPAL_PREFIX,
47                  "Event");
48      }
49  
50      /**
51       * Returns the unmarshalled <code>Event</code> child {@link Element}s of
52       * specified {@link Element} using the {@link Event#unmarshal()} method.
53       * 
54       * @return the unmarshalled <code>Event</code> child {@link Element}s.
55       * @throws ContextException if unmarshalling of any <code>Event</code> child
56       *         {@link Element} fails.
57       */
58      @Override
59      public String[] unmarshal() throws ContextException {
60          final List<String> result = unmarshalList();
61  
62          return result.toArray(new String[result.size()]);
63      }
64  
65      @Override
66      protected String unmarshal(final Element element) throws ContextException {
67          return new Event(element).unmarshal();
68      }
69  
70      @Override
71      protected void marshal(final String publishedType, final Element element) {
72          new Event(element).marshal(publishedType);
73      }
74  }