01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */
16: package com.google.gwt.user.client.rpc.impl;
17:
18: /**
19: * Base class for the client and server serialization streams. This class
20: * handles the basic serialization and deserialization formatting for primitive
21: * types since these are common between the client and the server.
22: */
23: public abstract class AbstractSerializationStream {
24:
25: public static final int SERIALIZATION_STREAM_FLAGS_NO_TYPE_VERSIONING = 1;
26: public static final int SERIALIZATION_STREAM_VERSION = 3;
27:
28: /**
29: * The last legacy stream version which does not use a
30: * {@link com.google.gwt.user.server.rpc.SerializationPolicy SerializationPolicy}.
31: */
32: public static final int SERIALIZATION_STREAM_VERSION_WITHOUT_SERIALIZATION_POLICY = 2;
33:
34: private int flags = 0;
35:
36: private int version = SERIALIZATION_STREAM_VERSION;
37:
38: public final void addFlags(int flags) {
39: this .flags |= flags;
40: }
41:
42: public final int getFlags() {
43: return flags;
44: }
45:
46: public final int getVersion() {
47: return version;
48: }
49:
50: public final void setFlags(int flags) {
51: this .flags = flags;
52: }
53:
54: public final boolean shouldEnforceTypeVersioning() {
55: return (flags & SERIALIZATION_STREAM_FLAGS_NO_TYPE_VERSIONING) == 0;
56: }
57:
58: /**
59: * Returns <code>true</code> if this stream encodes information which can be
60: * used to lookup a {@link com.google.gwt.user.server.rpc.SerializationPolicy}.
61: *
62: * @return <code>true</code> if this stream encodes information which can be
63: * used to lookup a <code>SerializationPolicy</code>
64: */
65: protected boolean hasSerializationPolicyInfo() {
66: return getVersion() > SERIALIZATION_STREAM_VERSION_WITHOUT_SERIALIZATION_POLICY;
67: }
68:
69: protected final void setVersion(int version) {
70: this.version = version;
71: }
72: }
|