felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r963387 - in /felix/trunk/ipojo/webconsole-plugin/src/main: java/org/apache/felix/ipojo/webconsole/ resources/res/ resources/res/ui/
Date Mon, 12 Jul 2010 17:42:04 GMT
Author: clement
Date: Mon Jul 12 17:42:03 2010
New Revision: 963387

URL: http://svn.apache.org/viewvc?rev=963387&view=rev
Log:
Add factory detail (work in progress).
Add the ipojo.css file and load it.

Modified:
    felix/trunk/ipojo/webconsole-plugin/src/main/java/org/apache/felix/ipojo/webconsole/IPOJOPlugin.java
    felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/factories.html
    felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/handlers.html
    felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/instances.html
    felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/factory.js
    felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/handler.js
    felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/ipojo.js

Modified: felix/trunk/ipojo/webconsole-plugin/src/main/java/org/apache/felix/ipojo/webconsole/IPOJOPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/webconsole-plugin/src/main/java/org/apache/felix/ipojo/webconsole/IPOJOPlugin.java?rev=963387&r1=963386&r2=963387&view=diff
==============================================================================
--- felix/trunk/ipojo/webconsole-plugin/src/main/java/org/apache/felix/ipojo/webconsole/IPOJOPlugin.java
(original)
+++ felix/trunk/ipojo/webconsole-plugin/src/main/java/org/apache/felix/ipojo/webconsole/IPOJOPlugin.java
Mon Jul 12 17:42:03 2010
@@ -5,6 +5,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintWriter;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import javax.servlet.ServletException;
@@ -22,7 +24,6 @@ import org.apache.felix.ipojo.annotation
 import org.apache.felix.ipojo.architecture.Architecture;
 import org.apache.felix.webconsole.AbstractWebConsolePlugin;
 import org.apache.felix.webconsole.DefaultVariableResolver;
-import org.apache.felix.webconsole.SimpleWebConsolePlugin;
 import org.apache.felix.webconsole.WebConsoleUtil;
 import org.json.JSONArray;
 import org.json.JSONException;
@@ -33,11 +34,12 @@ import org.json.JSONObject;
 @Instantiate
 public class IPOJOPlugin extends AbstractWebConsolePlugin {
     
-    private static final String CSS[] = { "/res/ui/bundles.css" };
+    private static final String CSS[] = { "/res/ui/bundles.css" , "/iPOJO_2/res/ui/ipojo.css"
}; // TODO Change
 
     private final String INSTANCES;
     private final String FACTORIES;
     private final String HANDLERS;
+    private final String FACTORY_DETAILS;
 
     
     /**
@@ -53,7 +55,7 @@ public class IPOJOPlugin extends Abstrac
     private String m_title = "iPOJO_2";  // TODO CHANGE
     
     @ServiceProperty(name= "felix.webconsole.css")
-    private String m_css = CSS[0];
+    protected String[] m_css = CSS;
 
     /**
      * List of available Architecture service.
@@ -77,38 +79,30 @@ public class IPOJOPlugin extends Abstrac
         INSTANCES = readTemplateFile(this.getClass(), "/res/instances.html" );
         FACTORIES = readTemplateFile(this.getClass(), "/res/factories.html" );
         HANDLERS = readTemplateFile(this.getClass(), "/res/handlers.html" );
+        FACTORY_DETAILS = readTemplateFile(this.getClass(), "/res/factory.html" );
     }
     
-    private final String readTemplateFile(final Class clazz, final String templateFile)
-    {
-        InputStream templateStream = getClass().getResourceAsStream(templateFile);
-        if (templateStream != null)
-        {
+    private final String readTemplateFile(final Class clazz,
+            final String templateFile) {
+        InputStream templateStream = getClass().getResourceAsStream(
+                templateFile);
+        if (templateStream != null) {
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             byte[] data = new byte[1024];
-            try
-            {
+            try {
                 int len = 0;
-                while ((len = templateStream.read(data)) > 0)
-                {
+                while ((len = templateStream.read(data)) > 0) {
                     baos.write(data, 0, len);
                 }
                 return baos.toString("UTF-8");
-            }
-            catch (IOException e)
-            {
+            } catch (IOException e) {
                 // don't use new Exception(message, cause) because cause is 1.4+
                 throw new RuntimeException("readTemplateFile: Error loading "
-                    + templateFile + ": " + e);
-            }
-            finally
-            {
-                try
-                {
+                        + templateFile + ": " + e);
+            } finally {
+                try {
                     templateStream.close();
-                }
-                catch (IOException e)
-                {
+                } catch (IOException e) {
                     /* ignore */
                 }
 
@@ -116,8 +110,8 @@ public class IPOJOPlugin extends Abstrac
         }
 
         // template file does not exist, return an empty string
-        log("readTemplateFile: File '" + templateFile + "' not found through class "
-            + clazz);
+        log("readTemplateFile: File '" + templateFile
+                + "' not found through class " + clazz);
         return "";
     }
 
