001/** 002 * GRANITE DATA SERVICES 003 * Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S. 004 * 005 * This file is part of the Granite Data Services Platform. 006 * 007 * Granite Data Services is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * Granite Data Services is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 015 * General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 020 * USA, or see <http://www.gnu.org/licenses/>. 021 */ 022package org.granite.messaging.jmf; 023 024import java.util.ArrayList; 025import java.util.Arrays; 026import java.util.Collections; 027import java.util.Date; 028import java.util.HashMap; 029import java.util.HashSet; 030import java.util.List; 031import java.util.Map; 032import java.util.Set; 033 034import org.granite.messaging.AliasRegistry; 035import org.granite.messaging.DefaultAliasRegistry; 036import org.granite.messaging.reflect.Reflection; 037 038/** 039 * @author Franck WOLFF 040 */ 041public class DefaultSharedContext implements SharedContext { 042 043 protected static List<String> JAVA_DEFAULT_STORED_STRINGS = Arrays.asList( 044 Boolean.class.getName(), 045 Character.class.getName(), 046 Byte.class.getName(), 047 Short.class.getName(), 048 Integer.class.getName(), 049 Long.class.getName(), 050 Float.class.getName(), 051 Double.class.getName(), 052 053 String.class.getName(), 054 Object.class.getName(), 055 056 Date.class.getName(), 057 058 List.class.getName(), 059 ArrayList.class.getName(), 060 061 Set.class.getName(), 062 HashSet.class.getName(), 063 064 Map.class.getName(), 065 HashMap.class.getName(), 066 067 JMFConstants.CLIENT_PERSISTENCE_COLLECTION_PACKAGE + ".PersistentList", 068 JMFConstants.CLIENT_PERSISTENCE_COLLECTION_PACKAGE + ".PersistentMap", 069 JMFConstants.CLIENT_PERSISTENCE_COLLECTION_PACKAGE + ".PersistentSet", 070 JMFConstants.CLIENT_PERSISTENCE_COLLECTION_PACKAGE + ".PersistentBag", 071 JMFConstants.CLIENT_PERSISTENCE_COLLECTION_PACKAGE + ".PersistentSortedSet", 072 JMFConstants.CLIENT_PERSISTENCE_COLLECTION_PACKAGE + ".PersistentSortedMap" 073 ); 074 075 protected final CodecRegistry codecRegistry; 076 protected final Reflection reflection; 077 protected final List<String> defaultStoredStrings; 078 protected final AliasRegistry aliasRegistry; 079 080 public DefaultSharedContext() { 081 this(null, null, null, null); 082 } 083 084 public DefaultSharedContext(CodecRegistry codecRegistry) { 085 this(codecRegistry, null, null, null); 086 } 087 088 public DefaultSharedContext(CodecRegistry codecRegistry, List<String> defaultStoredStrings) { 089 this(codecRegistry, defaultStoredStrings, null, null); 090 } 091 092 public DefaultSharedContext(CodecRegistry codecRegistry, List<String> defaultStoredStrings, Reflection reflection, AliasRegistry aliasRegistry) { 093 this.codecRegistry = (codecRegistry != null ? codecRegistry : new DefaultCodecRegistry()); 094 095 List<String> defaultStoredStringsTmp = new ArrayList<String>(JAVA_DEFAULT_STORED_STRINGS); 096 if (defaultStoredStrings != null) 097 defaultStoredStringsTmp.addAll(defaultStoredStrings); 098 this.defaultStoredStrings = Collections.unmodifiableList(defaultStoredStringsTmp); 099 100 this.reflection = (reflection != null ? reflection : new Reflection(null)); 101 102 this.aliasRegistry = aliasRegistry != null ? aliasRegistry : new DefaultAliasRegistry(); 103 } 104 105 public CodecRegistry getCodecRegistry() { 106 return codecRegistry; 107 } 108 109 public Reflection getReflection() { 110 return reflection; 111 } 112 113 public List<String> getDefaultStoredStrings() { 114 return defaultStoredStrings; 115 } 116 117 public AliasRegistry getAliasRegistry() { 118 return aliasRegistry; 119 } 120 121 public String getRemoteAlias(String className) { 122 return aliasRegistry.getAliasForType(className); 123 } 124 125 public String getClassName(String remoteAlias) { 126 return aliasRegistry.getTypeForAlias(remoteAlias); 127 } 128}