Fix issue Felix-675
Improve the JMX handler to support the Platform MBean Server.
Use the latest iPOJO version

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@683898 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/handler/jmx/LICENSE b/ipojo/handler/jmx/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/ipojo/handler/jmx/LICENSE
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/ipojo/handler/jmx/NOTICE b/ipojo/handler/jmx/NOTICE
new file mode 100644
index 0000000..6b1c994
--- /dev/null
+++ b/ipojo/handler/jmx/NOTICE
@@ -0,0 +1,18 @@
+Apache Felix iPOJO Event Admin Handler
+Copyright 2008 The Apache Software Foundation
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+II. Used Software
+
+This product uses software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright 2006 The OSGi Alliance.
+Licensed under the Apache License 2.0.
+
+III. License Summary
+- Apache License 2.0
diff --git a/ipojo/handler/jmx/metadata.xml b/ipojo/handler/jmx/metadata.xml
new file mode 100644
index 0000000..c20ebbb
--- /dev/null
+++ b/ipojo/handler/jmx/metadata.xml
@@ -0,0 +1,22 @@
+<!--
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements.  See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership.  The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License.  You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied.  See the License for the
+	specific language governing permissions and limitations
+	under the License.
+-->
+<ipojo>
+<handler classname="org.apache.felix.ipojo.handlers.jmx.MBeanHandler" name="config" namespace="org.apache.felix.ipojo.handlers.jmx.MBeanHandler">
+</handler>	
+</ipojo>
\ No newline at end of file
diff --git a/ipojo/handler/jmx/obr.xml b/ipojo/handler/jmx/obr.xml
new file mode 100644
index 0000000..fd462e1
--- /dev/null
+++ b/ipojo/handler/jmx/obr.xml
@@ -0,0 +1,25 @@
+<!--
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements.  See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership.  The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License.  You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied.  See the License for the
+	specific language governing permissions and limitations
+	under the License.
+-->
+<obr>
+	<capability name="ipojo.handler">
+		<p n="name" v="config"/>
+		<p n="namespace" v="org.apache.felix.ipojo.handlers.jmx.MBeanHandler"/>
+		<p n="type" v="primitive"/>
+	</capability>
+</obr>
\ No newline at end of file
diff --git a/ipojo/handler/jmx/pom.xml b/ipojo/handler/jmx/pom.xml
index 30939eb..1889dfb 100644
--- a/ipojo/handler/jmx/pom.xml
+++ b/ipojo/handler/jmx/pom.xml
@@ -1,95 +1,100 @@
-<!--

-	Licensed to the Apache Software Foundation (ASF) under one

-	or more contributor license agreements.  See the NOTICE file

-	distributed with this work for additional information

-	regarding copyright ownership.  The ASF licenses this file

-	to you under the Apache License, Version 2.0 (the

-	"License"); you may not use this file except in compliance

-	with the License.  You may obtain a copy of the License at

-	

-	http://www.apache.org/licenses/LICENSE-2.0

-	

-	Unless required by applicable law or agreed to in writing,

-	software distributed under the License is distributed on an

-	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

-	KIND, either express or implied.  See the License for the

-	specific language governing permissions and limitations

-	under the License.

--->

-<project>

-	<modelVersion>4.0.0</modelVersion>

-	<packaging>bundle</packaging>

-	<artifactId>org.apache.felix.ipojo.handler.jmx</artifactId>

-	<groupId>org.apache.felix</groupId>

-	<version>0.9.0-SNAPSHOT</version>

-	<name>Apache Felix iPOJO JMX Handler</name>

-

-	<dependencies>

-		<dependency>

-			<groupId>org.apache.felix</groupId>

-			<artifactId>org.osgi.core</artifactId>

-			<version>1.0.0</version>

-		</dependency>

-		<dependency>

-			<groupId>org.apache.felix</groupId>

-			<artifactId>org.osgi.compendium</artifactId>

-			<version>1.0.0</version>

-		</dependency>

-		<dependency>

-			<groupId>org.apache.felix</groupId>

-			<artifactId>org.apache.felix.ipojo.metadata</artifactId>

-			<version>0.9.0-SNAPSHOT</version>

-		</dependency>

-		<dependency>

-			<groupId>org.apache.felix</groupId>

-			<artifactId>org.apache.felix.ipojo</artifactId>

-			<version>0.9.0-SNAPSHOT</version>

-		</dependency>

-	</dependencies>

-

-	<build>

-		<plugins>

-			<plugin>

-				<groupId>org.apache.felix</groupId>

-				<artifactId>maven-bundle-plugin</artifactId>

-				<version>1.4.0</version>

-				<extensions>true</extensions>

-				<configuration>

-					<instructions>

-						<Private-Package>

-							org.apache.felix.ipojo.handlers.jmx

-						</Private-Package>

-						<Bundle-Name>${pom.name}</Bundle-Name>

-						<Bundle-SymbolicName>

-							ipojo.jmx.handler

-						</Bundle-SymbolicName>

-            <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
-					</instructions>

-				</configuration>

-			</plugin>

-			<plugin>

-				<groupId>org.apache.maven.plugins</groupId>

-				<artifactId>maven-compiler-plugin</artifactId>

-				<configuration>

-					<source>1.5</source>

-					<target>1.5</target>

-				</configuration>

-			</plugin>

-			<plugin>

-				<groupId>org.apache.felix</groupId>

-				<artifactId>maven-ipojo-plugin</artifactId>

-				<version>0.9.0-SNAPSHOT</version>

-				<executions>

-					<execution>

-						<goals>

-							<goal>ipojo-bundle</goal>

-						</goals>

-						<configuration>

-							<metadata>metadata.xml</metadata>

-						</configuration>

-					</execution>

-				</executions>

-			</plugin>

-		</plugins>

-	</build>

-</project>

+<!--
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements.  See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership.  The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License.  You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied.  See the License for the
+	specific language governing permissions and limitations
+	under the License.
+-->
+<project>
+	<modelVersion>4.0.0</modelVersion>
+	<packaging>bundle</packaging>
+	<name>Apache Felix iPOJO JMX Handler</name>
+	<artifactId>org.apache.felix.ipojo.handler.jmx</artifactId>
+	<groupId>org.apache.felix</groupId>
+	<version>0.9.0-SNAPSHOT</version>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo</artifactId>
+			<version>0.9.0-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo.metadata</artifactId>
+			<version>0.9.0-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.osgi.core</artifactId>
+			<version>1.0.0</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.osgi.compendium</artifactId>
+			<version>1.0.0</version>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<version>1.4.0</version>
+				<extensions>true</extensions>
+				<configuration>
+					<instructions>
+						<Private-Package>
+							org.apache.felix.ipojo.handlers.jmx
+						</Private-Package>
+						<Bundle-Name>${pom.name}</Bundle-Name>
+						<Bundle-SymbolicName>
+							org.apache.felix.ipojo.handler.jmx 
+						</Bundle-SymbolicName>
+						<Bundle-Vendor>The Apache Software 
+							Foundation</Bundle-Vendor>
+						<Include-Resource>
+							META-INF/LICENCE=LICENSE,
+							META-INF/NOTICE=NOTICE
+						</Include-Resource>
+					</instructions>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.5</source>
+					<target>1.5</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-ipojo-plugin</artifactId>
+				<version>0.9.0-SNAPSHOT</version>
+				<executions>
+					<execution>
+						<goals>
+							<goal>ipojo-bundle</goal>
+						</goals>
+						<configuration>
+							<metadata>metadata.xml</metadata>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+</project>
diff --git a/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java
index c539f82..0585e05 100644
--- a/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java
+++ b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java
@@ -1,374 +1,436 @@
-/* 

- * Licensed to the Apache Software Foundation (ASF) under one

- * or more contributor license agreements.  See the NOTICE file

- * distributed with this work for additional information

- * regarding copyright ownership.  The ASF licenses this file

- * to you under the Apache License, Version 2.0 (the

- * "License"); you may not use this file except in compliance

- * with the License.  You may obtain a copy of the License at

- *

- *   http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing,

- * software distributed under the License is distributed on an

- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

- * KIND, either express or implied.  See the License for the

- * specific language governing permissions and limitations

- * under the License.

- */

-

-package org.apache.felix.ipojo.handlers.jmx;

-

-import java.lang.reflect.InvocationTargetException;

-import java.util.ArrayList;

-import java.util.Iterator;

-import java.util.List;

-

-import javax.management.Attribute;

-import javax.management.AttributeChangeNotification;

-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.MBeanNotificationInfo;

-import javax.management.MBeanOperationInfo;

-import javax.management.Notification;

-import javax.management.NotificationBroadcasterSupport;

-import javax.management.ReflectionException;

-import javax.management.RuntimeOperationsException;

-

-import org.apache.felix.ipojo.InstanceManager;

-import org.apache.felix.ipojo.parser.MethodMetadata;

-import org.apache.felix.ipojo.util.Callback;

-import org.apache.felix.ipojo.util.Logger;

-

-/** 

- * this class implements iPOJO DynamicMBean.

- * it builds the dynamic MBean 

- *  

- *  @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>

- */

-public class DynamicMBeanImpl extends NotificationBroadcasterSupport implements DynamicMBean {

-    /** 

-     * JmxConfigDFieldMap : store the data extracted from metadata.xml.

-     */

-    private JmxConfigFieldMap m_configMap;

-

-    /** 

-     * InstanceManager: use to store the InstanceManager instance.

-     */

-    private InstanceManager m_instanceManager;

-

-    /** 

-     * MBeanInfo : class wich store the MBean Informations.

-     */

-    private MBeanInfo m_mBeanInfo;

-

-    /**

-     * String : constant which store the name of the class.

-     */

-    private String m_className = this.getClass().getName();

-

-    /** 

-     * sequenceNumber : use to calculate unique id to notification.

-     */

-    private int m_sequenceNumber = 0;

-

-    /** 

-     * DynamicMBeanImpl : constructor.

-     * @param properties : data extracted from metadat.xml file

-     * @param instanceManager : InstanceManager instance

-     */

-    public DynamicMBeanImpl(JmxConfigFieldMap properties, InstanceManager instanceManager) {

-        m_configMap = properties;

-        m_instanceManager = instanceManager;

-        this.buildMBeanInfo();

-    }

-

-    /** 

-     * getAttribute implements from JMX.

-     * get the value of the required attribute 

-     * @param arg0 name of required attribute

-     * @throws AttributeNotFoundException : if the attribute doesn't exist

-     * @throws MBeanException : 

-     * @throws ReflectionException : 

-     * @return  the object attribute

-     */

-    public Object getAttribute(String arg0) throws AttributeNotFoundException, MBeanException, ReflectionException {

-        PropertyField attribute = m_configMap.getPropertyFromName(arg0);

-

-        if (attribute == null) {

-            throw new AttributeNotFoundException(arg0 + " not found");

-        } else {

-            return attribute.getValue();

-        }

-    }

-

-    /** 

-     * getAttributes : implement from JMX.

-     * get values of reuqired attributes 

-     * @param attributeNames : names of the required attributes

-     * @return return the list of the attribute

-     */

-    public AttributeList getAttributes(String[] attributeNames) {

-

-        if (attributeNames == null) {

-            throw new IllegalArgumentException("attributeNames[] cannot be null");

-        }

-

-        AttributeList resultList = new AttributeList();

-        for (int i = 0; i < attributeNames.length; i++) {

-            PropertyField propertyField = (PropertyField) m_configMap.getPropertyFromField((String) attributeNames[i]);

-

-            if (propertyField != null) {

-                resultList.add(new Attribute(attributeNames[i], propertyField.getValue()));

-            }

-        }

-        return resultList;

-    }

-

-    /** 

-     * getMBeanInfo : return the MBean Class builded.

-     * @return  return MBeanInfo class constructed by buildMBeanInfo

-     */

-    public MBeanInfo getMBeanInfo() {

-        return m_mBeanInfo;

-    }

-

-    /** 

-     * invoke : invoke the required method on the targeted POJO.

-     * @param operationName : name of the method called

-     * @param params : parameters given to the method

-     * @param signature : determine which method called

-     * @return Object : the object return by the method

-     * @throws MBeanException :

-     * @throws ReflectionException : 

-     */

-    public Object invoke(String operationName, Object[] params, String[] signature) throws MBeanException, ReflectionException {

-

-        MethodField method = m_configMap.getMethodFromName(operationName, signature);

-        if (method != null) {

-            MethodMetadata methodCall = method.getMethod();

-            Callback mc = new Callback(methodCall, m_instanceManager);

-            try {

-                return mc.call(params);

-            } catch (NoSuchMethodException e) {

-                System.err.println("No such method!: " + operationName);

-                e.printStackTrace();

-            } catch (IllegalAccessException e) {

-                System.err.println("Illegal Access Exception");

-                e.printStackTrace();

-            } catch (InvocationTargetException e) {

-                System.err.println("Invocation Target Exception");

-                e.printStackTrace();

-            }

-        } else {

-            throw new ReflectionException(new NoSuchMethodException(operationName), "Cannot find the operation "

-                    + operationName

-                    + " in "

-                    + m_className);

-        }

-

-        return null;

-    }

-

-    /** 

-     * setAttribute : change specified attribute value.

-     * @param attribute : attribute with new value to be changed

-     * @throws AttributeNotFoundException : if the requiered attribute was not found

-     * @throws InvalidAttributeValueException : the value is inccorrect type

-     * @throws MBeanException :

-     * @throws ReflectionException :

-     */

-    public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException,

-            ReflectionException {

-

-        // Check attribute is not null to avoid NullPointerException later on

-        if (attribute == null) {

-            throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Cannot invoke a setter of "

-                    + m_className

-                    + " with null attribute");

-        }

-        String name = attribute.getName();

-        Object value = attribute.getValue();

-

-        if (name == null) {

-            throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null"), "Cannot invoke the setter of "

-                    + m_className

-                    + " with null attribute name");

-        }

