001: /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
002: *
003: * ***** BEGIN LICENSE BLOCK *****
004: * Version: MPL 1.1/GPL 2.0
005: *
006: * The contents of this file are subject to the Mozilla Public License Version
007: * 1.1 (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: * http://www.mozilla.org/MPL/
010: *
011: * Software distributed under the License is distributed on an "AS IS" basis,
012: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013: * for the specific language governing rights and limitations under the
014: * License.
015: *
016: * The Original Code is Rhino code, released
017: * May 6, 1999.
018: *
019: * The Initial Developer of the Original Code is
020: * Netscape Communications Corporation.
021: * Portions created by the Initial Developer are Copyright (C) 1997-1999
022: * the Initial Developer. All Rights Reserved.
023: *
024: * Contributor(s):
025: * Igor Bukanov
026: *
027: * Alternatively, the contents of this file may be used under the terms of
028: * the GNU General Public License Version 2 or later (the "GPL"), in which
029: * case the provisions of the GPL are applicable instead of those above. If
030: * you wish to allow use of your version of this file only under the terms of
031: * the GPL and not to allow others to use your version of this file under the
032: * MPL, indicate your decision by deleting the provisions above and replacing
033: * them with the notice and other provisions required by the GPL. If you do
034: * not delete the provisions above, a recipient may use your version of this
035: * file under either the MPL or the GPL.
036: *
037: * ***** END LICENSE BLOCK ***** */
038:
039: package org.mozilla.javascript;
040:
041: import java.io.Serializable;
042:
043: /**
044: * Class instances represent serializable tags to mark special Object values.
045: * <p>
046: * Compatibility note: under jdk 1.1 use
047: * org.mozilla.javascript.serialize.ScriptableInputStream to read serialized
048: * instances of UniqueTag as under this JDK version the default
049: * ObjectInputStream would not restore them correctly as it lacks support
050: * for readResolve method
051: */
052: public final class UniqueTag implements Serializable {
053: static final long serialVersionUID = -4320556826714577259L;
054:
055: private static final int ID_NOT_FOUND = 1;
056: private static final int ID_NULL_VALUE = 2;
057: private static final int ID_DOUBLE_MARK = 3;
058:
059: /**
060: * Tag to mark non-existing values.
061: */
062: public static final UniqueTag NOT_FOUND = new UniqueTag(
063: ID_NOT_FOUND);
064:
065: /**
066: * Tag to distinguish between uninitialized and null values.
067: */
068: public static final UniqueTag NULL_VALUE = new UniqueTag(
069: ID_NULL_VALUE);
070:
071: /**
072: * Tag to indicate that a object represents "double" with the real value
073: * stored somewhere else.
074: */
075: public static final UniqueTag DOUBLE_MARK = new UniqueTag(
076: ID_DOUBLE_MARK);
077:
078: private final int tagId;
079:
080: private UniqueTag(int tagId) {
081: this .tagId = tagId;
082: }
083:
084: public Object readResolve() {
085: switch (tagId) {
086: case ID_NOT_FOUND:
087: return NOT_FOUND;
088: case ID_NULL_VALUE:
089: return NULL_VALUE;
090: case ID_DOUBLE_MARK:
091: return DOUBLE_MARK;
092: }
093: throw new IllegalStateException(String.valueOf(tagId));
094: }
095:
096: // Overridden for better debug printouts
097: public String toString() {
098: String name;
099: switch (tagId) {
100: case ID_NOT_FOUND:
101: name = "NOT_FOUND";
102: break;
103: case ID_NULL_VALUE:
104: name = "NULL_VALUE";
105: break;
106: case ID_DOUBLE_MARK:
107: name = "DOUBLE_MARK";
108: break;
109: default:
110: throw Kit.codeBug();
111: }
112: return super .toString() + ": " + name;
113: }
114:
115: }
|