| 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.AbstractPropertyCollection; |
| 21 | import org.deduced.PropertyCollection; |
| 22 | import org.deduced.implementation.OrderingPropertyCollectionTypeImplementation; |
| 23 | import org.deduced.viewer.web.shared.OrderedModel; |
| 24 | |
| 25 | /** |
| 26 | * OrderedModelSerializer |
| 27 | * |
| 28 | * @author Steve McDuff |
| 29 | * |
| 30 | */ |
| 31 | public abstract class OrderedModelSerializer extends ModelSerializer |
| 32 | { |
| 33 | /** |
| 34 | * fill the Ordered Model by extracting the ordering instance |
| 35 | * |
| 36 | * @param object the collection to serialize |
| 37 | * @param modelToFill the model to fill |
| 38 | */ |
| 39 | public static void fillOrderedModel( |
| 40 | PropertyCollection<?, ?> object, OrderedModel modelToFill) |
| 41 | { |
| 42 | PropertyCollection orderingInstance = |
| 43 | OrderingPropertyCollectionTypeImplementation |
| 44 | .getOrderingInstance(object.type()); |
| 45 | |
| 46 | if (orderingInstance != null) |
| 47 | { |
| 48 | Object orderingKey = |
| 49 | AbstractPropertyCollection |
| 50 | .getInstanceIdentityKey(orderingInstance); |
| 51 | |
| 52 | Object sortingValue = object.getPropertyValue(orderingKey); |
| 53 | |
| 54 | if (sortingValue instanceof Serializable) |
| 55 | { |
| 56 | modelToFill |
| 57 | .setSerializableSortingValue((Serializable) sortingValue); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * (non-JSDoc) |
| 64 | * |
| 65 | * @see org.deduced.viewer.web.serializer.ModelSerializer#fillSerializedObject(java.io.Serializable, |
| 66 | * org.deduced.PropertyCollection, |
| 67 | * org.deduced.viewer.web.serializer.MasterWebSerializer) |
| 68 | */ |
| 69 | @Override |
| 70 | public void fillSerializedObject( |
| 71 | Serializable serializedObject, PropertyCollection<?, ?> collection, |
| 72 | MasterWebSerializer masterSerializer) |
| 73 | { |
| 74 | fillOrderedModel(collection, (OrderedModel) serializedObject); |
| 75 | |
| 76 | super.fillSerializedObject(serializedObject, collection, |
| 77 | masterSerializer); |
| 78 | } |
| 79 | } |