Author: pderop
Date: Sat Feb 27 18:06:05 2016
New Revision: 1732660

URL: http://svn.apache.org/viewvc?rev=1732660&view=rev
Log:
FELIX-5201: Improve how components are displayed with gogo shell.

Modified:
    
felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java

Modified: 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java?rev=1732660&r1=1732659&r2=1732660&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
 (original)
+++ 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
 Sat Feb 27 18:06:05 2016
@@ -702,6 +702,7 @@ public class ComponentImpl implements Co
     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 @@ public class ComponentImpl implements Co
             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;


Reply via email to