@@ -128,15 +122,28 @@ public class IPOJOPlugin extends Abstrac
         final RequestInfo reqInfo = getRequestInfo(request);
         // prepare variables
         DefaultVariableResolver vars = ( ( DefaultVariableResolver ) WebConsoleUtil.getVariableResolver(
request ) );
-        String view = request.getParameter("view");
         
-        if (view == null || view.equals("instances")) {
-            response.getWriter().print( INSTANCES );
-        } else if (view.equals("factories")) {
-            response.getWriter().print( FACTORIES );
-        } else if (view.equals("handlers")) {
+        System.out.println("Render content for " + request.getPathInfo());
+        
+        if (reqInfo.instances) {
+            if (reqInfo.name == null) {
+                response.getWriter().print( INSTANCES );
+            } else {
+                // TODO
+            }
+        } else if (reqInfo.factories) {
+            if (reqInfo.name == null) {
+                response.getWriter().print( FACTORIES );
+            } else {
+                vars.put("name", reqInfo.name);
+                response.getWriter().print( FACTORY_DETAILS );
+            }
+        } else if (reqInfo.handlers) {
             response.getWriter().print( HANDLERS );
-        }             
+        } else {
+            // Default
+            response.getWriter().print( INSTANCES );
+        }
     }
     
     private void renderAllInstances(PrintWriter pw) {
@@ -233,6 +240,72 @@ public class IPOJOPlugin extends Abstrac
         }
     }
     
+    private void renderFactoryDetail(PrintWriter pw, String name) {
+        System.out.println("Render factory detail for " + name);
+        // Find the factory
+        Factory factory = null;
+        for (Factory fact : m_factories) {
+            if (fact.getName().equals(name)) {
+                factory = fact;
+            }
+        }
+        
+        if (factory == null) {
+            // TODO Error management
+            System.err.println("factory " + name + "  not found");
+            return;
+        }
+        
+        try {
+            JSONObject resp = new JSONObject();
+            resp.put("count", m_factories.size());
+            resp.put("valid_count", getValidFactoriesCount());
+            resp.put("invalid_count", getInvalidFactoriesCount());
+            
+            // Factory object
+            JSONObject data = new JSONObject();
+            data.put("name", factory.getName());
+            data.put("state", getFactoryState(factory.getState()));
+            
+            String bundle = factory.getBundleContext().getBundle().getSymbolicName()
+            + " (" + factory.getBundleContext().getBundle().getBundleId() + ")";
+            data.put("bundle", bundle);
+            
+            if (factory.getComponentDescription().getprovidedServiceSpecification().length
!= 0) {
+                JSONArray services = new JSONArray
+                    (Arrays.asList(factory.getComponentDescription().getprovidedServiceSpecification()));
+                data.put("services", services);
+            }
+            
+            if (! factory.getRequiredHandlers().isEmpty()) {
+                JSONArray req = new JSONArray
+                    (factory.getRequiredHandlers());
+                data.put("requiredHandlers", req);
+            }
+            
+            if (! factory.getMissingHandlers().isEmpty()) {
+                JSONArray req = new JSONArray
+                    (factory.getMissingHandlers());
+                data.put("missingHandlers", req);
+            }
+            
+            List instances = getInstanceList(name);
+            if (! instances.isEmpty()) {
+                JSONArray req = new JSONArray(instances);
+                data.put("instances", req);
+            }
+            
+            data.put("architecture", factory.getDescription().toString());
+            resp.put("data", data);
+            
+            pw.print(resp.toString());
+        } catch (JSONException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        
+    }
+    
     @Override
     protected void doGet(HttpServletRequest request,
             HttpServletResponse response) throws ServletException, IOException {
@@ -257,7 +330,8 @@ public class IPOJOPlugin extends Abstrac
                     this.renderAllFactories(response.getWriter());
                     return;
                 } else {
-                    // TODO
+                    System.out.println("Render details for " + reqInfo.name);
+                    this.renderFactoryDetail(response.getWriter(), reqInfo.name);
                     return;
                 }
             }
@@ -383,6 +457,22 @@ public class IPOJOPlugin extends Abstrac
         }
     }
     
