diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/configuration/JMXConfig.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/configuration/JMXConfig.java
deleted file mode 100644
index 60e2ccb..0000000
--- a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/configuration/JMXConfig.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Demoiselle Framework
- * Copyright (C) 2010 SERPRO
- * ----------------------------------------------------------------------------
- * This file is part of Demoiselle Framework.
- *
- * Demoiselle Framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License version 3
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License version 3
- * along with this program; if not, see
- * or write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- * ----------------------------------------------------------------------------
- * Este arquivo é parte do Framework Demoiselle.
- *
- * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
- * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
- * do Software Livre (FSF).
- *
- * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
- * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
- * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
- * para maiores detalhes.
- *
- * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
- * "LICENCA.txt", junto com esse programa. Se não, acesse
- * ou escreva para a Fundação do Software Livre (FSF) Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-package br.gov.frameworkdemoiselle.configuration;
-
-import javax.management.NotificationBroadcaster;
-
-import br.gov.frameworkdemoiselle.annotation.Name;
-import br.gov.frameworkdemoiselle.configuration.Configuration;
-import br.gov.frameworkdemoiselle.stereotype.ManagementController;
-
-/**
- *
- * Contains configuration parameters to control how {@link Managed} classes are exposed to the MBean server.
- *
- * To use this class, inject it into your code using the {@link Inject} annotation.
- *
- * ex:
- *
- * public class BusinessClass(){
- *
- * //...
- *
- * &at;Inject
- * private JMXConfig jmxConfiguration;
- *
- * //...
- *
- * }
- *
- *
- * @author serpro
- *
- */
-@Configuration(prefix = "frameworkdemoiselle.management.jmx.")
-public class JMXConfig {
-
- @Name("mbean.domain")
- private String mbeanDomain;
-
- @Name("notification.domain")
- private String notificationDomain = "br.gov.frameworkdemoiselle.jmx";
-
- @Name("notification.name")
- private String notificationMBeanName = "NotificationBroadcaster";
-
- /**
- * The domain to register all {@link ManagementController} classes found during boot.
- *
- * The full name of a MBean has the format of domain:name=MBeanName
(ex: br.gov.frameworkdemoiselle.jmx:name=NotificationBroadcaster
), this
- * parameter is the "domain" portion of the full name.
- *
- * The default is null
and when is set to null
, all {@link Managed} classes will use it's own package as the domain.
- *
- */
- public String getMbeanDomain() {
- return mbeanDomain;
- }
-
- /**
- * @see #getMbeanDomain()
- */
- public void setMbeanDomain(String mbeanDomain) {
- this.mbeanDomain = mbeanDomain;
- }
-
- /**
- * The name the {@link NotificationBroadcaster} MBean will be registered to. The full name
- * of a MBean has the format of domain:name=MBeanName
(ex: br.gov.frameworkdemoiselle.jmx:name=NotificationBroadcaster
), this
- * parameter is the ":name=MBeanName" portion without the ":name=".
- *
- * The default is the value returned by {@link Class#getSimpleName()} when called from the {@link NotificationBroadcaster} class.
- *
- * @see #getMbeanDomain()
- */
- public String getNotificationMBeanName() {
- return notificationMBeanName;
- }
-
- /**
- * @see #getNotificationMBeanName()
- */
- public void setNotificationMBeanName(String notificationMBeanName) {
- this.notificationMBeanName = notificationMBeanName;
- }
-
- /**
- * The domain to register the {@link NotificationBroadcaster} MBean.
- *
- * The full name of a MBean has the format of domain:name=MBeanName
(ex: br.gov.frameworkdemoiselle.jmx:name=NotificationBroadcaster
), this
- * parameter is the "domain" portion of the full name.
- *
- * The default is br.gov.frameworkdemoiselle.jmx
.
- *
- */
- public String getNotificationDomain() {
- return notificationDomain;
- }
-
- /**
- * @see #getNotificationDomain()
- */
- public void setNotificationDomain(String notificationDomain) {
- this.notificationDomain = notificationDomain;
- }
-
-
-
-}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/DynamicMBeanProxy.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/DynamicMBeanProxy.java
deleted file mode 100644
index a05dae8..0000000
--- a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/DynamicMBeanProxy.java
+++ /dev/null
@@ -1,300 +0,0 @@
-/*
- * Demoiselle Framework
- * Copyright (C) 2010 SERPRO
- * ----------------------------------------------------------------------------
- * This file is part of Demoiselle Framework.
- *
- * Demoiselle Framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License version 3
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License version 3
- * along with this program; if not, see
- * or write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- * ----------------------------------------------------------------------------
- * Este arquivo é parte do Framework Demoiselle.
- *
- * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
- * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
- * do Software Livre (FSF).
- *
- * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
- * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
- * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
- * para maiores detalhes.
- *
- * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
- * "LICENCA.txt", junto com esse programa. Se não, acesse
- * ou escreva para a Fundação do Software Livre (FSF) Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-package br.gov.frameworkdemoiselle.internal;
-
-import java.util.ArrayList;
-import java.util.Locale;
-import java.util.Map.Entry;
-
-import javax.management.Attribute;
-import javax.management.AttributeList;
-import javax.management.AttributeNotFoundException;
-import javax.management.DynamicMBean;
-import javax.management.InvalidAttributeValueException;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanException;
-import javax.management.MBeanInfo;
-import javax.management.MBeanOperationInfo;
-import javax.management.MBeanParameterInfo;
-import javax.management.ReflectionException;
-
-import br.gov.frameworkdemoiselle.DemoiselleException;
-import br.gov.frameworkdemoiselle.internal.management.ManagedType;
-import br.gov.frameworkdemoiselle.internal.management.ManagedType.FieldDetail;
-import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail;
-import br.gov.frameworkdemoiselle.internal.management.ManagedType.ParameterDetail;
-import br.gov.frameworkdemoiselle.internal.management.Management;
-import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException;
-import br.gov.frameworkdemoiselle.management.ManagedInvokationException;
-import br.gov.frameworkdemoiselle.stereotype.ManagementController;
-import br.gov.frameworkdemoiselle.util.Beans;
-import br.gov.frameworkdemoiselle.util.ResourceBundle;
-
-/**
- *
- * This class is a MBean that gets registered everytime you mark a class with {@link ManagementController}. It dynamicaly reads the
- * fields and operations contained in a {@link ManagementController} class and exposes them to the MBean server. Everytime a client
- * tries to call an operation or read/write a property inside a ManagementController class, this class will call the appropriate
- * method and pass the result to the MBean client.
- *
- *
- * @author SERPRO
- */
-public class DynamicMBeanProxy implements DynamicMBean {
-
- private MBeanInfo delegateInfo;
-
- private ManagedType managedType;
-
- private ResourceBundle bundle;
-
- public DynamicMBeanProxy(ManagedType type) {
- if (type == null) {
- throw new NullPointerException(getBundle().getString("mbean-null-type-defined"));
- }
- managedType = type;
- }
-
- @Override
- public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
- // Se o bean ainda não foi lido para determinar seus atributos, o faz agora.
- if (delegateInfo == null) {
- initializeMBeanInfo();
- }
-
- Management manager = Beans.getReference(Management.class);
-
- try{
- return manager.getProperty(managedType, attribute);
- }
- catch(DemoiselleException de){
- if (ManagedAttributeNotFoundException.class.isInstance(de)){
- throw new AttributeNotFoundException(de.getMessage());
- }
- else if (ManagedInvokationException.class.isInstance(de)){
- throw new MBeanException(new Exception(de.getMessage()));
- }
- else{
- throw de;
- }
- }
- }
-
- @Override
- public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException,
- MBeanException, ReflectionException {
-
- // Se o bean ainda não foi lido para determinar seus atributos, o faz agora.
- if (delegateInfo == null) {
- initializeMBeanInfo();
- }
-
- Management manager = Beans.getReference(Management.class);
-
- try{
- manager.setProperty(managedType, attribute.getName(), attribute.getValue());
- }
- catch(DemoiselleException de){
- if (ManagedAttributeNotFoundException.class.isInstance(de)){
- throw new AttributeNotFoundException(de.getMessage());
- }
- else if (ManagedInvokationException.class.isInstance(de)){
- throw new MBeanException(new Exception(de.getMessage()));
- }
- else{
- throw de;
- }
- }
- }
-
- @Override
- public AttributeList getAttributes(String[] attributes) {
- if (attributes != null) {
- AttributeList list = new AttributeList();
- for (String attribute : attributes) {
- try {
- Object value = getAttribute(attribute);
- list.add(new Attribute(attribute, value));
- } catch (Throwable t) {
- }
- }
-
- return list;
- }
-
- return null;
- }
-
- @Override
- public AttributeList setAttributes(AttributeList attributes) {
- AttributeList settedAttributes = new AttributeList();
- if (attributes != null) {
- for (Attribute attribute : attributes.asList()) {
- try {
- setAttribute(attribute);
-
- // A razão para separarmos a criação do atributo de sua adição na lista é que
- // caso a obtenção do novo valor do atributo dispare uma exceção então o atributo não será
- // adicionado na lista de atributos que foram afetados.
- Attribute attributeWithNewValue = new Attribute(attribute.getName(),
- getAttribute(attribute.getName()));
- settedAttributes.add(attributeWithNewValue);
- } catch (Throwable t) {
- }
- }
- }
-
- return settedAttributes;
- }
-
- @Override
- public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException,
- ReflectionException {
-
- // Se o bean ainda não foi lido para determinar seus atributos, o faz agora.
- if (this.delegateInfo == null) {
- initializeMBeanInfo();
- }
-
- Management manager = Beans.getReference(Management.class);
-
- try{
- return manager.invoke(managedType, actionName, params);
- }
- catch(DemoiselleException de){
- throw new MBeanException(new Exception(de.getMessage()));
- }
- }
-
- /**
- * Initialize the Managed information for this instance of Managed
- */
- private void initializeMBeanInfo() {
- // Aqui vamos armazenar nossos atributos
- ArrayList attributes = new ArrayList();
-
- // Aqui vamos armazenar nossas operações
- ArrayList operations = new ArrayList();
-
- // Para cada propriedade descoberta no ManagementController, cria um attributeInfo correspondente
- for (Entry fieldEntry : managedType.getFields().entrySet()) {
-
- try {
-
- MBeanAttributeInfo attributeInfo = new MBeanAttributeInfo(fieldEntry.getKey(), fieldEntry.getValue()
- .getDescription(), fieldEntry.getValue().getGetterMethod(), fieldEntry.getValue()
- .getSetterMethod());
- attributes.add(attributeInfo);
-
- } catch (javax.management.IntrospectionException e) {
- throw new DemoiselleException(getBundle().getString("mbean-introspection-error", managedType.getType()
- .getSimpleName()));
- }
- }
-
- // Para cada operação descoberta no ManagementController, cria um operationInfo correspondente
- for (Entry methodEntry : managedType.getOperationMethods().entrySet()) {
-
- MethodDetail methodDetail = methodEntry.getValue();
-
- ParameterDetail[] parameterTypes = methodDetail.getParameterTypers();
-
- MBeanParameterInfo[] parameters = parameterTypes.length > 0 ? new MBeanParameterInfo[parameterTypes.length]
- : null;
-
- if (parameters != null) {
-
- for (int i = 0; i < parameterTypes.length; i++) {
-
- parameters[i] = new MBeanParameterInfo(parameterTypes[i].getParameterName(), parameterTypes[i]
- .getParameterType().getCanonicalName(), parameterTypes[i].getParameterDescription());
- }
- }
-
- // Com todas as informações, criamos nossa instância de MBeanOperationInfo e
- // acrescentamos na lista de todas as operações.
- int operationType = 0;
- switch(methodDetail.getType()){
- case ACTION:
- operationType = MBeanOperationInfo.ACTION;
- break;
-
- case INFO:
- operationType = MBeanOperationInfo.INFO;
- break;
-
- case ACTION_INFO:
- operationType = MBeanOperationInfo.ACTION_INFO;
- break;
-
- default:
- operationType = MBeanOperationInfo.UNKNOWN;
- }
-
- MBeanOperationInfo operation = new MBeanOperationInfo(methodDetail.getMethod().getName(),
- methodDetail.getDescription(), parameters, methodDetail.getMethod().getReturnType().getName(),
- operationType);
-
- operations.add(operation);
-
- }
-
- // Por fim criamos nosso bean info.
- delegateInfo = new MBeanInfo(managedType.getType().getCanonicalName(), managedType.getDescription(),
- attributes.toArray(new MBeanAttributeInfo[0]), null, operations.toArray(new MBeanOperationInfo[0]),
- null);
-
- }
-
- @Override
- public MBeanInfo getMBeanInfo() {
- if (delegateInfo == null) {
- initializeMBeanInfo();
- }
-
- return delegateInfo;
- }
-
- public ResourceBundle getBundle(){
- if (bundle==null){
- bundle = new ResourceBundle("demoiselle-jmx-bundle", Locale.getDefault());
- }
-
- return bundle;
- }
-
-}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/JMXManagementExtension.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/JMXManagementExtension.java
deleted file mode 100644
index 9ddfdf1..0000000
--- a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/JMXManagementExtension.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Demoiselle Framework
- * Copyright (C) 2010 SERPRO
- * ----------------------------------------------------------------------------
- * This file is part of Demoiselle Framework.
- *
- * Demoiselle Framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License version 3
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License version 3
- * along with this program; if not, see
- * or write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- * ----------------------------------------------------------------------------
- * Este arquivo é parte do Framework Demoiselle.
- *
- * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
- * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
- * do Software Livre (FSF).
- *
- * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
- * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
- * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
- * para maiores detalhes.
- *
- * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
- * "LICENCA.txt", junto com esse programa. Se não, acesse
- * ou escreva para a Fundação do Software Livre (FSF) Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-package br.gov.frameworkdemoiselle.internal;
-
-import java.util.List;
-
-import javax.management.ObjectInstance;
-
-import br.gov.frameworkdemoiselle.annotation.Name;
-import br.gov.frameworkdemoiselle.configuration.JMXConfig;
-import br.gov.frameworkdemoiselle.internal.management.ManagedType;
-import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension;
-import br.gov.frameworkdemoiselle.util.Beans;
-
-public class JMXManagementExtension implements ManagementExtension {
-
- public void registerNotificationMBean(){
- MBeanManager mbeanManager = Beans.getReference(MBeanManager.class);
- JMXConfig configuration = Beans.getReference(JMXConfig.class);
-
- StringBuffer notificationMBeanName = new StringBuffer()
- .append( configuration.getNotificationDomain()!=null ? configuration.getNotificationDomain() : "br.gov.frameworkdemoiselle.jmx" )
- .append(":name=")
- .append(configuration.getNotificationMBeanName());
-
- if (mbeanManager.findMBeanInstance(notificationMBeanName.toString()) == null){
- NotificationEventListener listener = Beans.getReference(NotificationEventListener.class);
-
- ObjectInstance instance = MBeanHelper.register(listener.createNotificationBroadcaster(), notificationMBeanName.toString());
- mbeanManager.storeRegisteredMBean(instance);
- }
- }
-
- @Override
- public void initialize(List managedTypes) {
- MBeanManager manager = Beans.getReference(MBeanManager.class);
- JMXConfig configuration = Beans.getReference(JMXConfig.class);
-
- for (ManagedType type : managedTypes) {
- DynamicMBeanProxy beanProxy = new DynamicMBeanProxy(type);
-
- Name nameAnnotation = type.getType().getAnnotation(Name.class);
- String mbeanName = nameAnnotation != null ? nameAnnotation.value() : type.getType().getSimpleName();
-
- StringBuffer name = new StringBuffer()
- .append( configuration.getMbeanDomain()!=null ? configuration.getMbeanDomain() : type.getType().getPackage().getName() )
- .append(":name=")
- .append( mbeanName );
-
-
- if (manager.findMBeanInstance(name.toString()) == null){
- ObjectInstance instance = MBeanHelper.register(beanProxy, name.toString());
- manager.storeRegisteredMBean(instance);
- }
- }
-
- registerNotificationMBean();
- }
-
- @Override
- public void shutdown(List managedTypes) {
- MBeanManager manager = Beans.getReference(MBeanManager.class);
- for (ObjectInstance instance : manager.listRegisteredMBeans()){
- MBeanHelper.unregister(instance.getObjectName());
- }
-
- manager.cleanRegisteredMBeans();
- }
-
-}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/MBeanHelper.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/MBeanHelper.java
deleted file mode 100644
index a7b08ad..0000000
--- a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/MBeanHelper.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Demoiselle Framework
- * Copyright (C) 2010 SERPRO
- * ----------------------------------------------------------------------------
- * This file is part of Demoiselle Framework.
- *
- * Demoiselle Framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License version 3
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License version 3
- * along with this program; if not, see
- * or write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- * ----------------------------------------------------------------------------
- * Este arquivo é parte do Framework Demoiselle.
- *
- * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
- * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
- * do Software Livre (FSF).
- *
- * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
- * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
- * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
- * para maiores detalhes.
- *
- * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
- * "LICENCA.txt", junto com esse programa. Se não, acesse
- * ou escreva para a Fundação do Software Livre (FSF) Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-package br.gov.frameworkdemoiselle.internal;
-
-import java.lang.management.ManagementFactory;
-import java.util.Locale;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectInstance;
-import javax.management.ObjectName;
-
-import org.slf4j.Logger;
-
-import br.gov.frameworkdemoiselle.DemoiselleException;
-import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
-import br.gov.frameworkdemoiselle.util.ResourceBundle;
-
-/**
- * Class with common tools for registering MBeans into an Managed server
- *
- * @author SERPRO
- */
-public class MBeanHelper {
-
- private static final Logger logger = LoggerProducer.create(MBeanHelper.class);
-
- private static ResourceBundle bundle = new ResourceBundle("demoiselle-jmx-bundle", Locale.getDefault());
-
- private static final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
-
- /**
- * Return the MBean Server instance.
- *
- * @return MBeanServer
- */
- public static final MBeanServer getMBeanServer() {
- return server;
- }
-
- /**
- * Register a given managed bean (MBean) with the specified name.
- *
- * @param mbean
- * the managed bean to register
- * @param name
- * the name under which to register the bean
- * @return the object name of the mbean, for later deregistration
- */
- public static ObjectInstance register(final Object mbean, final String name) {
-
- logger.info(bundle.getString("mbean-registration",name));
-
- ObjectInstance instance = null;
- try {
- ObjectName objectName = new ObjectName(name);
- instance = server.registerMBean(mbean, objectName);
- } catch (Exception e) {
- logger.error(bundle.getString("mbean-registration-error",name),e);
- throw new DemoiselleException(bundle.getString("mbean-registration-error",name), e);
- }
-
- return instance;
- }
-
- /**
- * Remove the registration of a mbean.
- *
- * @param objectName
- * the name of the bean to unregister
- */
- public static void unregister(final ObjectName objectName) {
-
- logger.info(bundle.getString("mbean-deregistration",objectName.getCanonicalName()));
-
- try {
- server.unregisterMBean(objectName);
- } catch (Exception e) {
- logger.error(bundle.getString("mbean-deregistration",objectName.getCanonicalName()),e);
- throw new DemoiselleException(bundle.getString("mbean-deregistration",objectName.getCanonicalName()), e);
- }
- }
-}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/MBeanManager.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/MBeanManager.java
deleted file mode 100644
index 6e681f0..0000000
--- a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/MBeanManager.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Demoiselle Framework
- * Copyright (C) 2010 SERPRO
- * ----------------------------------------------------------------------------
- * This file is part of Demoiselle Framework.
- *
- * Demoiselle Framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License version 3
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License version 3
- * along with this program; if not, see
- * or write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- * ----------------------------------------------------------------------------
- * Este arquivo é parte do Framework Demoiselle.
- *
- * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
- * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
- * do Software Livre (FSF).
- *
- * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
- * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
- * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
- * para maiores detalhes.
- *
- * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
- * "LICENCA.txt", junto com esse programa. Se não, acesse
- * ou escreva para a Fundação do Software Livre (FSF) Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-package br.gov.frameworkdemoiselle.internal;
-
-import java.util.Collection;
-import java.util.HashMap;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.management.ObjectInstance;
-
-@ApplicationScoped
-public class MBeanManager {
-
- private HashMap registeredMBeans = new HashMap();
-
- public void storeRegisteredMBean(ObjectInstance instance){
- registeredMBeans.put(instance.getObjectName().getCanonicalName(),instance);
- }
-
- public Collection listRegisteredMBeans(){
- return registeredMBeans.values();
- }
-
- public ObjectInstance findMBeanInstance(String name){
- ObjectInstance instance = registeredMBeans.get(name);
- return instance;
- }
-
- public void cleanRegisteredMBeans(){
- registeredMBeans.clear();
- }
-
-}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationBroadcaster.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationBroadcaster.java
deleted file mode 100644
index 9ff41c9..0000000
--- a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationBroadcaster.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Demoiselle Framework
- * Copyright (C) 2010 SERPRO
- * ----------------------------------------------------------------------------
- * This file is part of Demoiselle Framework.
- *
- * Demoiselle Framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License version 3
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License version 3
- * along with this program; if not, see
- * or write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- * ----------------------------------------------------------------------------
- * Este arquivo é parte do Framework Demoiselle.
- *
- * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
- * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
- * do Software Livre (FSF).
- *
- * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
- * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
- * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
- * para maiores detalhes.
- *
- * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
- * "LICENCA.txt", junto com esse programa. Se não, acesse
- * ou escreva para a Fundação do Software Livre (FSF) Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-package br.gov.frameworkdemoiselle.internal;
-
-import java.io.Serializable;
-
-import javax.management.AttributeChangeNotification;
-import javax.management.Notification;
-import javax.management.NotificationBroadcasterSupport;
-
-import br.gov.frameworkdemoiselle.configuration.JMXConfig;
-import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent;
-import br.gov.frameworkdemoiselle.management.NotificationManager;
-
-/**
- * Implementation of the {@link NotificationBroadcaster} MBean.
- * When the {@link NotificationManager} sends an event, a {@link NotificationEventListener} captures the notification and uses
- * this MBean to send it as a JMX notification.
- *
- * @author serpro
- *
- */
-public final class NotificationBroadcaster extends NotificationBroadcasterSupport implements NotificationBroadcasterMBean,Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private int sequenceNumber = 1;
-
- private static final String NOTIFICATION_TYPE_GENERIC = "jmx.message";
-
- protected void sendNotification( ManagementNotificationEvent event , JMXConfig config ) {
- br.gov.frameworkdemoiselle.management.GenericNotification demoiselleNotification = event.getNotification();
- Notification n = new Notification(NOTIFICATION_TYPE_GENERIC, config.getNotificationMBeanName(), sequenceNumber++, System.currentTimeMillis(), demoiselleNotification.getMessage().toString());
- sendNotification(n);
- }
-
- protected void sendAttributeChangedMessage( ManagementNotificationEvent event , JMXConfig config ) {
- br.gov.frameworkdemoiselle.management.AttributeChangeNotification demoiselleNotification = (br.gov.frameworkdemoiselle.management.AttributeChangeNotification)event.getNotification();
-
- AttributeChangeNotification n = new AttributeChangeNotification(config.getNotificationMBeanName(), sequenceNumber++
- , System.currentTimeMillis(), demoiselleNotification.getMessage().toString()
- , demoiselleNotification.getAttributeName(), demoiselleNotification.getAttributeType().getSimpleName()
- , demoiselleNotification.getOldValue(), demoiselleNotification.getNewValue());
-
- sendNotification(n);
- }
-
-}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationBroadcasterMBean.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationBroadcasterMBean.java
deleted file mode 100644
index 56aa5cb..0000000
--- a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationBroadcasterMBean.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Demoiselle Framework
- * Copyright (C) 2010 SERPRO
- * ----------------------------------------------------------------------------
- * This file is part of Demoiselle Framework.
- *
- * Demoiselle Framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License version 3
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License version 3
- * along with this program; if not, see
- * or write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- * ----------------------------------------------------------------------------
- * Este arquivo é parte do Framework Demoiselle.
- *
- * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
- * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
- * do Software Livre (FSF).
- *
- * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
- * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
- * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
- * para maiores detalhes.
- *
- * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
- * "LICENCA.txt", junto com esse programa. Se não, acesse
- * ou escreva para a Fundação do Software Livre (FSF) Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-package br.gov.frameworkdemoiselle.internal;
-
-
-
-/**
- * MBean interface responsible for sending MBean notifications to remote clients.
- *
- * @author serpro
- *
- */
-public interface NotificationBroadcasterMBean {
-}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationEventListener.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationEventListener.java
deleted file mode 100644
index 7936266..0000000
--- a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationEventListener.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Demoiselle Framework
- * Copyright (C) 2010 SERPRO
- * ----------------------------------------------------------------------------
- * This file is part of Demoiselle Framework.
- *
- * Demoiselle Framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License version 3
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License version 3
- * along with this program; if not, see
- * or write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- * ----------------------------------------------------------------------------
- * Este arquivo é parte do Framework Demoiselle.
- *
- * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
- * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
- * do Software Livre (FSF).
- *
- * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
- * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
- * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
- * para maiores detalhes.
- *
- * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
- * "LICENCA.txt", junto com esse programa. Se não, acesse
- * ou escreva para a Fundação do Software Livre (FSF) Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-package br.gov.frameworkdemoiselle.internal;
-
-import java.io.Serializable;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-
-import br.gov.frameworkdemoiselle.configuration.JMXConfig;
-import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange;
-import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic;
-import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent;
-import br.gov.frameworkdemoiselle.management.NotificationManager;
-
-/**
- * Listens to {@link NotificationManager} notification events and proxies them
- * to a {@link NotificationBroadcaster} MBean. This MBean will send the notification to
- * any JMX clients connected and listening.
- *
- * @author serpro
- *
- */
-@ApplicationScoped
-@SuppressWarnings("serial")
-public class NotificationEventListener implements Serializable {
-
- private NotificationBroadcaster notificationBroadcaster;
-
- public void sendNotification( @Observes @Generic ManagementNotificationEvent event , JMXConfig config ) {
- createNotificationBroadcaster().sendNotification(event,config);
- }
-
- public void sendAttributeChangedMessage( @Observes @AttributeChange ManagementNotificationEvent event , JMXConfig config ) {
- createNotificationBroadcaster().sendAttributeChangedMessage(event, config);
- }
-
- public NotificationBroadcaster createNotificationBroadcaster(){
- if (notificationBroadcaster==null){
- notificationBroadcaster = new NotificationBroadcaster();
- }
-
- return notificationBroadcaster;
- }
-
-}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JMXConfig.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JMXConfig.java
new file mode 100644
index 0000000..f73a2fa
--- /dev/null
+++ b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JMXConfig.java
@@ -0,0 +1,142 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.configuration;
+
+import javax.management.NotificationBroadcaster;
+
+import br.gov.frameworkdemoiselle.annotation.Name;
+import br.gov.frameworkdemoiselle.configuration.Configuration;
+import br.gov.frameworkdemoiselle.stereotype.ManagementController;
+
+/**
+ *
+ * Contains configuration parameters to control how {@link Managed} classes are exposed to the MBean server.
+ *
+ * To use this class, inject it into your code using the {@link Inject} annotation.
+ *
+ * ex:
+ *
+ * public class BusinessClass(){
+ *
+ * //...
+ *
+ * &at;Inject
+ * private JMXConfig jmxConfiguration;
+ *
+ * //...
+ *
+ * }
+ *
+ *
+ * @author serpro
+ *
+ */
+@Configuration(prefix = "frameworkdemoiselle.management.jmx")
+public class JMXConfig {
+
+ @Name("mbean.domain")
+ private String mbeanDomain;
+
+ @Name("notification.domain")
+ private String notificationDomain = "br.gov.frameworkdemoiselle.jmx";
+
+ @Name("notification.name")
+ private String notificationMBeanName = "NotificationBroadcaster";
+
+ /**
+ * The domain to register all {@link ManagementController} classes found during boot.
+ *
+ * The full name of a MBean has the format of domain:name=MBeanName
(ex: br.gov.frameworkdemoiselle.jmx:name=NotificationBroadcaster
), this
+ * parameter is the "domain" portion of the full name.
+ *
+ * The default is null
and when is set to null
, all {@link Managed} classes will use it's own package as the domain.
+ *
+ */
+ public String getMbeanDomain() {
+ return mbeanDomain;
+ }
+
+ /**
+ * @see #getMbeanDomain()
+ */
+ public void setMbeanDomain(String mbeanDomain) {
+ this.mbeanDomain = mbeanDomain;
+ }
+
+ /**
+ * The name the {@link NotificationBroadcaster} MBean will be registered to. The full name
+ * of a MBean has the format of domain:name=MBeanName
(ex: br.gov.frameworkdemoiselle.jmx:name=NotificationBroadcaster
), this
+ * parameter is the ":name=MBeanName" portion without the ":name=".
+ *
+ * The default is the value returned by {@link Class#getSimpleName()} when called from the {@link NotificationBroadcaster} class.
+ *
+ * @see #getMbeanDomain()
+ */
+ public String getNotificationMBeanName() {
+ return notificationMBeanName;
+ }
+
+ /**
+ * @see #getNotificationMBeanName()
+ */
+ public void setNotificationMBeanName(String notificationMBeanName) {
+ this.notificationMBeanName = notificationMBeanName;
+ }
+
+ /**
+ * The domain to register the {@link NotificationBroadcaster} MBean.
+ *
+ * The full name of a MBean has the format of domain:name=MBeanName
(ex: br.gov.frameworkdemoiselle.jmx:name=NotificationBroadcaster
), this
+ * parameter is the "domain" portion of the full name.
+ *
+ * The default is br.gov.frameworkdemoiselle.jmx
.
+ *
+ */
+ public String getNotificationDomain() {
+ return notificationDomain;
+ }
+
+ /**
+ * @see #getNotificationDomain()
+ */
+ public void setNotificationDomain(String notificationDomain) {
+ this.notificationDomain = notificationDomain;
+ }
+
+
+
+}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/JMXManagementExtension.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/JMXManagementExtension.java
new file mode 100644
index 0000000..77b1662
--- /dev/null
+++ b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/JMXManagementExtension.java
@@ -0,0 +1,104 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.implementation;
+
+import java.util.List;
+
+import javax.management.ObjectInstance;
+
+import br.gov.frameworkdemoiselle.annotation.Name;
+import br.gov.frameworkdemoiselle.internal.configuration.JMXConfig;
+import br.gov.frameworkdemoiselle.internal.proxy.DynamicMBeanProxy;
+import br.gov.frameworkdemoiselle.management.ManagementExtension;
+import br.gov.frameworkdemoiselle.util.Beans;
+
+public class JMXManagementExtension implements ManagementExtension {
+
+ public void registerNotificationMBean(){
+ MBeanManager mbeanManager = Beans.getReference(MBeanManager.class);
+ JMXConfig configuration = Beans.getReference(JMXConfig.class);
+
+ StringBuffer notificationMBeanName = new StringBuffer()
+ .append( configuration.getNotificationDomain()!=null ? configuration.getNotificationDomain() : "br.gov.frameworkdemoiselle.jmx" )
+ .append(":name=")
+ .append(configuration.getNotificationMBeanName());
+
+ if (mbeanManager.findMBeanInstance(notificationMBeanName.toString()) == null){
+ NotificationEventListener listener = Beans.getReference(NotificationEventListener.class);
+
+ ObjectInstance instance = MBeanHelper.register(listener.createNotificationBroadcaster(), notificationMBeanName.toString());
+ mbeanManager.storeRegisteredMBean(instance);
+ }
+ }
+
+ @Override
+ public void initialize(List managedTypes) {
+ MBeanManager manager = Beans.getReference(MBeanManager.class);
+ JMXConfig configuration = Beans.getReference(JMXConfig.class);
+
+ for (ManagedType type : managedTypes) {
+ DynamicMBeanProxy beanProxy = new DynamicMBeanProxy(type);
+
+ Name nameAnnotation = type.getType().getAnnotation(Name.class);
+ String mbeanName = nameAnnotation != null ? nameAnnotation.value() : type.getType().getSimpleName();
+
+ StringBuffer name = new StringBuffer()
+ .append( configuration.getMbeanDomain()!=null ? configuration.getMbeanDomain() : type.getType().getPackage().getName() )
+ .append(":name=")
+ .append( mbeanName );
+
+
+ if (manager.findMBeanInstance(name.toString()) == null){
+ ObjectInstance instance = MBeanHelper.register(beanProxy, name.toString());
+ manager.storeRegisteredMBean(instance);
+ }
+ }
+
+ registerNotificationMBean();
+ }
+
+ @Override
+ public void shutdown(List managedTypes) {
+ MBeanManager manager = Beans.getReference(MBeanManager.class);
+ for (ObjectInstance instance : manager.listRegisteredMBeans()){
+ MBeanHelper.unregister(instance.getObjectName());
+ }
+
+ manager.cleanRegisteredMBeans();
+ }
+
+}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MBeanHelper.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MBeanHelper.java
new file mode 100644
index 0000000..2d476b9
--- /dev/null
+++ b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MBeanHelper.java
@@ -0,0 +1,116 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.implementation;
+
+import java.lang.management.ManagementFactory;
+import java.util.Locale;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+
+import org.slf4j.Logger;
+
+import br.gov.frameworkdemoiselle.DemoiselleException;
+import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer;
+import br.gov.frameworkdemoiselle.util.ResourceBundle;
+
+/**
+ * Class with common tools for registering MBeans into an Managed server
+ *
+ * @author SERPRO
+ */
+public class MBeanHelper {
+
+ private static final Logger logger = LoggerProducer.create(MBeanHelper.class);
+
+ private static ResourceBundle bundle = new ResourceBundle("demoiselle-jmx-bundle", Locale.getDefault());
+
+ private static final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+
+ /**
+ * Return the MBean Server instance.
+ *
+ * @return MBeanServer
+ */
+ public static final MBeanServer getMBeanServer() {
+ return server;
+ }
+
+ /**
+ * Register a given managed bean (MBean) with the specified name.
+ *
+ * @param mbean
+ * the managed bean to register
+ * @param name
+ * the name under which to register the bean
+ * @return the object name of the mbean, for later deregistration
+ */
+ public static ObjectInstance register(final Object mbean, final String name) {
+
+ logger.info(bundle.getString("mbean-registration",name));
+
+ ObjectInstance instance = null;
+ try {
+ ObjectName objectName = new ObjectName(name);
+ instance = server.registerMBean(mbean, objectName);
+ } catch (Exception e) {
+ logger.error(bundle.getString("mbean-registration-error",name),e);
+ throw new DemoiselleException(bundle.getString("mbean-registration-error",name), e);
+ }
+
+ return instance;
+ }
+
+ /**
+ * Remove the registration of a mbean.
+ *
+ * @param objectName
+ * the name of the bean to unregister
+ */
+ public static void unregister(final ObjectName objectName) {
+
+ logger.info(bundle.getString("mbean-deregistration",objectName.getCanonicalName()));
+
+ try {
+ server.unregisterMBean(objectName);
+ } catch (Exception e) {
+ logger.error(bundle.getString("mbean-deregistration",objectName.getCanonicalName()),e);
+ throw new DemoiselleException(bundle.getString("mbean-deregistration",objectName.getCanonicalName()), e);
+ }
+ }
+}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MBeanManager.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MBeanManager.java
new file mode 100644
index 0000000..0e0512c
--- /dev/null
+++ b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MBeanManager.java
@@ -0,0 +1,67 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.implementation;
+
+import java.util.Collection;
+import java.util.HashMap;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.management.ObjectInstance;
+
+@ApplicationScoped
+public class MBeanManager {
+
+ private HashMap registeredMBeans = new HashMap();
+
+ public void storeRegisteredMBean(ObjectInstance instance){
+ registeredMBeans.put(instance.getObjectName().getCanonicalName(),instance);
+ }
+
+ public Collection listRegisteredMBeans(){
+ return registeredMBeans.values();
+ }
+
+ public ObjectInstance findMBeanInstance(String name){
+ ObjectInstance instance = registeredMBeans.get(name);
+ return instance;
+ }
+
+ public void cleanRegisteredMBeans(){
+ registeredMBeans.clear();
+ }
+
+}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationBroadcaster.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationBroadcaster.java
new file mode 100644
index 0000000..db246f6
--- /dev/null
+++ b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationBroadcaster.java
@@ -0,0 +1,82 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.implementation;
+
+import java.io.Serializable;
+
+import javax.management.AttributeChangeNotification;
+import javax.management.Notification;
+import javax.management.NotificationBroadcasterSupport;
+
+import br.gov.frameworkdemoiselle.internal.configuration.JMXConfig;
+import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent;
+import br.gov.frameworkdemoiselle.management.NotificationManager;
+
+/**
+ * Implementation of the {@link NotificationBroadcaster} MBean.
+ * When the {@link NotificationManager} sends an event, a {@link NotificationEventListener} captures the notification and uses
+ * this MBean to send it as a JMX notification.
+ *
+ * @author serpro
+ *
+ */
+public final class NotificationBroadcaster extends NotificationBroadcasterSupport implements NotificationBroadcasterMBean,Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private int sequenceNumber = 1;
+
+ private static final String NOTIFICATION_TYPE_GENERIC = "jmx.message";
+
+ protected void sendNotification( ManagementNotificationEvent event , JMXConfig config ) {
+ br.gov.frameworkdemoiselle.management.GenericNotification demoiselleNotification = event.getNotification();
+ Notification n = new Notification(NOTIFICATION_TYPE_GENERIC, config.getNotificationMBeanName(), sequenceNumber++, System.currentTimeMillis(), demoiselleNotification.getMessage().toString());
+ sendNotification(n);
+ }
+
+ protected void sendAttributeChangedMessage( ManagementNotificationEvent event , JMXConfig config ) {
+ br.gov.frameworkdemoiselle.management.AttributeChangeNotification demoiselleNotification = (br.gov.frameworkdemoiselle.management.AttributeChangeNotification)event.getNotification();
+
+ AttributeChangeNotification n = new AttributeChangeNotification(config.getNotificationMBeanName(), sequenceNumber++
+ , System.currentTimeMillis(), demoiselleNotification.getMessage().toString()
+ , demoiselleNotification.getAttributeName(), demoiselleNotification.getAttributeType().getSimpleName()
+ , demoiselleNotification.getOldValue(), demoiselleNotification.getNewValue());
+
+ sendNotification(n);
+ }
+
+}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationBroadcasterMBean.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationBroadcasterMBean.java
new file mode 100644
index 0000000..8b45893
--- /dev/null
+++ b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationBroadcasterMBean.java
@@ -0,0 +1,48 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.implementation;
+
+
+
+/**
+ * MBean interface responsible for sending MBean notifications to remote clients.
+ *
+ * @author serpro
+ *
+ */
+public interface NotificationBroadcasterMBean {
+}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationEventListener.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationEventListener.java
new file mode 100644
index 0000000..f77bd18
--- /dev/null
+++ b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationEventListener.java
@@ -0,0 +1,78 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.implementation;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+
+import br.gov.frameworkdemoiselle.internal.configuration.JMXConfig;
+import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent;
+import br.gov.frameworkdemoiselle.management.NotificationManager;
+
+/**
+ * Listens to {@link NotificationManager} notification events and proxies them
+ * to a {@link NotificationBroadcaster} MBean. This MBean will send the notification to
+ * any JMX clients connected and listening.
+ *
+ * @author serpro
+ *
+ */
+@ApplicationScoped
+@SuppressWarnings("serial")
+public class NotificationEventListener implements Serializable {
+
+ private NotificationBroadcaster notificationBroadcaster;
+
+ public void sendNotification( @Observes @Generic ManagementNotificationEvent event , JMXConfig config ) {
+ createNotificationBroadcaster().sendNotification(event,config);
+ }
+
+ public void sendAttributeChangedMessage( @Observes @AttributeChange ManagementNotificationEvent event , JMXConfig config ) {
+ createNotificationBroadcaster().sendAttributeChangedMessage(event, config);
+ }
+
+ public NotificationBroadcaster createNotificationBroadcaster(){
+ if (notificationBroadcaster==null){
+ notificationBroadcaster = new NotificationBroadcaster();
+ }
+
+ return notificationBroadcaster;
+ }
+
+}
diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/DynamicMBeanProxy.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/DynamicMBeanProxy.java
new file mode 100644
index 0000000..4b91e91
--- /dev/null
+++ b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/DynamicMBeanProxy.java
@@ -0,0 +1,300 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package br.gov.frameworkdemoiselle.internal.proxy;
+
+import java.util.ArrayList;
+import java.util.Locale;
+import java.util.Map.Entry;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.DynamicMBean;
+import javax.management.InvalidAttributeValueException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanParameterInfo;
+import javax.management.ReflectionException;
+
+import br.gov.frameworkdemoiselle.DemoiselleException;
+import br.gov.frameworkdemoiselle.internal.implementation.ManagedType;
+import br.gov.frameworkdemoiselle.internal.implementation.ManagedType.FieldDetail;
+import br.gov.frameworkdemoiselle.internal.implementation.ManagedType.MethodDetail;
+import br.gov.frameworkdemoiselle.internal.implementation.ManagedType.ParameterDetail;
+import br.gov.frameworkdemoiselle.internal.implementation.Management;
+import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException;
+import br.gov.frameworkdemoiselle.management.ManagedInvokationException;
+import br.gov.frameworkdemoiselle.stereotype.ManagementController;
+import br.gov.frameworkdemoiselle.util.Beans;
+import br.gov.frameworkdemoiselle.util.ResourceBundle;
+
+/**
+ *
+ * This class is a MBean that gets registered everytime you mark a class with {@link ManagementController}. It dynamicaly reads the
+ * fields and operations contained in a {@link ManagementController} class and exposes them to the MBean server. Everytime a client
+ * tries to call an operation or read/write a property inside a ManagementController class, this class will call the appropriate
+ * method and pass the result to the MBean client.
+ *
+ *
+ * @author SERPRO
+ */
+public class DynamicMBeanProxy implements DynamicMBean {
+
+ private MBeanInfo delegateInfo;
+
+ private ManagedType managedType;
+
+ private ResourceBundle bundle;
+
+ public DynamicMBeanProxy(ManagedType type) {
+ if (type == null) {
+ throw new NullPointerException(getBundle().getString("mbean-null-type-defined"));
+ }
+ managedType = type;
+ }
+
+ @Override
+ public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
+ // Se o bean ainda não foi lido para determinar seus atributos, o faz agora.
+ if (delegateInfo == null) {
+ initializeMBeanInfo();
+ }
+
+ Management manager = Beans.getReference(Management.class);
+
+ try{
+ return manager.getProperty(managedType, attribute);
+ }
+ catch(DemoiselleException de){
+ if (ManagedAttributeNotFoundException.class.isInstance(de)){
+ throw new AttributeNotFoundException(de.getMessage());
+ }
+ else if (ManagedInvokationException.class.isInstance(de)){
+ throw new MBeanException(new Exception(de.getMessage()));
+ }
+ else{
+ throw de;
+ }
+ }
+ }
+
+ @Override
+ public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException,
+ MBeanException, ReflectionException {
+
+ // Se o bean ainda não foi lido para determinar seus atributos, o faz agora.
+ if (delegateInfo == null) {
+ initializeMBeanInfo();
+ }
+
+ Management manager = Beans.getReference(Management.class);
+
+ try{
+ manager.setProperty(managedType, attribute.getName(), attribute.getValue());
+ }
+ catch(DemoiselleException de){
+ if (ManagedAttributeNotFoundException.class.isInstance(de)){
+ throw new AttributeNotFoundException(de.getMessage());
+ }
+ else if (ManagedInvokationException.class.isInstance(de)){
+ throw new MBeanException(new Exception(de.getMessage()));
+ }
+ else{
+ throw de;
+ }
+ }
+ }
+
+ @Override
+ public AttributeList getAttributes(String[] attributes) {
+ if (attributes != null) {
+ AttributeList list = new AttributeList();
+ for (String attribute : attributes) {
+ try {
+ Object value = getAttribute(attribute);
+ list.add(new Attribute(attribute, value));
+ } catch (Throwable t) {
+ }
+ }
+
+ return list;
+ }
+
+ return null;
+ }
+
+ @Override
+ public AttributeList setAttributes(AttributeList attributes) {
+ AttributeList settedAttributes = new AttributeList();
+ if (attributes != null) {
+ for (Attribute attribute : attributes.asList()) {
+ try {
+ setAttribute(attribute);
+
+ // A razão para separarmos a criação do atributo de sua adição na lista é que
+ // caso a obtenção do novo valor do atributo dispare uma exceção então o atributo não será
+ // adicionado na lista de atributos que foram afetados.
+ Attribute attributeWithNewValue = new Attribute(attribute.getName(),
+ getAttribute(attribute.getName()));
+ settedAttributes.add(attributeWithNewValue);
+ } catch (Throwable t) {
+ }
+ }
+ }
+
+ return settedAttributes;
+ }
+
+ @Override
+ public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException,
+ ReflectionException {
+
+ // Se o bean ainda não foi lido para determinar seus atributos, o faz agora.
+ if (this.delegateInfo == null) {
+ initializeMBeanInfo();
+ }
+
+ Management manager = Beans.getReference(Management.class);
+
+ try{
+ return manager.invoke(managedType, actionName, params);
+ }
+ catch(DemoiselleException de){
+ throw new MBeanException(new Exception(de.getMessage()));
+ }
+ }
+
+ /**
+ * Initialize the Managed information for this instance of Managed
+ */
+ private void initializeMBeanInfo() {
+ // Aqui vamos armazenar nossos atributos
+ ArrayList attributes = new ArrayList();
+
+ // Aqui vamos armazenar nossas operações
+ ArrayList operations = new ArrayList();
+
+ // Para cada propriedade descoberta no ManagementController, cria um attributeInfo correspondente
+ for (Entry fieldEntry : managedType.getFields().entrySet()) {
+
+ try {
+
+ MBeanAttributeInfo attributeInfo = new MBeanAttributeInfo(fieldEntry.getKey(), fieldEntry.getValue()
+ .getDescription(), fieldEntry.getValue().getGetterMethod(), fieldEntry.getValue()
+ .getSetterMethod());
+ attributes.add(attributeInfo);
+
+ } catch (javax.management.IntrospectionException e) {
+ throw new DemoiselleException(getBundle().getString("mbean-introspection-error", managedType.getType()
+ .getSimpleName()));
+ }
+ }
+
+ // Para cada operação descoberta no ManagementController, cria um operationInfo correspondente
+ for (Entry methodEntry : managedType.getOperationMethods().entrySet()) {
+
+ MethodDetail methodDetail = methodEntry.getValue();
+
+ ParameterDetail[] parameterTypes = methodDetail.getParameterTypers();
+
+ MBeanParameterInfo[] parameters = parameterTypes.length > 0 ? new MBeanParameterInfo[parameterTypes.length]
+ : null;
+
+ if (parameters != null) {
+
+ for (int i = 0; i < parameterTypes.length; i++) {
+
+ parameters[i] = new MBeanParameterInfo(parameterTypes[i].getParameterName(), parameterTypes[i]
+ .getParameterType().getCanonicalName(), parameterTypes[i].getParameterDescription());
+ }
+ }
+
+ // Com todas as informações, criamos nossa instância de MBeanOperationInfo e
+ // acrescentamos na lista de todas as operações.
+ int operationType = 0;
+ switch(methodDetail.getType()){
+ case ACTION:
+ operationType = MBeanOperationInfo.ACTION;
+ break;
+
+ case INFO:
+ operationType = MBeanOperationInfo.INFO;
+ break;
+
+ case ACTION_INFO:
+ operationType = MBeanOperationInfo.ACTION_INFO;
+ break;
+
+ default:
+ operationType = MBeanOperationInfo.UNKNOWN;
+ }
+
+ MBeanOperationInfo operation = new MBeanOperationInfo(methodDetail.getMethod().getName(),
+ methodDetail.getDescription(), parameters, methodDetail.getMethod().getReturnType().getName(),
+ operationType);
+
+ operations.add(operation);
+
+ }
+
+ // Por fim criamos nosso bean info.
+ delegateInfo = new MBeanInfo(managedType.getType().getCanonicalName(), managedType.getDescription(),
+ attributes.toArray(new MBeanAttributeInfo[0]), null, operations.toArray(new MBeanOperationInfo[0]),
+ null);
+
+ }
+
+ @Override
+ public MBeanInfo getMBeanInfo() {
+ if (delegateInfo == null) {
+ initializeMBeanInfo();
+ }
+
+ return delegateInfo;
+ }
+
+ public ResourceBundle getBundle(){
+ if (bundle==null){
+ bundle = new ResourceBundle("demoiselle-jmx-bundle", Locale.getDefault());
+ }
+
+ return bundle;
+ }
+
+}
diff --git a/impl/extension/jmx/src/test/java/management/tests/basic/DynamicMBeanProxyTest.java b/impl/extension/jmx/src/test/java/management/tests/basic/DynamicMBeanProxyTest.java
index fb692f2..f9b028f 100644
--- a/impl/extension/jmx/src/test/java/management/tests/basic/DynamicMBeanProxyTest.java
+++ b/impl/extension/jmx/src/test/java/management/tests/basic/DynamicMBeanProxyTest.java
@@ -55,7 +55,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
-import br.gov.frameworkdemoiselle.internal.MBeanManager;
+import br.gov.frameworkdemoiselle.internal.implementation.MBeanManager;
import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess;
import br.gov.frameworkdemoiselle.util.Beans;
diff --git a/impl/extension/jmx/src/test/java/management/tests/notification/NotificationBroadcasterTest.java b/impl/extension/jmx/src/test/java/management/tests/notification/NotificationBroadcasterTest.java
index a8ec782..d218cbf 100644
--- a/impl/extension/jmx/src/test/java/management/tests/notification/NotificationBroadcasterTest.java
+++ b/impl/extension/jmx/src/test/java/management/tests/notification/NotificationBroadcasterTest.java
@@ -57,8 +57,8 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
-import br.gov.frameworkdemoiselle.configuration.JMXConfig;
-import br.gov.frameworkdemoiselle.internal.MBeanManager;
+import br.gov.frameworkdemoiselle.internal.configuration.JMXConfig;
+import br.gov.frameworkdemoiselle.internal.implementation.MBeanManager;
import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess;
import br.gov.frameworkdemoiselle.management.AttributeChangeNotification;
--
libgit2 0.21.2