1 | /** |
2 | * Copyright 2005-2011 Steve McDuff d-duff@users.sourceforge.net |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | package org.deduced.viewer.web.serializer; |
17 | |
18 | import java.io.Serializable; |
19 | import java.util.List; |
20 | |
21 | import org.deduced.PropertyCollection; |
22 | import org.deduced.viewer.web.shared.Model; |
23 | import org.deduced.viewer.web.shared.ModelListModel; |
24 | |
25 | /** |
26 | * Model List Model Serializer |
27 | * |
28 | * @author Steve McDuff |
29 | * |
30 | */ |
31 | public class ModelListModelSerializer extends ModelSerializer |
32 | { |
33 | /** |
34 | * fill List Model |
35 | * |
36 | * @param <x> the type of model in the list |
37 | * @param object the list to serialize |
38 | * @param modelToFill the model to fill |
39 | * @param masterSerializer the master serializer used to serialize child |
40 | * collections. |
41 | */ |
42 | public static <x extends Model> void fillListModel( |
43 | PropertyCollection<?, ?> object, ModelListModel<x> modelToFill, |
44 | MasterWebSerializer masterSerializer) |
45 | { |
46 | List<?> asValueList = object.asValueList(); |
47 | for (Object child : asValueList) |
48 | { |
49 | @SuppressWarnings("unchecked") |
50 | x leaf = |
51 | (x) masterSerializer |
52 | .serialize((PropertyCollection<?, ?>) child); |
53 | |
54 | modelToFill.getList().add(leaf); |
55 | } |
56 | } |
57 | |
58 | /** |
59 | * (non-JSDoc) |
60 | * |
61 | * @see org.deduced.viewer.web.serializer.WebSerializer#createSerializedObject(org.deduced.PropertyCollection) |
62 | */ |
63 | @Override |
64 | public Model createSerializedObject( |
65 | PropertyCollection<?, ?> collection) |
66 | { |
67 | return new ModelListModel<Model>(); |
68 | } |
69 | |
70 | /** |
71 | * (non-JSDoc) |
72 | * |
73 | * @see org.deduced.viewer.web.serializer.ModelSerializer#fillSerializedObject(java.io.Serializable, |
74 | * org.deduced.PropertyCollection, |
75 | * org.deduced.viewer.web.serializer.MasterWebSerializer) |
76 | */ |
77 | @SuppressWarnings("unchecked") |
78 | @Override |
79 | public void fillSerializedObject( |
80 | Serializable serializedObject, PropertyCollection<?, ?> collection, |
81 | MasterWebSerializer masterSerializer) |
82 | { |
83 | fillListModel(collection, (ModelListModel) serializedObject, |
84 | masterSerializer); |
85 | |
86 | super.fillSerializedObject(serializedObject, collection, |
87 | masterSerializer); |
88 | } |
89 | } |