Commit 0bac8554b36c32f2601712c8b32a31c3f2856b24

Authored by Dancovich
1 parent a72f5cbe
Exists in master

Resolvendo problema onde contextos personalizados não suportam

serialização.
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractCustomContext.java
... ... @@ -157,8 +157,8 @@ public abstract class AbstractCustomContext implements CustomContext {
157 157 return this.scope;
158 158 }
159 159  
160   - protected static Store createStore(Class<?> owningClass) {
161   - return new Store(owningClass);
  160 + protected static Store createStore() {
  161 + return new Store();
162 162 }
163 163  
164 164 private ResourceBundle getBundle(){
... ... @@ -200,33 +200,26 @@ public abstract class AbstractCustomContext implements CustomContext {
200 200  
201 201 private final String SEPARATOR = "#";
202 202  
203   - private final String ID_PREFIX;
204   -
205 203 private Map<String, Object> cache = Collections.synchronizedMap(new HashMap<String, Object>());
206 204  
207   - private Store(Class<?> owningClass) {
208   - ID_PREFIX = Thread.currentThread().getContextClassLoader().toString()
209   - + SEPARATOR + owningClass.getCanonicalName();
210   - }
211   -
212 205 private boolean contains(final Class<?> type) {
213   - return cache.containsKey( prefixId(type.getCanonicalName()) );
  206 + return cache.containsKey( prefixId(type) );
214 207 }
215 208  
216 209 private Object get(final Class<?> type) {
217   - return cache.get( prefixId(type.getCanonicalName()) );
  210 + return cache.get( prefixId(type) );
218 211 }
219 212  
220 213 private void put(final Class<?> type, final Object instance) {
221   - cache.put( prefixId(type.getCanonicalName()) , instance);
  214 + cache.put( prefixId(type) , instance);
222 215 }
223 216  
224 217 public void clear() {
225 218 cache.clear();
226 219 }
227 220  
228   - private String prefixId(String id){
229   - return ID_PREFIX + SEPARATOR + id;
  221 + private String prefixId(Class<?> type){
  222 + return Thread.currentThread().getContextClassLoader().toString() + SEPARATOR + type.getCanonicalName();
230 223 }
231 224  
232 225 /*private Map<String, Object> getMap() {
... ...
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractStaticContext.java
... ... @@ -37,9 +37,6 @@
37 37 package br.gov.frameworkdemoiselle.internal.context;
38 38  
39 39 import java.lang.annotation.Annotation;
40   -import java.util.Collections;
41   -import java.util.HashMap;
42   -import java.util.Map;
43 40  
44 41 import br.gov.frameworkdemoiselle.annotation.Priority;
45 42 import br.gov.frameworkdemoiselle.annotation.StaticScoped;
... ... @@ -61,7 +58,7 @@ import br.gov.frameworkdemoiselle.configuration.Configuration;
61 58 @Priority(Priority.MIN_PRIORITY)
62 59 public abstract class AbstractStaticContext extends AbstractCustomContext {
63 60  
64   - private static Map<String, Store> cache = Collections.synchronizedMap( new HashMap<String, Store>() );
  61 + private final static Store store = createStore();
65 62  
66 63 /**
67 64 * Constructs this context to control the provided scope
... ... @@ -72,16 +69,11 @@ public abstract class AbstractStaticContext extends AbstractCustomContext {
72 69  
73 70 @Override
74 71 protected Store getStore() {
75   - Store store = cache.get( this.getClass().getCanonicalName() );
76   - if ( store==null ){
77   - store = createStore(this.getClass());
78   - cache.put(this.getClass().getCanonicalName(), store);
79   - }
80 72 return store;
81 73 }
82 74  
83 75 @Override
84 76 protected boolean isStoreInitialized() {
85   - return cache.get( this.getClass().getCanonicalName() )!=null;
  77 + return store!=null;
86 78 }
87 79 }
... ...
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/AbstractThreadLocalContext.java
... ... @@ -73,7 +73,7 @@ public abstract class AbstractThreadLocalContext extends AbstractCustomContext {
73 73 @Override
74 74 protected Store getStore() {
75 75 if (this.threadLocal.get() == null) {
76   - this.threadLocal.set(createStore(getClass()));
  76 + this.threadLocal.set(createStore());
77 77 }
78 78  
79 79 return this.threadLocal.get();
... ...
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/context/FacesViewContextImpl.java
... ... @@ -75,7 +75,7 @@ public class FacesViewContextImpl extends AbstractCustomContext implements ViewC
75 75 String key = Store.class.getName();
76 76  
77 77 if (!viewMap.containsKey(key)) {
78   - viewMap.put(key, createStore( getClass() ));
  78 + viewMap.put(key, createStore());
79 79 }
80 80  
81 81 return (Store) viewMap.get(key);
... ...