Fix for Felix-3560
* New class CustomHandlerInfo is added for custom handlers to embed their custom information into ComponentTypeDescription for both later retrieval and contribution to description output in Arch commands.
* ComponentTypeDescription is extended to accept CustomHandlerInfo and dump it as output in getDescription()
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1359458 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentTypeDescription.java b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentTypeDescription.java
index f7a3ce5..04b8683 100644
--- a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentTypeDescription.java
+++ b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentTypeDescription.java
@@ -19,6 +19,8 @@
package org.apache.felix.ipojo.architecture;
import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
import java.util.Properties;
import org.apache.felix.ipojo.ComponentFactory;
@@ -45,6 +47,11 @@
* Configuration Properties accepted by the component type.
*/
private PropertyDescription[] m_properties = new PropertyDescription[0];
+
+ /*
+ * Used by custom handlers to keep and retrieve custom info.
+ */
+ private Dictionary m_handlerInfoSlot = new Hashtable();
/**
* Represented factory.
@@ -140,6 +147,32 @@
newProps[m_properties.length] = pd;
m_properties = newProps;
}
+
+ /**
+ * Adds the HandlerInfo for specified handler.
+ * @param handlerNs Handler's namespace
+ * @param handlerName Handler's name
+ * @param info HandlerInfo associated with the given custom handler.
+ */
+ public void setHandlerInfo(String handlerNs, String handlerName, CustomHandlerInfo info)
+ {
+ String fullHandlerName = handlerNs + ":" + handlerName;
+
+ if(info == null)
+ {
+ m_handlerInfoSlot.remove(fullHandlerName);
+ }
+ else
+ {
+ m_handlerInfoSlot.put(fullHandlerName, info);
+ }
+ }
+
+ public CustomHandlerInfo getHandlerInfo(String handlerNs, String handlerName)
+ {
+ String fullHandlerName = handlerNs + ":" + handlerName;
+ return (CustomHandlerInfo)m_handlerInfoSlot.get(fullHandlerName);
+ }
/**
* Gets the list of provided service offered by instances of this type.
@@ -255,6 +288,19 @@
}
desc.addElement(prop);
}
+
+ if(m_handlerInfoSlot.size() > 0)
+ {
+ Enumeration keys = m_handlerInfoSlot.keys();
+
+ while(keys.hasMoreElements())
+ {
+ String fullHandlerName = (String) keys.nextElement();
+
+ CustomHandlerInfo handlerInfo = (CustomHandlerInfo)m_handlerInfoSlot.get(fullHandlerName);
+ desc.addElement( handlerInfo.getDescription() );
+ }
+ }
return desc;
}
diff --git a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/CustomHandlerInfo.java b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/CustomHandlerInfo.java
new file mode 100644
index 0000000..8bfb023
--- /dev/null
+++ b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/CustomHandlerInfo.java
@@ -0,0 +1,37 @@
+/*
+ * 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.architecture;
+
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.metadata.Element;
+
+/**
+ * Information slot for custom {@link Handler}s to put their own custom
+ * information into {@link ComponentTypeDescription}
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface CustomHandlerInfo
+{
+ /**
+ * Returns the custom handler information in readable
+ * format to be displayed in ComponentTypeDescription.
+ * @return Custom Handler information
+ */
+ Element getDescription();
+}