View Javadoc
1   /*
2    * This file is part of Waarp Project (named also Waarp or GG).
3    *
4    *  Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
5    *  tags. See the COPYRIGHT.txt in the distribution for a full listing of
6    * individual contributors.
7    *
8    *  All Waarp Project is free software: you can redistribute it and/or
9    * modify it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation, either version 3 of the License, or (at your
11   * option) any later version.
12   *
13   * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
14   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15   * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License along with
18   * Waarp . If not, see <http://www.gnu.org/licenses/>.
19   */
20  
21  package org.waarp.openr66.protocol.http.restv2.utils;
22  
23  import org.waarp.common.role.RoleDefault;
24  import org.waarp.openr66.database.data.DbTaskRunner;
25  import org.waarp.openr66.pojo.Host;
26  import org.waarp.openr66.pojo.Rule;
27  import org.waarp.openr66.pojo.RuleTask;
28  import org.waarp.openr66.pojo.Transfer;
29  
30  import javax.xml.bind.annotation.XmlAccessType;
31  import javax.xml.bind.annotation.XmlAccessorType;
32  import javax.xml.bind.annotation.XmlElement;
33  import javax.xml.bind.annotation.XmlElementWrapper;
34  import javax.xml.bind.annotation.XmlList;
35  import javax.xml.bind.annotation.XmlRootElement;
36  import javax.xml.bind.annotation.XmlType;
37  import java.util.ArrayList;
38  import java.util.List;
39  
40  import static org.waarp.openr66.configuration.FileBasedElements.*;
41  import static org.waarp.openr66.configuration.RuleFileBasedConfiguration.*;
42  import static org.waarp.openr66.database.data.DbHostConfiguration.*;
43  
44  /**
45   * An interface for POJOs used in XML (de)serialization.
46   * <p>
47   * Classes implementing this interface, as well as their fields' classes *MUST*
48   * be annotated with the required
49   * JAXB annotations to allow the objects to be marshalled and unmarshalled using
50   * JAXB.
51   *
52   * @see javax.xml.bind.Marshaller
53   * @see javax.xml.bind.Unmarshaller
54   */
55  @SuppressWarnings("CanBeFinal")
56  @XmlRootElement
57  @XmlAccessorType(XmlAccessType.NONE)
58  public interface XmlSerializable {
59  
60    /**
61     * A POJO representing a list of business ids for XML (de)serialisation
62     * purposes.
63     */
64    @XmlRootElement(name = XML_BUSINESS)
65    final class Businesses implements XmlSerializable {
66      /**
67       * The list of host names.
68       */
69      @XmlElement(name = XML_BUSINESSID)
70      public List<String> business = new ArrayList<String>();
71    }
72  
73    /**
74     * A container for a list of roles for XML (de)serialisation purposes.
75     */
76    @XmlRootElement(name = XML_ROLES)
77    final class Roles implements XmlSerializable {
78      /**
79       * The list of roles.
80       */
81      @XmlElement(name = XML_ROLE)
82      public List<RoleEntry> roles = new ArrayList<RoleEntry>();
83  
84      public Roles() {
85      }
86  
87      public Roles(final List<RoleEntry> roles) {
88        this.roles = roles;
89      }
90  
91      /**
92       * A POJO representing a role entry for XML (de)serialisation purposes.
93       */
94      @XmlType
95      public static final class RoleEntry {
96        /**
97         * The host's id.
98         */
99        @XmlElement(name = XML_ROLEID)
100       public String hostName;
101 
102       /**
103        * The list of allowed actions on the server.
104        */
105       @XmlElement(name = XML_ROLESET)
106       @XmlList
107       public List<RoleDefault.ROLE> roleList =
108           new ArrayList<RoleDefault.ROLE>();
109     }
110   }
111 
112   /**
113    * A container for a list of aliases for XML (de)serialisation purposes.
114    */
115   @XmlRootElement(name = XML_ALIASES)
116   final class Aliases implements XmlSerializable {
117     /**
118      * The list of aliases.
119      */
120     @XmlElement(name = XML_ALIAS)
121     public List<AliasEntry> aliases = new ArrayList<AliasEntry>();
122 
123     public Aliases() {
124     }
125 
126     public Aliases(final List<AliasEntry> aliases) {
127       this.aliases = aliases;
128     }
129 
130     /**
131      * A POJO representing an alias entry for XML (de)serialisation
132      * purposes.
133      */
134     @XmlType
135     public static final class AliasEntry {
136       /**
137        * The host's id.
138        */
139       @XmlElement(name = XML_REALID)
140       public String hostName;
141 
142       /**
143        * The list of the server's known aliases.
144        */
145       @XmlElement(name = XML_ALIASID)
146       @XmlList
147       public List<String> aliasList = new ArrayList<String>();
148     }
149   }
150 
151   /**
152    * A container for a list of hosts for XML (de)serialisation purposes.
153    */
154   @XmlRootElement(name = XML_AUTHENTICATION_ROOT)
155   final class Hosts implements XmlSerializable {
156     /**
157      * The list of {@link Host}.
158      */
159     @XmlElement(name = XML_AUTHENTICATION_ENTRY)
160     public List<Host> hosts = new ArrayList<Host>();
161 
162     public Hosts() {
163     }
164 
165     public Hosts(final List<Host> hosts) {
166       this.hosts = hosts;
167     }
168   }
169 
170   /**
171    * A container for a list of rules for XML (de)serialisation purposes.
172    */
173   @XmlRootElement(name = MULTIPLEROOT)
174   final class Rules implements XmlSerializable {
175     /**
176      * The list of rules.
177      */
178     @XmlElement(name = ROOT)
179     public List<Rule> rules = new ArrayList<Rule>();
180 
181     public Rules() {
182     }
183 
184     public Rules(final List<Rule> rules) {
185       this.rules = rules;
186     }
187 
188     /**
189      * A POJO representing a list of tasks for XML (de)serialisation
190      * purposes.
191      */
192     @XmlType(name = XTASKS)
193     public static final class Tasks {
194       /**
195        * The list of tasks.
196        */
197       @XmlElementWrapper(name = XTASKS)
198       @XmlElement(name = XTASK)
199       public List<RuleTask> tasks;
200 
201       public Tasks() {
202       }
203 
204       public Tasks(final List<RuleTask> tasks) {
205         this.tasks = tasks;
206       }
207     }
208   }
209 
210   /**
211    * container for a list of transfers for XML (de)serialisation purposes.
212    */
213   @XmlRootElement(name = DbTaskRunner.XMLRUNNERS)
214   class Transfers implements XmlSerializable {
215     @XmlElement(name = DbTaskRunner.XMLRUNNER)
216     public List<Transfer> transfers = new ArrayList<Transfer>();
217 
218     public Transfers() {
219     }
220 
221     public Transfers(final List<Transfer> transfers) {
222       this.transfers = transfers;
223     }
224   }
225 }