-        // Check for a recognized attribute name and call the corresponding

-        // setter

-        //

-

-        PropertyField propertyField = (PropertyField) m_configMap.getPropertyFromName(name);

-        if (propertyField == null) {

-            // unrecognized attribute name:

-            throw new AttributeNotFoundException("Attribute " + name + " not found in " + m_className);

-        }

-        if (!propertyField.isWritable()) {

-            throw new InvalidAttributeValueException("Attribute " + name + " can not be setted");

-        }

-

-        if (value == null) {

-            try {

-                m_instanceManager.onSet(null, propertyField.getField(), null);

-            } catch (Exception e) {

-                throw new InvalidAttributeValueException("Cannot set attribute " + name + " to null");

-            }

-        } else { // if non null value, make sure it is assignable to the attribute

-            if (true /* TODO type.class.isAssignableFrom(value.getClass())*/) {

-                //propertyField.setValue(value);

-                // setValue(attributeField.getField(),null);

-                m_instanceManager.onSet(null, propertyField.getField(), value);

-            } else {

-                throw new InvalidAttributeValueException("Cannot set attribute "

-                        + name

-                        + " to a "

-                        + value.getClass().getName()

-                        + " object, String expected");

-            }

-        }

-

-    }

-

-    /** 

-     * setAttributes : change all the attributes value.

-     * @param attributes : list of attribute value to be changed

-     * @return AttributeList : list of new attribute

-     */

-    public AttributeList setAttributes(AttributeList attributes) {

-

-        //       Check attributes is not null to avoid NullPointerException later on

-        if (attributes == null) {

-            throw new RuntimeOperationsException(new IllegalArgumentException("AttributeList attributes cannot be null"),

-                    "Cannot invoke a setter of " + m_className);

-        }

-        AttributeList resultList = new AttributeList();

-

-        // if attributeNames is empty, nothing more to do

-        if (attributes.isEmpty()) {

-            return resultList;

-        }

-

-        // for each attribute, try to set it and add to the result list if

-        // successfull

-        for (Iterator i = attributes.iterator(); i.hasNext();) {

-            Attribute attr = (Attribute) i.next();

-            try {

-                setAttribute(attr);

-                String name = attr.getName();

-                Object value = getAttribute(name);

-                resultList.add(new Attribute(name, value));

-            } catch (Exception e) {

-                e.printStackTrace();

-            }

-        }

-        return resultList;

-    }

-

-    /** 

-     * buildMBeanInfo : build the MBean information on initialization.

-     * this value don't change after

-     */

-    private void buildMBeanInfo() {

-        String dDescription = m_configMap.getDecription();

-

-        // generate infos for attributes

-        MBeanAttributeInfo[] dAttributes = null;

-

-        if (m_configMap == null) {

-            return;

-        }

-

-        if (m_configMap.getProperties() != null) {

-            List<MBeanAttributeInfo> lAttributes = null;

-            lAttributes = new ArrayList<MBeanAttributeInfo>();

-

-            Iterator<PropertyField> iterator = m_configMap.getProperties().iterator();

-            while (iterator.hasNext()) {

-                PropertyField propertyField = (PropertyField) iterator.next();

-                lAttributes.add(new MBeanAttributeInfo(propertyField.getName(), propertyField.getType(), propertyField.getDescription(),

-                        propertyField.isReadable(), propertyField.isWritable(), false));

-            }

-            dAttributes = (MBeanAttributeInfo[]) lAttributes.toArray(new MBeanAttributeInfo[lAttributes.size()]);

-        }

-

-        MBeanOperationInfo[] dOperations = null;

-        if (m_configMap.getMethods() != null) {

-

-            List<MBeanOperationInfo> lOperations = new ArrayList<MBeanOperationInfo>();

-

-            Iterator<MethodField[]> iterator = m_configMap.getMethods().iterator();

-            while (iterator.hasNext()) {

-                MethodField[] method = (MethodField[]) iterator.next();

-                for (int i = 0; i < method.length; i++) {

-                    lOperations.add(new MBeanOperationInfo(method[i].getName(), method[i].getDescription(), method[i].getParams(), method[i]

-                            .getReturnType(), MBeanOperationInfo.UNKNOWN));

-                }

-                dOperations = (MBeanOperationInfo[]) lOperations.toArray(new MBeanOperationInfo[lOperations.size()]);

-            }

-        }

-

-        MBeanNotificationInfo[] dNotification = new MBeanNotificationInfo[0];

-        if (m_configMap.getMethods() != null) {

-

-            List<MBeanNotificationInfo> lNotifications = new ArrayList<MBeanNotificationInfo>();

-

-            Iterator<NotificationField> iterator = m_configMap.getNotifications().iterator();

-            while (iterator.hasNext()) {

-                NotificationField notification = (NotificationField) iterator.next();

-                lNotifications.add(notification.getNotificationInfo());

-            }

-            dNotification = (MBeanNotificationInfo[]) lNotifications.toArray(new MBeanNotificationInfo[lNotifications.size()]);

-        }

-

-        m_mBeanInfo = new MBeanInfo(this.m_className, dDescription, dAttributes, null, // No constructor 

-                dOperations, dNotification);

-    }

-

-    /** 

-     * getNotificationInfo : get the notification informations (use by JMX).

-     * @return MBeanNotificationInfo[] : structure which describe the notifications 

-     */

-    public MBeanNotificationInfo[] getNotificationInfo() {

-        MBeanNotificationInfo[] dNotification = new MBeanNotificationInfo[0];

-        if (m_configMap.getMethods() != null) {

-

-            List<MBeanNotificationInfo> lNotifications = new ArrayList<MBeanNotificationInfo>();

-

-            Iterator<NotificationField> iterator = m_configMap.getNotifications().iterator();

-            while (iterator.hasNext()) {

-                NotificationField notification = (NotificationField) iterator.next();

-                lNotifications.add(notification.getNotificationInfo());

-            }

-            dNotification = (MBeanNotificationInfo[]) lNotifications.toArray(new MBeanNotificationInfo[lNotifications.size()]);

-        }

-        return dNotification;

-    }

-

-    /** 

-     * sendNotification : send a notification to a subscriver.

-     * @param msg : msg to send

-     * @param attributeName : name of the attribute

-     * @param attributeType : type of the attribute

-     * @param oldValue : oldvalue of the attribute

-     * @param newValue : new value of the attribute

-     */

-    public void sendNotification(String msg, String attributeName, String attributeType, Object oldValue, Object newValue) {

-

-        long timeStamp = System.currentTimeMillis();

-

-        if (newValue.equals(oldValue)) {

-            return;

-        }

-        m_sequenceNumber++;

-        Notification notification =

-                new AttributeChangeNotification(this, m_sequenceNumber, timeStamp, msg, attributeName, attributeType, oldValue, newValue);

-        sendNotification(notification);

-        m_instanceManager.getFactory().getLogger().log(Logger.INFO, "Notification sent");

-    }

-}

