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.xml;
19  
20  import org.w3c.dom.Element;
21  import at.ac.tuwien.infosys.sm4all.copal.api.util.Marshaller;
22  import at.ac.tuwien.infosys.sm4all.copal.api.util.Unmarshaller;
23  
24  /**
25   * Unmarshals and marshals a {@link String} value of an attribute from/to an
26   * {@link Element}.
27   * 
28   * @author sanjin
29   */
30  public class StringAttribute extends Attribute<String> {
31  
32      /**
33       * Creates instance of an attribute {@link Unmarshaller} and
34       * {@link Marshaller} which uses specified {@link Element} to unmarshal
35       * and/or marshal the {@link String} value of the attribute with specified
36       * name.
37       * 
38       * @param name the name of the attribute in the {@link Element} used for
39       *        unmarshalling and marshalling.
40       * @param element the {@link Element} used for unmarshalling and
41       *        marshalling.
42       * @throws NullPointerException if specified {@link Element} or name is
43       *         <code>null</code>.
44       * @throws IllegalArgumentException if specified name is an empty or blank
45       *         string.
46       */
47      public StringAttribute(final String name, final Element element) {
48          super(name, element);
49      }
50  
51      @Override
52      protected String toString(final String str) {
53          return str;
54      }
55  
56      @Override
57      protected String valueOf(final String str) {
58          return str;
59      }
60  
61      /**
62       * Builder of {@link StringAttribute}.
63       * 
64       * @author sanjin
65       */
66      public static class Builder extends Attribute.Builder<String> {
67  
68          /**
69           * Create an uninitialized instance of {@link StringAttribute.Builder}.
70           */
71          public Builder() {
72              super();
73          }
74  
75          /**
76           * Clone-constructor.
77           * 
78           * @param builder the cloned {@link StringAttribute.Builder}.
79           */
80          protected Builder(final Builder builder) {
81              super(builder);
82          }
83  
84          /**
85           * Create instance of {@link StringAttribute}.
86           * 
87           * @return a {@link StringAttribute}.
88           */
89          @Override
90          public StringAttribute build() {
91              return new StringAttribute(getName(), getElement());
92          }
93  
94          @Override
95          protected Builder copy() {
96              return new Builder(this);
97          }
98      }
99  }