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