Commit ee348c188d8fd39320cf524ee37f8f8768d22186
1 parent
c73cbad5
Exists in
master
Ajustes na implementação do ConfigurationBootstrap
Showing
5 changed files
with
81 additions
and
52 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/configuration/Configuration.java
@@ -43,6 +43,8 @@ import java.lang.annotation.Inherited; | @@ -43,6 +43,8 @@ import java.lang.annotation.Inherited; | ||
43 | import java.lang.annotation.Retention; | 43 | import java.lang.annotation.Retention; |
44 | import java.lang.annotation.Target; | 44 | import java.lang.annotation.Target; |
45 | 45 | ||
46 | +import javax.enterprise.context.ApplicationScoped; | ||
47 | +import javax.enterprise.context.RequestScoped; | ||
46 | import javax.enterprise.inject.Stereotype; | 48 | import javax.enterprise.inject.Stereotype; |
47 | import javax.enterprise.util.Nonbinding; | 49 | import javax.enterprise.util.Nonbinding; |
48 | import javax.inject.Singleton; | 50 | import javax.inject.Singleton; |
@@ -62,7 +64,7 @@ import javax.inject.Singleton; | @@ -62,7 +64,7 @@ import javax.inject.Singleton; | ||
62 | * | 64 | * |
63 | * @author SERPRO | 65 | * @author SERPRO |
64 | */ | 66 | */ |
65 | -@Singleton | 67 | +//@Singleton |
66 | @Stereotype | 68 | @Stereotype |
67 | @Inherited | 69 | @Inherited |
68 | @Target(TYPE) | 70 | @Target(TYPE) |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ConfigurationBootstrap.java
@@ -42,7 +42,6 @@ import java.util.List; | @@ -42,7 +42,6 @@ import java.util.List; | ||
42 | 42 | ||
43 | import javassist.ClassPool; | 43 | import javassist.ClassPool; |
44 | import javassist.CtClass; | 44 | import javassist.CtClass; |
45 | -import javassist.CtField; | ||
46 | import javassist.CtMethod; | 45 | import javassist.CtMethod; |
47 | import javassist.CtNewMethod; | 46 | import javassist.CtNewMethod; |
48 | import javassist.LoaderClassPath; | 47 | import javassist.LoaderClassPath; |
@@ -55,6 +54,7 @@ import javax.enterprise.inject.spi.Extension; | @@ -55,6 +54,7 @@ import javax.enterprise.inject.spi.Extension; | ||
55 | import javax.enterprise.inject.spi.ProcessAnnotatedType; | 54 | import javax.enterprise.inject.spi.ProcessAnnotatedType; |
56 | 55 | ||
57 | import br.gov.frameworkdemoiselle.configuration.Configuration; | 56 | import br.gov.frameworkdemoiselle.configuration.Configuration; |
57 | +import br.gov.frameworkdemoiselle.internal.implementation.ConfigurationImpl; | ||
58 | 58 | ||
59 | public class ConfigurationBootstrap implements Extension { | 59 | public class ConfigurationBootstrap implements Extension { |
60 | 60 | ||
@@ -84,6 +84,8 @@ public class ConfigurationBootstrap implements Extension { | @@ -84,6 +84,8 @@ public class ConfigurationBootstrap implements Extension { | ||
84 | String chieldClassName = superClassName + "__DemoiselleProxy"; | 84 | String chieldClassName = superClassName + "__DemoiselleProxy"; |
85 | 85 | ||
86 | ClassPool pool = ClassPool.getDefault(); | 86 | ClassPool pool = ClassPool.getDefault(); |
87 | + ClassPool.doPruning = true; | ||
88 | + | ||
87 | CtClass ctChieldClass = pool.getOrNull(chieldClassName); | 89 | CtClass ctChieldClass = pool.getOrNull(chieldClassName); |
88 | 90 | ||
89 | ClassLoader classLoader = type.getClassLoader(); | 91 | ClassLoader classLoader = type.getClassLoader(); |
@@ -97,20 +99,26 @@ public class ConfigurationBootstrap implements Extension { | @@ -97,20 +99,26 @@ public class ConfigurationBootstrap implements Extension { | ||
97 | 99 | ||
98 | CtClass ctSuperClass = pool.get(superClassName); | 100 | CtClass ctSuperClass = pool.get(superClassName); |
99 | 101 | ||
100 | - ctChieldClass = pool.makeClass(chieldClassName, ctSuperClass); | 102 | + // ctChieldClass = pool.makeClass(chieldClassName, ctSuperClass); |
103 | + ctChieldClass = pool.getAndRename(ConfigurationImpl.class.getCanonicalName(), chieldClassName); | ||
104 | + ctChieldClass.setSuperclass(ctSuperClass); | ||
101 | 105 | ||
102 | - CtClass ctClassX = pool.get("br.gov.frameworkdemoiselle.internal.implementation.X"); | 106 | + // for (CtField ctFieldImpl : ctClassImpl.getDeclaredFields()) { |
107 | + // ctChieldClass.addField(new CtField(ctFieldImpl, ctChieldClass)); | ||
108 | + // System.out.println("FFFFFFFFFFFFFFFFFFFFFFFFFF-----------" + ctFieldImpl.toString()); | ||
109 | + // } | ||
103 | 110 | ||
104 | - CtField ctFieldX = ctClassX.getField("cache"); | ||
105 | - ctChieldClass.addField(new CtField(ctFieldX, ctChieldClass)); | ||
106 | - | ||
107 | - CtMethod ctMethodX = ctClassX.getDeclaredMethod("loadProxyConfigurarion"); | ||
108 | - ctChieldClass.addMethod(new CtMethod(ctMethodX, ctChieldClass, null)); | 111 | + // for (CtMethod ctMethodImpl : ctClassImpl.getDeclaredMethods()) { |
112 | + // ctChieldClass.addMethod(new CtMethod(ctMethodImpl, ctChieldClass, null)); | ||
113 | + // System.out.println("MMMMMMMMMMMMMMMMMMMMMMMMMM-----------" + ctMethodImpl.toString()); | ||
114 | + // } | ||
109 | 115 | ||
110 | CtMethod ctChieldMethod; | 116 | CtMethod ctChieldMethod; |
111 | for (CtMethod ctSuperMethod : ctSuperClass.getDeclaredMethods()) { | 117 | for (CtMethod ctSuperMethod : ctSuperClass.getDeclaredMethods()) { |
112 | ctChieldMethod = CtNewMethod.delegator(ctSuperMethod, ctChieldClass); | 118 | ctChieldMethod = CtNewMethod.delegator(ctSuperMethod, ctChieldClass); |
113 | - ctChieldMethod.insertBefore("loadProxyConfigurarion();"); | 119 | + ctChieldMethod.insertBefore("loadProxyConfigurarion(this);"); |
120 | + // ctChieldMethod | ||
121 | + // .insertBefore("new br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader().load(this);"); | ||
114 | 122 | ||
115 | ctChieldClass.addMethod(ctChieldMethod); | 123 | ctChieldClass.addMethod(ctChieldMethod); |
116 | } | 124 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ProxyBean.java
@@ -42,6 +42,7 @@ import java.util.Collections; | @@ -42,6 +42,7 @@ import java.util.Collections; | ||
42 | import java.util.HashSet; | 42 | import java.util.HashSet; |
43 | import java.util.Set; | 43 | import java.util.Set; |
44 | 44 | ||
45 | +import javax.enterprise.context.Dependent; | ||
45 | import javax.enterprise.context.spi.CreationalContext; | 46 | import javax.enterprise.context.spi.CreationalContext; |
46 | import javax.enterprise.inject.Any; | 47 | import javax.enterprise.inject.Any; |
47 | import javax.enterprise.inject.Default; | 48 | import javax.enterprise.inject.Default; |
@@ -51,7 +52,7 @@ import javax.enterprise.inject.spi.BeanManager; | @@ -51,7 +52,7 @@ import javax.enterprise.inject.spi.BeanManager; | ||
51 | import javax.enterprise.inject.spi.InjectionPoint; | 52 | import javax.enterprise.inject.spi.InjectionPoint; |
52 | import javax.enterprise.inject.spi.InjectionTarget; | 53 | import javax.enterprise.inject.spi.InjectionTarget; |
53 | import javax.enterprise.util.AnnotationLiteral; | 54 | import javax.enterprise.util.AnnotationLiteral; |
54 | -import javax.inject.Singleton; | 55 | +import javax.inject.Scope; |
55 | 56 | ||
56 | /** | 57 | /** |
57 | * @see http://docs.jboss.org/weld/reference/latest/en-US/html_single/#d0e5035 | 58 | * @see http://docs.jboss.org/weld/reference/latest/en-US/html_single/#d0e5035 |
@@ -101,7 +102,7 @@ public class ProxyBean implements Bean<Object> { | @@ -101,7 +102,7 @@ public class ProxyBean implements Bean<Object> { | ||
101 | } | 102 | } |
102 | 103 | ||
103 | public Class<? extends Annotation> getScope() { | 104 | public Class<? extends Annotation> getScope() { |
104 | - return Singleton.class; | 105 | + return Dependent.class; |
105 | } | 106 | } |
106 | 107 | ||
107 | public String getName() { | 108 | public String getName() { |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationImpl.java
0 → 100644
@@ -0,0 +1,58 @@ | @@ -0,0 +1,58 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.implementation; | ||
2 | + | ||
3 | +import java.util.ArrayList; | ||
4 | +import java.util.Collections; | ||
5 | +import java.util.HashMap; | ||
6 | +import java.util.List; | ||
7 | +import java.util.Map; | ||
8 | + | ||
9 | +import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader; | ||
10 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
11 | + | ||
12 | +public class ConfigurationImpl { | ||
13 | + | ||
14 | + private static Map<ClassLoader, List<Class<?>>> cache; | ||
15 | + | ||
16 | + private boolean loaded = false; | ||
17 | + | ||
18 | + private synchronized static Map<ClassLoader, List<Class<?>>> getCache() { | ||
19 | + if (cache == null) { | ||
20 | + cache = Collections.synchronizedMap(new HashMap<ClassLoader, List<Class<?>>>()); | ||
21 | + } | ||
22 | + | ||
23 | + return cache; | ||
24 | + } | ||
25 | + | ||
26 | + @SuppressWarnings("unused") | ||
27 | + private synchronized void loadProxyConfigurarion(Object instance) { | ||
28 | + if (!loaded) { | ||
29 | + Beans.getReference(ConfigurationLoader.class).load(instance); | ||
30 | + loaded = true; | ||
31 | + } | ||
32 | + } | ||
33 | + | ||
34 | + @SuppressWarnings("unused") | ||
35 | + private synchronized static void loadProxyConfigurarionX(Object instance) { | ||
36 | + Class<?> clazz = instance.getClass().getSuperclass(); | ||
37 | + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
38 | + | ||
39 | + boolean loaded = true; | ||
40 | + | ||
41 | + if (getCache().containsKey(classLoader)) { | ||
42 | + if (!getCache().get(classLoader).contains(clazz)) { | ||
43 | + loaded = false; | ||
44 | + } | ||
45 | + | ||
46 | + } else { | ||
47 | + List<Class<?>> classes = Collections.synchronizedList(new ArrayList<Class<?>>()); | ||
48 | + getCache().put(classLoader, classes); | ||
49 | + loaded = false; | ||
50 | + } | ||
51 | + | ||
52 | + if (!loaded) { | ||
53 | +// new br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader().load(instance); | ||
54 | + Beans.getReference(ConfigurationLoader.class).load(instance); | ||
55 | + getCache().get(classLoader).add(clazz); | ||
56 | + } | ||
57 | + } | ||
58 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/X.java
@@ -1,40 +0,0 @@ | @@ -1,40 +0,0 @@ | ||
1 | -package br.gov.frameworkdemoiselle.internal.implementation; | ||
2 | - | ||
3 | -import java.util.ArrayList; | ||
4 | -import java.util.Collections; | ||
5 | -import java.util.HashMap; | ||
6 | -import java.util.List; | ||
7 | -import java.util.Map; | ||
8 | - | ||
9 | -import br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader; | ||
10 | - | ||
11 | -public class X { | ||
12 | - | ||
13 | - private final Map<ClassLoader, List<Class<?>>> cache = Collections | ||
14 | - .synchronizedMap(new HashMap<ClassLoader, List<Class<?>>>()); | ||
15 | - | ||
16 | - private void loadProxyConfigurarion() { | ||
17 | - Class<?> clazz = this.getClass(); | ||
18 | - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
19 | - | ||
20 | - boolean loaded = true; | ||
21 | - | ||
22 | - if (cache.containsKey(classLoader)) { | ||
23 | - if (!cache.get(classLoader).contains(clazz)) { | ||
24 | - loaded = false; | ||
25 | - } | ||
26 | - | ||
27 | - } else { | ||
28 | - List<Class<?>> classes = Collections.synchronizedList(new ArrayList<Class<?>>()); | ||
29 | - cache.put(classLoader, classes); | ||
30 | - loaded = false; | ||
31 | - } | ||
32 | - | ||
33 | - if (!loaded) { | ||
34 | - new ConfigurationLoader().load(this); | ||
35 | - cache.get(classLoader).add(clazz); | ||
36 | - } | ||
37 | - | ||
38 | - new ConfigurationLoader().load(this); | ||
39 | - } | ||
40 | -} |