You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2010/10/11 18:22:58 UTC

svn commit: r1021407 - /felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java

Author: cziegeler
Date: Mon Oct 11 16:22:58 2010
New Revision: 1021407

URL: http://svn.apache.org/viewvc?rev=1021407&view=rev
Log:
FELIX-2652 : Allow attachment providers which do not implement the interface

Modified:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java?rev=1021407&r1=1021406&r2=1021407&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java Mon Oct 11 16:22:58 2010
@@ -282,6 +282,18 @@ public class ConfigurationRender extends
         }
     }
 
+    private Method searchMethod(final Object obj, final String mName, final Class[] params)
+    {
+        try
+        {
+            return obj.getClass().getDeclaredMethod(mName, params);
+        }
+        catch (NoSuchMethodException nsme)
+        {
+            // ignore
+        }
+        return null;
+    }
 
     private final synchronized List getConfigurationPrinters()
     {
@@ -326,31 +338,25 @@ public class ConfigurationRender extends
                         else
                         {
                             ConfigurationPrinter cfgPrinter = null;
+
                             // first: printConfiguration(PrintWriter, String)
-                            try
+                            final Method method2Params = this.searchMethod(service, "printConfiguration",
+                                    new Class[] {PrintWriter.class, String.class});
+                            if ( method2Params != null )
                             {
-                                final Method method = service.getClass().getDeclaredMethod("printConfiguration",
-                                        new Class[] {PrintWriter.class, String.class});
                                 cfgPrinter = new ModeAwareConfigurationPrinterAdapter(service,
-                                        (String)ref.getProperty(  WebConsoleConstants.PLUGIN_TITLE ), method);
-                            }
-                            catch (NoSuchMethodException nsme)
-                            {
-                                // ignore
+                                        (String)ref.getProperty(  WebConsoleConstants.PLUGIN_TITLE ), method2Params);
                             }
+
                             if ( cfgPrinter == null )
                             {
                                 // second: printConfiguration(PrintWriter)
-                                try
+                                final Method method1Params = this.searchMethod(service, "printConfiguration",
+                                        new Class[] {PrintWriter.class});
+                                if ( method1Params != null )
                                 {
-                                   final Method method = service.getClass().getDeclaredMethod("printConfiguration",
-                                           new Class[] {PrintWriter.class});
                                    cfgPrinter = new ConfigurationPrinterAdapter(service,
-                                           (String)ref.getProperty(  WebConsoleConstants.PLUGIN_TITLE ), method);
-                                }
-                                catch (NoSuchMethodException nsme)
-                                {
-                                    // ignore
+                                           (String)ref.getProperty(  WebConsoleConstants.PLUGIN_TITLE ), method1Params);
                                 }
                             }
 
@@ -662,14 +668,30 @@ public class ConfigurationRender extends
             if ( desc.match(mode) )
             {
                 // check if printer implements binary configuration printer
+                URL[] attachments = null;
                 if ( desc.printer instanceof AttachmentProvider )
                 {
-                    final URL[] attachments = ((AttachmentProvider)desc.printer).getAttachments(mode);
-                    if ( attachments != null )
+                    attachments = ((AttachmentProvider)desc.printer).getAttachments(mode);
+                }
+                else
+                {
+                    final Method m = this.searchMethod(desc.printer, "getAttachments", new Class[] {String.class});
+                    if ( m != null )
                     {
-                        cf.handleAttachments( desc.title, attachments );
+                        try
+                        {
+                            attachments = (URL[])m.invoke(desc.printer, new Object[] {mode});
+                        }
+                        catch (Throwable t)
+                        {
+                            // ignore this!
+                        }
                     }
                 }
+                if ( attachments != null )
+                {
+                    cf.handleAttachments( desc.title, attachments );
+                }
             }
         }