Fix FELIX-2633 Rename JMX annotations
The @Conifug annotation is now @JmxBean which make more sense.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1023215 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/Config.java b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/Config.java
index 2b574eb..9a0d5e9 100644
--- a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/Config.java
+++ b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/Config.java
@@ -27,6 +27,7 @@
* Be aware that despite is it provided in the annotations jar,
* it refers to an external handler.
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ * @deprecated replaced by {@link JMXBean}
*/
@Target(ElementType.TYPE)
public @interface Config {
diff --git a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/JMXBean.java b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/JMXBean.java
new file mode 100644
index 0000000..ca31185
--- /dev/null
+++ b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/JMXBean.java
@@ -0,0 +1,61 @@
+/*
+ * 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.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * JMX Handler annotation.
+ * Allows exposing the instances as a JMX MBean.
+ * Be aware that despite is it provided in the annotations jar,
+ * it refers to an external handler.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@Target(ElementType.TYPE)
+public @interface JMXBean {
+
+ /**
+ * Enables or Disables MOSGi usage.
+ * If MOSGi is used, MBeans are exposed with the MOSGi mechanism.
+ * Otherwise the MBean Platform Server is used.
+ * Default : false
+ */
+ boolean usesMOSGi() default false;
+
+ /**
+ * Sets the MBean object name.
+ * Default : 'package-name:factory-name:instance-name'.
+ */
+ String objectname() default "";
+
+ /**
+ * Sets the MBean domain.
+ * Default : 'package-name'
+ */
+ String domain() default "";
+
+ /**
+ * Sets the MBean name.
+ * Default : 'instance-name'
+ */
+ String name() default "";
+
+
+}
diff --git a/ipojo/handler/jmx/metadata.xml b/ipojo/handler/jmx/metadata.xml
index ed20e9b..67b6b38 100644
--- a/ipojo/handler/jmx/metadata.xml
+++ b/ipojo/handler/jmx/metadata.xml
@@ -17,6 +17,6 @@
under the License.
-->
<ipojo>
-<handler classname="org.apache.felix.ipojo.handlers.jmx.MBeanHandler" name="config" namespace="org.apache.felix.ipojo.handlers.jmx">
-</handler>
+<handler classname="org.apache.felix.ipojo.handlers.jmx.MBeanHandler" name="config" namespace="org.apache.felix.ipojo.handlers.jmx" />
+<handler classname="org.apache.felix.ipojo.handlers.jmx.MBeanHandler" name="JMXBean" namespace="org.apache.felix.ipojo.handlers.jmx" />
</ipojo>
\ No newline at end of file
diff --git a/ipojo/handler/jmx/obr.xml b/ipojo/handler/jmx/obr.xml
index df0b21c..310c385 100644
--- a/ipojo/handler/jmx/obr.xml
+++ b/ipojo/handler/jmx/obr.xml
@@ -22,4 +22,9 @@
<p n="namespace" v="org.apache.felix.ipojo.handlers.jmx"/>
<p n="type" v="primitive"/>
</capability>
+ <capability name="ipojo.handler">
+ <p n="name" v="JMXBean"/>
+ <p n="namespace" v="org.apache.felix.ipojo.handlers.jmx"/>
+ <p n="type" v="primitive"/>
+ </capability>
</obr>
\ No newline at end of file
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 dc3e8c1..d2fe8f2 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,4 +1,4 @@
-/*
+/*
* 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
@@ -393,7 +393,8 @@
long timeStamp = System.currentTimeMillis();
- if (newValue.equals(oldValue)) {
+ if ((newValue == null && oldValue == null)
+ || (newValue != null && newValue.equals(oldValue))) {
return;
}
m_sequenceNumber++;
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 efffc22..9bbd354 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
@@ -76,6 +76,11 @@
private static final String JMX_CONFIG_ELT = "config";
/**
+ * The name of the global configuration element.
+ */
+ private static final String JMX_CONFIG_ALT_ELT = "JmxBean";
+
+ /**
* The name of the component object full name attribute.
*/
private static final String JMX_OBJ_NAME_ELT = "objectName";
@@ -103,7 +108,7 @@
/**
* The alternative name of a method element.
*/
- private static final String JMX_METHOD_ELT_ALT = "method";
+ private static final String JMX_METHOD_ELT_ALT = "JmxMethod";
/**
* The name of the property or method name attribute.
@@ -123,7 +128,7 @@
/**
* The alternative name of a property element.
*/
- private static final String JMX_PROPERTY_ELT_ALT = "property";
+ private static final String JMX_PROPERTY_ELT_ALT = "JmxProperty";
/**
* The name of the field attribute.
@@ -222,9 +227,12 @@
// Build the hashmap
Element[] mbeans = metadata.getElements(JMX_CONFIG_ELT, m_namespace);
+ if (mbeans == null || mbeans.length == 0) {
+ mbeans = metadata.getElements(JMX_CONFIG_ALT_ELT, m_namespace);
+ }
if (mbeans.length != 1) {
- error("A component must have at most one " + JMX_CONFIG_ELT + ".");
+ error("A component must have exactly one " + JMX_CONFIG_ELT + " or " + JMX_CONFIG_ALT_ELT + " element.");
error("The JMX handler configuration is ignored.");
return;
}
@@ -532,6 +540,21 @@
PropertyField propertyField = (PropertyField) m_jmxConfigFieldMap
.getPropertyFromField(fieldName);
if (propertyField != null) {
+ // Do we have a value to inject ?
+ Object v = propertyField.getValue();
+ if (v == null) {
+ String type = propertyField.getType();
+ if ("boolean".equals(type)) { v = Boolean.FALSE; }
+ else if ("byte".equals(type)) { v = new Byte((byte) 0); }
+ else if ("short".equals(type)) { v = new Short((short) 0); }
+ else if ("int".equals(type)) { v = new Integer(0); }
+ else if ("long".equals(type)) { v = new Long(0); }
+ else if ("float".equals(type)) { v = new Float(0); }
+ else if ("double".equals(type)) { v =new Double(0); }
+ else if ("char".equals(type)) { v = new Character((char) 0); }
+
+ return v;
+ }
m_instanceManager.onSet(pojo, fieldName, propertyField.getValue());
return propertyField.getValue();
}