1    /*
2     * Copyright 2009 :torweg free software group
3     *
4     * This program is free software: you can redistribute it and/or modify
5     * it under the terms of the GNU General Public License as published by
6     * the Free Software Foundation, either version 3 of the License, or
7     * (at your option) any later version.
8     * 
9     * This program is distributed in the hope that it will be useful,
10    * but WITHOUT ANY WARRANTY; without even the implied warranty of
11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    * GNU General Public License for more details.
13    * 
14    * You should have received a copy of the GNU General Public License
15    * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16    *
17    */
18   package org.torweg.pulse.util.entity;
19   
20   import java.util.ArrayList;
21   import java.util.Collections;
22   import java.util.List;
23   
24   import javax.xml.bind.annotation.XmlAccessOrder;
25   import javax.xml.bind.annotation.XmlAccessType;
26   import javax.xml.bind.annotation.XmlAccessorOrder;
27   import javax.xml.bind.annotation.XmlAccessorType;
28   import javax.xml.bind.annotation.XmlAttribute;
29   import javax.xml.bind.annotation.XmlElement;
30   import javax.xml.bind.annotation.XmlElementWrapper;
31   import javax.xml.bind.annotation.XmlRootElement;
32   
33   import org.jdom.Element;
34   import org.torweg.pulse.configuration.Configuration;
35   
36   /**
37    * The Configuration for the image versions of an
38    * {@code AbstractImageGroup}.
39    * 
40    * 
41    * @author Daniel Dietz
42    * @version $Revision: 1408 $
43    * 
44    */
45   @XmlRootElement(name = "abstract-image-group-configuration")
46   @XmlAccessorOrder(XmlAccessOrder.UNDEFINED)
47   @XmlAccessorType(XmlAccessType.FIELD)
48   public abstract class AbstractImageGroupConfiguration extends Configuration {
49   
50       /**
51        * The serialVersionUID.
52        */
53       private static final long serialVersionUID = 3728475342837920452L;
54   
55       /**
56        * The image version names.
57        */
58       @XmlElementWrapper(name = "versions")
59       @XmlElement(name = "version")
60       private final List<Version> versions = new ArrayList<Version>();
61   
62       /**
63        * Returns a {@code List} containing the {@code Version}s.
64        * 
65        * @return an unmodifiable {@code List} containing the
66        *         {@code Version}s
67        */
68       public final List<Version> getVersions() {
69           return Collections.unmodifiableList(this.versions);
70       }
71   
72       /**
73        * A version-definition for an {@code StoreContentImageGroup}.
74        * 
75        * @author Daniel Dietz
76        * @version $Revision: 1408 $
77        * 
78        */
79       @XmlRootElement(name = "version")
80       @XmlAccessorOrder(XmlAccessOrder.UNDEFINED)
81       @XmlAccessorType(XmlAccessType.FIELD)
82       public static final class Version {
83   
84           /**
85            * The version-name.
86            */
87           @XmlAttribute(name = "name")
88           private String name;
89   
90           /**
91            * The width.
92            */
93           @XmlAttribute(name = "x")
94           private Integer x = null;
95   
96           /**
97            * The height.
98            */
99           @XmlAttribute(name = "y")
100          private Integer y = null;
101  
102          /**
103           * Indicates whether the {@code Version} is required for the
104           * {@code StoreContentImageGroup}.
105           */
106          @XmlAttribute(name = "required")
107          private boolean required = true;
108  
109          /**
110           * Default constructor.
111           */
112          @Deprecated
113          protected Version() {
114              super();
115          }
116  
117          /**
118           * Creates a new Version with the given name.
119           * 
120           * @param n
121           *            the name
122           * 
123           */
124          public Version(final String n) {
125              super();
126              this.name = n;
127          }
128  
129          /**
130           * Creates a new {@code Version} from the given
131           * {@code Element}.
132           * 
133           * @param el
134           *            the {@code Element}
135           * 
136           * @throws IllegalArgumentException
137           *             if el.getAttributeValue("name") is {@code null} or
138           *             empty string
139           */
140          public Version(final Element el) {
141              super();
142              if (el.getAttribute("name") == null
143                      || el.getAttributeValue("name").equals("")) {
144                  throw new IllegalArgumentException(
145                          "Given el/@name must not be null aor empty string.");
146              }
147              this.name = el.getAttributeValue("name");
148              if (el.getAttribute("x") == null
149                      || el.getAttributeValue("x").equals("")) {
150                  this.x = Integer.parseInt(el.getAttributeValue("x"));
151              }
152              if (el.getAttribute("y") == null
153                      || el.getAttributeValue("y").equals("")) {
154                  this.y = Integer.parseInt(el.getAttributeValue("y"));
155              }
156              if (el.getAttribute("required") == null
157                      || el.getAttributeValue("required").equals("")) {
158                  this.required = Boolean.parseBoolean(el
159                          .getAttributeValue("required"));
160              }
161          }
162  
163          /**
164           * @return the name
165           */
166          public String getName() {
167              return this.name;
168          }
169  
170          /**
171           * @return the x
172           */
173          public Integer getX() {
174              return this.x;
175          }
176  
177          /**
178           * @return the y
179           */
180          public Integer getY() {
181              return this.y;
182          }
183  
184          /**
185           * @return the required
186           */
187          public boolean isRequired() {
188              return this.required;
189          }
190  
191      }
192  
193  }
194