Commit 8968457b327aaf41d8875f7ea478ceaa3145e3dc
Exists in
master
Merge branch '2.4.0' of git@github.com:demoiselle/framework.git into 2.4.0
Showing
44 changed files
with
2334 additions
and
1282 deletions
Show diff stats
impl/core/pom.xml
... | ... | @@ -77,15 +77,6 @@ |
77 | 77 | <scope>import</scope> |
78 | 78 | <type>pom</type> |
79 | 79 | </dependency> |
80 | - <!-- | |
81 | - <dependency> | |
82 | - <groupId>org.jboss.arquillian</groupId> | |
83 | - <artifactId>arquillian-bom</artifactId> | |
84 | - <version>${arquillian.version}</version> | |
85 | - <scope>import</scope> | |
86 | - <type>pom</type> | |
87 | - </dependency> | |
88 | - --> | |
89 | 80 | </dependencies> |
90 | 81 | </dependencyManagement> |
91 | 82 | |
... | ... | @@ -248,6 +239,13 @@ |
248 | 239 | <artifactId>slf4j-log4j12</artifactId> |
249 | 240 | <scope>test</scope> |
250 | 241 | </dependency> |
242 | + | |
243 | + <dependency> | |
244 | + <groupId>br.gov.frameworkdemoiselle.component</groupId> | |
245 | + <artifactId>demoiselle-validation</artifactId> | |
246 | + <scope>test</scope> | |
247 | + <version>${demoiselle.validation.version}</version> | |
248 | + </dependency> | |
251 | 249 | </dependencies> |
252 | 250 | |
253 | 251 | <repositories> |
... | ... | @@ -279,5 +277,6 @@ |
279 | 277 | <!-- |
280 | 278 | <jacoco.version>0.6.0.201210061924</jacoco.version> |
281 | 279 | --> |
280 | + <demoiselle.validation.version>2.4.0-BETA2-SNAPSHOT</demoiselle.validation.version> | |
282 | 281 | </properties> |
283 | 282 | </project> | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/ManagedOperation.java
0 → 100644
... | ... | @@ -0,0 +1,74 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package br.gov.frameworkdemoiselle.annotation; | |
38 | + | |
39 | +import java.lang.annotation.Documented; | |
40 | +import java.lang.annotation.ElementType; | |
41 | +import java.lang.annotation.Retention; | |
42 | +import java.lang.annotation.RetentionPolicy; | |
43 | +import java.lang.annotation.Target; | |
44 | + | |
45 | +import javax.enterprise.util.Nonbinding; | |
46 | + | |
47 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
48 | + | |
49 | +/** | |
50 | + * <p>Indicates that a method is a <b>managed operation</b>, meaning you can manage some aspect of the application by calling it from a external management client.</p> | |
51 | + * <p>This annotation can't be used together with {@link ManagedProperty}, doing so will throw a {@link DemoiselleException}.</p> | |
52 | + * | |
53 | + * @author SERPRO | |
54 | + * | |
55 | + */ | |
56 | +@Documented | |
57 | +@Target({ElementType.METHOD}) | |
58 | +@Retention(RetentionPolicy.RUNTIME) | |
59 | +public @interface ManagedOperation { | |
60 | + | |
61 | + /** | |
62 | + * Description that will be used to publish the operation to clients. | |
63 | + * Defaults to an empty description. | |
64 | + */ | |
65 | + @Nonbinding | |
66 | + String description() default ""; | |
67 | + | |
68 | + /** | |
69 | + * Type of operation. Defaults to {@link OperationType#UNKNOWN}. | |
70 | + */ | |
71 | + @Nonbinding | |
72 | + OperationType type() default OperationType.UNKNOWN; | |
73 | + | |
74 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/ManagedProperty.java
0 → 100644
... | ... | @@ -0,0 +1,69 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package br.gov.frameworkdemoiselle.annotation; | |
38 | + | |
39 | +import java.lang.annotation.Documented; | |
40 | +import java.lang.annotation.ElementType; | |
41 | +import java.lang.annotation.Retention; | |
42 | +import java.lang.annotation.RetentionPolicy; | |
43 | +import java.lang.annotation.Target; | |
44 | + | |
45 | +import javax.enterprise.util.Nonbinding; | |
46 | + | |
47 | +/** | |
48 | + * <p>Indicates that a field must be exposed as a property to management clients.</p> | |
49 | + * <p>The property will be writable if there's a public setter method | |
50 | + * declared for the field and readable if there's a getter method.</p> | |
51 | + * <p>It's a runtime error to annotate a field with no getter and no setter method.</p> | |
52 | + * <p>It's also a runtime error to declare a field as a property and one or both of it's getter and setter | |
53 | + * methods as an operation using the {@link ManagedOperation} annotation.</p> | |
54 | + * | |
55 | + * @author SERPRO | |
56 | + * | |
57 | + */ | |
58 | +@Documented | |
59 | +@Target({ElementType.FIELD}) | |
60 | +@Retention(RetentionPolicy.RUNTIME) | |
61 | +public @interface ManagedProperty { | |
62 | + | |
63 | + /** | |
64 | + * @return The description of this property exposed to management clients. | |
65 | + */ | |
66 | + @Nonbinding | |
67 | + String description() default ""; | |
68 | + | |
69 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/OperationParameter.java
0 → 100644
... | ... | @@ -0,0 +1,73 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package br.gov.frameworkdemoiselle.annotation; | |
38 | + | |
39 | +import java.lang.annotation.Documented; | |
40 | +import java.lang.annotation.ElementType; | |
41 | +import java.lang.annotation.Retention; | |
42 | +import java.lang.annotation.RetentionPolicy; | |
43 | +import java.lang.annotation.Target; | |
44 | + | |
45 | +import javax.enterprise.util.Nonbinding; | |
46 | + | |
47 | +/** | |
48 | + * <p>Optional annotation to write additional detail about an operation's parameter.</p> | |
49 | + * <p>This annotation is ignored for non-operation methods.</p> | |
50 | + * | |
51 | + * @author SERPRO | |
52 | + * | |
53 | + */ | |
54 | +@Documented | |
55 | +@Target({ElementType.PARAMETER}) | |
56 | +@Retention(RetentionPolicy.RUNTIME) | |
57 | +public @interface OperationParameter { | |
58 | + | |
59 | + /** | |
60 | + * Name that will be used to publish this operation's parameter to clients. | |
61 | + */ | |
62 | + @Nonbinding | |
63 | + String name(); | |
64 | + | |
65 | + /** | |
66 | + * Optional description that will be used to publish this operation's parameter to clients. | |
67 | + * Defaults to an empty description. | |
68 | + */ | |
69 | + @Nonbinding | |
70 | + String description() default ""; | |
71 | + | |
72 | + | |
73 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/OperationType.java
0 → 100644
... | ... | @@ -0,0 +1,89 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package br.gov.frameworkdemoiselle.annotation; | |
38 | + | |
39 | +import javax.management.MBeanOperationInfo; | |
40 | + | |
41 | + | |
42 | +/** | |
43 | + * <p>Define the operation type for an operation inside a ManagementController class.</p> | |
44 | + * | |
45 | + * <p>This is an optional annotation and it's significanse will change based on the management extension | |
46 | + * used. Most extensions will just publish this information to the client so it can better show to the user the inner | |
47 | + * workings of the annotated operation.</p> | |
48 | + * | |
49 | + * | |
50 | + * @author SERPRO | |
51 | + * | |
52 | + */ | |
53 | +public enum OperationType { | |
54 | + | |
55 | + /** | |
56 | + * ManagedOperation is write-only, it causes the application | |
57 | + * to change some of it's behaviour but doesn't return any kind of information | |
58 | + */ | |
59 | + ACTION(MBeanOperationInfo.ACTION) | |
60 | + , | |
61 | + /** | |
62 | + * ManagedOperation is read-only, it will operate over data provided by the application and return some information, | |
63 | + * but will not change the application in any way. | |
64 | + */ | |
65 | + INFO(MBeanOperationInfo.INFO) | |
66 | + , | |
67 | + /** | |
68 | + * ManagedOperation is read-write, it will both change the way the application work and return some information regarding | |
69 | + * the result of the operation. | |
70 | + */ | |
71 | + ACTION_INFO(MBeanOperationInfo.ACTION_INFO) | |
72 | + , | |
73 | + /** | |
74 | + * The effect of calling this operation is unknown. This is the default type and if this type is assigned to an operation, | |
75 | + * the user must rely on the {@link ManagedOperation#description()} attribute to learn about how the operation works. | |
76 | + */ | |
77 | + UNKNOWN(MBeanOperationInfo.UNKNOWN); | |
78 | + | |
79 | + private int operationTypeValue; | |
80 | + | |
81 | + private OperationType(int type){ | |
82 | + this.operationTypeValue = type; | |
83 | + } | |
84 | + | |
85 | + public int getValue(){ | |
86 | + return operationTypeValue; | |
87 | + } | |
88 | + | |
89 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java
... | ... | @@ -17,10 +17,10 @@ import javax.enterprise.inject.spi.ProcessAnnotatedType; |
17 | 17 | |
18 | 18 | import br.gov.frameworkdemoiselle.internal.context.ContextManager; |
19 | 19 | import br.gov.frameworkdemoiselle.internal.context.ManagedContext; |
20 | -import br.gov.frameworkdemoiselle.management.annotation.Managed; | |
21 | -import br.gov.frameworkdemoiselle.management.extension.ManagementExtension; | |
22 | -import br.gov.frameworkdemoiselle.management.internal.ManagedType; | |
23 | -import br.gov.frameworkdemoiselle.management.internal.MonitoringManager; | |
20 | +import br.gov.frameworkdemoiselle.internal.management.ManagedType; | |
21 | +import br.gov.frameworkdemoiselle.internal.management.Management; | |
22 | +import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; | |
23 | +import br.gov.frameworkdemoiselle.stereotype.ManagementController; | |
24 | 24 | import br.gov.frameworkdemoiselle.util.Beans; |
25 | 25 | |
26 | 26 | public class ManagementBootstrap implements Extension { |
... | ... | @@ -31,7 +31,7 @@ public class ManagementBootstrap implements Extension { |
31 | 31 | |
32 | 32 | |
33 | 33 | public <T> void detectAnnotation(@Observes final ProcessAnnotatedType<T> event, final BeanManager beanManager) { |
34 | - if (event.getAnnotatedType().isAnnotationPresent(Managed.class)) { | |
34 | + if (event.getAnnotatedType().isAnnotationPresent(ManagementController.class)) { | |
35 | 35 | types.add(event.getAnnotatedType()); |
36 | 36 | } |
37 | 37 | } |
... | ... | @@ -43,7 +43,7 @@ public class ManagementBootstrap implements Extension { |
43 | 43 | |
44 | 44 | @SuppressWarnings("unchecked") |
45 | 45 | public void registerAvailableManagedTypes(@Observes final AfterDeploymentValidation event,BeanManager beanManager) { |
46 | - MonitoringManager monitoringManager = Beans.getReference(MonitoringManager.class); | |
46 | + Management monitoringManager = Beans.getReference(Management.class); | |
47 | 47 | for (AnnotatedType<?> type : types) { |
48 | 48 | ManagedType managedType = new ManagedType(type.getJavaClass()); |
49 | 49 | monitoringManager.addManagedType(managedType); |
... | ... | @@ -62,7 +62,7 @@ public class ManagementBootstrap implements Extension { |
62 | 62 | |
63 | 63 | public void unregisterAvailableManagedTypes(@Observes final BeforeShutdown event) { |
64 | 64 | |
65 | - MonitoringManager manager = Beans.getReference(MonitoringManager.class); | |
65 | + Management manager = Beans.getReference(Management.class); | |
66 | 66 | manager.shutdown(managementExtensionCache); |
67 | 67 | |
68 | 68 | managementExtensionCache.clear(); | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ManagedContext.java
... | ... | @@ -2,10 +2,10 @@ package br.gov.frameworkdemoiselle.internal.context; |
2 | 2 | |
3 | 3 | import javax.enterprise.context.RequestScoped; |
4 | 4 | |
5 | -import br.gov.frameworkdemoiselle.management.annotation.Managed; | |
5 | +import br.gov.frameworkdemoiselle.stereotype.ManagementController; | |
6 | 6 | |
7 | 7 | /** |
8 | - * Context that stores {@link RequestScoped} beans during client calls to {@link Managed} classes. | |
8 | + * Context that stores {@link RequestScoped} beans during client calls to {@link ManagementController} classes. | |
9 | 9 | * This context is only activated when no other context is active for {@link RequestScoped}. |
10 | 10 | * |
11 | 11 | * @author serpro | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/ManagedType.java
0 → 100644
... | ... | @@ -0,0 +1,334 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package br.gov.frameworkdemoiselle.internal.management; | |
38 | + | |
39 | +import java.lang.annotation.Annotation; | |
40 | +import java.lang.reflect.Field; | |
41 | +import java.lang.reflect.Method; | |
42 | +import java.util.TreeMap; | |
43 | + | |
44 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
45 | +import br.gov.frameworkdemoiselle.annotation.ManagedOperation; | |
46 | +import br.gov.frameworkdemoiselle.annotation.ManagedProperty; | |
47 | +import br.gov.frameworkdemoiselle.annotation.OperationParameter; | |
48 | +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
49 | +import br.gov.frameworkdemoiselle.stereotype.ManagementController; | |
50 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
51 | + | |
52 | +/** | |
53 | + * <p>Package class containing information about a discovered {@link ManagementController}.</p> | |
54 | + * | |
55 | + * <p>Instances if this class are passed to each discovered management extension during bootstrap so they can have | |
56 | + * enough information to expose all discovered {@link ManagementController}'s to management clients.</p> | |
57 | + * | |
58 | + * @author serpro | |
59 | + */ | |
60 | +public class ManagedType { | |
61 | + | |
62 | + private Class<?> type; | |
63 | + | |
64 | + private TreeMap<String, FieldDetail> fields; | |
65 | + | |
66 | + private TreeMap<String, MethodDetail> operationMethods; | |
67 | + | |
68 | + private ResourceBundle bundle; | |
69 | + | |
70 | + private String description; | |
71 | + | |
72 | + public ManagedType(Class<?> type) { | |
73 | + bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | |
74 | + | |
75 | + if (type == null) { | |
76 | + throw new DemoiselleException(bundle.getString("management-null-class-defined")); | |
77 | + } | |
78 | + if (!type.isAnnotationPresent(ManagementController.class)) { | |
79 | + throw new DemoiselleException(bundle.getString("management-no-annotation-found", type.getCanonicalName())); | |
80 | + } | |
81 | + | |
82 | + this.type = type; | |
83 | + fields = new TreeMap<String, FieldDetail>(); | |
84 | + operationMethods = new TreeMap<String, MethodDetail>(); | |
85 | + this.description = type.getAnnotation(ManagementController.class).description(); | |
86 | + | |
87 | + initialize(); | |
88 | + } | |
89 | + | |
90 | + public Class<?> getType() { | |
91 | + return type; | |
92 | + } | |
93 | + | |
94 | + public String getDescription() { | |
95 | + return description; | |
96 | + } | |
97 | + | |
98 | + public TreeMap<String, FieldDetail> getFields() { | |
99 | + return fields; | |
100 | + } | |
101 | + | |
102 | + public TreeMap<String, MethodDetail> getOperationMethods() { | |
103 | + return operationMethods; | |
104 | + } | |
105 | + | |
106 | + private void initialize() { | |
107 | + // Para cada atributo verifica se ele está anotado com ManagedProperty e extrai as informações dele (método get, set e | |
108 | + // descrição do atributo). | |
109 | + Field[] fields = type.getDeclaredFields(); | |
110 | + if (fields != null) { | |
111 | + for (Field field : fields) { | |
112 | + if (field.isAnnotationPresent(ManagedProperty.class)) { | |
113 | + // Obtém os métodos GET e SET para esta propriedade | |
114 | + Method getterMethod = getGetterMethod(field); | |
115 | + Method setterMethod = getSetterMethod(field); | |
116 | + if (getterMethod == null && setterMethod == null) { | |
117 | + throw new DemoiselleException(bundle.getString("management-invalid-property-no-getter-setter", | |
118 | + type.getSimpleName(), field.getName())); | |
119 | + } else if ((getterMethod != null && getterMethod.isAnnotationPresent(ManagedOperation.class)) | |
120 | + || (setterMethod != null && setterMethod.isAnnotationPresent(ManagedOperation.class))) { | |
121 | + throw new DemoiselleException(bundle.getString("management-invalid-property-as-operation", | |
122 | + type.getSimpleName())); | |
123 | + } | |
124 | + | |
125 | + String propertyDescription = field.getAnnotation(ManagedProperty.class).description(); | |
126 | + | |
127 | + this.fields.put(field.getName(), new FieldDetail(field, propertyDescription, getterMethod, | |
128 | + setterMethod)); | |
129 | + } | |
130 | + } | |
131 | + } | |
132 | + | |
133 | + // Para cada metodo verifica se ele está anotado com ManagedOperation e cria um MBeanOperationInfo para ele. | |
134 | + Method[] methodList = type.getMethods(); | |
135 | + if (methodList != null) { | |
136 | + for (Method method : methodList) { | |
137 | + ManagedOperation opAnnotation = method.getAnnotation(ManagedOperation.class); | |
138 | + | |
139 | + if (opAnnotation != null) { | |
140 | + // Lemos as informações sobre o método e criamos uma instância | |
141 | + // de MethodDetail para representar este método como uma | |
142 | + // operação. | |
143 | + | |
144 | + Class<?>[] parameterTypes = method.getParameterTypes(); | |
145 | + Annotation[][] parameterAnnotations = method.getParameterAnnotations(); | |
146 | + ParameterDetail[] parameterDetails = new ParameterDetail[parameterTypes.length]; | |
147 | + | |
148 | + for (int i = 0; i < parameterTypes.length; i++) { | |
149 | + OperationParameter paramAnnotation = null; | |
150 | + for (Annotation annotation : parameterAnnotations[i]) { | |
151 | + if (annotation.annotationType() == OperationParameter.class) { | |
152 | + paramAnnotation = (OperationParameter) annotation; | |
153 | + break; | |
154 | + } | |
155 | + } | |
156 | + | |
157 | + String name = paramAnnotation != null ? paramAnnotation.name() : ("arg" + i); | |
158 | + String description = paramAnnotation != null ? paramAnnotation.description() : null; | |
159 | + | |
160 | + parameterDetails[i] = new ParameterDetail(parameterTypes[i], name, description); | |
161 | + } | |
162 | + | |
163 | + // Com todas as informações, criamos nossa instância de MethodDetail e | |
164 | + // acrescentamos na lista de todas as operações. | |
165 | + MethodDetail detail = new MethodDetail(method, opAnnotation.description(), parameterDetails); | |
166 | + operationMethods.put(method.getName(), detail); | |
167 | + } | |
168 | + } | |
169 | + } | |
170 | + } | |
171 | + | |
172 | + /** | |
173 | + * Returns the public getter method for a given field, or <code>null</code> if no getter method can be found. | |
174 | + */ | |
175 | + private Method getGetterMethod(Field field) { | |
176 | + StringBuffer getterMethodName = new StringBuffer() | |
177 | + .append("get") | |
178 | + .append(field.getName().substring(0, 1).toUpperCase()) | |
179 | + .append(field.getName().substring(1)); | |
180 | + | |
181 | + Method getterMethod; | |
182 | + | |
183 | + try { | |
184 | + getterMethod = type.getMethod(getterMethodName.toString()); | |
185 | + } catch (Exception e) { | |
186 | + getterMethod = null; | |
187 | + } | |
188 | + | |
189 | + // Se atributo for boolean, procura método getter no formato "isAttribute". | |
190 | + if (getterMethod == null | |
191 | + && (Boolean.TYPE.isAssignableFrom(field.getType()) || Boolean.class.isAssignableFrom(field.getType()))) { | |
192 | + // Boolean.TYPE representa o tipo primitivo "boolean", Boolean.class é a classe wrapper. | |
193 | + getterMethodName = new StringBuffer() | |
194 | + .append("is") | |
195 | + .append(field.getName().substring(0, 1).toUpperCase()) | |
196 | + .append(field.getName().substring(1).toUpperCase()); | |
197 | + | |
198 | + try { | |
199 | + getterMethod = type.getMethod(getterMethodName.toString()); | |
200 | + } catch (Exception e) { | |
201 | + getterMethod = null; | |
202 | + } | |
203 | + } | |
204 | + | |
205 | + return getterMethod; | |
206 | + } | |
207 | + | |
208 | + /** | |
209 | + * Returns the public setter method for a given field, or <code>null</code> if no setter method can be found. | |
210 | + */ | |
211 | + private Method getSetterMethod(Field field) { | |
212 | + StringBuffer setterMethodName = new StringBuffer() | |
213 | + .append("set") | |
214 | + .append(field.getName().substring(0, 1).toUpperCase()) | |
215 | + .append(field.getName().substring(1)); | |
216 | + | |
217 | + Method setterMethod; | |
218 | + | |
219 | + try { | |
220 | + setterMethod = type.getMethod(setterMethodName.toString() , field.getType()); | |
221 | + } catch (Exception e) { | |
222 | + setterMethod = null; | |
223 | + } | |
224 | + | |
225 | + return setterMethod; | |
226 | + } | |
227 | + | |
228 | + public final class FieldDetail { | |
229 | + | |
230 | + private final Field field; | |
231 | + | |
232 | + private final String description; | |
233 | + | |
234 | + private Method getterMethod; | |
235 | + | |
236 | + private Method setterMethod; | |
237 | + | |
238 | + public FieldDetail(Field field, String description, Method getterMethod, Method setterMethod) { | |
239 | + super(); | |
240 | + this.field = field; | |
241 | + this.description = description; | |
242 | + this.getterMethod = getterMethod; | |
243 | + this.setterMethod = setterMethod; | |
244 | + } | |
245 | + | |
246 | + public Field getField() { | |
247 | + return field; | |
248 | + } | |
249 | + | |
250 | + public String getDescription() { | |
251 | + return description; | |
252 | + } | |
253 | + | |
254 | + public Method getGetterMethod() { | |
255 | + return getterMethod; | |
256 | + } | |
257 | + | |
258 | + public Method getSetterMethod() { | |
259 | + return setterMethod; | |
260 | + } | |
261 | + | |
262 | + } | |
263 | + | |
264 | + public final class MethodDetail { | |
265 | + | |
266 | + private final Method method; | |
267 | + | |
268 | + private final ParameterDetail[] parameterTypers; | |
269 | + | |
270 | + private String description; | |
271 | + | |
272 | + public MethodDetail(Method method, String description, ParameterDetail[] parameterTypers) { | |
273 | + super(); | |
274 | + this.method = method; | |
275 | + this.description = description; | |
276 | + this.parameterTypers = parameterTypers; | |
277 | + } | |
278 | + | |
279 | + public Method getMethod() { | |
280 | + return method; | |
281 | + } | |
282 | + | |
283 | + public ParameterDetail[] getParameterTypers() { | |
284 | + return parameterTypers; | |
285 | + } | |
286 | + | |
287 | + public String getDescription() { | |
288 | + return description; | |
289 | + } | |
290 | + | |
291 | + } | |
292 | + | |
293 | + public final class ParameterDetail { | |
294 | + | |
295 | + private final Class<?> parameterType; | |
296 | + | |
297 | + private final String parameterName; | |
298 | + | |
299 | + private final String parameterDescription; | |
300 | + | |
301 | + public ParameterDetail(Class<?> parameterType, String parameterName, String parameterDescription) { | |
302 | + super(); | |
303 | + this.parameterType = parameterType; | |
304 | + this.parameterName = parameterName; | |
305 | + this.parameterDescription = parameterDescription; | |
306 | + } | |
307 | + | |
308 | + public Class<?> getParameterType() { | |
309 | + return parameterType; | |
310 | + } | |
311 | + | |
312 | + public String getParameterName() { | |
313 | + return parameterName; | |
314 | + } | |
315 | + | |
316 | + public String getParameterDescription() { | |
317 | + return parameterDescription; | |
318 | + } | |
319 | + } | |
320 | + | |
321 | + /** | |
322 | + * Indicates another {@link ManagedType} represents the same {@link Class} as this one. This method also supports a | |
323 | + * {@link Class} as a parameter, in this case it will return <code>true</code> if the passed class is exactly the | |
324 | + * same Java class represented by this {@link ManagedType}. | |
325 | + */ | |
326 | + @Override | |
327 | + public boolean equals(Object other) { | |
328 | + if (other == null) { | |
329 | + return false; | |
330 | + } | |
331 | + | |
332 | + return ((ManagedType) other).getType().getCanonicalName().equals(this.getType().getCanonicalName()); | |
333 | + } | |
334 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/Management.java
0 → 100644
... | ... | @@ -0,0 +1,351 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package br.gov.frameworkdemoiselle.internal.management; | |
38 | + | |
39 | +import java.lang.reflect.Method; | |
40 | +import java.util.ArrayList; | |
41 | +import java.util.Collection; | |
42 | +import java.util.List; | |
43 | +import java.util.Set; | |
44 | + | |
45 | +import javax.enterprise.context.ApplicationScoped; | |
46 | +import javax.enterprise.context.RequestScoped; | |
47 | +import javax.inject.Inject; | |
48 | +import javax.management.ReflectionException; | |
49 | +import javax.validation.ConstraintViolation; | |
50 | +import javax.validation.Validation; | |
51 | +import javax.validation.ValidationException; | |
52 | +import javax.validation.Validator; | |
53 | + | |
54 | +import org.slf4j.Logger; | |
55 | + | |
56 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
57 | +import br.gov.frameworkdemoiselle.annotation.ManagedProperty; | |
58 | +import br.gov.frameworkdemoiselle.annotation.Name; | |
59 | +import br.gov.frameworkdemoiselle.internal.context.ContextManager; | |
60 | +import br.gov.frameworkdemoiselle.internal.context.ManagedContext; | |
61 | +import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail; | |
62 | +import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; | |
63 | +import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | |
64 | +import br.gov.frameworkdemoiselle.management.NotificationManager; | |
65 | +import br.gov.frameworkdemoiselle.stereotype.ManagementController; | |
66 | +import br.gov.frameworkdemoiselle.util.Beans; | |
67 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
68 | + | |
69 | +/** | |
70 | + * Central class used by management extensions to obtain information, access properties and call operations | |
71 | + * over discovered {@link ManagementController} classes. | |
72 | + * | |
73 | + * @author serpro | |
74 | + */ | |
75 | +@ApplicationScoped | |
76 | +public class Management { | |
77 | + | |
78 | + @Inject | |
79 | + private Logger logger; | |
80 | + | |
81 | + @Inject | |
82 | + @Name("demoiselle-core-bundle") | |
83 | + private ResourceBundle bundle; | |
84 | + | |
85 | + private final List<ManagedType> managedTypes = new ArrayList<ManagedType>(); | |
86 | + | |
87 | + private Validator validator; | |
88 | + | |
89 | + public void addManagedType(ManagedType managedType) { | |
90 | + managedTypes.add(managedType); | |
91 | + logger.debug(bundle.getString("management-debug-registering-managed-type",managedType.getType().getCanonicalName())); | |
92 | + } | |
93 | + | |
94 | + /** | |
95 | + * @return List all discovered {@link ManagementController} classes. | |
96 | + * The returned list is a shallow copy of the internal list, so you | |
97 | + * are free to modify it. | |
98 | + * | |
99 | + * TODO precisamos desse clone na lista? | |
100 | + */ | |
101 | + public List<ManagedType> getManagedTypes() { | |
102 | + ArrayList<ManagedType> cloneList = new ArrayList<ManagedType>(); | |
103 | + cloneList.addAll(managedTypes); | |
104 | + return cloneList; | |
105 | + } | |
106 | + | |
107 | + /** | |
108 | + * <p>Invoke an operation over a {@link ManagementController}.</p> | |
109 | + * | |
110 | + * <p>This method is not thread-safe, it's the user's responsibility to | |
111 | + * make the operations of the managed type synchronized if necessary.</p> | |
112 | + * | |
113 | + * @param managedType | |
114 | + * A type annotated with {@link ManagementController}. This method will create | |
115 | + * an (or obtain an already created) instance of this type and | |
116 | + * invoke the operation over it. | |
117 | + * @param actionName | |
118 | + * Name of method to be invoked, the type must have this | |
119 | + * operation on it's list | |
120 | + * @param params | |
121 | + * List of values for the operation parameters. Can be | |
122 | + * <code>null</code> if the operation require no parameters. | |
123 | + * @return The return value of the original invoked operation. Methods of | |
124 | + * return type <code>void</code> will return the {@link Void} type. | |
125 | + * @throws ReflectionException | |
126 | + * In case the operation doesn't exist or have a different | |
127 | + * signature | |
128 | + */ | |
129 | + public Object invoke(ManagedType managedType, String actionName, | |
130 | + Object[] params) { | |
131 | + if ( managedTypes.contains(managedType) ) { | |
132 | + activateContexts(managedType.getType()); | |
133 | + | |
134 | + Object delegate = Beans.getReference(managedType.getType()); | |
135 | + | |
136 | + MethodDetail method = managedType.getOperationMethods().get(actionName); | |
137 | + | |
138 | + if (method != null) { | |
139 | + try { | |
140 | + logger.debug(bundle | |
141 | + .getString("management-debug-invoking-operation",actionName,managedType.getType().getCanonicalName())); | |
142 | + return method.getMethod().invoke(delegate, params); | |
143 | + } catch (Exception e) { | |
144 | + throw new DemoiselleException(bundle.getString( | |
145 | + "management-invoke-error", actionName), e); | |
146 | + } finally { | |
147 | + deactivateContexts(managedType.getType()); | |
148 | + } | |
149 | + } else { | |
150 | + throw new DemoiselleException(bundle.getString( | |
151 | + "management-invoke-error", actionName)); | |
152 | + } | |
153 | + } else { | |
154 | + throw new DemoiselleException( | |
155 | + bundle.getString("management-type-not-found")); | |
156 | + } | |
157 | + } | |
158 | + | |
159 | + /** | |
160 | + * <p>Retrieve the current value of a property from a managed type. Properties | |
161 | + * are attributes annotated with {@link ManagedProperty}.</p> | |
162 | + * | |
163 | + * <p>This method is not thread-safe, it's the user's responsibility to | |
164 | + * create the property's access methods from the managed type synchronized if necessary.</p> | |
165 | + * | |
166 | + * @param managedType The type that has the property the client wants to know the value of. | |
167 | + * @param propertyName The name of the property | |
168 | + * @return The current value of the property | |
169 | + */ | |
170 | + public Object getProperty(ManagedType managedType, String propertyName) { | |
171 | + | |
172 | + if ( managedTypes.contains(managedType) ) { | |
173 | + Method getterMethod = managedType.getFields().get(propertyName).getGetterMethod(); | |
174 | + | |
175 | + if (getterMethod != null) { | |
176 | + logger.debug(bundle.getString( | |
177 | + "management-debug-acessing-property", getterMethod | |
178 | + .getName(), managedType.getType().getCanonicalName())); | |
179 | + | |
180 | + activateContexts(managedType.getType()); | |
181 | + | |
182 | + try { | |
183 | + Object delegate = Beans.getReference(managedType.getType()); | |
184 | + | |
185 | + return getterMethod.invoke(delegate, (Object[]) null); | |
186 | + } catch (Exception e) { | |
187 | + throw new DemoiselleException(bundle.getString( | |
188 | + "management-invoke-error", getterMethod.getName()), | |
189 | + e); | |
190 | + } finally { | |
191 | + deactivateContexts(managedType.getType()); | |
192 | + } | |
193 | + } else { | |
194 | + throw new DemoiselleException(bundle.getString( | |
195 | + "management-invoke-error", propertyName)); | |
196 | + } | |
197 | + } else { | |
198 | + throw new DemoiselleException( | |
199 | + bundle.getString("management-type-not-found")); | |
200 | + } | |
201 | + } | |
202 | + | |
203 | + /** | |
204 | + * <p>Sets a new value for a property contained inside a managed type. A property | |
205 | + * is an attribute annotated with {@link ManagedProperty}.</p> | |
206 | + * | |
207 | + * <p>This method is not thread-safe, it's the user's responsibility to | |
208 | + * create the property's access methods from the managed type synchronized if necessary.</p> | |
209 | + * | |
210 | + * @param managedType The type that has access to the property | |
211 | + * @param propertyName The name of the property | |
212 | + * @param newValue The new value of the property | |
213 | + */ | |
214 | + public void setProperty(ManagedType managedType, String propertyName, | |
215 | + Object newValue) { | |
216 | + | |
217 | + if ( managedTypes.contains(managedType) ) { | |
218 | + // Procura o método set do atributo em questão | |
219 | + Method method = managedType.getFields().get(propertyName).getSetterMethod(); | |
220 | + if (method != null) { | |
221 | + logger.debug(bundle.getString( | |
222 | + "management-debug-setting-property", method.getName(), | |
223 | + managedType.getType().getCanonicalName())); | |
224 | + | |
225 | + activateContexts(managedType.getType()); | |
226 | + try { | |
227 | + // Obtém uma instância da classe gerenciada, lembrando que | |
228 | + // classes | |
229 | + // anotadas com @ManagementController são sempre singletons. | |
230 | + Object delegate = Beans.getReference(managedType.getType()); | |
231 | + | |
232 | + //Se houver um validador anexado à propriedade alterada, executa o validador sobre | |
233 | + //o novo valor. | |
234 | + Validator validator = getDefaultValidator(); | |
235 | + if (validator!=null){ | |
236 | + Set<?> violations = validator.validateValue(managedType.getType(), propertyName, newValue); | |
237 | + if (violations.size()>0){ | |
238 | + StringBuffer errorBuffer = new StringBuffer(); | |
239 | + for (Object objectViolation : violations){ | |
240 | + ConstraintViolation<?> violation = (ConstraintViolation<?>) objectViolation; | |
241 | + errorBuffer.append(violation.getMessage()).append('\r').append('\n'); | |
242 | + } | |
243 | + | |
244 | + throw new DemoiselleException(bundle.getString("validation-constraint-violation",managedType.getType().getCanonicalName(),errorBuffer.toString())); | |
245 | + } | |
246 | + } | |
247 | + else{ | |
248 | + logger.warn(bundle.getString("validation-validator-not-found")); | |
249 | + } | |
250 | + | |
251 | + Method getterMethod = managedType.getFields().get(propertyName).getGetterMethod(); | |
252 | + Object oldValue; | |
253 | + try{ | |
254 | + oldValue = getterMethod.invoke(delegate, (Object[])null); | |
255 | + } | |
256 | + catch(Exception e){ | |
257 | + oldValue = null; | |
258 | + } | |
259 | + | |
260 | + method.invoke(delegate, new Object[] { newValue }); | |
261 | + | |
262 | + //Manda uma notificação de mudança de atributo | |
263 | + NotificationManager notificationManager = Beans.getReference(NotificationManager.class); | |
264 | + Class<? extends Object> attributeType = newValue!=null ? newValue.getClass() : null; | |
265 | + | |
266 | + AttributeChangeNotification notification = new AttributeChangeNotification(bundle.getString("management-notification-attribute-changed",propertyName,managedType.getType().getCanonicalName()) | |
267 | + , propertyName | |
268 | + , attributeType | |
269 | + , oldValue | |
270 | + , newValue); | |
271 | + notificationManager.sendNotification(notification); | |
272 | + | |
273 | + } catch (DemoiselleException de){ | |
274 | + throw de; | |
275 | + } catch (Exception e) { | |
276 | + throw new DemoiselleException(bundle.getString( | |
277 | + "management-invoke-error", method.getName()), e); | |
278 | + } finally { | |
279 | + deactivateContexts(managedType.getType()); | |
280 | + } | |
281 | + | |
282 | + } else { | |
283 | + throw new DemoiselleException(bundle.getString( | |
284 | + "management-invoke-error", propertyName)); | |
285 | + } | |
286 | + } else { | |
287 | + throw new DemoiselleException( | |
288 | + bundle.getString("management-type-not-found")); | |
289 | + } | |
290 | + | |
291 | + } | |
292 | + | |
293 | + private void activateContexts(Class<?> managedType) { | |
294 | + logger.debug(bundle.getString("management-debug-starting-custom-context", | |
295 | + ManagedContext.class.getCanonicalName(), | |
296 | + managedType.getCanonicalName())); | |
297 | + | |
298 | + ContextManager.activate(ManagedContext.class,RequestScoped.class); | |
299 | + } | |
300 | + | |
301 | + private void deactivateContexts(Class<?> managedType) { | |
302 | + logger.debug(bundle.getString("management-debug-stoping-custom-context", | |
303 | + ManagedContext.class.getCanonicalName(), | |
304 | + managedType.getCanonicalName())); | |
305 | + | |
306 | + ContextManager.deactivate(ManagedContext.class,RequestScoped.class); | |
307 | + } | |
308 | + | |
309 | + public void shutdown(Collection<Class<? extends ManagementExtension>> monitoringExtensions) { | |
310 | + | |
311 | + for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) { | |
312 | + | |
313 | + ManagementExtension monitoringExtension = Beans.getReference(monitoringExtensionClass); | |
314 | + | |
315 | + monitoringExtension.shutdown(this.getManagedTypes()); | |
316 | + | |
317 | + logger.debug( bundle.getString("management-debug-removing-management-extension",monitoringExtension.getClass().getCanonicalName()) ); | |
318 | + | |
319 | + } | |
320 | + | |
321 | + } | |
322 | + | |
323 | + public void initialize(Collection<Class<? extends ManagementExtension>> monitoringExtensions) { | |
324 | + | |
325 | + for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) { | |
326 | + | |
327 | + ManagementExtension monitoringExtension = Beans | |
328 | + .getReference(monitoringExtensionClass); | |
329 | + | |
330 | + monitoringExtension.initialize(this.getManagedTypes()); | |
331 | + | |
332 | + logger.debug( bundle.getString("management-debug-processing-management-extension",monitoringExtension.getClass().getCanonicalName()) ); | |
333 | + | |
334 | + } | |
335 | + | |
336 | + } | |
337 | + | |
338 | + private Validator getDefaultValidator(){ | |
339 | + if (validator == null){ | |
340 | + try{ | |
341 | + this.validator = Validation.buildDefaultValidatorFactory().getValidator(); | |
342 | + } | |
343 | + catch(ValidationException e){ | |
344 | + this.validator = null; | |
345 | + } | |
346 | + } | |
347 | + | |
348 | + return this.validator; | |
349 | + } | |
350 | + | |
351 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/ManagementNotificationEvent.java
0 → 100644
... | ... | @@ -0,0 +1,65 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package br.gov.frameworkdemoiselle.internal.management; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.management.Notification; | |
40 | +import br.gov.frameworkdemoiselle.management.NotificationManager; | |
41 | + | |
42 | +/** | |
43 | + * Event fired when a notification is sent by {@link NotificationManager}. | |
44 | + * Implementators can capture this event and be notified when the {@link NotificationManager} | |
45 | + * sends notifications, so they can pass the notification to the underlying technology. | |
46 | + * | |
47 | + * @author serpro | |
48 | + * | |
49 | + */ | |
50 | +public class ManagementNotificationEvent { | |
51 | + | |
52 | + private Notification notification; | |
53 | + | |
54 | + public ManagementNotificationEvent(Notification notification){ | |
55 | + this.notification = notification; | |
56 | + } | |
57 | + | |
58 | + public Notification getNotification() { | |
59 | + return notification; | |
60 | + } | |
61 | + | |
62 | + public void setNotification(Notification notification) { | |
63 | + this.notification = notification; | |
64 | + } | |
65 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/qualifier/AttributeChange.java
0 → 100644
... | ... | @@ -0,0 +1,62 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package br.gov.frameworkdemoiselle.internal.management.qualifier; | |
38 | + | |
39 | +import java.lang.annotation.ElementType; | |
40 | +import java.lang.annotation.Retention; | |
41 | +import java.lang.annotation.RetentionPolicy; | |
42 | +import java.lang.annotation.Target; | |
43 | + | |
44 | +import javax.inject.Qualifier; | |
45 | + | |
46 | +import br.gov.frameworkdemoiselle.internal.management.ManagementNotificationEvent; | |
47 | +import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | |
48 | + | |
49 | +/** | |
50 | + * | |
51 | + * Enables {@link ManagementNotificationEvent} observers to trigger only with notifications | |
52 | + * of the specialized type {@link AttributeChangeNotification}. | |
53 | + * | |
54 | + * @author serpro | |
55 | + * | |
56 | + */ | |
57 | +@Qualifier | |
58 | +@Retention(RetentionPolicy.RUNTIME) | |
59 | +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE}) | |
60 | +public @interface AttributeChange { | |
61 | + | |
62 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/qualifier/Generic.java
0 → 100644
... | ... | @@ -0,0 +1,62 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package br.gov.frameworkdemoiselle.internal.management.qualifier; | |
38 | + | |
39 | +import java.lang.annotation.ElementType; | |
40 | +import java.lang.annotation.Retention; | |
41 | +import java.lang.annotation.RetentionPolicy; | |
42 | +import java.lang.annotation.Target; | |
43 | + | |
44 | +import javax.inject.Qualifier; | |
45 | + | |
46 | +import br.gov.frameworkdemoiselle.internal.management.ManagementNotificationEvent; | |
47 | +import br.gov.frameworkdemoiselle.management.Notification; | |
48 | + | |
49 | +/** | |
50 | + * | |
51 | + * Enables {@link ManagementNotificationEvent} observers to trigger only with notifications | |
52 | + * of the base type {@link Notification}. | |
53 | + * | |
54 | + * @author serpro | |
55 | + * | |
56 | + */ | |
57 | +@Qualifier | |
58 | +@Retention(RetentionPolicy.RUNTIME) | |
59 | +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE}) | |
60 | +public @interface Generic { | |
61 | + | |
62 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/lifecycle/ManagementExtension.java
0 → 100644
... | ... | @@ -0,0 +1,76 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package br.gov.frameworkdemoiselle.lifecycle; | |
38 | + | |
39 | +import java.util.List; | |
40 | + | |
41 | +import br.gov.frameworkdemoiselle.internal.management.ManagedType; | |
42 | +import br.gov.frameworkdemoiselle.stereotype.ManagementController; | |
43 | + | |
44 | +/** | |
45 | + * | |
46 | + * <p>Interface defining the lifecycle of a <b>management extension</b>, an extension | |
47 | + * capable of exposing {@link ManagementController}'s to external clients in one | |
48 | + * of the available management technologies, such as JMX or SNMP.</p> | |
49 | + * | |
50 | + * <p>To include a management extension into the management lifecycle, it just needs | |
51 | + * to implement this interface and be a CDI bean (have a <b>beans.xml</b> file inside | |
52 | + * the META-INF folder of it's java package). The Demoiselle Core lifecycle controller | |
53 | + * will call the {@link #initialize(List managedTypes)} and {@link #shutdown(List managedTypes)} methods at the apropriate times.</p> | |
54 | + * | |
55 | + * @author serpro | |
56 | + * | |
57 | + */ | |
58 | +public interface ManagementExtension { | |
59 | + | |
60 | + /** | |
61 | + * This method is called during the application initialization process for each concrete | |
62 | + * implementation of this interface. | |
63 | + * | |
64 | + * @param managedTypes The list of discovered {@link ManagementController} classes. | |
65 | + */ | |
66 | + void initialize(List<ManagedType> managedTypes); | |
67 | + | |
68 | + /** | |
69 | + * This method is called during the application shutdown process for each concrete | |
70 | + * implementation of this interface. | |
71 | + * | |
72 | + * @param managedTypes The list of discovered {@link ManagementController} classes. | |
73 | + */ | |
74 | + void shutdown(List<ManagedType> managedTypes); | |
75 | + | |
76 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/AttributeChangeNotification.java
0 → 100644
... | ... | @@ -0,0 +1,110 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package br.gov.frameworkdemoiselle.management; | |
38 | + | |
39 | +/** | |
40 | + * Special notification to denote an attribute has changed values. | |
41 | + * | |
42 | + * @see Notification | |
43 | + * | |
44 | + * @author serpro | |
45 | + * | |
46 | + */ | |
47 | +public class AttributeChangeNotification extends Notification { | |
48 | + | |
49 | + private String attributeName; | |
50 | + | |
51 | + private Class<? extends Object> attributeType; | |
52 | + | |
53 | + private Object oldValue; | |
54 | + | |
55 | + private Object newValue; | |
56 | + | |
57 | + public AttributeChangeNotification(){} | |
58 | + | |
59 | + public AttributeChangeNotification(Object message, String attributeName, Class<? extends Object> attributeType, Object oldValue, | |
60 | + Object newValue) { | |
61 | + super(message); | |
62 | + this.attributeName = attributeName; | |
63 | + this.attributeType = attributeType; | |
64 | + this.oldValue = oldValue; | |
65 | + this.newValue = newValue; | |
66 | + } | |
67 | + | |
68 | + | |
69 | + public String getAttributeName() { | |
70 | + return attributeName; | |
71 | + } | |
72 | + | |
73 | + | |
74 | + public void setAttributeName(String attributeName) { | |
75 | + this.attributeName = attributeName; | |
76 | + } | |
77 | + | |
78 | + | |
79 | + public Class<? extends Object> getAttributeType() { | |
80 | + return attributeType; | |
81 | + } | |
82 | + | |
83 | + | |
84 | + public void setAttributeType(Class<? extends Object> attributeType) { | |
85 | + this.attributeType = attributeType; | |
86 | + } | |
87 | + | |
88 | + | |
89 | + public Object getOldValue() { | |
90 | + return oldValue; | |
91 | + } | |
92 | + | |
93 | + | |
94 | + public void setOldValue(Object oldValue) { | |
95 | + this.oldValue = oldValue; | |
96 | + } | |
97 | + | |
98 | + | |
99 | + public Object getNewValue() { | |
100 | + return newValue; | |
101 | + } | |
102 | + | |
103 | + | |
104 | + public void setNewValue(Object newValue) { | |
105 | + this.newValue = newValue; | |
106 | + } | |
107 | + | |
108 | + | |
109 | + | |
110 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/Notification.java
0 → 100644
... | ... | @@ -0,0 +1,77 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package br.gov.frameworkdemoiselle.management; | |
38 | + | |
39 | +/** | |
40 | + * | |
41 | + * Notification that can be sent by the {@link NotificationManager}. | |
42 | + * | |
43 | + * @author serpro | |
44 | + * | |
45 | + */ | |
46 | +public class Notification { | |
47 | + | |
48 | + private Object message; | |
49 | + | |
50 | + public Notification(){ | |
51 | + } | |
52 | + | |
53 | + public Notification(Object message) { | |
54 | + super(); | |
55 | + this.message = message; | |
56 | + } | |
57 | + | |
58 | + | |
59 | + public Object getMessage() { | |
60 | + return message; | |
61 | + } | |
62 | + | |
63 | + | |
64 | + public void setMessage(Object message) { | |
65 | + this.message = message; | |
66 | + } | |
67 | + | |
68 | + | |
69 | + public Class<? extends Object> getType() { | |
70 | + if (message!=null){ | |
71 | + return message.getClass(); | |
72 | + } | |
73 | + | |
74 | + return null; | |
75 | + } | |
76 | + | |
77 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/NotificationManager.java
0 → 100644
... | ... | @@ -0,0 +1,116 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package br.gov.frameworkdemoiselle.management; | |
38 | + | |
39 | +import java.io.Serializable; | |
40 | + | |
41 | +import javax.enterprise.context.ApplicationScoped; | |
42 | +import javax.enterprise.event.Event; | |
43 | +import javax.enterprise.event.Observes; | |
44 | +import javax.enterprise.util.AnnotationLiteral; | |
45 | +import javax.inject.Inject; | |
46 | + | |
47 | +import br.gov.frameworkdemoiselle.internal.management.ManagementNotificationEvent; | |
48 | +import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange; | |
49 | +import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic; | |
50 | +import br.gov.frameworkdemoiselle.util.Beans; | |
51 | + | |
52 | +/** | |
53 | + * | |
54 | + * <p>Central class to manage sending notifications to management clients. | |
55 | + * This class allows applications to send management notifications without | |
56 | + * knowledge of the technology used to send those notifications.</p> | |
57 | + * | |
58 | + * <p>To obtain an instance of the {@link NotificationManager} simply inject it in | |
59 | + * your code using {@link Inject} or the {@link Beans#getReference(Class beanType)} method. The {@link NotificationManager} | |
60 | + * is {@link ApplicationScoped}, so you can inject it as many times as needed and still have only one instance per application.</p> | |
61 | + * | |
62 | + * <p>Implementators of management protocols must observe the {@link ManagementNotificationEvent} event (using the {@link Observes} annotation), this way | |
63 | + * they will receive an event containing the original notification and can translate this notification to a specific protocol. Optionaly, | |
64 | + * the implementator can use qualifiers like the {@link Generic} and {@link AttributeChange} qualifiers | |
65 | + * to filter what king of notifications they will handle. One example of an implementator is the <b>demoiselle-jmx</b> extension.</p> | |
66 | + * | |
67 | + * @author serpro | |
68 | + * | |
69 | + */ | |
70 | +@ApplicationScoped | |
71 | +@SuppressWarnings("serial") | |
72 | +public class NotificationManager implements Serializable{ | |
73 | + | |
74 | + @Inject | |
75 | + @Generic | |
76 | + private Event<ManagementNotificationEvent> genericNotificationEvent; | |
77 | + | |
78 | + @Inject | |
79 | + @AttributeChange | |
80 | + private Event<ManagementNotificationEvent> attributeChangeNotificationEvent; | |
81 | + | |
82 | + /** | |
83 | + * Sends a generic notification to all management clients. | |
84 | + * | |
85 | + * @param notification The notification to send | |
86 | + */ | |
87 | + public void sendNotification(Notification notification) { | |
88 | + if (! AttributeChangeNotification.class.isInstance(notification) ){ | |
89 | + getGenericNotificationEvent().fire(new ManagementNotificationEvent(notification)); | |
90 | + } | |
91 | + else{ | |
92 | + getAttributeChangeNotificationEvent().fire(new ManagementNotificationEvent(notification)); | |
93 | + } | |
94 | + } | |
95 | + | |
96 | + @SuppressWarnings("unchecked") | |
97 | + private Event<ManagementNotificationEvent> getGenericNotificationEvent() { | |
98 | + if (genericNotificationEvent==null){ | |
99 | + genericNotificationEvent = Beans.getReference(Event.class , new AnnotationLiteral<Generic>() {}); | |
100 | + } | |
101 | + | |
102 | + return genericNotificationEvent; | |
103 | + } | |
104 | + | |
105 | + @SuppressWarnings("unchecked") | |
106 | + private Event<ManagementNotificationEvent> getAttributeChangeNotificationEvent() { | |
107 | + if (attributeChangeNotificationEvent==null){ | |
108 | + attributeChangeNotificationEvent = Beans.getReference(Event.class , new AnnotationLiteral<AttributeChange>() {}); | |
109 | + } | |
110 | + | |
111 | + return attributeChangeNotificationEvent; | |
112 | + } | |
113 | + | |
114 | + | |
115 | + | |
116 | +} | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/annotation/Managed.java
... | ... | @@ -1,80 +0,0 @@ |
1 | -/* | |
2 | - * Demoiselle Framework | |
3 | - * Copyright (C) 2011 SERPRO | |
4 | - * ---------------------------------------------------------------------------- | |
5 | - * This file is part of Demoiselle Framework. | |
6 | - * | |
7 | - * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | - * as published by the Free Software Foundation. | |
10 | - * | |
11 | - * This program is distributed in the hope that it will be useful, | |
12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | - * GNU General Public License for more details. | |
15 | - * | |
16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | - * ---------------------------------------------------------------------------- | |
21 | - * Este arquivo é parte do Framework Demoiselle. | |
22 | - * | |
23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | - * do Software Livre (FSF). | |
26 | - * | |
27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | - * para maiores detalhes. | |
31 | - * | |
32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | - */ | |
37 | -package br.gov.frameworkdemoiselle.management.annotation; | |
38 | - | |
39 | -import static java.lang.annotation.ElementType.TYPE; | |
40 | -import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
41 | - | |
42 | -import java.lang.annotation.Documented; | |
43 | -import java.lang.annotation.Inherited; | |
44 | -import java.lang.annotation.Retention; | |
45 | -import java.lang.annotation.Target; | |
46 | - | |
47 | -import javax.enterprise.context.ApplicationScoped; | |
48 | -import javax.enterprise.inject.Stereotype; | |
49 | -import javax.enterprise.util.Nonbinding; | |
50 | -import javax.interceptor.InterceptorBinding; | |
51 | - | |
52 | -/** | |
53 | - * Stereotype to indicate a given class is managed. What it means is that an external client can manage the application | |
54 | - * this class is in by reading or writing it's attributes and calling it's operations. | |
55 | - * <p> | |
56 | - * Only fields annotated with {@link br.gov.frameworkdemoiselle.management.annotation.Property} or | |
57 | - * methods annotated with {@link br.gov.frameworkdemoiselle.management.annotation.Operation} will be exposed | |
58 | - * to clients.</p> | |
59 | - * <p>This stereotype only defines a class as managed, you need to choose an extension that will expose this managed class | |
60 | - * to external clients using any technology available. One example is the Demoiselle JMX extension, that will expose | |
61 | - * managed classes as MBeans.</p> | |
62 | - * | |
63 | - * @author SERPRO | |
64 | - */ | |
65 | -@Documented | |
66 | -@Stereotype | |
67 | -@InterceptorBinding | |
68 | -@Inherited | |
69 | -@Retention(RUNTIME) | |
70 | -@Target({ TYPE }) | |
71 | -@ApplicationScoped | |
72 | -public @interface Managed { | |
73 | - | |
74 | - /** | |
75 | - * @return Human readable description of this managed class. | |
76 | - */ | |
77 | - @Nonbinding | |
78 | - String description() default ""; | |
79 | - | |
80 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/annotation/Operation.java
... | ... | @@ -1,37 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.annotation; | |
2 | - | |
3 | -import java.lang.annotation.Documented; | |
4 | -import java.lang.annotation.ElementType; | |
5 | -import java.lang.annotation.Retention; | |
6 | -import java.lang.annotation.RetentionPolicy; | |
7 | -import java.lang.annotation.Target; | |
8 | - | |
9 | -import javax.enterprise.util.Nonbinding; | |
10 | -import javax.management.MBeanException; | |
11 | - | |
12 | -/** | |
13 | - * <p>Indicates that a method is an operation, meaning you can manage some aspect of the application by calling it.</p> | |
14 | - * <p>This annotation can't be used together with {@link Property}, doing so will throw a {@link MBeanException}.</p> | |
15 | - * | |
16 | - * @author SERPRO | |
17 | - * | |
18 | - */ | |
19 | -@Documented | |
20 | -@Target({ElementType.METHOD}) | |
21 | -@Retention(RetentionPolicy.RUNTIME) | |
22 | -public @interface Operation { | |
23 | - | |
24 | - /** | |
25 | - * Description that will be used to publish the operation to clients. | |
26 | - * Defaults to an empty description. | |
27 | - */ | |
28 | - @Nonbinding | |
29 | - String description() default ""; | |
30 | - | |
31 | - /** | |
32 | - * Type of operation. Defaults to {@link OperationType#UNKNOWN}. | |
33 | - */ | |
34 | - @Nonbinding | |
35 | - OperationType type() default OperationType.UNKNOWN; | |
36 | - | |
37 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/annotation/OperationParameter.java
... | ... | @@ -1,37 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.annotation; | |
2 | - | |
3 | -import java.lang.annotation.Documented; | |
4 | -import java.lang.annotation.ElementType; | |
5 | -import java.lang.annotation.Retention; | |
6 | -import java.lang.annotation.RetentionPolicy; | |
7 | -import java.lang.annotation.Target; | |
8 | - | |
9 | -import javax.enterprise.util.Nonbinding; | |
10 | - | |
11 | -/** | |
12 | - * <p>Optional annotation to write additional detail about an operation's parameter.</p> | |
13 | - * <p>This annotation is ignored for non-operation methods.</p> | |
14 | - * | |
15 | - * @author SERPRO | |
16 | - * | |
17 | - */ | |
18 | -@Documented | |
19 | -@Target({ElementType.PARAMETER}) | |
20 | -@Retention(RetentionPolicy.RUNTIME) | |
21 | -public @interface OperationParameter { | |
22 | - | |
23 | - /** | |
24 | - * Name that will be used to publish this operation's parameter to clients. | |
25 | - */ | |
26 | - @Nonbinding | |
27 | - String name(); | |
28 | - | |
29 | - /** | |
30 | - * Optional description that will be used to publish this operation's parameter to clients. | |
31 | - * Defaults to an empty description. | |
32 | - */ | |
33 | - @Nonbinding | |
34 | - String description() default ""; | |
35 | - | |
36 | - | |
37 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/annotation/OperationType.java
... | ... | @@ -1,45 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.annotation; | |
2 | - | |
3 | -import javax.management.MBeanOperationInfo; | |
4 | - | |
5 | - | |
6 | -/** | |
7 | - * Define the operation type for an operation inside a Managed class. | |
8 | - * | |
9 | - * | |
10 | - * @author SERPRO | |
11 | - * | |
12 | - */ | |
13 | -public enum OperationType { | |
14 | - | |
15 | - /** | |
16 | - * Operation is write-only | |
17 | - */ | |
18 | - ACTION(MBeanOperationInfo.ACTION) | |
19 | - , | |
20 | - /** | |
21 | - * Operation is read-only | |
22 | - */ | |
23 | - INFO(MBeanOperationInfo.INFO) | |
24 | - , | |
25 | - /** | |
26 | - * Operation is read-write | |
27 | - */ | |
28 | - ACTION_INFO(MBeanOperationInfo.ACTION_INFO) | |
29 | - , | |
30 | - /** | |
31 | - * Operation is unkown | |
32 | - */ | |
33 | - UNKNOWN(MBeanOperationInfo.UNKNOWN); | |
34 | - | |
35 | - private int operationTypeValue; | |
36 | - | |
37 | - private OperationType(int type){ | |
38 | - this.operationTypeValue = type; | |
39 | - } | |
40 | - | |
41 | - public int getValue(){ | |
42 | - return operationTypeValue; | |
43 | - } | |
44 | - | |
45 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/annotation/Property.java
... | ... | @@ -1,33 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.annotation; | |
2 | - | |
3 | -import java.lang.annotation.Documented; | |
4 | -import java.lang.annotation.ElementType; | |
5 | -import java.lang.annotation.Retention; | |
6 | -import java.lang.annotation.RetentionPolicy; | |
7 | -import java.lang.annotation.Target; | |
8 | - | |
9 | -import javax.enterprise.util.Nonbinding; | |
10 | - | |
11 | -/** | |
12 | - * <p>Indicates that a field must be exposed as a property to management clients.</p> | |
13 | - * <p>The property will be writable if there's a public setter method | |
14 | - * declared for the field and readable if there's a getter method.</p> | |
15 | - * <p>It's a runtime error to annotate a field with no getter and no setter method.</p> | |
16 | - * <p>It's also a runtime error to declare a field as a property and one or both of it's getter and setter | |
17 | - * methods as an operation using the {@link Operation} annotation.</p> | |
18 | - * | |
19 | - * @author SERPRO | |
20 | - * | |
21 | - */ | |
22 | -@Documented | |
23 | -@Target({ElementType.FIELD}) | |
24 | -@Retention(RetentionPolicy.RUNTIME) | |
25 | -public @interface Property { | |
26 | - | |
27 | - /** | |
28 | - * @return The description of this property exposed to management clients. | |
29 | - */ | |
30 | - @Nonbinding | |
31 | - String description() default ""; | |
32 | - | |
33 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/annotation/validation/AllowedValues.java
... | ... | @@ -1,40 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.annotation.validation; | |
2 | - | |
3 | -import static java.lang.annotation.ElementType.FIELD; | |
4 | -import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
5 | - | |
6 | -import java.lang.annotation.Documented; | |
7 | -import java.lang.annotation.Retention; | |
8 | -import java.lang.annotation.Target; | |
9 | - | |
10 | -import javax.validation.Constraint; | |
11 | - | |
12 | -import br.gov.frameworkdemoiselle.management.internal.validators.AllowedValuesValidator; | |
13 | - | |
14 | -@Documented | |
15 | -@Target({ FIELD}) | |
16 | -@Retention(RUNTIME) | |
17 | -@Constraint(validatedBy = AllowedValuesValidator.class) | |
18 | -/** | |
19 | - * Validate a value against a list of allowed values. | |
20 | - * | |
21 | - * @author serpro | |
22 | - * | |
23 | - */ | |
24 | -public @interface AllowedValues { | |
25 | - | |
26 | - /** | |
27 | - * List of accepted values | |
28 | - */ | |
29 | - String[] allows(); | |
30 | - | |
31 | - /** | |
32 | - * Type of allowed values. Defaults to {@link ValueType#STRING}. | |
33 | - */ | |
34 | - ValueType valueType() default ValueType.STRING; | |
35 | - | |
36 | - enum ValueType { | |
37 | - STRING,INTEGER,DECIMAL; | |
38 | - } | |
39 | - | |
40 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/extension/ManagementExtension.java
... | ... | @@ -1,20 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.extension; | |
2 | - | |
3 | -import java.util.List; | |
4 | - | |
5 | -import br.gov.frameworkdemoiselle.management.internal.ManagedType; | |
6 | - | |
7 | -/** | |
8 | - * | |
9 | - * Define an entry point for monitoring extension. | |
10 | - * | |
11 | - * @author serpro | |
12 | - * | |
13 | - */ | |
14 | -public interface ManagementExtension { | |
15 | - | |
16 | - void initialize(List<ManagedType> managedTypes); | |
17 | - | |
18 | - void shutdown(List<ManagedType> managedTypes); | |
19 | - | |
20 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/internal/ManagedType.java
... | ... | @@ -1,295 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.internal; | |
2 | - | |
3 | -import java.lang.annotation.Annotation; | |
4 | -import java.lang.reflect.Field; | |
5 | -import java.lang.reflect.Method; | |
6 | -import java.util.TreeMap; | |
7 | - | |
8 | -import br.gov.frameworkdemoiselle.DemoiselleException; | |
9 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
10 | -import br.gov.frameworkdemoiselle.management.annotation.Managed; | |
11 | -import br.gov.frameworkdemoiselle.management.annotation.Operation; | |
12 | -import br.gov.frameworkdemoiselle.management.annotation.OperationParameter; | |
13 | -import br.gov.frameworkdemoiselle.management.annotation.Property; | |
14 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
15 | - | |
16 | -/** | |
17 | - * Represents a detected managed type, a Java class annotated with {@link Managed}. | |
18 | - * | |
19 | - * @author serpro | |
20 | - */ | |
21 | -public class ManagedType { | |
22 | - | |
23 | - private Class<?> type; | |
24 | - | |
25 | - private TreeMap<String, FieldDetail> fields; | |
26 | - | |
27 | - private TreeMap<String, MethodDetail> operationMethods; | |
28 | - | |
29 | - private ResourceBundle bundle; | |
30 | - | |
31 | - private String description; | |
32 | - | |
33 | - public ManagedType(Class<?> type) { | |
34 | - bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | |
35 | - | |
36 | - if (type == null) { | |
37 | - throw new DemoiselleException(bundle.getString("management-null-class-defined")); | |
38 | - } | |
39 | - if (!type.isAnnotationPresent(Managed.class)) { | |
40 | - throw new DemoiselleException(bundle.getString("management-no-annotation-found", type.getCanonicalName())); | |
41 | - } | |
42 | - | |
43 | - this.type = type; | |
44 | - fields = new TreeMap<String, FieldDetail>(); | |
45 | - operationMethods = new TreeMap<String, MethodDetail>(); | |
46 | - this.description = type.getAnnotation(Managed.class).description(); | |
47 | - | |
48 | - initialize(); | |
49 | - } | |
50 | - | |
51 | - public Class<?> getType() { | |
52 | - return type; | |
53 | - } | |
54 | - | |
55 | - public String getDescription() { | |
56 | - return description; | |
57 | - } | |
58 | - | |
59 | - public TreeMap<String, FieldDetail> getFields() { | |
60 | - return fields; | |
61 | - } | |
62 | - | |
63 | - public TreeMap<String, MethodDetail> getOperationMethods() { | |
64 | - return operationMethods; | |
65 | - } | |
66 | - | |
67 | - private void initialize() { | |
68 | - // Para cada atributo verifica se ele está anotado com Property e extrai as informações dele (método get, set e | |
69 | - // descrição do atributo). | |
70 | - Field[] fields = type.getDeclaredFields(); | |
71 | - if (fields != null) { | |
72 | - for (Field field : fields) { | |
73 | - if (field.isAnnotationPresent(Property.class)) { | |
74 | - // Obtém os métodos GET e SET para esta propriedade | |
75 | - Method getterMethod = getGetterMethod(field); | |
76 | - Method setterMethod = getSetterMethod(field); | |
77 | - if (getterMethod == null && setterMethod == null) { | |
78 | - throw new DemoiselleException(bundle.getString("management-invalid-property-no-getter-setter", | |
79 | - type.getSimpleName(), field.getName())); | |
80 | - } else if ((getterMethod != null && getterMethod.isAnnotationPresent(Operation.class)) | |
81 | - || (setterMethod != null && setterMethod.isAnnotationPresent(Operation.class))) { | |
82 | - throw new DemoiselleException(bundle.getString("management-invalid-property-as-operation", | |
83 | - type.getSimpleName())); | |
84 | - } | |
85 | - | |
86 | - String propertyDescription = field.getAnnotation(Property.class).description(); | |
87 | - | |
88 | - this.fields.put(field.getName(), new FieldDetail(field, propertyDescription, getterMethod, | |
89 | - setterMethod)); | |
90 | - } | |
91 | - } | |
92 | - } | |
93 | - | |
94 | - // Para cada metodo verifica se ele está anotado com Operation e cria um MBeanOperationInfo para ele. | |
95 | - Method[] methodList = type.getMethods(); | |
96 | - if (methodList != null) { | |
97 | - for (Method method : methodList) { | |
98 | - Operation opAnnotation = method.getAnnotation(Operation.class); | |
99 | - | |
100 | - if (opAnnotation != null) { | |
101 | - // Lemos as informações sobre o método e criamos uma instância | |
102 | - // de MethodDetail para representar este método como uma | |
103 | - // operação. | |
104 | - | |
105 | - Class<?>[] parameterTypes = method.getParameterTypes(); | |
106 | - Annotation[][] parameterAnnotations = method.getParameterAnnotations(); | |
107 | - ParameterDetail[] parameterDetails = new ParameterDetail[parameterTypes.length]; | |
108 | - | |
109 | - for (int i = 0; i < parameterTypes.length; i++) { | |
110 | - OperationParameter paramAnnotation = null; | |
111 | - for (Annotation annotation : parameterAnnotations[i]) { | |
112 | - if (annotation.annotationType() == OperationParameter.class) { | |
113 | - paramAnnotation = (OperationParameter) annotation; | |
114 | - break; | |
115 | - } | |
116 | - } | |
117 | - | |
118 | - String name = paramAnnotation != null ? paramAnnotation.name() : ("arg" + i); | |
119 | - String description = paramAnnotation != null ? paramAnnotation.description() : null; | |
120 | - | |
121 | - parameterDetails[i] = new ParameterDetail(parameterTypes[i], name, description); | |
122 | - } | |
123 | - | |
124 | - // Com todas as informações, criamos nossa instância de MethodDetail e | |
125 | - // acrescentamos na lista de todas as operações. | |
126 | - MethodDetail detail = new MethodDetail(method, opAnnotation.description(), parameterDetails); | |
127 | - operationMethods.put(method.getName(), detail); | |
128 | - } | |
129 | - } | |
130 | - } | |
131 | - } | |
132 | - | |
133 | - /** | |
134 | - * Returns the public getter method for a given field, or <code>null</code> if no getter method can be found. | |
135 | - */ | |
136 | - private Method getGetterMethod(Field field) { | |
137 | - StringBuffer getterMethodName = new StringBuffer() | |
138 | - .append("get") | |
139 | - .append(field.getName().substring(0, 1).toUpperCase()) | |
140 | - .append(field.getName().substring(1)); | |
141 | - | |
142 | - Method getterMethod; | |
143 | - | |
144 | - try { | |
145 | - getterMethod = type.getMethod(getterMethodName.toString()); | |
146 | - } catch (Exception e) { | |
147 | - getterMethod = null; | |
148 | - } | |
149 | - | |
150 | - // Se atributo for boolean, procura método getter no formato "isAttribute". | |
151 | - if (getterMethod == null | |
152 | - && (Boolean.TYPE.isAssignableFrom(field.getType()) || Boolean.class.isAssignableFrom(field.getType()))) { | |
153 | - // Boolean.TYPE representa o tipo primitivo "boolean", Boolean.class é a classe wrapper. | |
154 | - getterMethodName = new StringBuffer() | |
155 | - .append("is") | |
156 | - .append(field.getName().substring(0, 1).toUpperCase()) | |
157 | - .append(field.getName().substring(1).toUpperCase()); | |
158 | - | |
159 | - try { | |
160 | - getterMethod = type.getMethod(getterMethodName.toString()); | |
161 | - } catch (Exception e) { | |
162 | - getterMethod = null; | |
163 | - } | |
164 | - } | |
165 | - | |
166 | - return getterMethod; | |
167 | - } | |
168 | - | |
169 | - /** | |
170 | - * Returns the public setter method for a given field, or <code>null</code> if no setter method can be found. | |
171 | - */ | |
172 | - private Method getSetterMethod(Field field) { | |
173 | - StringBuffer setterMethodName = new StringBuffer() | |
174 | - .append("set") | |
175 | - .append(field.getName().substring(0, 1).toUpperCase()) | |
176 | - .append(field.getName().substring(1)); | |
177 | - | |
178 | - Method setterMethod; | |
179 | - | |
180 | - try { | |
181 | - setterMethod = type.getMethod(setterMethodName.toString() , field.getType()); | |
182 | - } catch (Exception e) { | |
183 | - setterMethod = null; | |
184 | - } | |
185 | - | |
186 | - return setterMethod; | |
187 | - } | |
188 | - | |
189 | - public final class FieldDetail { | |
190 | - | |
191 | - private final Field field; | |
192 | - | |
193 | - private final String description; | |
194 | - | |
195 | - private Method getterMethod; | |
196 | - | |
197 | - private Method setterMethod; | |
198 | - | |
199 | - public FieldDetail(Field field, String description, Method getterMethod, Method setterMethod) { | |
200 | - super(); | |
201 | - this.field = field; | |
202 | - this.description = description; | |
203 | - this.getterMethod = getterMethod; | |
204 | - this.setterMethod = setterMethod; | |
205 | - } | |
206 | - | |
207 | - public Field getField() { | |
208 | - return field; | |
209 | - } | |
210 | - | |
211 | - public String getDescription() { | |
212 | - return description; | |
213 | - } | |
214 | - | |
215 | - public Method getGetterMethod() { | |
216 | - return getterMethod; | |
217 | - } | |
218 | - | |
219 | - public Method getSetterMethod() { | |
220 | - return setterMethod; | |
221 | - } | |
222 | - | |
223 | - } | |
224 | - | |
225 | - public final class MethodDetail { | |
226 | - | |
227 | - private final Method method; | |
228 | - | |
229 | - private final ParameterDetail[] parameterTypers; | |
230 | - | |
231 | - private String description; | |
232 | - | |
233 | - public MethodDetail(Method method, String description, ParameterDetail[] parameterTypers) { | |
234 | - super(); | |
235 | - this.method = method; | |
236 | - this.description = description; | |
237 | - this.parameterTypers = parameterTypers; | |
238 | - } | |
239 | - | |
240 | - public Method getMethod() { | |
241 | - return method; | |
242 | - } | |
243 | - | |
244 | - public ParameterDetail[] getParameterTypers() { | |
245 | - return parameterTypers; | |
246 | - } | |
247 | - | |
248 | - public String getDescription() { | |
249 | - return description; | |
250 | - } | |
251 | - | |
252 | - } | |
253 | - | |
254 | - public final class ParameterDetail { | |
255 | - | |
256 | - private final Class<?> parameterType; | |
257 | - | |
258 | - private final String parameterName; | |
259 | - | |
260 | - private final String parameterDescription; | |
261 | - | |
262 | - public ParameterDetail(Class<?> parameterType, String parameterName, String parameterDescription) { | |
263 | - super(); | |
264 | - this.parameterType = parameterType; | |
265 | - this.parameterName = parameterName; | |
266 | - this.parameterDescription = parameterDescription; | |
267 | - } | |
268 | - | |
269 | - public Class<?> getParameterType() { | |
270 | - return parameterType; | |
271 | - } | |
272 | - | |
273 | - public String getParameterName() { | |
274 | - return parameterName; | |
275 | - } | |
276 | - | |
277 | - public String getParameterDescription() { | |
278 | - return parameterDescription; | |
279 | - } | |
280 | - } | |
281 | - | |
282 | - /** | |
283 | - * Indicates another {@link ManagedType} represents the same {@link Class} as this one. This method also supports a | |
284 | - * {@link Class} as a parameter, in this case it will return <code>true</code> if the passed class is exactly the | |
285 | - * same Java class represented by this {@link ManagedType}. | |
286 | - */ | |
287 | - @Override | |
288 | - public boolean equals(Object other) { | |
289 | - if (other == null) { | |
290 | - return false; | |
291 | - } | |
292 | - | |
293 | - return ((ManagedType) other).getType().getCanonicalName().equals(this.getType().getCanonicalName()); | |
294 | - } | |
295 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/internal/MonitoringManager.java
... | ... | @@ -1,266 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.internal; | |
2 | - | |
3 | -import java.lang.reflect.Method; | |
4 | -import java.util.ArrayList; | |
5 | -import java.util.Collection; | |
6 | -import java.util.List; | |
7 | - | |
8 | -import javax.enterprise.context.ApplicationScoped; | |
9 | -import javax.enterprise.context.RequestScoped; | |
10 | -import javax.inject.Inject; | |
11 | -import javax.management.ReflectionException; | |
12 | - | |
13 | -import org.slf4j.Logger; | |
14 | - | |
15 | -import br.gov.frameworkdemoiselle.DemoiselleException; | |
16 | -import br.gov.frameworkdemoiselle.annotation.Name; | |
17 | -import br.gov.frameworkdemoiselle.internal.context.ContextManager; | |
18 | -import br.gov.frameworkdemoiselle.internal.context.ManagedContext; | |
19 | -import br.gov.frameworkdemoiselle.management.annotation.Managed; | |
20 | -import br.gov.frameworkdemoiselle.management.annotation.Property; | |
21 | -import br.gov.frameworkdemoiselle.management.extension.ManagementExtension; | |
22 | -import br.gov.frameworkdemoiselle.management.internal.ManagedType.MethodDetail; | |
23 | -import br.gov.frameworkdemoiselle.management.notification.AttributeChangeNotification; | |
24 | -import br.gov.frameworkdemoiselle.management.notification.NotificationManager; | |
25 | -import br.gov.frameworkdemoiselle.util.Beans; | |
26 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
27 | - | |
28 | -/** | |
29 | - * A manager that helps implementators of the management framework to obtain a | |
30 | - * list of managed classes, set or obtain values from them or invoke operations | |
31 | - * over them. | |
32 | - * | |
33 | - * @author serpro | |
34 | - */ | |
35 | -@ApplicationScoped | |
36 | -public class MonitoringManager { | |
37 | - | |
38 | - @Inject | |
39 | - private Logger logger; | |
40 | - | |
41 | - @Inject | |
42 | - @Name("demoiselle-core-bundle") | |
43 | - private ResourceBundle bundle; | |
44 | - | |
45 | - private final List<ManagedType> managedTypes = new ArrayList<ManagedType>(); | |
46 | - | |
47 | - public void addManagedType(ManagedType managedType) { | |
48 | - managedTypes.add(managedType); | |
49 | - logger.debug(bundle.getString("management-debug-registering-managed-type",managedType.getType().getCanonicalName())); | |
50 | - } | |
51 | - | |
52 | - /** | |
53 | - * @return A list all managed types, classes annotated with {@link Managed}. | |
54 | - * The returned list is a shallow copy of the internal list, so you | |
55 | - * are free to modify it. | |
56 | - * | |
57 | - * TODO precisamos desse clone na lista? | |
58 | - */ | |
59 | - public List<ManagedType> getManagedTypes() { | |
60 | - ArrayList<ManagedType> cloneList = new ArrayList<ManagedType>(); | |
61 | - cloneList.addAll(managedTypes); | |
62 | - return cloneList; | |
63 | - } | |
64 | - | |
65 | - /** | |
66 | - * Invoke an operation over a managed type. | |
67 | - * | |
68 | - * @param managedType | |
69 | - * A type annotated with {@link Managed}. This method will create | |
70 | - * an (or obtain an already created) instance of this type and | |
71 | - * invoke the operation over it. | |
72 | - * @param actionName | |
73 | - * Name of method to be invoked, the type must have this | |
74 | - * operation on it's list | |
75 | - * @param params | |
76 | - * List of values for the operation parameters. Can be | |
77 | - * <code>null</code> if the operation require no parameters. | |
78 | - * @return The return value of the original invoked operation. Methods of | |
79 | - * return type <code>void</code> will return the {@link Void} type. | |
80 | - * @throws ReflectionException | |
81 | - * In case the operation doesn't exist or have a different | |
82 | - * signature | |
83 | - */ | |
84 | - public synchronized Object invoke(ManagedType managedType, String actionName, | |
85 | - Object[] params) { | |
86 | - if ( managedTypes.contains(managedType) ) { | |
87 | - activateContexts(managedType.getType()); | |
88 | - | |
89 | - Object delegate = Beans.getReference(managedType.getType()); | |
90 | - | |
91 | - MethodDetail method = managedType.getOperationMethods().get(actionName); | |
92 | - | |
93 | - if (method != null) { | |
94 | - try { | |
95 | - logger.debug(bundle | |
96 | - .getString("management-debug-invoking-operation",actionName,managedType.getType().getCanonicalName())); | |
97 | - return method.getMethod().invoke(delegate, params); | |
98 | - } catch (Exception e) { | |
99 | - throw new DemoiselleException(bundle.getString( | |
100 | - "management-invoke-error", actionName), e); | |
101 | - } finally { | |
102 | - deactivateContexts(managedType.getType()); | |
103 | - } | |
104 | - } else { | |
105 | - throw new DemoiselleException(bundle.getString( | |
106 | - "management-invoke-error", actionName)); | |
107 | - } | |
108 | - } else { | |
109 | - throw new DemoiselleException( | |
110 | - bundle.getString("management-type-not-found")); | |
111 | - } | |
112 | - } | |
113 | - | |
114 | - /** | |
115 | - * Retrieve the current value of a property from a managed type. Properties | |
116 | - * are attributes annotated with {@link Property}. | |
117 | - * | |
118 | - * @param managedType The type that has the property the client wants to know the value of. | |
119 | - * @param propertyName The name of the property | |
120 | - * @return The current value of the property | |
121 | - */ | |
122 | - public synchronized Object getProperty(ManagedType managedType, String propertyName) { | |
123 | - | |
124 | - if ( managedTypes.contains(managedType) ) { | |
125 | - Method getterMethod = managedType.getFields().get(propertyName).getGetterMethod(); | |
126 | - | |
127 | - if (getterMethod != null) { | |
128 | - logger.debug(bundle.getString( | |
129 | - "management-debug-acessing-property", getterMethod | |
130 | - .getName(), managedType.getType().getCanonicalName())); | |
131 | - | |
132 | - activateContexts(managedType.getType()); | |
133 | - | |
134 | - try { | |
135 | - Object delegate = Beans.getReference(managedType.getType()); | |
136 | - | |
137 | - return getterMethod.invoke(delegate, (Object[]) null); | |
138 | - } catch (Exception e) { | |
139 | - throw new DemoiselleException(bundle.getString( | |
140 | - "management-invoke-error", getterMethod.getName()), | |
141 | - e); | |
142 | - } finally { | |
143 | - deactivateContexts(managedType.getType()); | |
144 | - } | |
145 | - } else { | |
146 | - throw new DemoiselleException(bundle.getString( | |
147 | - "management-invoke-error", propertyName)); | |
148 | - } | |
149 | - } else { | |
150 | - throw new DemoiselleException( | |
151 | - bundle.getString("management-type-not-found")); | |
152 | - } | |
153 | - } | |
154 | - | |
155 | - /** | |
156 | - * Sets a new value for a property contained inside a managed type. A property | |
157 | - * is an attribute annotated with {@link Property}. | |
158 | - * | |
159 | - * @param managedType The type that has access to the property | |
160 | - * @param propertyName The name of the property | |
161 | - * @param newValue The new value of the property | |
162 | - */ | |
163 | - public synchronized void setProperty(ManagedType managedType, String propertyName, | |
164 | - Object newValue) { | |
165 | - | |
166 | - if ( managedTypes.contains(managedType) ) { | |
167 | - // Procura o método set do atributo em questão | |
168 | - Method method = managedType.getFields().get(propertyName).getSetterMethod(); | |
169 | - if (method != null) { | |
170 | - logger.debug(bundle.getString( | |
171 | - "management-debug-setting-property", method.getName(), | |
172 | - managedType.getType().getCanonicalName())); | |
173 | - | |
174 | - // Obtém uma instância da classe gerenciada, lembrando que | |
175 | - // classes | |
176 | - // anotadas com @Managed são sempre singletons. | |
177 | - activateContexts(managedType.getType()); | |
178 | - try { | |
179 | - Object delegate = Beans.getReference(managedType.getType()); | |
180 | - | |
181 | - Method getterMethod = managedType.getFields().get(propertyName).getGetterMethod(); | |
182 | - Object oldValue; | |
183 | - try{ | |
184 | - oldValue = getterMethod.invoke(delegate, (Object[])null); | |
185 | - } | |
186 | - catch(Exception e){ | |
187 | - oldValue = null; | |
188 | - } | |
189 | - | |
190 | - method.invoke(delegate, new Object[] { newValue }); | |
191 | - | |
192 | - //Manda uma notificação de mudança de atributo | |
193 | - NotificationManager notificationManager = Beans.getReference(NotificationManager.class); | |
194 | - Class<? extends Object> attributeType = newValue!=null ? newValue.getClass() : null; | |
195 | - | |
196 | - AttributeChangeNotification notification = new AttributeChangeNotification(bundle.getString("management-notification-attribute-changed",propertyName,managedType.getType().getCanonicalName()) | |
197 | - , propertyName | |
198 | - , attributeType | |
199 | - , oldValue | |
200 | - , newValue); | |
201 | - notificationManager.sendNotification(notification); | |
202 | - | |
203 | - } catch (Exception e) { | |
204 | - throw new DemoiselleException(bundle.getString( | |
205 | - "management-invoke-error", method.getName()), e); | |
206 | - } finally { | |
207 | - deactivateContexts(managedType.getType()); | |
208 | - } | |
209 | - | |
210 | - } else { | |
211 | - throw new DemoiselleException(bundle.getString( | |
212 | - "management-invoke-error", propertyName)); | |
213 | - } | |
214 | - } else { | |
215 | - throw new DemoiselleException( | |
216 | - bundle.getString("management-type-not-found")); | |
217 | - } | |
218 | - | |
219 | - } | |
220 | - | |
221 | - private void activateContexts(Class<?> managedType) { | |
222 | - logger.debug(bundle.getString("management-debug-starting-custom-context", | |
223 | - ManagedContext.class.getCanonicalName(), | |
224 | - managedType.getCanonicalName())); | |
225 | - | |
226 | - ContextManager.activate(ManagedContext.class,RequestScoped.class); | |
227 | - } | |
228 | - | |
229 | - private void deactivateContexts(Class<?> managedType) { | |
230 | - logger.debug(bundle.getString("management-debug-stoping-custom-context", | |
231 | - ManagedContext.class.getCanonicalName(), | |
232 | - managedType.getCanonicalName())); | |
233 | - | |
234 | - ContextManager.deactivate(ManagedContext.class,RequestScoped.class); | |
235 | - } | |
236 | - | |
237 | - public void shutdown(Collection<Class<? extends ManagementExtension>> monitoringExtensions) { | |
238 | - | |
239 | - for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) { | |
240 | - | |
241 | - ManagementExtension monitoringExtension = Beans.getReference(monitoringExtensionClass); | |
242 | - | |
243 | - monitoringExtension.shutdown(this.getManagedTypes()); | |
244 | - | |
245 | - logger.debug( bundle.getString("management-debug-removing-management-extension",monitoringExtension.getClass().getCanonicalName()) ); | |
246 | - | |
247 | - } | |
248 | - | |
249 | - } | |
250 | - | |
251 | - public void initialize(Collection<Class<? extends ManagementExtension>> monitoringExtensions) { | |
252 | - | |
253 | - for (Class<? extends ManagementExtension> monitoringExtensionClass : monitoringExtensions) { | |
254 | - | |
255 | - ManagementExtension monitoringExtension = Beans | |
256 | - .getReference(monitoringExtensionClass); | |
257 | - | |
258 | - monitoringExtension.initialize(this.getManagedTypes()); | |
259 | - | |
260 | - logger.debug( bundle.getString("management-debug-processing-management-extension",monitoringExtension.getClass().getCanonicalName()) ); | |
261 | - | |
262 | - } | |
263 | - | |
264 | - } | |
265 | - | |
266 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/internal/notification/event/NotificationEvent.java
... | ... | @@ -1,29 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.internal.notification.event; | |
2 | - | |
3 | -import br.gov.frameworkdemoiselle.management.notification.Notification; | |
4 | -import br.gov.frameworkdemoiselle.management.notification.NotificationManager; | |
5 | - | |
6 | -/** | |
7 | - * Event fired when a notification is sent by {@link NotificationManager}. | |
8 | - * Implementators can capture this event and by notified when the {@link NotificationManager} | |
9 | - * sends notifications, so they can pass the notification to a underlying protocol such as JMX. | |
10 | - * | |
11 | - * @author serpro | |
12 | - * | |
13 | - */ | |
14 | -public class NotificationEvent { | |
15 | - | |
16 | - private Notification notification; | |
17 | - | |
18 | - public NotificationEvent(Notification notification){ | |
19 | - this.notification = notification; | |
20 | - } | |
21 | - | |
22 | - public Notification getNotification() { | |
23 | - return notification; | |
24 | - } | |
25 | - | |
26 | - public void setNotification(Notification notification) { | |
27 | - this.notification = notification; | |
28 | - } | |
29 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/internal/notification/qualifier/AttributeChange.java
... | ... | @@ -1,26 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.internal.notification.qualifier; | |
2 | - | |
3 | -import java.lang.annotation.ElementType; | |
4 | -import java.lang.annotation.Retention; | |
5 | -import java.lang.annotation.RetentionPolicy; | |
6 | -import java.lang.annotation.Target; | |
7 | - | |
8 | -import javax.inject.Qualifier; | |
9 | - | |
10 | -import br.gov.frameworkdemoiselle.management.internal.notification.event.NotificationEvent; | |
11 | -import br.gov.frameworkdemoiselle.management.notification.AttributeChangeNotification; | |
12 | - | |
13 | -/** | |
14 | - * | |
15 | - * Enables {@link NotificationEvent} observers to trigger only with notifications | |
16 | - * of the specialized type {@link AttributeChangeNotification}. | |
17 | - * | |
18 | - * @author serpro | |
19 | - * | |
20 | - */ | |
21 | -@Qualifier | |
22 | -@Retention(RetentionPolicy.RUNTIME) | |
23 | -@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE}) | |
24 | -public @interface AttributeChange { | |
25 | - | |
26 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/internal/notification/qualifier/Generic.java
... | ... | @@ -1,26 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.internal.notification.qualifier; | |
2 | - | |
3 | -import java.lang.annotation.ElementType; | |
4 | -import java.lang.annotation.Retention; | |
5 | -import java.lang.annotation.RetentionPolicy; | |
6 | -import java.lang.annotation.Target; | |
7 | - | |
8 | -import javax.inject.Qualifier; | |
9 | - | |
10 | -import br.gov.frameworkdemoiselle.management.internal.notification.event.NotificationEvent; | |
11 | -import br.gov.frameworkdemoiselle.management.notification.Notification; | |
12 | - | |
13 | -/** | |
14 | - * | |
15 | - * Enables {@link NotificationEvent} observers to trigger only with notifications | |
16 | - * of the base type {@link Notification}. | |
17 | - * | |
18 | - * @author serpro | |
19 | - * | |
20 | - */ | |
21 | -@Qualifier | |
22 | -@Retention(RetentionPolicy.RUNTIME) | |
23 | -@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE}) | |
24 | -public @interface Generic { | |
25 | - | |
26 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/internal/validators/AllowedValuesValidator.java
... | ... | @@ -1,68 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.internal.validators; | |
2 | - | |
3 | -import java.math.BigDecimal; | |
4 | - | |
5 | -import javax.validation.ConstraintValidator; | |
6 | -import javax.validation.ConstraintValidatorContext; | |
7 | - | |
8 | -import br.gov.frameworkdemoiselle.management.annotation.validation.AllowedValues; | |
9 | - | |
10 | - | |
11 | -public class AllowedValuesValidator implements ConstraintValidator<AllowedValues, Object> { | |
12 | - | |
13 | - private br.gov.frameworkdemoiselle.management.annotation.validation.AllowedValues.ValueType valueType; | |
14 | - private String[] allowedValues; | |
15 | - | |
16 | - @Override | |
17 | - public void initialize(AllowedValues constraintAnnotation) { | |
18 | - valueType = constraintAnnotation.valueType(); | |
19 | - allowedValues = constraintAnnotation.allows(); | |
20 | - } | |
21 | - | |
22 | - @Override | |
23 | - public boolean isValid(Object value, ConstraintValidatorContext context) { | |
24 | - | |
25 | - if (value==null){ | |
26 | - return false; | |
27 | - } | |
28 | - | |
29 | - switch(valueType){ | |
30 | - case STRING: | |
31 | - for (String str : allowedValues){ | |
32 | - if (str.equals(value)) return true; | |
33 | - } | |
34 | - return false; | |
35 | - | |
36 | - case INTEGER: | |
37 | - try{ | |
38 | - Integer number = Integer.valueOf(value.toString()); | |
39 | - String strNumber = number.toString(); | |
40 | - for (String str : allowedValues){ | |
41 | - if (str.equals(strNumber)) return true; | |
42 | - } | |
43 | - | |
44 | - return false; | |
45 | - } | |
46 | - catch(NumberFormatException ne){ | |
47 | - return false; | |
48 | - } | |
49 | - | |
50 | - case DECIMAL: | |
51 | - try{ | |
52 | - BigDecimal number = new BigDecimal(value.toString()); | |
53 | - String strNumber = number.toString(); | |
54 | - for (String str : allowedValues){ | |
55 | - if (str.equals(strNumber)) return true; | |
56 | - } | |
57 | - } | |
58 | - catch(NumberFormatException ne){ | |
59 | - return false; | |
60 | - } | |
61 | - | |
62 | - return false; | |
63 | - } | |
64 | - | |
65 | - return false; | |
66 | - } | |
67 | - | |
68 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/notification/AttributeChangeNotification.java
... | ... | @@ -1,74 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.notification; | |
2 | - | |
3 | -/** | |
4 | - * Special notification to denote an attribute has changed values. | |
5 | - * | |
6 | - * @see Notification | |
7 | - * | |
8 | - * @author serpro | |
9 | - * | |
10 | - */ | |
11 | -public class AttributeChangeNotification extends Notification { | |
12 | - | |
13 | - private String attributeName; | |
14 | - | |
15 | - private Class<? extends Object> attributeType; | |
16 | - | |
17 | - private Object oldValue; | |
18 | - | |
19 | - private Object newValue; | |
20 | - | |
21 | - public AttributeChangeNotification(){} | |
22 | - | |
23 | - public AttributeChangeNotification(Object message, String attributeName, Class<? extends Object> attributeType, Object oldValue, | |
24 | - Object newValue) { | |
25 | - super(message); | |
26 | - this.attributeName = attributeName; | |
27 | - this.attributeType = attributeType; | |
28 | - this.oldValue = oldValue; | |
29 | - this.newValue = newValue; | |
30 | - } | |
31 | - | |
32 | - | |
33 | - public String getAttributeName() { | |
34 | - return attributeName; | |
35 | - } | |
36 | - | |
37 | - | |
38 | - public void setAttributeName(String attributeName) { | |
39 | - this.attributeName = attributeName; | |
40 | - } | |
41 | - | |
42 | - | |
43 | - public Class<? extends Object> getAttributeType() { | |
44 | - return attributeType; | |
45 | - } | |
46 | - | |
47 | - | |
48 | - public void setAttributeType(Class<? extends Object> attributeType) { | |
49 | - this.attributeType = attributeType; | |
50 | - } | |
51 | - | |
52 | - | |
53 | - public Object getOldValue() { | |
54 | - return oldValue; | |
55 | - } | |
56 | - | |
57 | - | |
58 | - public void setOldValue(Object oldValue) { | |
59 | - this.oldValue = oldValue; | |
60 | - } | |
61 | - | |
62 | - | |
63 | - public Object getNewValue() { | |
64 | - return newValue; | |
65 | - } | |
66 | - | |
67 | - | |
68 | - public void setNewValue(Object newValue) { | |
69 | - this.newValue = newValue; | |
70 | - } | |
71 | - | |
72 | - | |
73 | - | |
74 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/notification/Notification.java
... | ... | @@ -1,41 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.notification; | |
2 | - | |
3 | -/** | |
4 | - * | |
5 | - * Notification that can be sent by the {@link NotificationManager}. | |
6 | - * | |
7 | - * @author serpro | |
8 | - * | |
9 | - */ | |
10 | -public class Notification { | |
11 | - | |
12 | - private Object message; | |
13 | - | |
14 | - public Notification(){ | |
15 | - } | |
16 | - | |
17 | - public Notification(Object message) { | |
18 | - super(); | |
19 | - this.message = message; | |
20 | - } | |
21 | - | |
22 | - | |
23 | - public Object getMessage() { | |
24 | - return message; | |
25 | - } | |
26 | - | |
27 | - | |
28 | - public void setMessage(Object message) { | |
29 | - this.message = message; | |
30 | - } | |
31 | - | |
32 | - | |
33 | - public Class<? extends Object> getType() { | |
34 | - if (message!=null){ | |
35 | - return message.getClass(); | |
36 | - } | |
37 | - | |
38 | - return null; | |
39 | - } | |
40 | - | |
41 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/notification/NotificationManager.java
... | ... | @@ -1,80 +0,0 @@ |
1 | -package br.gov.frameworkdemoiselle.management.notification; | |
2 | - | |
3 | -import java.io.Serializable; | |
4 | - | |
5 | -import javax.enterprise.context.ApplicationScoped; | |
6 | -import javax.enterprise.event.Event; | |
7 | -import javax.enterprise.event.Observes; | |
8 | -import javax.enterprise.util.AnnotationLiteral; | |
9 | -import javax.inject.Inject; | |
10 | - | |
11 | -import br.gov.frameworkdemoiselle.management.internal.notification.event.NotificationEvent; | |
12 | -import br.gov.frameworkdemoiselle.management.internal.notification.qualifier.AttributeChange; | |
13 | -import br.gov.frameworkdemoiselle.management.internal.notification.qualifier.Generic; | |
14 | -import br.gov.frameworkdemoiselle.util.Beans; | |
15 | - | |
16 | -/** | |
17 | - * | |
18 | - * <p>Central class to manage sending notifications to management clients. | |
19 | - * This class allows applications to send management notifications without | |
20 | - * knowledge of the technology used to send those notifications.</p> | |
21 | - * | |
22 | - * <p>To obtain an instance of the {@link NotificationManager} simply inject it in | |
23 | - * your code using {@link Inject} or the {@link Beans#getReference(Class beanType)} method. The {@link NotificationManager} | |
24 | - * is {@link ApplicationScoped}, so you can inject it as many times as needed and still have only one instance per application.</p> | |
25 | - * | |
26 | - * <p>Implementators of management protocols must observe the {@link NotificationEvent} event (using the {@link Observes} annotation), this way | |
27 | - * they will receive an event containing the original notification and can translate this notification to a specific protocol. Optionaly, | |
28 | - * the implementator can use qualifiers like the {@link Generic} and {@link AttributeChange} qualifiers | |
29 | - * to filter what king of notifications they will handle. One example of an implementator is the <b>demoiselle-jmx</b> extension.</p> | |
30 | - * | |
31 | - * @author serpro | |
32 | - * | |
33 | - */ | |
34 | -@ApplicationScoped | |
35 | -@SuppressWarnings("serial") | |
36 | -public class NotificationManager implements Serializable{ | |
37 | - | |
38 | - @Inject | |
39 | - @Generic | |
40 | - private Event<NotificationEvent> genericNotificationEvent; | |
41 | - | |
42 | - @Inject | |
43 | - @AttributeChange | |
44 | - private Event<NotificationEvent> attributeChangeNotificationEvent; | |
45 | - | |
46 | - /** | |
47 | - * Sends a generic notification to all management clients. | |
48 | - * | |
49 | - * @param notification The notification to send | |
50 | - */ | |
51 | - public void sendNotification(Notification notification) { | |
52 | - if (! AttributeChangeNotification.class.isInstance(notification) ){ | |
53 | - getGenericNotificationEvent().fire(new NotificationEvent(notification)); | |
54 | - } | |
55 | - else{ | |
56 | - getAttributeChangeNotificationEvent().fire(new NotificationEvent(notification)); | |
57 | - } | |
58 | - } | |
59 | - | |
60 | - @SuppressWarnings("unchecked") | |
61 | - private Event<NotificationEvent> getGenericNotificationEvent() { | |
62 | - if (genericNotificationEvent==null){ | |
63 | - genericNotificationEvent = Beans.getReference(Event.class , new AnnotationLiteral<Generic>() {}); | |
64 | - } | |
65 | - | |
66 | - return genericNotificationEvent; | |
67 | - } | |
68 | - | |
69 | - @SuppressWarnings("unchecked") | |
70 | - private Event<NotificationEvent> getAttributeChangeNotificationEvent() { | |
71 | - if (attributeChangeNotificationEvent==null){ | |
72 | - attributeChangeNotificationEvent = Beans.getReference(Event.class , new AnnotationLiteral<AttributeChange>() {}); | |
73 | - } | |
74 | - | |
75 | - return attributeChangeNotificationEvent; | |
76 | - } | |
77 | - | |
78 | - | |
79 | - | |
80 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/stereotype/ManagementController.java
0 → 100644
... | ... | @@ -0,0 +1,79 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2011 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package br.gov.frameworkdemoiselle.stereotype; | |
38 | + | |
39 | +import static java.lang.annotation.ElementType.TYPE; | |
40 | +import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
41 | + | |
42 | +import java.lang.annotation.Documented; | |
43 | +import java.lang.annotation.Inherited; | |
44 | +import java.lang.annotation.Retention; | |
45 | +import java.lang.annotation.Target; | |
46 | + | |
47 | +import javax.enterprise.context.ApplicationScoped; | |
48 | +import javax.enterprise.inject.Stereotype; | |
49 | +import javax.enterprise.util.Nonbinding; | |
50 | + | |
51 | +/** | |
52 | + * <p>Identifies a <b>management controller</b> class. What it means is that an external client can manage the application | |
53 | + * this class is in by reading or writing it's attributes and calling it's operations.</p> | |
54 | + * <p> | |
55 | + * Only fields annotated with {@link br.gov.frameworkdemoiselle.annotation.ManagedProperty} or | |
56 | + * methods annotated with {@link br.gov.frameworkdemoiselle.annotation.ManagedOperation} will be exposed | |
57 | + * to clients.</p> | |
58 | + * <p>This stereotype only defines a class as managed, you need to choose an extension that will expose this managed class | |
59 | + * to external clients using any technology available. One example is the Demoiselle JMX extension, that will expose | |
60 | + * managed classes as MBeans.</p> | |
61 | + * | |
62 | + * @author SERPRO | |
63 | + */ | |
64 | +@ApplicationScoped | |
65 | +@Stereotype | |
66 | +@Documented | |
67 | +@Controller | |
68 | +@Inherited | |
69 | +@Retention(RUNTIME) | |
70 | +@Target({ TYPE }) | |
71 | +public @interface ManagementController { | |
72 | + | |
73 | + /** | |
74 | + * @return Human readable description of this managed class. | |
75 | + */ | |
76 | + @Nonbinding | |
77 | + String description() default ""; | |
78 | + | |
79 | +} | ... | ... |
impl/core/src/main/resources/demoiselle-core-bundle.properties
... | ... | @@ -113,4 +113,6 @@ management-debug-starting-custom-context=Levantando contexto {0} para executar c |
113 | 113 | management-debug-stoping-custom-context=Desligando contexto {0} para classe gerenciada {1} |
114 | 114 | management-debug-registering-managed-type=Registrando classe gerenciada [{0}] |
115 | 115 | management-debug-processing-management-extension=Processando extens\u00E3o de gerenciamento [{0}] |
116 | -management-debug-removing-management-extension=Desativando extens\u00E3o de gerenciamento [{0}] | |
117 | 116 | \ No newline at end of file |
117 | +management-debug-removing-management-extension=Desativando extens\u00E3o de gerenciamento [{0}] | |
118 | + | |
119 | +validation-validator-not-found=Nenhum provedor de valida\u00E7\u00E3o de beans encontrado, as anota\u00E7\u00F5es de valida\u00E7\u00E3o n\u00E3o ser\u00E3o processadas | ... | ... |
impl/core/src/test/java/management/ManagedClassStore.java
... | ... | @@ -1,25 +0,0 @@ |
1 | -package management; | |
2 | - | |
3 | -import java.util.ArrayList; | |
4 | -import java.util.Collection; | |
5 | -import java.util.List; | |
6 | - | |
7 | -import javax.enterprise.context.ApplicationScoped; | |
8 | - | |
9 | -import br.gov.frameworkdemoiselle.management.internal.ManagedType; | |
10 | - | |
11 | -@ApplicationScoped | |
12 | -public class ManagedClassStore { | |
13 | - | |
14 | - private List<ManagedType> managedTypes = new ArrayList<ManagedType>(); | |
15 | - | |
16 | - | |
17 | - public List<ManagedType> getManagedTypes() { | |
18 | - return managedTypes; | |
19 | - } | |
20 | - | |
21 | - public void addManagedTypes(Collection<ManagedType> managedTypes){ | |
22 | - this.managedTypes.addAll(managedTypes); | |
23 | - } | |
24 | - | |
25 | -} |
impl/core/src/test/java/management/ManagementBootstrapTestCase.java
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
1 | 37 | package management; |
2 | 38 | |
3 | 39 | import java.io.File; |
... | ... | @@ -6,6 +42,7 @@ import java.util.List; |
6 | 42 | import management.testclasses.DummyManagedClass; |
7 | 43 | import management.testclasses.DummyManagedClassPropertyError; |
8 | 44 | import management.testclasses.DummyManagementExtension; |
45 | +import management.testclasses.ManagedClassStore; | |
9 | 46 | |
10 | 47 | import org.jboss.arquillian.container.test.api.Deployer; |
11 | 48 | import org.jboss.arquillian.container.test.api.Deployment; |
... | ... | @@ -19,8 +56,8 @@ import org.junit.Test; |
19 | 56 | import org.junit.runner.RunWith; |
20 | 57 | |
21 | 58 | import test.LocaleProducer; |
22 | -import br.gov.frameworkdemoiselle.management.extension.ManagementExtension; | |
23 | -import br.gov.frameworkdemoiselle.management.internal.ManagedType; | |
59 | +import br.gov.frameworkdemoiselle.internal.management.ManagedType; | |
60 | +import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; | |
24 | 61 | import br.gov.frameworkdemoiselle.util.Beans; |
25 | 62 | |
26 | 63 | @RunWith(Arquillian.class) |
... | ... | @@ -44,7 +81,7 @@ public class ManagementBootstrapTestCase { |
44 | 81 | new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), |
45 | 82 | "services/javax.enterprise.inject.spi.Extension") |
46 | 83 | .addPackages(false, ManagementBootstrapTestCase.class.getPackage()) |
47 | - .addClasses(DummyManagementExtension.class,DummyManagedClass.class); | |
84 | + .addClasses(DummyManagementExtension.class,DummyManagedClass.class,ManagedClassStore.class); | |
48 | 85 | } |
49 | 86 | |
50 | 87 | /** |
... | ... | @@ -63,7 +100,7 @@ public class ManagementBootstrapTestCase { |
63 | 100 | new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), |
64 | 101 | "services/javax.enterprise.inject.spi.Extension") |
65 | 102 | .addPackages(false, ManagementBootstrapTestCase.class.getPackage()) |
66 | - .addClasses(DummyManagementExtension.class,DummyManagedClassPropertyError.class); | |
103 | + .addClasses(DummyManagementExtension.class,DummyManagedClassPropertyError.class,ManagedClassStore.class); | |
67 | 104 | } |
68 | 105 | |
69 | 106 | /** |
... | ... | @@ -74,7 +111,7 @@ public class ManagementBootstrapTestCase { |
74 | 111 | deployer.deploy("default"); |
75 | 112 | |
76 | 113 | // "store" é application scoped e é usado pelo DummyManagementExtension para |
77 | - // armazenar todos os beans anotados com @Managed. Se o bootstrap rodou corretamente, | |
114 | + // armazenar todos os beans anotados com @ManagementController. Se o bootstrap rodou corretamente, | |
78 | 115 | // ele chamou DummyManagementExtension.initialize e este store conterá o bean de teste que anotamos. |
79 | 116 | ManagedClassStore store = Beans.getReference(ManagedClassStore.class); |
80 | 117 | |
... | ... | @@ -92,7 +129,7 @@ public class ManagementBootstrapTestCase { |
92 | 129 | deployer.deploy("default"); |
93 | 130 | |
94 | 131 | // "store" é application scoped e é usado pelo DummyManagementExtension para |
95 | - // armazenar todos os beans anotados com @Managed. Se o bootstrap rodou corretamente, | |
132 | + // armazenar todos os beans anotados com @ManagementController. Se o bootstrap rodou corretamente, | |
96 | 133 | // ele chamou DummyManagementExtension.initialize e este store conterá o bean de teste que anotamos. |
97 | 134 | // Nós então disparamos o evento de shutdown onde ele deverá limpar o store. |
98 | 135 | ManagedClassStore store = Beans.getReference(ManagedClassStore.class); | ... | ... |
impl/core/src/test/java/management/ManagementTestCase.java
0 → 100644
... | ... | @@ -0,0 +1,164 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package management; | |
38 | + | |
39 | +import java.io.File; | |
40 | + | |
41 | +import junit.framework.Assert; | |
42 | +import management.testclasses.DummyManagedClass; | |
43 | +import management.testclasses.DummyManagementExtension; | |
44 | +import management.testclasses.ManagedClassStore; | |
45 | + | |
46 | +import org.jboss.arquillian.container.test.api.Deployment; | |
47 | +import org.jboss.arquillian.junit.Arquillian; | |
48 | +import org.jboss.shrinkwrap.api.ShrinkWrap; | |
49 | +import org.jboss.shrinkwrap.api.asset.FileAsset; | |
50 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
51 | +import org.junit.Test; | |
52 | +import org.junit.runner.RunWith; | |
53 | + | |
54 | +import test.LocaleProducer; | |
55 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
56 | +import br.gov.frameworkdemoiselle.util.Beans; | |
57 | + | |
58 | +/** | |
59 | + * Test case that simulates a management extension and tests if properties and operations on a managed class can be | |
60 | + * easily accessed and invoked. | |
61 | + * | |
62 | + * @author serpro | |
63 | + */ | |
64 | +@RunWith(Arquillian.class) | |
65 | +public class ManagementTestCase { | |
66 | + | |
67 | + @Deployment | |
68 | + public static JavaArchive createMultithreadedDeployment() { | |
69 | + return ShrinkWrap | |
70 | + .create(JavaArchive.class) | |
71 | + .addClass(LocaleProducer.class) | |
72 | + .addPackages(true, "br") | |
73 | + .addAsResource(new FileAsset(new File("src/test/resources/test/beans.xml")), "beans.xml") | |
74 | + .addAsManifestResource( | |
75 | + new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), | |
76 | + "services/javax.enterprise.inject.spi.Extension") | |
77 | + .addPackages(false, ManagementTestCase.class.getPackage()) | |
78 | + .addClasses(DummyManagementExtension.class, DummyManagedClass.class, ManagedClassStore.class); | |
79 | + } | |
80 | + | |
81 | + @Test | |
82 | + public void testReadProperty() { | |
83 | + DummyManagedClass managedClass = Beans.getReference(DummyManagedClass.class); | |
84 | + managedClass.setName("Test Name"); | |
85 | + | |
86 | + // store é nossa extensão de gerenciamento falsa, então estamos testando um "cliente" acessando | |
87 | + // nosso tipo gerenciado DummyManagedClass remotamente. | |
88 | + ManagedClassStore store = Beans.getReference(ManagedClassStore.class); | |
89 | + Object name = store.getProperty(DummyManagedClass.class, "name"); | |
90 | + Assert.assertEquals("Test Name", name); | |
91 | + } | |
92 | + | |
93 | + @Test | |
94 | + public void testWriteProperty() { | |
95 | + // store é nossa extensão de gerenciamento falsa, então estamos testando um "cliente" definindo | |
96 | + // um novo valor em uma propriedade de nosso tipo gerenciado DummyManagedClass remotamente. | |
97 | + ManagedClassStore store = Beans.getReference(ManagedClassStore.class); | |
98 | + store.setProperty(DummyManagedClass.class, "name", "Test Name"); | |
99 | + | |
100 | + DummyManagedClass managedClass = Beans.getReference(DummyManagedClass.class); | |
101 | + Assert.assertEquals("Test Name", managedClass.getName()); | |
102 | + } | |
103 | + | |
104 | + @Test | |
105 | + public void testReadAWriteOnly() { | |
106 | + | |
107 | + ManagedClassStore store = Beans.getReference(ManagedClassStore.class); | |
108 | + | |
109 | + try { | |
110 | + store.getProperty(DummyManagedClass.class, "writeOnlyProperty"); | |
111 | + Assert.fail(); | |
112 | + } catch (DemoiselleException de) { | |
113 | + // SUCCESS | |
114 | + } | |
115 | + | |
116 | + } | |
117 | + | |
118 | + @Test | |
119 | + public void testWriteAReadOnly() { | |
120 | + | |
121 | + ManagedClassStore store = Beans.getReference(ManagedClassStore.class); | |
122 | + | |
123 | + try { | |
124 | + store.setProperty(DummyManagedClass.class, "readOnlyProperty", "New Value"); | |
125 | + Assert.fail(); | |
126 | + } catch (DemoiselleException de) { | |
127 | + // SUCCESS | |
128 | + } | |
129 | + | |
130 | + } | |
131 | + | |
132 | + @Test | |
133 | + public void testInvokeOperation() { | |
134 | + | |
135 | + ManagedClassStore store = Beans.getReference(ManagedClassStore.class); | |
136 | + | |
137 | + try { | |
138 | + store.setProperty(DummyManagedClass.class, "firstFactor", new Integer(10)); | |
139 | + store.setProperty(DummyManagedClass.class, "secondFactor", new Integer(15)); | |
140 | + Integer response = (Integer) store.invoke(DummyManagedClass.class, "sumFactors"); | |
141 | + Assert.assertEquals(new Integer(25), response); | |
142 | + } catch (DemoiselleException de) { | |
143 | + Assert.fail(de.getMessage()); | |
144 | + } | |
145 | + | |
146 | + } | |
147 | + | |
148 | + @Test | |
149 | + public void testInvokeNonAnnotatedOperation() { | |
150 | + | |
151 | + ManagedClassStore store = Beans.getReference(ManagedClassStore.class); | |
152 | + | |
153 | + try { | |
154 | + // O método "nonOperationAnnotatedMethod" existe na classe DummyManagedClass, mas não está anotado como | |
155 | + // "@ManagedOperation", então | |
156 | + // ela não pode ser exposta para extensões. | |
157 | + store.invoke(DummyManagedClass.class, "nonOperationAnnotatedMethod"); | |
158 | + Assert.fail(); | |
159 | + } catch (DemoiselleException de) { | |
160 | + // SUCCESS | |
161 | + } | |
162 | + | |
163 | + } | |
164 | +} | ... | ... |
impl/core/src/test/java/management/NotificationTestCase.java
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
1 | 37 | package management; |
2 | 38 | |
3 | 39 | import java.io.File; |
... | ... | @@ -18,11 +54,11 @@ import org.junit.runner.RunWith; |
18 | 54 | |
19 | 55 | import test.LocaleProducer; |
20 | 56 | import br.gov.frameworkdemoiselle.annotation.Name; |
21 | -import br.gov.frameworkdemoiselle.management.internal.ManagedType; | |
22 | -import br.gov.frameworkdemoiselle.management.internal.MonitoringManager; | |
23 | -import br.gov.frameworkdemoiselle.management.notification.AttributeChangeNotification; | |
24 | -import br.gov.frameworkdemoiselle.management.notification.Notification; | |
25 | -import br.gov.frameworkdemoiselle.management.notification.NotificationManager; | |
57 | +import br.gov.frameworkdemoiselle.internal.management.ManagedType; | |
58 | +import br.gov.frameworkdemoiselle.internal.management.Management; | |
59 | +import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | |
60 | +import br.gov.frameworkdemoiselle.management.Notification; | |
61 | +import br.gov.frameworkdemoiselle.management.NotificationManager; | |
26 | 62 | import br.gov.frameworkdemoiselle.util.Beans; |
27 | 63 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
28 | 64 | |
... | ... | @@ -53,7 +89,7 @@ public class NotificationTestCase { |
53 | 89 | .addAsManifestResource( |
54 | 90 | new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), |
55 | 91 | "services/javax.enterprise.inject.spi.Extension") |
56 | - .addPackages(false, ManagementBootstrapTestCase.class.getPackage()) | |
92 | + .addPackages(false, NotificationTestCase.class.getPackage()) | |
57 | 93 | .addClasses(DummyNotificationListener.class,DummyManagedClass.class); |
58 | 94 | } |
59 | 95 | |
... | ... | @@ -83,7 +119,7 @@ public class NotificationTestCase { |
83 | 119 | */ |
84 | 120 | @Test |
85 | 121 | public void testNotifyChangeManagedClass(){ |
86 | - MonitoringManager manager = Beans.getReference(MonitoringManager.class); | |
122 | + Management manager = Beans.getReference(Management.class); | |
87 | 123 | |
88 | 124 | for (ManagedType type : manager.getManagedTypes()){ |
89 | 125 | if (type.getType().equals(DummyManagedClass.class)){ | ... | ... |
impl/core/src/test/java/management/ValidationTestCase.java
0 → 100644
... | ... | @@ -0,0 +1,62 @@ |
1 | +package management; | |
2 | + | |
3 | +import java.io.File; | |
4 | + | |
5 | +import management.testclasses.DummyManagedClass; | |
6 | +import management.testclasses.DummyManagementExtension; | |
7 | +import management.testclasses.ManagedClassStore; | |
8 | + | |
9 | +import org.jboss.arquillian.container.test.api.Deployment; | |
10 | +import org.jboss.arquillian.junit.Arquillian; | |
11 | +import org.jboss.shrinkwrap.api.ShrinkWrap; | |
12 | +import org.jboss.shrinkwrap.api.asset.FileAsset; | |
13 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
14 | +import org.junit.Assert; | |
15 | +import org.junit.Test; | |
16 | +import org.junit.runner.RunWith; | |
17 | + | |
18 | +import test.LocaleProducer; | |
19 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
20 | +import br.gov.frameworkdemoiselle.util.Beans; | |
21 | + | |
22 | +@RunWith(Arquillian.class) | |
23 | +public class ValidationTestCase { | |
24 | + | |
25 | + @Deployment | |
26 | + public static JavaArchive createDeployment() { | |
27 | + return ShrinkWrap | |
28 | + .create(JavaArchive.class) | |
29 | + .addClass(LocaleProducer.class) | |
30 | + .addPackages(true, "br") | |
31 | + .addAsResource(new FileAsset(new File("src/test/resources/test/beans.xml")), "beans.xml") | |
32 | + .addAsManifestResource( | |
33 | + new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), | |
34 | + "services/javax.enterprise.inject.spi.Extension") | |
35 | + .addPackages(false, NotificationTestCase.class.getPackage()) | |
36 | + .addClasses(DummyManagementExtension.class,ManagedClassStore.class,DummyManagedClass.class); | |
37 | + } | |
38 | + | |
39 | + /** | |
40 | + * Test if changing properties of a management controller passes through | |
41 | + * validation phase. | |
42 | + */ | |
43 | + @Test | |
44 | + public void testManagedClassValidation(){ | |
45 | + | |
46 | + //Testa se é possível definir um valor válido para uma propriedade. | |
47 | + ManagedClassStore store = Beans.getReference(ManagedClassStore.class); | |
48 | + store.setProperty(DummyManagedClass.class, "id", new Integer(1)); | |
49 | + Assert.assertEquals(new Integer(1), store.getProperty(DummyManagedClass.class, "id")); | |
50 | + | |
51 | + //Testa se definir um valor inválido dispara o erro adequado | |
52 | + try{ | |
53 | + store.setProperty(DummyManagedClass.class, "id", new Integer(5)); | |
54 | + Assert.fail(); | |
55 | + } | |
56 | + catch(DemoiselleException e){ | |
57 | + //SUCCESS | |
58 | + } | |
59 | + | |
60 | + } | |
61 | + | |
62 | +} | ... | ... |
impl/core/src/test/java/management/testclasses/DummyManagedClass.java
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
1 | 37 | package management.testclasses; |
2 | 38 | |
3 | 39 | import java.util.UUID; |
4 | 40 | |
5 | -import br.gov.frameworkdemoiselle.management.annotation.Managed; | |
6 | -import br.gov.frameworkdemoiselle.management.annotation.Operation; | |
7 | -import br.gov.frameworkdemoiselle.management.annotation.Property; | |
8 | -import br.gov.frameworkdemoiselle.management.annotation.validation.AllowedValues; | |
9 | -import br.gov.frameworkdemoiselle.management.annotation.validation.AllowedValues.ValueType; | |
41 | +import br.gov.frameworkdemoiselle.annotation.ManagedOperation; | |
42 | +import br.gov.frameworkdemoiselle.annotation.ManagedProperty; | |
43 | +import br.gov.frameworkdemoiselle.stereotype.ManagementController; | |
44 | +import br.gov.frameworkdemoiselle.validation.annotation.AllowedValues; | |
45 | +import br.gov.frameworkdemoiselle.validation.annotation.AllowedValues.ValueType; | |
10 | 46 | |
11 | -@Managed | |
47 | +@ManagementController | |
12 | 48 | public class DummyManagedClass { |
13 | 49 | |
14 | - @Property | |
15 | - @AllowedValues(allows={"f","m","F","M"},valueType=ValueType.INTEGER) | |
50 | + @ManagedProperty | |
51 | + private String name; | |
52 | + | |
53 | + @ManagedProperty | |
54 | + @AllowedValues(allows={"1","2","3","4"},valueType=ValueType.INTEGER) | |
16 | 55 | private Integer id; |
17 | 56 | |
18 | - @Property | |
57 | + @ManagedProperty | |
58 | + private Integer firstFactor , secondFactor; | |
59 | + | |
60 | + @ManagedProperty | |
19 | 61 | private String uuid; |
20 | 62 | |
21 | - @Property | |
63 | + @ManagedProperty | |
22 | 64 | private String writeOnlyProperty; |
23 | 65 | |
66 | + @ManagedProperty | |
67 | + private String readOnlyProperty = "Default Value"; | |
68 | + | |
24 | 69 | /** |
25 | 70 | * Propriedade para testar detecção de métodos GET e SET quando propriedade tem apenas uma letra. |
26 | 71 | */ |
27 | - @Property | |
72 | + @ManagedProperty | |
28 | 73 | private Integer a; |
29 | 74 | |
30 | 75 | /** |
31 | 76 | * Propriedade para testar detecção de métodos GET e SET quando propriedade tem apenas letras maiúsculas. |
32 | 77 | */ |
33 | - @Property | |
78 | + @ManagedProperty | |
34 | 79 | private Integer MAIUSCULO; |
35 | 80 | |
36 | 81 | public Integer getId() { |
... | ... | @@ -66,9 +111,92 @@ public class DummyManagedClass { |
66 | 111 | MAIUSCULO = mAIUSCULO; |
67 | 112 | } |
68 | 113 | |
69 | - @Operation(description="Generates a random UUID") | |
114 | + @ManagedOperation(description="Generates a random UUID") | |
70 | 115 | public String generateUUID(){ |
71 | 116 | this.uuid = UUID.randomUUID().toString(); |
72 | 117 | return this.uuid; |
73 | 118 | } |
119 | + | |
120 | + | |
121 | + public String getName() { | |
122 | + return name; | |
123 | + } | |
124 | + | |
125 | + | |
126 | + public void setName(String name) { | |
127 | + this.name = name; | |
128 | + } | |
129 | + | |
130 | + | |
131 | + public String getReadOnlyProperty() { | |
132 | + return readOnlyProperty; | |
133 | + } | |
134 | + | |
135 | + | |
136 | + public Integer getFirstFactor() { | |
137 | + return firstFactor; | |
138 | + } | |
139 | + | |
140 | + | |
141 | + public void setFirstFactor(Integer firstFactor) { | |
142 | + this.firstFactor = firstFactor; | |
143 | + } | |
144 | + | |
145 | + | |
146 | + public Integer getSecondFactor() { | |
147 | + return secondFactor; | |
148 | + } | |
149 | + | |
150 | + | |
151 | + public void setSecondFactor(Integer secondFactor) { | |
152 | + this.secondFactor = secondFactor; | |
153 | + } | |
154 | + | |
155 | + @ManagedOperation | |
156 | + public Integer calculateFactorsNonSynchronized(Integer firstFactor , Integer secondFactor){ | |
157 | + setFirstFactor(firstFactor); | |
158 | + setSecondFactor(secondFactor); | |
159 | + | |
160 | + try { | |
161 | + int temp = firstFactor + secondFactor; | |
162 | + Thread.sleep( (long)(Math.random() * 100)); | |
163 | + | |
164 | + temp = temp + firstFactor; | |
165 | + Thread.sleep( (long)(Math.random() * 100)); | |
166 | + | |
167 | + temp = temp + secondFactor; | |
168 | + Thread.sleep( (long)(Math.random() * 100)); | |
169 | + | |
170 | + return temp; | |
171 | + } catch (InterruptedException e) { | |
172 | + throw new RuntimeException(e); | |
173 | + } | |
174 | + } | |
175 | + | |
176 | + @ManagedOperation | |
177 | + public synchronized Integer calculateFactorsSynchronized(Integer firstFactor , Integer secondFactor){ | |
178 | + setFirstFactor(firstFactor); | |
179 | + setSecondFactor(secondFactor); | |
180 | + | |
181 | + try { | |
182 | + int temp = firstFactor + secondFactor; | |
183 | + Thread.sleep( (long)(Math.random() * 100)); | |
184 | + | |
185 | + temp = temp + firstFactor; | |
186 | + Thread.sleep( (long)(Math.random() * 100)); | |
187 | + | |
188 | + temp = temp + secondFactor; | |
189 | + Thread.sleep( (long)(Math.random() * 100)); | |
190 | + | |
191 | + return temp; | |
192 | + } catch (InterruptedException e) { | |
193 | + throw new RuntimeException(e); | |
194 | + } | |
195 | + } | |
196 | + | |
197 | + public void nonOperationAnnotatedMethod(){ | |
198 | + System.out.println("Test"); | |
199 | + } | |
200 | + | |
201 | + | |
74 | 202 | } | ... | ... |
impl/core/src/test/java/management/testclasses/DummyManagedClassPropertyError.java
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
1 | 37 | package management.testclasses; |
2 | 38 | |
3 | -import br.gov.frameworkdemoiselle.management.annotation.Managed; | |
4 | -import br.gov.frameworkdemoiselle.management.annotation.Property; | |
39 | +import br.gov.frameworkdemoiselle.annotation.ManagedProperty; | |
40 | +import br.gov.frameworkdemoiselle.stereotype.ManagementController; | |
5 | 41 | |
6 | 42 | |
7 | 43 | /** |
... | ... | @@ -11,13 +47,13 @@ import br.gov.frameworkdemoiselle.management.annotation.Property; |
11 | 47 | * @author serpro |
12 | 48 | * |
13 | 49 | */ |
14 | -@Managed | |
50 | +@ManagementController | |
15 | 51 | public class DummyManagedClassPropertyError { |
16 | 52 | |
17 | 53 | /** |
18 | - * Property with no setter or getter | |
54 | + * ManagedProperty with no setter or getter | |
19 | 55 | */ |
20 | - @Property | |
56 | + @ManagedProperty | |
21 | 57 | private Long property; |
22 | 58 | |
23 | 59 | } | ... | ... |
impl/core/src/test/java/management/testclasses/DummyManagementExtension.java
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
1 | 37 | package management.testclasses; |
2 | 38 | |
3 | 39 | import java.util.List; |
4 | 40 | |
5 | 41 | import javax.inject.Inject; |
6 | 42 | |
7 | -import management.ManagedClassStore; | |
8 | 43 | |
9 | -import br.gov.frameworkdemoiselle.management.extension.ManagementExtension; | |
10 | -import br.gov.frameworkdemoiselle.management.internal.ManagedType; | |
44 | +import br.gov.frameworkdemoiselle.internal.management.ManagedType; | |
45 | +import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; | |
11 | 46 | |
12 | 47 | public class DummyManagementExtension implements ManagementExtension { |
13 | 48 | ... | ... |
impl/core/src/test/java/management/testclasses/DummyNotificationListener.java
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
1 | 37 | package management.testclasses; |
2 | 38 | |
3 | 39 | import javax.enterprise.context.ApplicationScoped; |
4 | 40 | import javax.enterprise.event.Observes; |
5 | 41 | |
6 | -import br.gov.frameworkdemoiselle.management.internal.notification.event.NotificationEvent; | |
7 | -import br.gov.frameworkdemoiselle.management.internal.notification.qualifier.AttributeChange; | |
8 | -import br.gov.frameworkdemoiselle.management.internal.notification.qualifier.Generic; | |
9 | -import br.gov.frameworkdemoiselle.management.notification.AttributeChangeNotification; | |
10 | -import br.gov.frameworkdemoiselle.management.notification.NotificationManager; | |
42 | +import br.gov.frameworkdemoiselle.internal.management.ManagementNotificationEvent; | |
43 | +import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange; | |
44 | +import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic; | |
45 | +import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | |
46 | +import br.gov.frameworkdemoiselle.management.NotificationManager; | |
11 | 47 | |
12 | 48 | /** |
13 | 49 | * Dummy class to test receiving of notifications sent by the {@link NotificationManager} |
... | ... | @@ -20,11 +56,11 @@ public class DummyNotificationListener { |
20 | 56 | |
21 | 57 | private String message = null; |
22 | 58 | |
23 | - public void listenNotification(@Observes @Generic NotificationEvent event){ | |
59 | + public void listenNotification(@Observes @Generic ManagementNotificationEvent event){ | |
24 | 60 | message = event.getNotification().getMessage().toString(); |
25 | 61 | } |
26 | 62 | |
27 | - public void listenAttributeChangeNotification(@Observes @AttributeChange NotificationEvent event){ | |
63 | + public void listenAttributeChangeNotification(@Observes @AttributeChange ManagementNotificationEvent event){ | |
28 | 64 | AttributeChangeNotification notification = (AttributeChangeNotification)event.getNotification(); |
29 | 65 | message = notification.getMessage().toString() + " - " + notification.getAttributeName(); |
30 | 66 | } | ... | ... |
impl/core/src/test/java/management/testclasses/ManagedClassStore.java
0 → 100644
... | ... | @@ -0,0 +1,102 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package management.testclasses; | |
38 | + | |
39 | +import java.util.ArrayList; | |
40 | +import java.util.Collection; | |
41 | +import java.util.List; | |
42 | + | |
43 | +import javax.enterprise.context.ApplicationScoped; | |
44 | + | |
45 | +import br.gov.frameworkdemoiselle.internal.management.ManagedType; | |
46 | +import br.gov.frameworkdemoiselle.internal.management.Management; | |
47 | +import br.gov.frameworkdemoiselle.util.Beans; | |
48 | + | |
49 | +/** | |
50 | + * Dummy class that stores managed types detected by the management bootstrap | |
51 | + * and can read/write properties and invoke operations on them, simulating a management | |
52 | + * extension like JMX or SNMP. | |
53 | + * | |
54 | + * @author serpro | |
55 | + * | |
56 | + */ | |
57 | +@ApplicationScoped | |
58 | +public class ManagedClassStore { | |
59 | + | |
60 | + private List<ManagedType> managedTypes = new ArrayList<ManagedType>(); | |
61 | + | |
62 | + | |
63 | + public List<ManagedType> getManagedTypes() { | |
64 | + return managedTypes; | |
65 | + } | |
66 | + | |
67 | + public void addManagedTypes(Collection<ManagedType> managedTypes){ | |
68 | + this.managedTypes.addAll(managedTypes); | |
69 | + } | |
70 | + | |
71 | + public void setProperty(Class<?> managedClass , String attributeName , Object newValue){ | |
72 | + Management manager = Beans.getReference(Management.class); | |
73 | + for (ManagedType type : manager.getManagedTypes()){ | |
74 | + if (type.getType().equals(managedClass)){ | |
75 | + manager.setProperty(type, attributeName, newValue); | |
76 | + break; | |
77 | + } | |
78 | + } | |
79 | + } | |
80 | + | |
81 | + public Object getProperty(Class<?> managedClass , String attributeName ){ | |
82 | + Management manager = Beans.getReference(Management.class); | |
83 | + for (ManagedType type : manager.getManagedTypes()){ | |
84 | + if (type.getType().equals(managedClass)){ | |
85 | + return manager.getProperty(type, attributeName); | |
86 | + } | |
87 | + } | |
88 | + | |
89 | + return null; | |
90 | + } | |
91 | + | |
92 | + public Object invoke(Class<?> managedClass , String operation , Object... params){ | |
93 | + Management manager = Beans.getReference(Management.class); | |
94 | + for (ManagedType type : manager.getManagedTypes()){ | |
95 | + if (type.getType().equals(managedClass)){ | |
96 | + return manager.invoke(type, operation, params); | |
97 | + } | |
98 | + } | |
99 | + | |
100 | + return null; | |
101 | + } | |
102 | +} | ... | ... |