FELIX-5201: Improve how components are displayed with gogo shell.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1732660 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java b/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
index 3fed28e..866258e 100644
--- a/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
+++ b/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
@@ -702,6 +702,7 @@
public String getName() {
StringBuffer sb = new StringBuffer();
Object serviceName = m_serviceName;
+ // If the component provides service(s), return the services as the component name.
if (serviceName instanceof String[]) {
String[] names = (String[]) serviceName;
for (int i = 0; i < names.length; i++) {
@@ -715,32 +716,50 @@
sb.append(serviceName.toString());
appendProperties(sb);
} else {
- Object implementation = m_componentDefinition;
- if (implementation != null) {
- if (implementation instanceof Class) {
- sb.append(((Class<?>) implementation).getName());
+ // The component does not provide a service, use the component definition as the name.
+ Object componentDefinition = m_componentDefinition;
+ if (componentDefinition != null) {
+ getName(componentDefinition, sb);
+ } else {
+ // No component definition means we are using a factory. If the component instance is available use it as the component name,
+ // alse use teh factory object as the component name.
+ Object componentInstance = m_componentInstance;
+ if (componentInstance != null) {
+ sb.append(componentInstance.getClass().getName());
} else {
- // If the implementation instance does not override "toString", just display
- // the class name, else display the component using its toString method
- try {
- Method m = implementation.getClass().getMethod("toString", new Class[0]);
- if (m.getDeclaringClass().equals(Object.class)) {
- sb.append(implementation.getClass().getName());
- } else {
- sb.append(implementation.toString());
- }
- } catch (java.lang.NoSuchMethodException e) {
- // Just display the class name
- sb.append(implementation.getClass().getName());
+ // Check if a factory is set.
+ Object instanceFactory = m_instanceFactory;
+ if (instanceFactory != null) {
+ getName(instanceFactory, sb);
+ } else {
+ sb.append(super.toString());
}
}
- } else {
- sb.append(super.toString());
}
}
return sb.toString();
}
+ private void getName(Object implementation, StringBuffer sb) {
+ if (implementation instanceof Class) {
+ sb.append(((Class<?>) implementation).getName());
+ } else {
+ // If the implementation instance does not override "toString", just display
+ // the class name, else display the component using its toString method
+ try {
+ Method m = implementation.getClass().getMethod("toString", new Class[0]);
+ if (m.getDeclaringClass().equals(Object.class)) {
+ sb.append(implementation.getClass().getName());
+ } else {
+ sb.append(implementation.toString());
+ }
+ } catch (java.lang.NoSuchMethodException e) {
+ // Just display the class name
+ sb.append(implementation.getClass().getName());
+ }
+ }
+ }
+
@Override
public BundleContext getBundleContext() {
return m_context;