+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.handlers.jmx;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.management.Attribute;
+import javax.management.AttributeChangeNotification;
+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.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.Notification;
+import javax.management.NotificationBroadcasterSupport;
+import javax.management.ReflectionException;
+import javax.management.RuntimeOperationsException;
+
+import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.parser.MethodMetadata;
+import org.apache.felix.ipojo.util.Callback;
+import org.apache.felix.ipojo.util.Logger;
+
+/**
+ * This class implements iPOJO DynamicMBean. it builds the dynamic MBean
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class DynamicMBeanImpl extends NotificationBroadcasterSupport implements
+        DynamicMBean {
+
+    /**
+     * InstanceManager: use to store the InstanceManager instance.
+     */
+    protected final InstanceManager m_instanceManager;
+
+    /**
+     * JmxConfigDFieldMap : store the data extracted from metadata.xml.
+     */
+    private JmxConfigFieldMap m_configMap;
+
+    /**
+     * MBeanInfo : class wich store the MBean Informations.
+     */
+    private MBeanInfo m_mBeanInfo;
+
+    /**
+     * String : constant which store the name of the class.
+     */
+    private String m_className = this.getClass().getName();
+
+    /**
+     * sequenceNumber : use to calculate unique id to notification.
+     */
+    private int m_sequenceNumber = 0;
+
+    /**
+     * DynamicMBeanImpl : constructor.
+     * 
+     * @param properties
+     *            : data extracted from metadat.xml file
+     * @param instanceManager
+     *            : InstanceManager instance
+     */
+    public DynamicMBeanImpl(JmxConfigFieldMap properties,
+            InstanceManager instanceManager) {
+        m_configMap = properties;
+        m_instanceManager = instanceManager;
+        this.buildMBeanInfo();
+    }
+
+    /**
+     * getAttribute implements from JMX. get the value of the required attribute
+     * 
+     * @param arg0
+     *            name of required attribute
+     * @throws AttributeNotFoundException
+     *             : if the attribute doesn't exist
+     * @throws MBeanException
+     *             :
+     * @throws ReflectionException
+     *             :
+     * @return the object attribute
+     */
+    public Object getAttribute(String arg0) throws AttributeNotFoundException,
+        MBeanException, ReflectionException {
+        PropertyField attribute = m_configMap.getPropertyFromName(arg0);
+
+        if (attribute == null) {
+            throw new AttributeNotFoundException(arg0 + " not found");
+        } else {
+            return attribute.getValue();
+        }
+    }
+
+    /**
+     * getAttributes : implement from JMX. get values of reuqired attributes
+     * 
+     * @param attributeNames
+     *            : names of the required attributes
+     * @return return the list of the attribute
+     */
+    public AttributeList getAttributes(String[] attributeNames) {
+
+        if (attributeNames == null) {
+            throw new IllegalArgumentException(
+                "attributeNames[] cannot be null");
+        }
+
+        AttributeList resultList = new AttributeList();
+        for (int i = 0; i < attributeNames.length; i++) {
+            PropertyField propertyField = (PropertyField) m_configMap
+                .getPropertyFromField((String) attributeNames[i]);
+
+            if (propertyField != null) {
+                resultList.add(new Attribute(attributeNames[i], propertyField
+                    .getValue()));
+            }
+        }
+        return resultList;
+    }
+
+    /**
+     * getMBeanInfo : return the MBean Class builded.
+     * 
+     * @return return MBeanInfo class constructed by buildMBeanInfo
+     */
+    public MBeanInfo getMBeanInfo() {
+        return m_mBeanInfo;
+    }
+
+    /**
+     * invoke : invoke the required method on the targeted POJO.
+     * 
+     * @param operationName
+     *            : name of the method called
+     * @param params
+     *            : parameters given to the method
+     * @param signature
+     *            : determine which method called
+     * @return Object : the object return by the method
+     * @throws MBeanException
+     *             :
+     * @throws ReflectionException
+     *             :
+     */
+    public Object invoke(String operationName, Object[] params,
+            String[] signature) throws MBeanException, ReflectionException {
+
+        MethodField method = m_configMap.getMethodFromName(operationName,
+            signature);
+        if (method != null) {
+            MethodMetadata methodCall = method.getMethod();
+            Callback mc = new Callback(methodCall, m_instanceManager);
+            try {
+                return mc.call(params);
+            } catch (NoSuchMethodException e) {
+                System.err.println("No such method!: " + operationName);
+                e.printStackTrace();
+            } catch (IllegalAccessException e) {
+                System.err.println("Illegal Access Exception");
+                e.printStackTrace();
+            } catch (InvocationTargetException e) {
+                System.err.println("Invocation Target Exception");
+                e.printStackTrace();
+            }
+        } else {
+            throw new ReflectionException(new NoSuchMethodException(
+                operationName), "Cannot find the operation " + operationName
+                    + " in " + m_className);
+        }
+
+        return null;
+    }
+
+    /**
+     * setAttribute : change specified attribute value.
+     * 
+     * @param attribute
+     *            : attribute with new value to be changed
+     * @throws AttributeNotFoundException
+     *             : if the requiered attribute was not found
+     * @throws InvalidAttributeValueException
+     *             : the value is inccorrect type
+     * @throws MBeanException
+     *             :
+     * @throws ReflectionException
+     *             :
+     */
+    public void setAttribute(Attribute attribute)
+        throws AttributeNotFoundException, InvalidAttributeValueException,
+        MBeanException, ReflectionException {
+
+        // Check attribute is not null to avoid NullPointerException later on
+        if (attribute == null) {
+            throw new RuntimeOperationsException(new IllegalArgumentException(
+                "Attribute cannot be null"), "Cannot invoke a setter of "
+                    + m_className + " with null attribute");
+        }
+        String name = attribute.getName();
+        Object value = attribute.getValue();
+
+        if (name == null) {
+            throw new RuntimeOperationsException(new IllegalArgumentException(
+                "Attribute name cannot be null"),
+                "Cannot invoke the setter of " + m_className
+                        + " with null attribute name");
+        }
+        // Check for a recognized attribute name and call the corresponding
+        // setter
+        //
+
+        PropertyField propertyField = (PropertyField) m_configMap
+            .getPropertyFromName(name);
+        if (propertyField == null) {
+            // unrecognized attribute name:
+            throw new AttributeNotFoundException("Attribute " + name
+                    + " not found in " + m_className);
+        }
+        if (!propertyField.isWritable()) {
+            throw new InvalidAttributeValueException("Attribute " + name
+                    + " can not be setted");
+        }
+
+        if (value == null) {
+            try {
+                m_instanceManager.onSet(null, propertyField.getField(), null);
+            } catch (Exception e) {
+                throw new InvalidAttributeValueException(
+                    "Cannot set attribute " + name + " to null");
+            }
+        } else { // if non null value, make sure it is assignable to the
+            // attribute
+            if (true /* TODO type.class.isAssignableFrom(value.getClass()) */) {
+                // propertyField.setValue(value);
+                // setValue(attributeField.getField(),null);
+                m_instanceManager.onSet(null, propertyField.getField(), value);
+            } else {
+                throw new InvalidAttributeValueException(
+                    "Cannot set attribute " + name + " to a "
+                            + value.getClass().getName()
+                            + " object, String expected");
+            }
+        }
+
+    }
+
+    /**
+     * setAttributes : change all the attributes value.
+     * 
+     * @param attributes
+     *            : list of attribute value to be changed
+     * @return AttributeList : list of new attribute
+     */
+    public AttributeList setAttributes(AttributeList attributes) {
+
+        // Check attributes is not null to avoid NullPointerException later on
+        if (attributes == null) {
+            throw new RuntimeOperationsException(new IllegalArgumentException(
+                "AttributeList attributes cannot be null"),
+                "Cannot invoke a setter of " + m_className);
+        }
+        AttributeList resultList = new AttributeList();
+
+        // if attributeNames is empty, nothing more to do
+        if (attributes.isEmpty()) {
+            return resultList;
+        }
+
+        // for each attribute, try to set it and add to the result list if
+        // successfull
+        for (Iterator i = attributes.iterator(); i.hasNext();) {
+            Attribute attr = (Attribute) i.next();
+            try {
+                setAttribute(attr);
+                String name = attr.getName();
+                Object value = getAttribute(name);
+                resultList.add(new Attribute(name, value));
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return resultList;
+    }
+
+    /**
+     * buildMBeanInfo : build the MBean information on initialization. this
+     * value don't change after
+     */
+    private void buildMBeanInfo() {
+        String dDescription = m_configMap.getDecription();
+
+        // generate infos for attributes
+        MBeanAttributeInfo[] dAttributes = null;
+
+        if (m_configMap == null) {
+            return;
+        }
+
+        if (m_configMap.getProperties() != null) {
+            List < MBeanAttributeInfo > lAttributes = null;
+            lAttributes = new ArrayList < MBeanAttributeInfo >();
+
+            Iterator < PropertyField > iterator = m_configMap.getProperties()
+                .iterator();
+            while (iterator.hasNext()) {
+                PropertyField propertyField = (PropertyField) iterator.next();
+                lAttributes.add(new MBeanAttributeInfo(propertyField.getName(),
+                    propertyField.getType(), propertyField.getDescription(),
+                    propertyField.isReadable(), propertyField.isWritable(),
+                    false));
+            }
+            dAttributes = (MBeanAttributeInfo[]) lAttributes
+                .toArray(new MBeanAttributeInfo[lAttributes.size()]);
+        }
+
+        MBeanOperationInfo[] dOperations = null;
+        if (m_configMap.getMethods() != null) {
+
+            List < MBeanOperationInfo > lOperations = new ArrayList < MBeanOperationInfo >();
+
+            Iterator < MethodField[] > iterator = m_configMap.getMethods()
+                .iterator();
+            while (iterator.hasNext()) {
+                MethodField[] method = (MethodField[]) iterator.next();
+                for (int i = 0; i < method.length; i++) {
+                    lOperations.add(new MBeanOperationInfo(method[i].getName(),
+                        method[i].getDescription(), method[i].getParams(),
+                        method[i].getReturnType(), MBeanOperationInfo.UNKNOWN));
+                }
+                dOperations = (MBeanOperationInfo[]) lOperations
+                    .toArray(new MBeanOperationInfo[lOperations.size()]);
+            }
+        }
+
+        MBeanNotificationInfo[] dNotification = new MBeanNotificationInfo[0];
+        if (m_configMap.getMethods() != null) {
+
+            List < MBeanNotificationInfo > lNotifications = new ArrayList < MBeanNotificationInfo >();
+
+            Iterator < NotificationField > iterator = m_configMap
+                .getNotifications().iterator();
+            while (iterator.hasNext()) {
+                NotificationField notification = (NotificationField) iterator
+                    .next();
+                lNotifications.add(notification.getNotificationInfo());
+            }
+            dNotification = (MBeanNotificationInfo[]) lNotifications
+                .toArray(new MBeanNotificationInfo[lNotifications.size()]);
+        }
+
+        m_mBeanInfo = new MBeanInfo(this.m_className, dDescription,
+            dAttributes, null, // No constructor
+            dOperations, dNotification);
+    }
+
+    /**
+     * getNotificationInfo : get the notification informations (use by JMX).
+     * 
+     * @return MBeanNotificationInfo[] : structure which describe the
+     *         notifications
+     */
+    public MBeanNotificationInfo[] getNotificationInfo() {
+        MBeanNotificationInfo[] dNotification = new MBeanNotificationInfo[0];
+        if (m_configMap.getMethods() != null) {
+
+            List < MBeanNotificationInfo > lNotifications = new ArrayList < MBeanNotificationInfo >();
+
+            Iterator < NotificationField > iterator = m_configMap
+                .getNotifications().iterator();
+            while (iterator.hasNext()) {
+                NotificationField notification = (NotificationField) iterator
+                    .next();
+                lNotifications.add(notification.getNotificationInfo());
+            }
+            dNotification = (MBeanNotificationInfo[]) lNotifications
+                .toArray(new MBeanNotificationInfo[lNotifications.size()]);
+        }
+        return dNotification;
+    }
+
+    /**
+     * sendNotification : send a notification to a subscriver.
+     * 
+     * @param msg
+     *            : msg to send
+     * @param attributeName
+     *            : name of the attribute
+     * @param attributeType
+     *            : type of the attribute
+     * @param oldValue
+     *            : oldvalue of the attribute
+     * @param newValue
+     *            : new value of the attribute
+     */
+    public void sendNotification(String msg, String attributeName,
+            String attributeType, Object oldValue, Object newValue) {
+
+        long timeStamp = System.currentTimeMillis();
+
+        if (newValue.equals(oldValue)) {
+            return;
+        }
+        m_sequenceNumber++;
+        Notification notification = new AttributeChangeNotification(this,
+            m_sequenceNumber, timeStamp, msg, attributeName, attributeType,
+            oldValue, newValue);
+        sendNotification(notification);
+        m_instanceManager.getFactory().getLogger().log(Logger.INFO,
+            "Notification sent");
+    }
+}
diff --git a/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanWRegisterImpl.java b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanWRegisterImpl.java
new file mode 100644
index 0000000..5ec9066
--- /dev/null
+++ b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanWRegisterImpl.java
@@ -0,0 +1,183 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.handlers.jmx;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.parser.MethodMetadata;
+import org.apache.felix.ipojo.util.Callback;
+
+/**
+ * This class implements a 'wide' iPOJO DynamicMBean that can perform actions
+ * before and after its registration and deregistration.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class DynamicMBeanWRegisterImpl extends DynamicMBeanImpl implements
+        MBeanRegistration {
+
+    /**
+     * preRegister method of MBeanRegistration interface.
+     */
+    private MethodMetadata m_preRegisterMeth;
+    /**
+     * postRegister method of MBeanRegistration interface.
+     */
+    private MethodMetadata m_postRegisterMeth;
+    /**
+     * preDeregister method of MBeanRegistration interface.
+     */
+    private MethodMetadata m_preDeregisterMeth;
+    /**
+     * postDeregister method of MBeanRegistration interface.
+     */
+    private MethodMetadata m_postDeregisterMeth;
+    /**
+     * Effective name of the MBean.
+     */
+    private ObjectName m_objName;
+
+    /**
+     * Constructs a new DynamicMBeanWRegisterImpl.
+     * 
+     * @param properties
+     *            data extracted from the metadata.xml
+     * @param instanceManager
+     *            the instance manager
+     * @param preRegisterMeth
+     *            the method to call before MBean registration
+     * @param postRegisterMeth
+     *            the method to call after MBean registration
+     * @param preDeregisterMeth
+     *            the method to call before MBean deregistration
+     * @param postDeregisterMeth
+     *            the method to call after MBean registration
+     */
+    public DynamicMBeanWRegisterImpl(JmxConfigFieldMap properties,
+            InstanceManager instanceManager, MethodMetadata preRegisterMeth,
+            MethodMetadata postRegisterMeth, MethodMetadata preDeregisterMeth,
+            MethodMetadata postDeregisterMeth) {
+        super(properties, instanceManager);
+
+        m_preRegisterMeth = preRegisterMeth;
+        m_postRegisterMeth = postRegisterMeth;
+        m_preDeregisterMeth = preDeregisterMeth;
+        m_postDeregisterMeth = postDeregisterMeth;
+    }
+
+    /**
+     * Return the MBean name used to register it.
+     * 
+     * @return the MBean name used to register it.
+     */
+    public ObjectName getObjectName() {
+        return m_objName;
+    }
+
+    /**
+     * This method is executed before the MBean registration.
+     * 
+     * @param server
+     *            the server on which the MBean will be registered
+     * @param name
+     *            the name of the MBean to expose
+     * @throws Exception
+     *             This exception will be caught by the MBean server and
+     *             re-thrown as an MBeanRegistrationException.
+     * @return the name with which the MBean will be registered
+     */
+    public ObjectName preRegister(MBeanServer server, ObjectName name)
+        throws Exception {
+        m_objName = (ObjectName) callMethod(m_preRegisterMeth,
+            MBeanHandler.PRE_REGISTER_METH_NAME, new Object[] { server, name });
+        return m_objName;
+    }
+
+    /**
+     * This method is executed after the MBean registration.
+     * 
+     * @param registrationDone
+     *            Indicates whether or not the MBean has been successfully
+     *            registered in the MBean server.
+     */
+    public void postRegister(Boolean registrationDone) {
+        callMethod(m_postRegisterMeth, MBeanHandler.POST_REGISTER_METH_NAME,
+            new Object[] { registrationDone });
+    }
+
+    /**
+     * This method is before after the MBean deregistration.
+     * 
+     * @throws Exception
+     *             This exception will be caught by the MBean server and
+     *             re-thrown as an MBeanRegistrationException.
+     */
+    public void preDeregister() throws Exception {
+        callMethod(m_preDeregisterMeth, MBeanHandler.PRE_DEREGISTER_METH_NAME,
+            null);
+    }
+
+    /**
+     * This method is executed after the MBean deregistration.
+     */
+    public void postDeregister() {
+        callMethod(m_postDeregisterMeth,
+            MBeanHandler.POST_DEREGISTER_METH_NAME, null);
+    }
+
+    /**
+     * Private method used to execute a given callback.
+     * 
+     * @param methodMetadata
+     *            the metadata description of the callback
+     * @param methodName
+     *            the name of the callback
+     * @param params
+     *            the parameters of the callback
+     * @return the object eventually returned by the callback, or null if
+     *         nothing's returned
+     */
+    private Object callMethod(MethodMetadata methodMetadata, String methodName,
+            Object[] params) {
+        Callback mc = new Callback(methodMetadata, m_instanceManager);
+        try {
+            if ((params == null) || (params.length == 0)) {
+                return mc.call();
+            } else {
+                return mc.call(params);
+            }
+        } catch (NoSuchMethodException e) {
+            // should never happen : method exists
+            System.err.println("No such method!: " + methodName);
+            e.printStackTrace();
+        } catch (IllegalAccessException e) {
+            System.err.println("Illegal Access Exception");
+            e.printStackTrace();
+        } catch (InvocationTargetException e) {
+            System.err.println("Invocation Target Exception");
+            e.printStackTrace();
+        }
+        return null;
+    }
+}
diff --git a/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/JMXHandlerDescription.java b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/JMXHandlerDescription.java
new file mode 100644
index 0000000..4942971
--- /dev/null
+++ b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/JMXHandlerDescription.java
@@ -0,0 +1,72 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.handlers.jmx;
+
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+
+/**
+ * Description of the JMX handler.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class JMXHandlerDescription extends HandlerDescription {
+
+    /**
+     * The referenced handler.
+     */
+    private MBeanHandler m_handler;
+
+    /**
+     * Construct a new handler description for the given handler.
+     * 
+     * @param handler
+     *            the handler to describe
+     */
+    public JMXHandlerDescription(MBeanHandler handler) {
+        super(handler);
+        m_handler = handler;
+    }
+
+    /**
+     * Get handler information.
+     * 
+     * @return the handler information.
+     */
+    public Element getHandlerInfo() {
+        Element elem = super.getHandlerInfo();
+        elem.addAttribute(new Attribute("registered", Boolean
+            .toString(m_handler.isRegistered())));
+        elem.addAttribute(new Attribute("objectName", m_handler
+            .getUsedObjectName()));
+        if (m_handler.isUsesMOSGi()) {
+            String foundStr = null;
+
+            if (m_handler.isMOSGiExists()) {
+                foundStr = "found";
+            } else {
+                foundStr = "not_found";
+            }
+            elem.addAttribute(new Attribute("mosgi", foundStr));
+        }
+
+        return elem;
+    }
+}
diff --git a/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/JmxConfigFieldMap.java b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/JmxConfigFieldMap.java
index c3df29d..d689cbb 100644
--- a/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/JmxConfigFieldMap.java
+++ b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/JmxConfigFieldMap.java
@@ -1,282 +1,320 @@
-/* 

- * Licensed to the Apache Software Foundation (ASF) under one

- * or more contributor license agreements.  See the NOTICE file

- * distributed with this work for additional information

- * regarding copyright ownership.  The ASF licenses this file

- * to you under the Apache License, Version 2.0 (the

- * "License"); you may not use this file except in compliance

- * with the License.  You may obtain a copy of the License at

- *

- *   http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing,

- * software distributed under the License is distributed on an

- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

- * KIND, either express or implied.  See the License for the

- * specific language governing permissions and limitations

- * under the License.

- */

