Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
//================================================================================
//Copyright (c) 2012, David Yu
//All rights reserved.
//--------------------------------------------------------------------------------
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. Neither the name of protostuff nor the names of its contributors may be used
// to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//================================================================================
package io.protostuff.runtime;
import static io.protostuff.runtime.RuntimeFieldFactory.ID_ENUM_MAP;
import static io.protostuff.runtime.RuntimeFieldFactory.ID_MAP;
import static io.protostuff.runtime.RuntimeFieldFactory.STR_ENUM_MAP;
import static io.protostuff.runtime.RuntimeFieldFactory.STR_MAP;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.IdentityHashMap;
import java.util.Map;
import io.protostuff.GraphInput;
import io.protostuff.Input;
import io.protostuff.Output;
import io.protostuff.Pipe;
import io.protostuff.ProtostuffException;
import io.protostuff.Schema;
import io.protostuff.StatefulOutput;
import io.protostuff.runtime.IdStrategy.Wrapper;
import io.protostuff.runtime.RuntimeEnv.Instantiator;
/**
* Used when the type is an interface (Map/SortedMap).
*
* @author David Yu
* @created Apr 24, 2012
*/
public abstract class PolymorphicMapSchema extends PolymorphicSchema
{
static final int ID_EMPTY_MAP = 1, ID_SINGLETON_MAP = 2,
ID_UNMODIFIABLE_MAP = 3, ID_UNMODIFIABLE_SORTED_MAP = 4,
ID_SYNCHRONIZED_MAP = 5, ID_SYNCHRONIZED_SORTED_MAP = 6,
ID_CHECKED_MAP = 7, ID_CHECKED_SORTED_MAP = 8;
static final String STR_EMPTY_MAP = "a", STR_SINGLETON_MAP = "b",
STR_UNMODIFIABLE_MAP = "c", STR_UNMODIFIABLE_SORTED_MAP = "d",
STR_SYNCHRONIZED_MAP = "e", STR_SYNCHRONIZED_SORTED_MAP = "f",
STR_CHECKED_MAP = "g", STR_CHECKED_SORTED_MAP = "h";
static final IdentityHashMap, Integer> __nonPublicMaps = new IdentityHashMap, Integer>();
static final Field fSingletonMap_k, fSingletonMap_v,
fUnmodifiableMap_m,
fUnmodifiableSortedMap_sm,
fSynchronizedMap_m,
fSynchronizedSortedMap_sm,
fSynchronizedMap_mutex,
fCheckedMap_m, fCheckedSortedMap_sm, fCheckedMap_keyType,
fCheckedMap_valueType;
static final Instantiator> iSingletonMap,
iUnmodifiableMap, iUnmodifiableSortedMap,
iSynchronizedMap, iSynchronizedSortedMap,
iCheckedMap, iCheckedSortedMap;
static
{
map("java.util.Collections$EmptyMap", ID_EMPTY_MAP);
Class> cSingletonMap = map("java.util.Collections$SingletonMap",
ID_SINGLETON_MAP);
Class> cUnmodifiableMap = map(
"java.util.Collections$UnmodifiableMap", ID_UNMODIFIABLE_MAP);
Class> cUnmodifiableSortedMap = map(
"java.util.Collections$UnmodifiableSortedMap",
ID_UNMODIFIABLE_SORTED_MAP);
Class> cSynchronizedMap = map(
"java.util.Collections$SynchronizedMap", ID_SYNCHRONIZED_MAP);
Class> cSynchronizedSortedMap = map(
"java.util.Collections$SynchronizedSortedMap",
ID_SYNCHRONIZED_SORTED_MAP);
Class> cCheckedMap = map("java.util.Collections$CheckedMap",
ID_CHECKED_MAP);
Class> cCheckedSortedMap = map(
"java.util.Collections$CheckedSortedMap", ID_CHECKED_SORTED_MAP);
try
{
fSingletonMap_k = cSingletonMap.getDeclaredField("k");
fSingletonMap_v = cSingletonMap.getDeclaredField("v");
fUnmodifiableMap_m = cUnmodifiableMap.getDeclaredField("m");
fUnmodifiableSortedMap_sm = cUnmodifiableSortedMap
.getDeclaredField("sm");
fSynchronizedMap_m = cSynchronizedMap.getDeclaredField("m");
fSynchronizedSortedMap_sm = cSynchronizedSortedMap
.getDeclaredField("sm");
fSynchronizedMap_mutex = cSynchronizedMap.getDeclaredField("mutex");
fCheckedMap_m = cCheckedMap.getDeclaredField("m");
fCheckedSortedMap_sm = cCheckedSortedMap.getDeclaredField("sm");
fCheckedMap_keyType = cCheckedMap.getDeclaredField("keyType");
fCheckedMap_valueType = cCheckedMap.getDeclaredField("valueType");
iSingletonMap = RuntimeEnv.newInstantiator(cSingletonMap);
iUnmodifiableMap = RuntimeEnv.newInstantiator(cUnmodifiableMap);
iUnmodifiableSortedMap = RuntimeEnv
.newInstantiator(cUnmodifiableSortedMap);
iSynchronizedMap = RuntimeEnv.newInstantiator(cSynchronizedMap);
iSynchronizedSortedMap = RuntimeEnv
.newInstantiator(cSynchronizedSortedMap);
iCheckedMap = RuntimeEnv.newInstantiator(cCheckedMap);
iCheckedSortedMap = RuntimeEnv.newInstantiator(cCheckedSortedMap);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
fSingletonMap_k.setAccessible(true);
fSingletonMap_v.setAccessible(true);
fUnmodifiableMap_m.setAccessible(true);
fUnmodifiableSortedMap_sm.setAccessible(true);
fSynchronizedMap_m.setAccessible(true);
fSynchronizedSortedMap_sm.setAccessible(true);
fSynchronizedMap_mutex.setAccessible(true);
fCheckedMap_m.setAccessible(true);
fCheckedSortedMap_sm.setAccessible(true);
fCheckedMap_keyType.setAccessible(true);
fCheckedMap_valueType.setAccessible(true);
}
private static Class> map(String className, int id)
{
Class> clazz = RuntimeEnv.loadClass(className);
__nonPublicMaps.put(clazz, id);
return clazz;
}
static String name(int number)
{
switch (number)
{
case ID_EMPTY_MAP:
return STR_EMPTY_MAP;
case ID_SINGLETON_MAP:
return STR_SINGLETON_MAP;
case ID_UNMODIFIABLE_MAP:
return STR_UNMODIFIABLE_MAP;
case ID_UNMODIFIABLE_SORTED_MAP:
return STR_UNMODIFIABLE_SORTED_MAP;
case ID_SYNCHRONIZED_MAP:
return STR_SYNCHRONIZED_MAP;
case ID_SYNCHRONIZED_SORTED_MAP:
return STR_SYNCHRONIZED_SORTED_MAP;
case ID_CHECKED_MAP:
return STR_CHECKED_MAP;
case ID_CHECKED_SORTED_MAP:
return STR_CHECKED_SORTED_MAP;
case ID_ENUM_MAP:
return STR_ENUM_MAP;
case ID_MAP:
return STR_MAP;
default:
return null;
}
}
static int number(String name)
{
return name.length() != 1 ? 0 : number(name.charAt(0));
}
static int number(char c)
{
switch (c)
{
case 'a':
return 1;
case 'b':
return 2;
case 'c':
return 3;
case 'd':
return 4;
case 'e':
return 5;
case 'f':
return 6;
case 'g':
return 7;
case 'h':
return 8;
case 'w':
return ID_ENUM_MAP;
case 'z':
return ID_MAP;
default:
return 0;
}
}
protected final Pipe.Schema