blob: 8c48686639635d70e9edfca0e3bafefd8053ab91 [file] [log] [blame]
nchalko@google.com49735242010-10-22 15:52:03 +00001/*
2 * Copyright 2010 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16package org.hibernate.validator.engine;
17
nchalko@google.comaf283dc2011-04-14 13:53:21 +000018import com.google.gwt.user.client.rpc.CustomFieldSerializer;
nchalko@google.com49735242010-10-22 15:52:03 +000019import com.google.gwt.user.client.rpc.SerializationException;
20import com.google.gwt.user.client.rpc.SerializationStreamReader;
21import com.google.gwt.user.client.rpc.SerializationStreamWriter;
22
23import java.lang.annotation.ElementType;
24
25import javax.validation.Path;
26import javax.validation.metadata.ConstraintDescriptor;
27
28/**
29 * Custom Serializer for {@link ConstraintViolationImpl}.
30 */
nchalko@google.comaf283dc2011-04-14 13:53:21 +000031@SuppressWarnings("rawtypes")
32public class ConstraintViolationImpl_CustomFieldSerializer extends
33 CustomFieldSerializer<ConstraintViolationImpl> {
nchalko@google.com49735242010-10-22 15:52:03 +000034
nchalko@google.comaf283dc2011-04-14 13:53:21 +000035 @SuppressWarnings("unused")
nchalko@google.com49735242010-10-22 15:52:03 +000036 public static void deserialize(SerializationStreamReader streamReader,
37 ConstraintViolationImpl instance) throws SerializationException {
38 // no fields
39 }
40
41 public static ConstraintViolationImpl<Object> instantiate(
42 SerializationStreamReader streamReader) throws SerializationException {
43
44 String messageTemplate = null;
45 String interpolatedMessage = streamReader.readString();
46 Class<Object> rootBeanClass = null;
47 Object rootBean = null;
48 Object leafBeanInstance = null;
49 Object value = null;
50 Path propertyPath = (Path) streamReader.readObject();
51 ConstraintDescriptor<?> constraintDescriptor = null;
52 ElementType elementType = null;
53 return new ConstraintViolationImpl<Object>(messageTemplate,
54 interpolatedMessage, rootBeanClass, rootBean, leafBeanInstance, value,
55 propertyPath, constraintDescriptor, elementType);
56 }
57
58 /**
59 * Only a subset of fields are actually serialized.
60 * <p/>
61 * There is no guarantee that the root bean is GWT-serializable or that it's
62 * appropriate for it to be exposed on the client. Even if the root bean could
63 * be sent back, the lack of reflection on the client makes it troublesome to
64 * interpret the path as a sequence of property accesses.
65 * <p/>
66 * The current implementation is the simplest-to-implement properties.
67 * <ol>
68 * <li>Message</li>
69 * <li>Property Path</li>
70 * </ol>
71 */
72 public static void serialize(SerializationStreamWriter streamWriter,
73 ConstraintViolationImpl instance) throws SerializationException {
74
75 // streamWriter.writeString(instance.getMessageTemplate());
76 streamWriter.writeString(instance.getMessage());
77 // streamWriter.writeObject(instance.getRootBeanClass());
78 // streamWriter.writeObject(instance.getRootBean());
79 // streamWriter.writeObject(instance.getLeafBean());
80 // streamWriter.writeObject(instance.getInvalidValue());
81 streamWriter.writeObject(instance.getPropertyPath());
82 // streamWriter.writeObject(instance.getConstraintDescriptor());
83 // ElementType
84 }
nchalko@google.comaf283dc2011-04-14 13:53:21 +000085
86 @Override
87 public void deserializeInstance(SerializationStreamReader streamReader,
88 ConstraintViolationImpl instance) throws SerializationException {
89 deserialize(streamReader, instance);
90 }
91
92 @Override
93 public boolean hasCustomInstantiateInstance() {
94 return true;
95 }
96
97 @Override
98 public ConstraintViolationImpl instantiateInstance(
99 SerializationStreamReader streamReader) throws SerializationException {
100 return instantiate(streamReader);
101 }
102
103 @Override
104 public void serializeInstance(SerializationStreamWriter streamWriter,
105 ConstraintViolationImpl instance) throws SerializationException {
106 serialize(streamWriter, instance);
107 }
nchalko@google.com49735242010-10-22 15:52:03 +0000108}