-

-

-package org.apache.felix.ipojo.handlers.jmx;

-

-import java.util.Collection;

-import java.util.HashMap;

-import java.util.Iterator;

-import java.util.Map;

-

-/** 

- * JmxConfigFieldMap : use to store the informations needed to build the Dynamic MBean.

- *  

- *  @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>

- */

-public class JmxConfigFieldMap {

-

-    /** 

-     * m_properties : use to store the attributes exposed.

-     */

-    private Map < String, PropertyField > m_properties = new HashMap < String, PropertyField >();

-    /** 

-     * m_methods : use to store the methods exposed.

-     */

-    private Map < String, MethodField[] > m_methods = new HashMap < String, MethodField[] >();

-    /** 

-     * m_notification : use to store the notification allowed.

-     */

-    private Map < String, NotificationField > m_notifications = new HashMap < String, NotificationField >();

-    /** 

-     * m_description : description of the Mbean.

-     */

-    private String m_description;

-    

-    

-    /** 

-     * JmxConfigFieldMap : constructor.

-     */

-    public JmxConfigFieldMap() {

-        

-    }

-    

-    /** 

-     * getDescription : get the descritpion of the MBean.

-     * @return String : Decription of the MBean

-     */

-    public String getDecription() {

-        return m_description;

-    }

-    

-    /** 

-     * setDescription : set the descritpion of the MBean.

-     * @param description : String which describe the Mbean

-     */

-    public void setDescription(String description) {

-        this.m_description = description;

-    }

-    

-    /** 

-     * addPropertyFromName : add a new attribute exposed in the Mbean.

-     * @param name : name of the new property

-     * @param propertyField : Field which describe the property

-     */

-    public void addPropertyFromName(String name, PropertyField propertyField) {

-        m_properties.put(name, propertyField);

-    }

-    

-    /** 

-     * getProperties : get all of the properties exposed.

-     * @return : collection of all properties

-     */

-    public Collection<PropertyField> getProperties() {

-        if (m_properties != null) {

-            return m_properties.values();

-        } else {

-            return null;

-        }     

-    }

-    

-    /** 

-     * getPropertyFromName : get the property by the name.

-     * @param name : name of the requiered property

-     * @return PropertyField : the field requiered or null if is not found

-     */

-    public PropertyField getPropertyFromName(String name) {

-        PropertyField prop = m_properties.get(name);

-        return prop;

-    }

-    

-    /** 

-     * getPropertyFromField : get the property by the field.

-     * @param field : the requiered field

-     * @return PropertyField : 

-     */

-    public PropertyField getPropertyFromField(String field) {

-        PropertyField property = null;

-        Iterator<PropertyField> it = m_properties.values().iterator();

-        while (it.hasNext()) {

-            PropertyField p = it.next();

-            if (p.getField().compareTo(field) == 0) {

-                if (property != null) {

-                    System.err.println("a field already exist");

-                } else {

-                    property = p;

-                }

-            }

-        }

-        return property;   

-    }

-    

-    

-    /** 

-     * addMethodFromName : add a new method descriptor from its name.

-     * @param name : name of the method

-     * @param methodField : descritpion of the method

-     */

-    public void addMethodFromName(String name, MethodField methodField) {

-        MethodField[] mf;

-        if (!m_methods.containsKey(name)) {

-            mf = new MethodField[1];

-            mf[0] = methodField;

-        } else {

-            MethodField[] temp = m_methods.get(name);

-            mf = new MethodField[temp.length + 1];

-            for (int i = 0; i < temp.length; i++) {

-                mf[i] = temp[i];

-            }

-            mf[temp.length] = methodField;

-        }

-        m_methods.put(name, mf);

-    }

-    

-    /** 

-     * addMethodFromName : add new methods descriptors from one name.

-     * (the method muste have the same name but different signature).

-     * @param name : name of the method

-     * @param methodsField : descritpion of the methods

-     */

-    public void addMethodFromName(String name, MethodField[] methodsField) {

-        MethodField[] mf;

-        if (!m_methods.containsKey(name)) {

-            mf = methodsField;

-        } else {

-            MethodField[] temp = m_methods.get(name);

-            mf = new MethodField[temp.length + methodsField.length];

-            for (int i = 0; i < temp.length; i++) {

-                mf[i] = temp[i];

-            }

-            for (int i = 0; i < methodsField.length; i++) {

-                mf[i + temp.length] = methodsField[i];

-            }

-        }

-        m_methods.put(name, mf);

-    }

-    

-    /** 

-     * DynamicMBeanImpl : add methods from name and erase the older if exist.

-     * @param name : name of the method

-     * @param methodField : method to be added

-     */

-    public void overrideMethodFromName(String name, MethodField methodField) {

-        MethodField[] mf = new MethodField[1];

-        mf[0] = methodField;

-        m_methods.put(name, mf);

-    }

-    

-    /** 

-     * DynamicMBeanImpl : add methods from name and erase the older if exist.

-     * @param name : name of the method

-     * @param methodsField : array of methods to be added

-     */

-    public void overrideMethodFromName(String name, MethodField[] methodsField) {

-        m_methods.put(name, methodsField);  

-    }

-    

-    /** 

-     * getMethodFromName : return the metod(s) which are similar.

-     * @param name : name of requiered method

-     * @return MethodField[] : list of returned methods

-     */

-    public MethodField[] getMethodFromName(String name) {

-        MethodField[] prop = m_methods.get(name);

-        return prop;

-    }

-    

-    /** 

-     * getMethodFromName : get the method which the good signature.

-     * @param operationName : name of the method requiered

-     * @param signature : signature requiered

-     * @return MethodField : the method which the same signature or null if not found

-     */

-    public MethodField getMethodFromName(String operationName, String[] signature) {

-        MethodField[] methods = m_methods.get(operationName);

-        for (int i = 0; i < methods.length; i++) {

-            if (isSameSignature(signature, methods[i].getSignature())) {

-                return methods[i];

-            }

-        }

-        return null;

-    }

-    

-    /** 

-     * isSameSignature : compare two method signature.

-     * @param sig1 : first signature

-     * @param sig2 : second signature

-     * @return boolean : return true if the signature are similar

-     *                   fale else

-     */

-    private boolean isSameSignature(String[] sig1, String[] sig2) {

-        if (sig1.length != sig2.length) {

-            return false;

-        } else {

-            for (int i = 0; i < sig1.length; i++) {

-                if (!sig1[i].equals(sig2[i])) {

-                    return false;

-                }

-            }

-            

-        }

-        return true;

-    }

-    

-    /** 

-     * getMethods : return all methods store.

-     * @return Collection : collection of methodField[]

-     */

-    public Collection<MethodField[]> getMethods() {

-        if (m_methods != null) {

-            return m_methods.values();

-        } else {

-            return null;

-        }

-    }   

-    

-    /** 

-     * addNotificationFromName : add a notification .

-     * @param name : 

-     * @param notificationField :

-     */

-    public void addNotificationFromName(String name, NotificationField notificationField) {

-        m_notifications.put(name, notificationField);

-    }

-    

-    /** 

-     * getNotificationFromName : return the notification with requiered name.

-     * @param name : name requiered

-     * @return NotificationField : return the notification if exist, null else

-     */

-    public NotificationField getNotificationFromName(String name) {

-        NotificationField prop = m_notifications.get(name);

-        return prop;

-    }

-    

-    /** 

-     * getNotification : get all notifications define.

-     * @return Collection : return collection of NotificationField

-     */

-    public Collection<NotificationField> getNotifications() {

-        if (m_notifications != null) {

-            return m_notifications.values();

-        } else {

-            return null;

-        }

-    }

-}

