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