1    /*
2     * Copyright 2008 :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.site.content.admin;
19   
20   import java.util.HashSet;
21   import java.util.Set;
22   
23   import javax.xml.bind.annotation.XmlAccessOrder;
24   import javax.xml.bind.annotation.XmlAccessType;
25   import javax.xml.bind.annotation.XmlAccessorOrder;
26   import javax.xml.bind.annotation.XmlAccessorType;
27   import javax.xml.bind.annotation.XmlAttribute;
28   import javax.xml.bind.annotation.XmlElement;
29   import javax.xml.bind.annotation.XmlElementWrapper;
30   import javax.xml.bind.annotation.XmlRootElement;
31   
32   import org.jdom.Content;
33   import org.torweg.pulse.site.content.AbstractBasicContent;
34   
35   /**
36    * the JAXB-enabled result for the {@code AbstractBasicContentEditor}.
37    * 
38    * @author Daniel Dietz
39    * @version $Revision: 1400 $
40    */
41   @XmlRootElement(name = "abstract-basic-content-editor-jaxb-result")
42   @XmlAccessorOrder(XmlAccessOrder.UNDEFINED)
43   @XmlAccessorType(XmlAccessType.FIELD)
44   public class AbstractBasicContentEditorJAXBResult {
45   
46       /**
47        * The {@code AbstractBasicContent} of the result.
48        */
49       @XmlElement(name = "content")
50       private AbstractBasicContent content;
51   
52       /**
53        * A set of {@code ResultAttribute}s to be added to the result.
54        */
55       @XmlElementWrapper(name = "result-attributes")
56       @XmlElement(name = "result-attribute")
57       private final Set<ResultAttribute> attributes = new HashSet<ResultAttribute>();
58   
59       /**
60        * The {@code Content}s of the result.
61        */
62       @XmlElementWrapper(name = "contents")
63       @XmlElement(name = "content")
64       private final Set<Content> contents = new HashSet<Content>();
65   
66       /**
67        * Sets the content of the result.
68        * 
69        * @param c
70        *            the {@code AbstractBasicContent} to be set
71        */
72       public final void setContent(final AbstractBasicContent c) {
73           this.content = c;
74       }
75   
76       /**
77        * Returns the {@code AbstractBasicContent}.
78        * 
79        * @return the {@code AbstractBasicContent}
80        */
81       public final AbstractBasicContent getContent() {
82           return this.content;
83       }
84   
85       /**
86        * Adds a attribute to the root-container of this result.
87        * 
88        * @param attributeName
89        *            the name of the attribute
90        * @param attributeValue
91        *            the value of the attribute
92        */
93       public final void addAttribute(final String attributeName,
94               final String attributeValue) {
95           this.attributes.add(new ResultAttribute(attributeName, attributeValue));
96       }
97   
98       /**
99        * Adds a {@code Content} for this result.
100       * 
101       * @param c
102       *            the {@code Content} to add
103       */
104      public final void addContent(final Content c) {
105          this.contents.add(c);
106      }
107  
108      /**
109       * Represents an "attribute" for the result - not to be confused with an
110       * attribute in XML.
111       * 
112       * @author Daniel Dietz
113       * @version $Revision: 1400 $
114       */
115      @XmlRootElement(name = "result-attribute")
116      @XmlAccessorOrder(XmlAccessOrder.UNDEFINED)
117      @XmlAccessorType(XmlAccessType.FIELD)
118      public static final class ResultAttribute {
119  
120          /**
121           * The name.
122           */
123          @XmlAttribute(name = "name")
124          private String name;
125  
126          /**
127           * The value.
128           */
129          @XmlAttribute(name = "value")
130          private String value;
131  
132          /**
133           * Default constructor.
134           */
135          @Deprecated
136          protected ResultAttribute() {
137              super();
138          }
139  
140          /**
141           * Creates a new {@code ResultAttribute} with the given name and
142           * the given value.
143           * 
144           * @param n
145           *            the name
146           * @param v
147           *            the value
148           */
149          public ResultAttribute(final String n, final String v) {
150              super();
151              setName(n);
152              setValue(v);
153          }
154  
155          /**
156           * Returns the name.
157           * 
158           * @return the <tt>name</tt>
159           */
160          public String getName() {
161              return this.name;
162          }
163  
164          /**
165           * @param n
166           *            the name to set
167           */
168          private void setName(final String n) {
169              this.name = n;
170          }
171  
172          /**
173           * Returns the value.
174           * 
175           * @return the <tt>value</tt>
176           */
177          public String getValue() {
178              return this.value;
179          }
180  
181          /**
182           * @param v
183           *            the value to set
184           */
185          private void setValue(final String v) {
186              this.value = v;
187          }
188  
189      }
190  
191  }
192