94 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.ui.light;
|
|
|
15 |
|
156 |
ilm |
16 |
import org.openconcerto.utils.io.JSONConverter;
|
|
|
17 |
import org.openconcerto.utils.io.Transferable;
|
|
|
18 |
|
|
|
19 |
import java.io.Externalizable;
|
|
|
20 |
import java.io.IOException;
|
|
|
21 |
import java.io.ObjectInput;
|
|
|
22 |
import java.io.ObjectOutput;
|
94 |
ilm |
23 |
import java.util.ArrayList;
|
|
|
24 |
import java.util.List;
|
|
|
25 |
|
|
|
26 |
import net.minidev.json.JSONArray;
|
149 |
ilm |
27 |
import net.minidev.json.JSONAware;
|
94 |
ilm |
28 |
import net.minidev.json.JSONObject;
|
|
|
29 |
|
156 |
ilm |
30 |
public class SearchSpec implements Transferable, JSONAware, Externalizable {
|
94 |
ilm |
31 |
private String tableId;
|
156 |
ilm |
32 |
private List<SearchContent> content = new ArrayList<>();
|
94 |
ilm |
33 |
|
156 |
ilm |
34 |
public SearchSpec() {
|
|
|
35 |
// Serialization
|
|
|
36 |
}
|
|
|
37 |
|
94 |
ilm |
38 |
public SearchSpec(final String tableId) {
|
|
|
39 |
this.tableId = tableId;
|
|
|
40 |
}
|
142 |
ilm |
41 |
|
94 |
ilm |
42 |
public SearchSpec(final JSONObject json) {
|
|
|
43 |
this.fromJSON(json);
|
|
|
44 |
}
|
|
|
45 |
|
142 |
ilm |
46 |
public final String getTableId() {
|
94 |
ilm |
47 |
return this.tableId;
|
|
|
48 |
}
|
|
|
49 |
|
142 |
ilm |
50 |
public final List<SearchContent> getContent() {
|
94 |
ilm |
51 |
return this.content;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
@Override
|
|
|
55 |
public JSONObject toJSON() {
|
|
|
56 |
final JSONObject json = new JSONObject();
|
|
|
57 |
json.put("table-id", this.tableId);
|
|
|
58 |
json.put("content", JSONConverter.getJSON(this.content));
|
|
|
59 |
return json;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
@Override
|
|
|
63 |
public void fromJSON(JSONObject json) {
|
|
|
64 |
this.tableId = (String) JSONConverter.getParameterFromJSON(json, "table-id", String.class);
|
|
|
65 |
final JSONArray jsonContent = (JSONArray) JSONConverter.getParameterFromJSON(json, "content", JSONArray.class);
|
|
|
66 |
if (jsonContent != null) {
|
|
|
67 |
this.content = new ArrayList<SearchContent>();
|
|
|
68 |
for (final Object o : jsonContent) {
|
|
|
69 |
this.content.add(new SearchContent((JSONObject) JSONConverter.getObjectFromJSON(o, JSONObject.class)));
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
}
|
149 |
ilm |
73 |
|
|
|
74 |
/*
|
|
|
75 |
* JSONAware pour que le JSONArray.toString() fonctionne quand cet objet est dans un JSONArray
|
|
|
76 |
*/
|
|
|
77 |
@Override
|
|
|
78 |
public String toJSONString() {
|
|
|
79 |
return toJSON().toJSONString();
|
|
|
80 |
}
|
156 |
ilm |
81 |
|
|
|
82 |
@Override
|
|
|
83 |
public void writeExternal(ObjectOutput out) throws IOException {
|
|
|
84 |
out.writeUTF(this.tableId);
|
|
|
85 |
out.writeObject(this.content);
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
@Override
|
|
|
89 |
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
|
|
|
90 |
this.tableId = in.readUTF();
|
|
|
91 |
this.content = (List<SearchContent>) in.readObject();
|
|
|
92 |
}
|
94 |
ilm |
93 |
}
|