| 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 | |
| 20 | import org.deduced.PropertyCollection; |
| 21 | import org.deduced.implementation.PropertyInstanceImplementation; |
| 22 | |
| 23 | /** |
| 24 | * ListModelSerializer |
| 25 | * |
| 26 | * @author Steve McDuff |
| 27 | * |
| 28 | */ |
| 29 | public class ListModelSerializer extends ModelSerializer |
| 30 | { |
| 31 | /** |
| 32 | * reference List Model Serializer |
| 33 | */ |
| 34 | private ReferenceListModelSerializer referenceListModelSerializer = |
| 35 | new ReferenceListModelSerializer(); |
| 36 | |
| 37 | /** |
| 38 | * model list model serializer |
| 39 | */ |
| 40 | private ModelListModelSerializer modelListModelSerializer = |
| 41 | new ModelListModelSerializer(); |
| 42 | |
| 43 | /** |
| 44 | * (non-JSDoc) |
| 45 | * |
| 46 | * @see org.deduced.viewer.web.serializer.WebSerializer#createSerializedObject(org.deduced.PropertyCollection) |
| 47 | */ |
| 48 | @Override |
| 49 | public Serializable createSerializedObject( |
| 50 | PropertyCollection<?, ?> collection) |
| 51 | { |
| 52 | ModelSerializer serializerForCollection = |
| 53 | getSerializerForCollection(collection); |
| 54 | |
| 55 | return serializerForCollection.createSerializedObject(collection); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * (non-JSDoc) |
| 60 | * |
| 61 | * @see org.deduced.viewer.web.serializer.ModelSerializer#fillSerializedObject(java.io.Serializable, |
| 62 | * org.deduced.PropertyCollection, |
| 63 | * org.deduced.viewer.web.serializer.MasterWebSerializer) |
| 64 | */ |
| 65 | @Override |
| 66 | public void fillSerializedObject( |
| 67 | Serializable serializedObject, PropertyCollection<?, ?> collection, |
| 68 | MasterWebSerializer masterSerializer) |
| 69 | { |
| 70 | ModelSerializer serializerForCollection = |
| 71 | getSerializerForCollection(collection); |
| 72 | |
| 73 | serializerForCollection.fillSerializedObject(serializedObject, |
| 74 | collection, masterSerializer); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * get Serializer For Collection based on the type of list we use |
| 79 | * |
| 80 | * @param collection the collection to serialize |
| 81 | * @return the associated serializer |
| 82 | */ |
| 83 | public ModelSerializer getSerializerForCollection( |
| 84 | PropertyCollection<?, ?> collection) |
| 85 | { |
| 86 | if (isReferenceList(collection)) |
| 87 | { |
| 88 | return referenceListModelSerializer; |
| 89 | } |
| 90 | return modelListModelSerializer; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * check if a collection is a reference list |
| 95 | * |
| 96 | * @param collection the collection to check |
| 97 | * @return true if the collection is a reference list |
| 98 | */ |
| 99 | public static boolean isReferenceList( |
| 100 | PropertyCollection<?, ?> collection) |
| 101 | { |
| 102 | PropertyCollection<?, ?> fixedInstance = collection.getFixedInstance(); |
| 103 | boolean reference = |
| 104 | PropertyInstanceImplementation.isReference(fixedInstance) |
| 105 | .booleanValue(); |
| 106 | return reference; |
| 107 | } |
| 108 | |
| 109 | } |