+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.handlers.jmx;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * JmxConfigFieldMap : use to store the informations needed to build the Dynamic
+ * MBean.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class JmxConfigFieldMap {
+
+    /**
+     * m_properties : use to store the attributes exposed.
+     */
+    private Map < String, PropertyField > m_properties = new HashMap < String, PropertyField >();
+    /**
+     * m_methods : use to store the methods exposed.
+     */
+    private Map < String, MethodField[] > m_methods = new HashMap < String, MethodField[] >();
+    /**
+     * m_notification : use to store the notification allowed.
+     */
+    private Map < String, NotificationField > m_notifications = new HashMap < String, NotificationField >();
+    /**
+     * m_description : description of the Mbean.
+     */
+    private String m_description;
+
+    /**
+     * JmxConfigFieldMap : constructor.
+     */
+    public JmxConfigFieldMap() {
+
+    }
+
+    /**
+     * getDescription : get the descritpion of the MBean.
+     * 
+     * @return String : Decription of the MBean
+     */
+    public String getDecription() {
+        return m_description;
+    }
+
+    /**
+     * setDescription : set the descritpion of the MBean.
+     * 
+     * @param description
+     *            : String which describe the Mbean
+     */
+    public void setDescription(String description) {
+        this.m_description = description;
+    }
+
+    /**
+     * addPropertyFromName : add a new attribute exposed in the Mbean.
+     * 
+     * @param name
+     *            : name of the new property
+     * @param propertyField
+     *            : Field which describe the property
+     */
+    public void addPropertyFromName(String name, PropertyField propertyField) {
+        m_properties.put(name, propertyField);
+    }
+
+    /**
+     * getProperties : get all of the properties exposed.
+     * 
+     * @return : collection of all properties
+     */
+    public Collection < PropertyField > getProperties() {
+        if (m_properties != null) {
+            return m_properties.values();
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * getPropertyFromName : get the property by the name.
+     * 
+     * @param name
+     *            : name of the requiered property
+     * @return PropertyField : the field requiered or null if is not found
+     */
+    public PropertyField getPropertyFromName(String name) {
+        PropertyField prop = m_properties.get(name);
+        return prop;
+    }
+
+    /**
+     * getPropertyFromField : get the property by the field.
+     * 
+     * @param field
+     *            : the requiered field
+     * @return PropertyField :
+     */
+    public PropertyField getPropertyFromField(String field) {
+        PropertyField property = null;
+        Iterator < PropertyField > it = m_properties.values().iterator();
+        while (it.hasNext()) {
+            PropertyField p = it.next();
+            if (p.getField().compareTo(field) == 0) {
+                if (property != null) {
+                    System.err.println("a field already exist");
+                } else {
+                    property = p;
+                }
+            }
+        }
+        return property;
+    }
+
+    /**
+     * addMethodFromName : add a new method descriptor from its name.
+     * 
+     * @param name
+     *            : name of the method
+     * @param methodField
+     *            : descritpion of the method
+     */
+    public void addMethodFromName(String name, MethodField methodField) {
+        MethodField[] mf;
+        if (!m_methods.containsKey(name)) {
+            mf = new MethodField[1];
+            mf[0] = methodField;
+        } else {
+            MethodField[] temp = m_methods.get(name);
+            mf = new MethodField[temp.length + 1];
+            for (int i = 0; i < temp.length; i++) {
+                mf[i] = temp[i];
+            }
+            mf[temp.length] = methodField;
+        }
+        m_methods.put(name, mf);
+    }
+
+    /**
+     * addMethodFromName : add new methods descriptors from one name. (the
+     * method muste have the same name but different signature).
+     * 
+     * @param name
+     *            : name of the method
+     * @param methodsField
+     *            : descritpion of the methods
+     */
+    public void addMethodFromName(String name, MethodField[] methodsField) {
+        MethodField[] mf;
+        if (!m_methods.containsKey(name)) {
+            mf = methodsField;
+        } else {
+            MethodField[] temp = m_methods.get(name);
+            mf = new MethodField[temp.length + methodsField.length];
+            for (int i = 0; i < temp.length; i++) {
+                mf[i] = temp[i];
+            }
+            for (int i = 0; i < methodsField.length; i++) {
+                mf[i + temp.length] = methodsField[i];
+            }
+        }
+        m_methods.put(name, mf);
+    }
+
+    /**
+     * DynamicMBeanImpl : add methods from name and erase the older if exist.
+     * 
+     * @param name
+     *            : name of the method
+     * @param methodField
+     *            : method to be added
+     */
+    public void overrideMethodFromName(String name, MethodField methodField) {
+        MethodField[] mf = new MethodField[1];
+        mf[0] = methodField;
+        m_methods.put(name, mf);
+    }
+
+    /**
+     * DynamicMBeanImpl : add methods from name and erase the older if exist.
+     * 
+     * @param name
+     *            : name of the method
+     * @param methodsField
+     *            : array of methods to be added
+     */
+    public void overrideMethodFromName(String name, MethodField[] methodsField) {
+        m_methods.put(name, methodsField);
+    }
+
+    /**
+     * getMethodFromName : return the metod(s) which are similar.
+     * 
+     * @param name
+     *            : name of requiered method
+     * @return MethodField[] : list of returned methods
+     */
+    public MethodField[] getMethodFromName(String name) {
+        MethodField[] prop = m_methods.get(name);
+        return prop;
+    }
+
+    /**
+     * getMethodFromName : get the method which the good signature.
+     * 
+     * @param operationName
+     *            : name of the method requiered
+     * @param signature
+     *            : signature requiered
+     * @return MethodField : the method which the same signature or null if not
+     *         found
+     */
+    public MethodField getMethodFromName(String operationName,
+            String[] signature) {
+        MethodField[] methods = m_methods.get(operationName);
+        for (int i = 0; i < methods.length; i++) {
+            if (isSameSignature(signature, methods[i].getSignature())) {
+                return methods[i];
+            }
+        }
+        return null;
+    }
+
+    /**
+     * isSameSignature : compare two method signature.
+     * 
+     * @param sig1
+     *            : first signature
+     * @param sig2
+     *            : second signature
+     * @return boolean : return true if the signature are similar fale else
+     */
+    private boolean isSameSignature(String[] sig1, String[] sig2) {
+        if (sig1.length != sig2.length) {
+            return false;
+        } else {
+            for (int i = 0; i < sig1.length; i++) {
+                if (!sig1[i].equals(sig2[i])) {
+                    return false;
+                }
+            }
+
+        }
+        return true;
+    }
+
+    /**
+     * getMethods : return all methods store.
+     * 
+     * @return Collection : collection of methodField[]
+     */
+    public Collection < MethodField[] > getMethods() {
+        if (m_methods != null) {
+            return m_methods.values();
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * addNotificationFromName : add a notification .
+     * 
+     * @param name
+     *            :
+     * @param notificationField
+     *            :
+     */
+    public void addNotificationFromName(String name,
+            NotificationField notificationField) {
+        m_notifications.put(name, notificationField);
+    }
+
+    /**
+     * getNotificationFromName : return the notification with requiered name.
+     * 
+     * @param name
+     *            : name requiered
+     * @return NotificationField : return the notification if exist, null else
+     */
+    public NotificationField getNotificationFromName(String name) {
+        NotificationField prop = m_notifications.get(name);
+        return prop;
+    }
+
+    /**
+     * getNotification : get all notifications define.
+     * 
+     * @return Collection : return collection of NotificationField
+     */
+    public Collection < NotificationField > getNotifications() {
+        if (m_notifications != null) {
+            return m_notifications.values();
+        } else {
+            return null;
+        }
+    }
+}
diff --git a/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java
index c751392..70d7361 100644
--- a/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java
+++ b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java
@@ -1,255 +1,621 @@
-/* 

- * Licensed to the Apache Software Foundation (ASF) under one

- * or more contributor license agreements.  See the NOTICE file

- * distributed with this work for additional information

- * regarding copyright ownership.  The ASF licenses this file

- * to you under the Apache License, Version 2.0 (the

- * "License"); you may not use this file except in compliance

- * with the License.  You may obtain a copy of the License at

- *

- *   http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing,

- * software distributed under the License is distributed on an

- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

- * KIND, either express or implied.  See the License for the

- * specific language governing permissions and limitations

- * under the License.

- */

-

-package org.apache.felix.ipojo.handlers.jmx;

-

-

-import java.util.Dictionary;

-import java.util.Properties;

-

-import org.apache.felix.ipojo.InstanceManager;

-import org.apache.felix.ipojo.PrimitiveHandler;

-import org.apache.felix.ipojo.metadata.Element;

-import org.apache.felix.ipojo.parser.FieldMetadata;

-import org.apache.felix.ipojo.parser.MethodMetadata;

-import org.apache.felix.ipojo.parser.PojoMetadata;

-import org.osgi.framework.BundleContext;

-import org.osgi.framework.ServiceRegistration;

-

-/** 

- * This class implements iPOJO Handler.

- * it builds the dynamic MBean from metadata.xml and expose it to the MBean Server.

- *  

- *  @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>

- */

-public class MBeanHandler extends PrimitiveHandler {

-    /** 

-     * InstanceManager: use to store the InstanceManager instance.

-     */

-    private InstanceManager m_instanceManager;

-    /**

-     * ServiceRegistration : use to register and unregister the Dynamic MBean.

-     */

-    private ServiceRegistration m_serviceRegistration;

-    /**

-     * JmxConfigFieldMap : use to store data when parsing metadata.xml.

-     */

-    private JmxConfigFieldMap m_jmxConfigFieldMap;

-    /**

-     * DynamicMBeanImpl : store the Dynamic MBean.

-     */

-    private DynamicMBeanImpl m_MBean;

-    /**

-     * String : constant which store the name of the class.

-     */

-    private String m_namespace = this.getClass().getName();

-

-    /** 

-     * configure : construct the structure JmxConfigFieldMap.and the Dynamic Mbean.

-     * @param metadata Element

-     * @param dict Dictionary

-     */

-    public void configure(Element metadata, Dictionary dict) {

-        

-        PojoMetadata manipulation = getPojoMetadata();

-        

-        m_instanceManager = getInstanceManager();

-

-

-        m_jmxConfigFieldMap = new JmxConfigFieldMap();

-

-        // Build the hashmap

-        Element[] mbeans = metadata.getElements("config", m_namespace);

-

-        if (mbeans.length != 1) { return; }

-        

-       

-        

-        // set property 

-        Element[] attributes = mbeans[0].getElements("property");

-        //String[] fields = new String[attributes.length];

-        if (attributes != null) {

-            for (int i = 0 ; attributes != null && i < attributes.length ; i++) {

-                boolean notif = false;

-                String rights;

-                String name;

-                String field = attributes[i].getAttribute("field");

-            

-                if (attributes[i].containsAttribute("name")) {

-                    name = attributes[i].getAttribute("name");

-                } else {

-                    name = field;

-                }

-                if (attributes[i].containsAttribute("rights")) {

-                    rights = attributes[i].getAttribute("rights");

-                } else {

-                    rights = "w";

-                }

-            

-                PropertyField property = new PropertyField(name, field, rights, getTypeFromAttributeField(field, manipulation));

-            

-                if (attributes[i].containsAttribute("notification")) {

-                    notif = Boolean.parseBoolean(attributes[i].getAttribute("notification"));

-                }

-            

-                property.setNotifiable(notif);

-            

-                if (notif) {

-                    //add the new notifiable property in structure

-                    NotificationField notification = new NotificationField(name, this.getClass().getName() + "." + field, null);

-                    m_jmxConfigFieldMap.addNotificationFromName(name, notification);

-                }

-                m_jmxConfigFieldMap.addPropertyFromName(name, property);

-                getInstanceManager().register(manipulation.getField(field), this);

-                info("property exposed:" + name + " " + field + ":" 

-                    + getTypeFromAttributeField(field, manipulation) + " " + rights 

-                    + ", Notif=" + notif);

-            }

-        }

-        

-        //set methods 

-        Element[] methods = mbeans[0].getElements("method");

-        for (int i = 0 ; methods != null && i < methods.length ; i++) {

-            String name = methods[i].getAttribute("name");

-            String description = null;

-            if (methods[i].containsAttribute("description")) {

-                description = methods[i].getAttribute("description");

-            }

-            

-            MethodField[] method = getMethodsFromName(name, manipulation, description);

-            

-            for (int j = 0 ; j < method.length ; j++) {

-                m_jmxConfigFieldMap.addMethodFromName(name, method[j]);

-            

-                info("method exposed:" + method[j].getReturnType() + " " + name);

-            }

-        }

-        

-    }

-    /**

-     * start : register the Dynamic Mbean.

-     */

-    public void start() {

-        // create the corresponding MBean

-        m_MBean = new DynamicMBeanImpl(m_jmxConfigFieldMap, m_instanceManager);

-        if (m_serviceRegistration != null) { m_serviceRegistration.unregister(); }

-

-        // Register the ManagedService

-        BundleContext bundleContext = m_instanceManager.getContext();

-        Properties properties = new Properties();

-        properties.put("jmxagent.objectName", "HandlerJMX:type=" 

-                + m_instanceManager.getClassName() 

-                + ",ServiceId=" 

-                + m_instanceManager.getInstanceName());

-

-        m_serviceRegistration = bundleContext.registerService(javax.management.DynamicMBean.class.getName(), m_MBean, properties);

-    }

-

-    /** 

-     * stop : unregister the Dynamic Mbean.

-     */

-    public void stop() {

-        if (m_serviceRegistration != null) { m_serviceRegistration.unregister(); }

-    }

-    

-    

-    /** 

-     * setterCallback : call when a POJO member is modified externally.

-     * @param pojo : the POJO object

-     * @param fieldName : name of the modified field 

-     * @param value     : new value of the field

-     */

-    public void onSet(Object pojo, String fieldName, Object value) {

-        // Check if the field is a configurable property

-

-        PropertyField propertyField = (PropertyField) m_jmxConfigFieldMap.getPropertyFromField(fieldName);

-        if (propertyField != null) {

-            if (propertyField.isNotifiable()) {

-                                            

-                m_MBean.sendNotification(propertyField.getName() + " changed", propertyField.getName(),

-                                         propertyField.getType(), propertyField.getValue(), value);

-            }

-            propertyField.setValue(value);

-        }

-    }

-

-    /** 

-     * getterCallback : call when a POJO member is modified by the MBean.

-     * @param pojo : pojo object.

-     * @param fieldName : name of the modified field 

-     * @param value     : old value of the field

-     * @return          : new value of the field

-     */

-    public Object onGet(Object pojo, String fieldName, Object value) {

-        

-        // Check if the field is a configurable property

-        PropertyField propertyField = (PropertyField) m_jmxConfigFieldMap.getPropertyFromField(fieldName);

-        if (propertyField != null) { 

-            m_instanceManager.onSet(pojo, fieldName, propertyField.getValue());

-            return propertyField.getValue();

-        }

-        m_instanceManager.onSet(pojo, fieldName, value);

-        return value;

-    }

-    

-    /** 

-     * getTypeFromAttributeField : get the type from a field name.

-     * @param fieldRequire : name of the requiered field 

-     * @param manipulation : metadata extract from metadata.xml file

-     * @return          : type of the field or null if it wasn't found

-     */

-    private static String getTypeFromAttributeField(String fieldRequire, PojoMetadata manipulation) {

-        

-        FieldMetadata field = manipulation.getField(fieldRequire);

-        if (field == null) {

-            return null;

-        } else {

-            return FieldMetadata.getReflectionType(field.getFieldType());

-        }

-    }

-    

-    /** 

-     * getMethodsFromName : get all the methods available which get this name.

-     * @param methodName : name of the requiered methods

-     * @param manipulation : metadata extract from metadata.xml file

-     * @param description  : description which appears in jmx console

-     * @return          : array of methods with the right name

-     */

-    private MethodField[] getMethodsFromName(String methodName, PojoMetadata manipulation, String description) {

-        

-        MethodMetadata[] fields = manipulation.getMethods(methodName);

-        if (fields.length == 0) {

-            return null;

-        }

-        

-        MethodField[] ret = new MethodField[fields.length];

-        

-        if (fields.length == 1) {

-            ret[0] = new MethodField(fields[0], description);

-            return ret;

-        } else {

-            for (int i = 0 ; i < fields.length ; i++) {

-                ret[i] = new MethodField(fields[i], description);

-            }

-            return ret;

-        }

-    }

-    

-

-}

+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.handlers.jmx;
+
+import java.lang.management.ManagementFactory;
+import java.util.Dictionary;
+import java.util.Properties;
+
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+
+import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.PrimitiveHandler;
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.parser.FieldMetadata;
+import org.apache.felix.ipojo.parser.MethodMetadata;
+import org.apache.felix.ipojo.parser.PojoMetadata;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * This class implements iPOJO Handler. it builds the dynamic MBean from
+ * metadata.xml and exposes it to the MBean Server.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class MBeanHandler extends PrimitiveHandler {
+
+    /**
+     * Name of the MBeanRegistration postDeregister method.
+     */
+    public static final String POST_DEREGISTER_METH_NAME = "postDeregister";
+
+    /**
+     * Name of the MBeanRegistration preDeregister method.
+     */
+    public static final String PRE_DEREGISTER_METH_NAME = "preDeregister";
+
+    /**
+     * Name of the MBeanRegistration postRegister method.
+     */
+    public static final String POST_REGISTER_METH_NAME = "postRegister";
+
+    /**
+     * Name of the MBeanRegistration preRegister method.
+     */
+    public static final String PRE_REGISTER_METH_NAME = "preRegister";
+
+    /**
+     * Name of the global configuration element.
+     */
+    private static final String JMX_CONFIG_ELT = "config";
+
+    /**
+     * Name of the component object full name attribute.
+     */
+    private static final String JMX_OBJ_NAME_ELT = "objectName";
+
+    /**
+     * Name of the component object name domain attribute.
+     */
+    private static final String JMX_OBJ_NAME_DOMAIN_ELT = "domain";
+
+    /**
+     * Name of the component object name attribute.
+     */
+    private static final String JMX_OBJ_NAME_WO_DOMAIN_ELT = "name";
+
+    /**
+     * Name of the attribute indicating if the handler uses MOSGi MBean server.
+     */
+    private static final String JMX_USES_MOSGI_ELT = "usesMOSGi";
+
+    /**
+     * Name of a method element.
+     */
+    private static final String JMX_METHOD_ELT = "method";
+
+    /**
+     * Name of the property or method name attribute.
+     */
+    private static final String JMX_NAME_ELT = "name";
+
+    /**
+     * Name of a method description attribute.
+     */
+    private static final String JMX_DESCRIPTION_ELT = "description";
+
+    /**
+     * Name of a property element.
+     */
+    private static final String JMX_PROPERTY_ELT = "property";
+
+    /**
+     * Name of the field attribute.
+     */
+    private static final String JMX_FIELD_ELT = "field";
+
+    /**
+     * Name of the notification attribute.
+     */
+    private static final String JMX_NOTIFICATION_ELT = "notification";
+
+    /**
+     * Name of the rights attribute.
+     */
+    private static final String JMX_RIGHTS_ELT = "rights";
+
+    /**
+     * InstanceManager: use to store the InstanceManager instance.
+     */
+    private InstanceManager m_instanceManager;
+    /**
+     * ServiceRegistration : use to register and unregister the Dynamic MBean.
+     */
+    private ServiceRegistration m_serviceRegistration;
+    /**
+     * JmxConfigFieldMap : use to store data when parsing metadata.xml.
+     */
+    private JmxConfigFieldMap m_jmxConfigFieldMap;
+    /**
+     * DynamicMBeanImpl : store the Dynamic MBean.
+     */
+    private DynamicMBeanImpl m_MBean;
+    /**
+     * String : constant which store the name of the class.
+     */
+    private String m_namespace = this.getClass().getName();
+    /**
+     * Flag used to say if we use MOSGi framework.
+     */
+    private boolean m_usesMOSGi = false;
+    /**
+     * ObjectName used to register the MBean.
+     */
+    private ObjectName m_objectName;
+    /**
+     * Flag used to say if the MBean is registered.
+     */
+    private boolean m_registered = false;
+    /**
+     * object name specified in handler configuration. It can be null.
+     */
+    private String m_completeObjNameElt;
+    /**
+     * object name without domain specified in handler configuration. It can be
+     * null.
+     */
+    private String m_objNameWODomainElt;
+    /**
+     * object name domain specified in handler configuration. It can be null.
+     */
+    private String m_domainElt;
+    /**
+     * flag representing if the Pojo implements MBeanRegistration interface.
+     */
+    private boolean m_registerCallbacks;
+    /**
+     * preRegister method of MBeanRegistration interface. It is null if pojo
+     * doesn't implement MBeanRegistration interface.
+     */
+    private MethodMetadata m_preRegisterMeth;
+    /**
+     * postRegister method of MBeanRegistration interface. It is null if pojo
+     * doesn't implement MBeanRegistration interface.
+     */
+    private MethodMetadata m_postRegisterMeth;
+    /**
+     * preDeregister method of MBeanRegistration interface. It is null if pojo
+     * doesn't implement MBeanRegistration interface.
+     */
+    private MethodMetadata m_preDeregisterMeth;
+    /**
+     * postDeregister method of MBeanRegistration interface. It is null if pojo
+     * doesn't implement MBeanRegistration interface.
+     */
+    private MethodMetadata m_postDeregisterMeth;
+
+    /**
+     * configure : construct the structure JmxConfigFieldMap.and the Dynamic
+     * Mbean.
+     * 
+     * @param metadata
+     *            Element
+     * @param dict
+     *            Dictionary
+     */
+    public void configure(Element metadata, Dictionary dict) {
+
+        PojoMetadata manipulation = getPojoMetadata();
+
+        m_instanceManager = getInstanceManager();
+
+        m_jmxConfigFieldMap = new JmxConfigFieldMap();
+
+        // Build the hashmap
+        Element[] mbeans = metadata.getElements(JMX_CONFIG_ELT, m_namespace);
+
+        if (mbeans.length != 1) {
+            error("A component must have at most one " + JMX_CONFIG_ELT + ".");
+            error("The JMX handler configuration is ignored.");
+            return;
+        }
+
+        // retrieve kind of MBeanServer to use
+        m_usesMOSGi = Boolean.parseBoolean(mbeans[0]
+            .getAttribute(JMX_USES_MOSGI_ELT));
+
+        // retrieve object name
+        m_completeObjNameElt = mbeans[0].getAttribute(JMX_OBJ_NAME_ELT);
+        m_domainElt = mbeans[0].getAttribute(JMX_OBJ_NAME_DOMAIN_ELT);
+        m_objNameWODomainElt = mbeans[0]
+            .getAttribute(JMX_OBJ_NAME_WO_DOMAIN_ELT);
+
+        // test if Pojo is interested in registration callbacks
+        m_registerCallbacks = manipulation
+            .isInterfaceImplemented(MBeanRegistration.class.getName());
+        if (m_registerCallbacks) {
+            // don't need to check that methods exist, the pojo implements
+            // MBeanRegistration interface
+            String[] preRegisterParams = { MBeanServer.class.getName(),
+                    ObjectName.class.getName() };
+            m_preRegisterMeth = manipulation.getMethod(PRE_REGISTER_METH_NAME,
+                preRegisterParams);
+
+            String[] postRegisterParams = { Boolean.class.getName() };
+            m_postRegisterMeth = manipulation.getMethod(
+                POST_REGISTER_METH_NAME, postRegisterParams);
+
+            m_preDeregisterMeth = manipulation.getMethod(
+                PRE_DEREGISTER_METH_NAME, new String[0]);
+
+            m_postDeregisterMeth = manipulation.getMethod(
+                POST_DEREGISTER_METH_NAME, new String[0]);
+        }
+
+        // set property
+        Element[] attributes = mbeans[0].getElements(JMX_PROPERTY_ELT);
+        // String[] fields = new String[attributes.length];
+        if (attributes != null) {
+            for (int i = 0; attributes != null && i < attributes.length; i++) {
+                boolean notif = false;
+                String rights;
+                String name;
+                String field = attributes[i].getAttribute(JMX_FIELD_ELT);
+
+                if (attributes[i].containsAttribute(JMX_NAME_ELT)) {
+                    name = attributes[i].getAttribute(JMX_NAME_ELT);
+                } else {
+                    name = field;
+                }
+                if (attributes[i].containsAttribute(JMX_RIGHTS_ELT)) {
+                    rights = attributes[i].getAttribute(JMX_RIGHTS_ELT);
+                } else {
+                    rights = "r";
+                }
+
+                PropertyField property = new PropertyField(name, field, rights,
+                    getTypeFromAttributeField(field, manipulation));
+
+                if (attributes[i].containsAttribute(JMX_NOTIFICATION_ELT)) {
+                    notif = Boolean.parseBoolean(attributes[i]
+                        .getAttribute(JMX_NOTIFICATION_ELT));
+                }
+
+                property.setNotifiable(notif);
+
+                if (notif) {
+                    // add the new notifiable property in structure
+                    NotificationField notification = new NotificationField(
+                        name, this.getClass().getName() + "." + field, null);
+                    m_jmxConfigFieldMap.addNotificationFromName(name,
+                        notification);
+                }
+                m_jmxConfigFieldMap.addPropertyFromName(name, property);
+                getInstanceManager().register(manipulation.getField(field),
+                    this);
+                info("property exposed:" + name + " " + field + ":"
+                        + getTypeFromAttributeField(field, manipulation) + " "
+                        + rights + ", Notif=" + notif);
+            }
+        }
+
+        // set methods
+        Element[] methods = mbeans[0].getElements(JMX_METHOD_ELT);
+        for (int i = 0; methods != null && i < methods.length; i++) {
+            String name = methods[i].getAttribute(JMX_NAME_ELT);
+            String description = null;
+            if (methods[i].containsAttribute(JMX_DESCRIPTION_ELT)) {
+                description = methods[i].getAttribute(JMX_DESCRIPTION_ELT);
+            }
+
+            MethodField[] method = getMethodsFromName(name, manipulation,
+                description);
+
+            for (int j = 0; j < method.length; j++) {
+                m_jmxConfigFieldMap.addMethodFromName(name, method[j]);
+
+                info("method exposed:" + method[j].getReturnType() + " " + name);
+            }
+        }
+
+    }
+
+    /**
+     * start : register the Dynamic Mbean.
+     */
+    public void start() {
+        // create the corresponding MBean
+        if (m_registerCallbacks) {
+            m_MBean = new DynamicMBeanWRegisterImpl(m_jmxConfigFieldMap,
+                m_instanceManager, m_preRegisterMeth, m_postRegisterMeth,
+                m_preDeregisterMeth, m_postDeregisterMeth);
+        } else {
+            m_MBean = new DynamicMBeanImpl(m_jmxConfigFieldMap,
+                m_instanceManager);
+        }
+
+        if (m_usesMOSGi) {
+            // use whiteboard pattern to register MBean
+
+            if (m_serviceRegistration != null) {
+                m_serviceRegistration.unregister();
+            }
+
+            // Register the ManagedService
+            BundleContext bundleContext = m_instanceManager.getContext();
+            Properties properties = new Properties();
+            try {
+                m_objectName = new ObjectName(getObjectNameString());
+
+                properties.put("jmxagent.objectName", m_objectName.toString());
+
+                m_serviceRegistration = bundleContext.registerService(
+                    javax.management.DynamicMBean.class.getName(), m_MBean,
+                    properties);
+
+                m_registered = true;
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        } else {
+            try {
+                m_objectName = new ObjectName(getObjectNameString());
+                ObjectInstance instance = ManagementFactory
+                    .getPlatformMBeanServer().registerMBean(m_MBean,
+                        m_objectName);
+
+                // we must retrieve object name used to register the MBean.
+                // It can have been changed by preRegister method of
+                // MBeanRegistration interface.
+                if (m_registerCallbacks) {
+                    m_objectName = instance.getObjectName();
+                }
+
+                m_registered = true;
+            } catch (Exception e) {
+                error("Registration of MBean failed.", e);
+            }
+        }
+    }
+
+    /**
+     * Return the object name of the exposed component.
+     * 
+     * @return the object name of the exposed component.
+     */
+    private String getObjectNameString() {
+        if (m_completeObjNameElt != null) {
+            return m_completeObjNameElt;
+        }
+
+        String domain;
+        if (m_domainElt != null) {
+            domain = m_domainElt;
+        } else {
+            domain = getPackageName(m_instanceManager.getClassName());
+        }
+
+        String name = "type=" + m_instanceManager.getClassName() + ",instance="
+                + m_instanceManager.getInstanceName();
+        if (m_objNameWODomainElt != null) {
+            name = m_objNameWODomainElt;
+        }
+
+        StringBuffer sb = new StringBuffer();
+        if ((domain != null) && (domain.length() > 0)) {
+            sb.append(domain + ":");
+        }
+        sb.append(name);
+
+        return sb.toString();
+    }
+
+    /**
+     * Extract the package name from of given type.
+     * 
+     * @param className
+     *            the type.
+     * @return the package name of the given type.
+     */
+    private String getPackageName(String className) {
+        String packageName = "";
+
+        int plotIdx = className.lastIndexOf(".");
+        if (plotIdx != -1) {
+            packageName = className.substring(0, plotIdx);
+        }
+
+        return packageName;
+    }
+
+    /**
+     * stop : unregister the Dynamic Mbean.
+     */
+    public void stop() {
+        if (m_usesMOSGi) {
+            if (m_serviceRegistration != null) {
+                m_serviceRegistration.unregister();
+            }
+        } else {
+            if (m_objectName != null) {
+                try {
+                    ManagementFactory.getPlatformMBeanServer().unregisterMBean(
+                        m_objectName);
+                } catch (Exception e) {
+                    error("Unregistration of MBean failed.", e);
+                }
+                m_objectName = null;
+            }
+        }
+
+        m_MBean = null;
+        m_registered = false;
+    }
+
+    /**
+     * setterCallback : call when a POJO member is modified externally.
+     * 
+     * @param pojo
+     *            : the POJO object
+     * @param fieldName
+     *            : name of the modified field
+     * @param value
+     *            : new value of the field
+     */
+    public void onSet(Object pojo, String fieldName, Object value) {
+        // Check if the field is a configurable property
+
+        PropertyField propertyField = (PropertyField) m_jmxConfigFieldMap
+            .getPropertyFromField(fieldName);
+        if (propertyField != null) {
+            if (propertyField.isNotifiable()) {
+                // TODO should send notif only when value has changed to a value
+                // different than the last one.
+                m_MBean.sendNotification(propertyField.getName() + " changed",
+                    propertyField.getName(), propertyField.getType(),
+                    propertyField.getValue(), value);
+            }
+            propertyField.setValue(value);
+        }
+    }
+
+    /**
+     * getterCallback : call when a POJO member is modified by the MBean.
+     * 
+     * @param pojo
+     *            : pojo object.
+     * @param fieldName
+     *            : name of the modified field
+     * @param value
+     *            : old value of the field
+     * @return : new value of the field
+     */
+    public Object onGet(Object pojo, String fieldName, Object value) {
+
+        // Check if the field is a configurable property
+        PropertyField propertyField = (PropertyField) m_jmxConfigFieldMap
+            .getPropertyFromField(fieldName);
+        if (propertyField != null) {
+            m_instanceManager.onSet(pojo, fieldName, propertyField.getValue());
+            return propertyField.getValue();
+        }
+        // m_instanceManager.onSet(pojo, fieldName, value);
+        return value;
+    }
+
+    /**
+     * getTypeFromAttributeField : get the type from a field name.
+     * 
+     * @param fieldRequire
+     *            : name of the requiered field
+     * @param manipulation
+     *            : metadata extract from metadata.xml file
+     * @return : type of the field or null if it wasn't found
+     */
+    private static String getTypeFromAttributeField(String fieldRequire,
+            PojoMetadata manipulation) {
+
+        FieldMetadata field = manipulation.getField(fieldRequire);
+        if (field == null) {
+            return null;
+        } else {
+            return FieldMetadata.getReflectionType(field.getFieldType());
+        }
+    }
+
+    /**
+     * getMethodsFromName : get all the methods available which get this name.
+     * 
+     * @param methodName
+     *            : name of the requiered methods
+     * @param manipulation
+     *            : metadata extract from metadata.xml file
+     * @param description
+     *            : description which appears in jmx console
+     * @return : array of methods with the right name
+     */
+    private MethodField[] getMethodsFromName(String methodName,
+            PojoMetadata manipulation, String description) {
+
+        MethodMetadata[] fields = manipulation.getMethods(methodName);
+        if (fields.length == 0) {
+            return null;
+        }
+
+        MethodField[] ret = new MethodField[fields.length];
+
+        if (fields.length == 1) {
+            ret[0] = new MethodField(fields[0], description);
+            return ret;
+        } else {
+            for (int i = 0; i < fields.length; i++) {
+                ret[i] = new MethodField(fields[i], description);
+            }
+            return ret;
+        }
+    }
+
+    /**
+     * Get the jmx handler description.
+     * 
+     * @return the jmx handler description.
+     * @see org.apache.felix.ipojo.Handler#getDescription()
+     */
+    public HandlerDescription getDescription() {
+        return new JMXHandlerDescription(this);
+    }
+
+    /**
+     * Return the objectName used to register the MBean. If the MBean is not
+     * registered, return an empty string.
+     * 
+     * @return the objectName used to register the MBean.
+     * @see org.apache.felix.ipojo.Handler#getDescription()
+     */
+    public String getUsedObjectName() {
+        if (m_objectName != null) {
+            return m_objectName.toString();
+        } else {
+            return "";
+        }
+    }
+
+    /**
+     * Return true if the MBean is registered.
+     * 
+     * @return true if the MBean is registered.
+     */
+    public boolean isRegistered() {
+        return m_registered;
+    }
+
+    /**
+     * Return true if the MBean must be registered thanks to whiteboard pattern
+     * of MOSGi.
+     * 
+     * @return true if the MBean must be registered thanks to whiteboard pattern
+     *         of MOSGi.
+     */
+    public boolean isUsesMOSGi() {
+        return m_usesMOSGi;
+    }
+
+    /**
+     * Return true if the MOSGi framework is present on the OSGi plateforme.
+     * 
+     * @return true if the MOSGi framework is present on the OSGi plateforme.
+     */
+    public boolean isMOSGiExists() {
+        for (Bundle bundle : m_instanceManager.getContext().getBundles()) {
+            String symbolicName = bundle.getSymbolicName();
+            if ("org.apache.felix.mosgi.jmx.agent".equals(symbolicName)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+}
diff --git a/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/MethodField.java b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/MethodField.java
index e4346d2..9a8658e 100644
--- a/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/MethodField.java
+++ b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/MethodField.java
@@ -1,86 +1,91 @@
-/* 

- * Licensed to the Apache Software Foundation (ASF) under one

- * or more contributor license agreements.  See the NOTICE file

- * distributed with this work for additional information

- * regarding copyright ownership.  The ASF licenses this file

- * to you under the Apache License, Version 2.0 (the

- * "License"); you may not use this file except in compliance

- * with the License.  You may obtain a copy of the License at

- *

- *   http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing,

- * software distributed under the License is distributed on an

- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

- * KIND, either express or implied.  See the License for the

- * specific language governing permissions and limitations

- * under the License.

- */

-

-package org.apache.felix.ipojo.handlers.jmx;

-

-import javax.management.MBeanParameterInfo;

-

-import org.apache.felix.ipojo.parser.MethodMetadata;

-

-/** 

- * this class build a method JMX description.

- *  

- *  @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>

- */

-public class MethodField {

-

-    /** 

-     * m_description : store the method descritpion.

-     */

-    private String m_description;

-    /** 

-     * m_method : store the method properties.

-     */

-    private MethodMetadata m_method;

-    

-    /** 

-     * MethodField : constructor.

-     * @param method : the metod properties

-     * @param description : thes method description

-     */

-    public MethodField(MethodMetadata method, String description) {

-        this.m_method = method;

-        this.m_description = description;

-    

-    }

-    

-

-    public MethodMetadata getMethod() {

-        return m_method;

-    }

-

-    public String getDescription() {

-        return m_description;

-    }

-

-    public String getName() {

-        return m_method.getMethodName();

-    }

-    

-    /** 

-     * getParams : get the parameter in JMX format.

-     * @return MBeanParameterInfo : return info on JMX format

-     */

-    public MBeanParameterInfo[] getParams() {

-        MBeanParameterInfo[] mbean = new MBeanParameterInfo[m_method.getMethodArguments().length];

-        for (int i = 0; i < m_method.getMethodArguments().length; i++) {

-            mbean[i] = new MBeanParameterInfo("arg" + i, m_method.getMethodArguments()[i], null);

-        }

-        return mbean;

-    }

-

-    public String[] getSignature() {

-        return m_method.getMethodArguments();

-    }

-    

-    public String getReturnType() {

-        return m_method.getMethodReturn();

-    }

-

-}

+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.handlers.jmx;
+
+import javax.management.MBeanParameterInfo;
+
+import org.apache.felix.ipojo.parser.MethodMetadata;
+
+/**
+ * this class build a method JMX description.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class MethodField {
+
+    /**
+     * m_description : store the method descritpion.
+     */
+    private String m_description;
+    /**
+     * m_method : store the method properties.
+     */
+    private MethodMetadata m_method;
+
+    /**
+     * MethodField : constructor.
+     * 
+     * @param method
+     *            : the metod properties
+     * @param description
+     *            : thes method description
+     */
+    public MethodField(MethodMetadata method, String description) {
+        this.m_method = method;
+        this.m_description = description;
+
+    }
+
+    public MethodMetadata getMethod() {
+        return m_method;
+    }
+
+    public String getDescription() {
+        return m_description;
+    }
+
+    public String getName() {
+        return m_method.getMethodName();
+    }
+
+    /**
+     * getParams : get the parameter in JMX format.
+     * 
+     * @return MBeanParameterInfo : return info on JMX format
+     */
+    public MBeanParameterInfo[] getParams() {
+        MBeanParameterInfo[] mbean = new MBeanParameterInfo[m_method
+            .getMethodArguments().length];
+        for (int i = 0; i < m_method.getMethodArguments().length; i++) {
+            mbean[i] = new MBeanParameterInfo("arg" + i, m_method
+                .getMethodArguments()[i], null);
+        }
+        return mbean;
+    }
+
+    public String[] getSignature() {
+        return m_method.getMethodArguments();
+    }
+
+    public String getReturnType() {
+        return m_method.getMethodReturn();
+    }
+
+}
diff --git a/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/NotificationField.java b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/NotificationField.java
index c6ff225..96df23d 100644
--- a/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/NotificationField.java
+++ b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/NotificationField.java
@@ -1,69 +1,72 @@
-/* 

- * Licensed to the Apache Software Foundation (ASF) under one

- * or more contributor license agreements.  See the NOTICE file

- * distributed with this work for additional information

- * regarding copyright ownership.  The ASF licenses this file

- * to you under the Apache License, Version 2.0 (the

- * "License"); you may not use this file except in compliance

- * with the License.  You may obtain a copy of the License at

- *

- *   http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing,

- * software distributed under the License is distributed on an

- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

- * KIND, either express or implied.  See the License for the

- * specific language governing permissions and limitations

- * under the License.

- */

-

-package org.apache.felix.ipojo.handlers.jmx;

-

-import javax.management.MBeanNotificationInfo;

-

-/** 

- * this calss build the notification descritpion structure.

- *  

- *  @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>

- */

-public class NotificationField {

-    /** 

-     * m_name : name of the notification.

-     */

-    private String m_name;

-    /** 

-     * m_description : description of the notification.

-     */

-    private String m_description;

-    /** 

-     * m_description : field of the notification.

-     */

-    private String m_field;

-    

-    /** 

-     * NotificationField : constructor.

-     * @param name : name of the notification 

-     * @param field : field which send a notification when it is modified

-     * @param description : descritpion which appears in jmx console

-     */

-    

-    public NotificationField(String name, String field, String description) {

-        this.m_name = name;

-        this.m_field = field;

-        this.m_description = description;

-    }

-

-    /** 

-     * getNotificationInfo : return the MBeanNotificationInfo from this class.

-     * @return          : type of the field or null if it wasn't found

-     */

-    public MBeanNotificationInfo getNotificationInfo() {

-        String[] notificationTypes = new String[1];

-        notificationTypes[0] = m_field;

-        MBeanNotificationInfo mbni = new MBeanNotificationInfo(

-                    notificationTypes,

-                    m_name,

-                    m_description);

-        return mbni;

-    }

-}

+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.handlers.jmx;
+
+import javax.management.MBeanNotificationInfo;
+
+/**
+ * this calss build the notification descritpion structure.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class NotificationField {
+    /**
+     * m_name : name of the notification.
+     */
+    private String m_name;
+    /**
+     * m_description : description of the notification.
+     */
+    private String m_description;
+    /**
+     * m_description : field of the notification.
+     */
+    private String m_field;
+
+    /**
+     * NotificationField : constructor.
+     * 
+     * @param name
+     *            : name of the notification
+     * @param field
+     *            : field which send a notification when it is modified
+     * @param description
+     *            : descritpion which appears in jmx console
+     */
+
+    public NotificationField(String name, String field, String description) {
+        this.m_name = name;
+        this.m_field = field;
+        this.m_description = description;
+    }
+
+    /**
+     * getNotificationInfo : return the MBeanNotificationInfo from this class.
+     * 
+     * @return : type of the field or null if it wasn't found
+     */
+    public MBeanNotificationInfo getNotificationInfo() {
+        String[] notificationTypes = new String[1];
+        notificationTypes[0] = m_field;
+        MBeanNotificationInfo mbni = new MBeanNotificationInfo(
+            notificationTypes, m_name, m_description);
+        return mbni;
+    }
+}
diff --git a/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/PropertyField.java b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/PropertyField.java
index d692894..cfbdf71 100644
--- a/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/PropertyField.java
+++ b/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/PropertyField.java
@@ -1,131 +1,145 @@
-/* 

- * Licensed to the Apache Software Foundation (ASF) under one

- * or more contributor license agreements.  See the NOTICE file

- * distributed with this work for additional information

- * regarding copyright ownership.  The ASF licenses this file

- * to you under the Apache License, Version 2.0 (the

- * "License"); you may not use this file except in compliance

- * with the License.  You may obtain a copy of the License at

- *

- *   http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing,

- * software distributed under the License is distributed on an

- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

- * KIND, either express or implied.  See the License for the

- * specific language governing permissions and limitations

- * under the License.

- */

-

-package org.apache.felix.ipojo.handlers.jmx;

-

-/** 

- * this calss build the notification descritpion structure.

- *  

- *  @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>

- */

-public class PropertyField {

-

-    /** 

-     * m_name : name of the notification.

-     */

-    private String m_name;

-    /** 

-     * m_name : name of the notification.

-     */

-    private String m_field;

-    /** 

-     * m_name : name of the notification.

-     */

-    private String m_rights;

-    /** 

-     * m_name : name of the notification.

-     */

-    private String m_type;

-    /** 

-     * m_name : name of the notification.

-     */

-    private Object m_value;

-    /** 

-     * m_name : name of the notification.

-     */

-    private boolean m_notification = false;

-    

-    /** 

-     * PropertyField : constructor.

-     * @param name : name of the properety 

-     * @param field : field which send a notification when it is modified

-     * @param rights : the rights of the attribute (ie: 'r' or 'w')

-     * @param type : the type of the attribute

-     */

-    public PropertyField(String name, String field, String rights, String type) {

-        this.setName(name);

-        this.setField(field);

-        this.m_type = type;

-        if (isRightsValid(rights)) {

-            this.setRights(rights);

-        } else {

-            this.setField("r"); //default rights is read only

-        }

-    }

-    

-    public String getField() {

-        return m_field;

-    }

-    public void setField(String field) {

-        this.m_field = field;

-    }

-    public String getName() {

-        return m_name;

-    }

-    public void setName(String name) {

-        this.m_name = name;

-    }

-    public String getRights() {

-        return m_rights;

-    }

-    public void setRights(String rights) {

-        this.m_rights = rights;

-    }

-    public Object getValue() {

-        return m_value;

-    }

-    public void setValue(Object value) {

-        this.m_value = value;

-    }

-

-    public String getType() {

-        return this.m_type;

-    }

-

-    public String getDescription() {

-        // TODO Auto-generated method stub

-        return null;

-    }

-

-    public boolean isReadable() {

-        return this.getRights().equals("r") || this.getRights().equals("w");

-    }

-

-    public boolean isWritable() {

-        return  this.getRights().equals("w");

-    }

-    

-    public boolean isNotifiable() {

-        return this.m_notification;

-    }

-    

-    public void setNotifiable(boolean value) {

-        this.m_notification = value;

-    }

-    

-    /** 

-     * isRightsValid : return is the rights is valid or not (ie = 'r' || 'w').

-     * @param rights :  string represents the rights

-     * @return boolean : return true if rights = 'r' or 'w'

-     */

-    public static boolean isRightsValid(String rights) {

-        return rights != null && (rights.equals("r") || rights.equals("w"));

-    }

-    

-}

+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.handlers.jmx;
+
+/**
+ * this calss build the notification descritpion structure.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class PropertyField {
+
+    /**
+     * m_name : name of the notification.
+     */
+    private String m_name;
+    /**
+     * m_name : name of the notification.
+     */
+    private String m_field;
+    /**
+     * m_name : name of the notification.
+     */
+    private String m_rights;
+    /**
+     * m_name : name of the notification.
+     */
+    private String m_type;
+    /**
+     * m_name : name of the notification.
+     */
+    private Object m_value;
+    /**
+     * m_name : name of the notification.
+     */
+    private boolean m_notification = false;
+
+    /**
+     * PropertyField : constructor.
+     * 
+     * @param name
+     *            : name of the properety
+     * @param field
+     *            : field which send a notification when it is modified
+     * @param rights
+     *            : the rights of the attribute (ie: 'r' or 'w')
+     * @param type
+     *            : the type of the attribute
+     */
+    public PropertyField(String name, String field, String rights, String type) {
+        this.setName(name);
+        this.setField(field);
+        this.m_type = type;
+        if (isRightsValid(rights)) {
+            this.setRights(rights);
+        } else {
+            this.setField("r"); // default rights is read only
+        }
+    }
+
+    public String getField() {
+        return m_field;
+    }
+
+    public void setField(String field) {
+        this.m_field = field;
+    }
+
+    public String getName() {
+        return m_name;
+    }
+
+    public void setName(String name) {
+        this.m_name = name;
+    }
+
+    public String getRights() {
+        return m_rights;
+    }
+
+    public void setRights(String rights) {
+        this.m_rights = rights;
+    }
+
+    public Object getValue() {
+        return m_value;
+    }
+
+    public void setValue(Object value) {
+        this.m_value = value;
+    }
+
+    public String getType() {
+        return this.m_type;
+    }
+
+    public String getDescription() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public boolean isReadable() {
+        return this.getRights().equals("r") || this.getRights().equals("w");
+    }
+
+    public boolean isWritable() {
+        return this.getRights().equals("w");
+    }
+
+    public boolean isNotifiable() {
+        return this.m_notification;
+    }
+
+    public void setNotifiable(boolean value) {
+        this.m_notification = value;
+    }
+
+    /**
+     * isRightsValid : return is the rights is valid or not (ie = 'r' || 'w').
+     * 
+     * @param rights
+     *            : string represents the rights
+     * @return boolean : return true if rights = 'r' or 'w'
+     */
+    public static boolean isRightsValid(String rights) {
+        return rights != null && (rights.equals("r") || rights.equals("w"));
+    }
+
+}
diff --git a/ipojo/handler/jmx/src/main/resources/metadata.xml b/ipojo/handler/jmx/src/main/resources/metadata.xml
deleted file mode 100644
index 65bdc15..0000000
--- a/ipojo/handler/jmx/src/main/resources/metadata.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<ipojo>

-<!-- Primitives handler -->

-<handler classname="org.apache.felix.ipojo.handlers.jmx.MBeanHandler" name="config" namespace="org.apache.felix.ipojo.handlers.jmx.MBeanHandler">

-</handler>	

-</ipojo>
\ No newline at end of file