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.event.xml.type;
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.event.DefaultAction;
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 {@link DefaultAction}s into/from an
29   * {@link Element}.
30   * 
31   * @author sanjin
32   */
33  public class XMLDefaultActions extends ArrayElement<DefaultAction> {
34  
35      /**
36       * Creates instance of {@link DefaultAction}s marshaller and unmarshaller
37       * which uses specified {@link Element} to marshal and/or unmarshal the
38       * {@link DefaultAction}s.
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 XMLDefaultActions(final Element element) {
46          super(element, Constants.COPAL_NAMESPACE_URI, Constants.COPAL_PREFIX,
47                  "Action");
48      }
49  
50      /**
51       * Returns the unmarshalled <code>Action</code> child {@link Element}s of
52       * specified {@link Element} using the {@link XMLDefaultAction#unmarshal()}
53       * method.
54       * 
55       * @return the unmarshalled <code>Action</code> child {@link Element}s.
56       * @throws ContextException if unmarshalling of any <code>Action</code>
57       *         child {@link Element} fails.
58       */
59      @Override
60      public DefaultAction[] unmarshal() throws ContextException {
61          final List<DefaultAction> result = unmarshalList();
62  
63          return result.toArray(new DefaultAction[result.size()]);
64      }
65  
66      @Override
67      protected DefaultAction unmarshal(final Element element)
68              throws ContextException {
69          return new XMLDefaultAction(element).unmarshal();
70      }
71  
72      @Override
73      protected void marshal(final DefaultAction action, final Element element) {
74          new XMLDefaultAction(element).marshal(action);
75      }
76  }