+    /**
+     * Gets the instance list created by the given factory.
+     * @param factory the factory name
+     * @return the list containing the created instances (name)
+     */
+    private List getInstanceList(String factory) {
+        List list = new ArrayList();
+        for (Architecture arch : m_archs) { // Cannot be null, an empty list is returned.
+            String n = arch.getInstanceDescription().getComponentDescription().getName();
+            if (factory.equals(n)) {
+                list.add(arch.getInstanceDescription().getName());
+            }
+        }
+        return list;
+    }
+    
     private final class RequestInfo {
         public final String extension;
         public final String path;
@@ -408,15 +498,18 @@ public class IPOJOPlugin extends Abstrac
 
             if (info.startsWith("/")) {
                 path = info.substring(1);
+                System.out.println("Info " + info);
+
                 instances = path.startsWith("instances");
                 factories = path.startsWith("factories");
                 handlers = path.startsWith("handlers");
                
+                System.out.println("Path " + path);
                 
                 if (instances  && path.startsWith("instances/")) {
-                    name = path.substring(0, "instances".length() + 1);
+                    name = path.substring("instances".length() + 1);
                 } else if (factories  && path.startsWith("factories/")) {
-                    name = path.substring(0, "factories".length() + 1);
+                    name = path.substring("factories".length() + 1);
                 } else {
                     name = null;
                 }

Modified: felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/factories.html
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/factories.html?rev=963387&r1=963386&r2=963387&view=diff
==============================================================================
--- felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/factories.html (original)
+++ felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/factories.html Mon Jul 12 17:42:03
2010
@@ -1,5 +1,10 @@
 <script type="text/javascript" src="${pluginRoot}/res/ui/factory.js"></script>
-
+<script>
+    var root_url = '${pluginRoot}';
+    var instances_url = '${pluginRoot}' + '/instances';
+    var factories_url = '${pluginRoot}' + '/factories';
+    var handlers_url = '${pluginRoot}' + '/handlers';
+</script>
 
 <!-- status line -->
 <p class="statline">&nbsp;</p>

Modified: felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/handlers.html
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/handlers.html?rev=963387&r1=963386&r2=963387&view=diff
==============================================================================
--- felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/handlers.html (original)
+++ felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/handlers.html Mon Jul 12 17:42:03
2010
@@ -1,5 +1,10 @@
 <script type="text/javascript" src="${pluginRoot}/res/ui/handler.js"></script>
-
+<script>
+    var root_url = '${pluginRoot}';
+    var instances_url = '${pluginRoot}' + '/instances';
+    var factories_url = '${pluginRoot}' + '/factories';
+    var handlers_url = '${pluginRoot}' + '/handlers';
+</script>
 
 <!-- status line -->
 <p class="statline">&nbsp;</p>

Modified: felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/instances.html
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/instances.html?rev=963387&r1=963386&r2=963387&view=diff
==============================================================================
--- felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/instances.html (original)
+++ felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/instances.html Mon Jul 12 17:42:03
2010
@@ -1,4 +1,10 @@
 <script type="text/javascript" src="${pluginRoot}/res/ui/ipojo.js"></script>
+<script>
+    var root_url = '${pluginRoot}';
+    var instances_url = '${pluginRoot}' + '/instances';
+    var factories_url = '${pluginRoot}' + '/factories';
+    var handlers_url = '${pluginRoot}' + '/handlers';
+</script>
 
 <!-- status line -->
 <p class="statline">&nbsp;</p>

Modified: felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/factory.js
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/factory.js?rev=963387&r1=963386&r2=963387&view=diff
==============================================================================
--- felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/factory.js (original)
+++ felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/factory.js Mon Jul 12 17:42:03
2010
@@ -38,7 +38,7 @@ function factoriesEntry(factory) {
 
     var _ = tableEntryTemplate.clone().appendTo(tableBody).attr('id', 'factory-' + factory.name);
 
-    _.find('td.name').html('<a href="' + window.location.pathname + '/factories/' + name
+ '">' + name + '</a>');
+    _.find('td.name').html('<a href="' + factories_url + '/' + name + '">' + name +
'</a>');
     _.find('td.bundle').text(bundle);
     _.find('td.state').text(state);
 }
@@ -53,11 +53,11 @@ function loadFactoriesData() {
 
 function loadInstancesData() {
     console.log("Go to instances"); 
-    window.location=window.location.pathname + "?view=instances"
+    window.location = instances_url;
 }
 
 function loadHandlersData() {
-    window.location=window.location.pathname + "?view=handlers"
+    window.location = handlers_url;
 }
 
 var tableBody = false;

Modified: felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/handler.js
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/handler.js?rev=963387&r1=963386&r2=963387&view=diff
==============================================================================
--- felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/handler.js (original)
+++ felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/handler.js Mon Jul 12 17:42:03
2010
@@ -60,11 +60,11 @@ function loadHandlersData() {
 }
 
 function loadInstancesData() {
-    window.location=window.location.pathname + "?view=instances"
+    window.location = instances_url;
 }
 
 function loadFactoriesData() {
-    window.location=window.location.pathname + "?view=factories"
+    window.location = factories_url;
 }
 
 var tableBody = false;

Modified: felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/ipojo.js
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/ipojo.js?rev=963387&r1=963386&r2=963387&view=diff
==============================================================================
--- felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/ipojo.js (original)
+++ felix/trunk/ipojo/webconsole-plugin/src/main/resources/res/ui/ipojo.js Mon Jul 12 17:42:03
2010
@@ -49,12 +49,11 @@ function loadInstancesData() {
 }
 
 function loadFactoriesData() {
-    console.log("Go to factories data");
-    window.location=window.location.pathname + '?view=factories'; 
+    window.location = factories_url; 
 }
 
 function loadHandlersData() {
-    window.location=window.location.pathname + "?view=handlers"
+    window.location = handlers_url;
 }
 
 var tableBody = false;



Mime
View raw message