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