geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmcma...@apache.org
Subject svn commit: r573711 - /geronimo/plugins/pluto/trunk/geronimo-pluto/src/main/java/org/apache/geronimo/pluto/AdminConsoleExtensionGBean.java
Date Fri, 07 Sep 2007 21:11:19 GMT
Author: pmcmahan
Date: Fri Sep  7 14:11:19 2007
New Revision: 573711

URL: http://svn.apache.org/viewvc?rev=573711&view=rev
Log:
GERONIMO-3413 updates to the AdminConsoleExtension gbean to make it provide better logging
and be less noisy on startup and shutdown

Modified:
    geronimo/plugins/pluto/trunk/geronimo-pluto/src/main/java/org/apache/geronimo/pluto/AdminConsoleExtensionGBean.java

Modified: geronimo/plugins/pluto/trunk/geronimo-pluto/src/main/java/org/apache/geronimo/pluto/AdminConsoleExtensionGBean.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/pluto/trunk/geronimo-pluto/src/main/java/org/apache/geronimo/pluto/AdminConsoleExtensionGBean.java?rev=573711&r1=573710&r2=573711&view=diff
==============================================================================
--- geronimo/plugins/pluto/trunk/geronimo-pluto/src/main/java/org/apache/geronimo/pluto/AdminConsoleExtensionGBean.java
(original)
+++ geronimo/plugins/pluto/trunk/geronimo-pluto/src/main/java/org/apache/geronimo/pluto/AdminConsoleExtensionGBean.java
Fri Sep  7 14:11:19 2007
@@ -19,6 +19,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -75,15 +76,14 @@
      * @see org.apache.geronimo.pluto.PlutoAccessInterface#addPortlets(java.lang.String,
java.lang.String, java.util.ArrayList)
      */
     public void addPortlets(String pageTitle, String portletContext, ArrayList<String>
portletList) {
-        PageConfig pageConfig = getPageConfigFromPluto(pageTitle); 
-
         if(pageExists(pageTitle)){
+            PageConfig pageConfig = getPageConfigFromPluto(pageTitle);
             int portletCount = portletList.size();
             for (int i=0; i<portletCount; i++){
                 pageConfig.addPortlet(portletContext,portletList.get(i));
             }
         }else{
-            //TODO: that page is not there......should we create one with that name?  throw
an error?
+            log.warn("Cannot add portlets to non-existent page " + pageTitle);
         }
     }
 
@@ -97,6 +97,7 @@
         
         //Get the handle on the pluto service
         PortalContainerServices container = getPortalContainerServices();
+        
         RenderConfigAdminService renderConfig = container.getAdminConfiguration().getRenderConfigAdminService();
         
         //This removePage method was added into Pluto as a patch (PLUTO-387). addPage functionality
@@ -112,9 +113,8 @@
      * @see org.apache.geronimo.pluto.PlutoAccessInterface#removePortlets(java.lang.String,
java.util.ArrayList)
      */
     public void removePortlets(String pageTitle, ArrayList<String> portletList) {
-        PageConfig pageConfig = getPageConfigFromPluto(pageTitle);
-        
-        if(pageExists(pageTitle)){
+        if(pageExists(pageTitle)) {
+            PageConfig pageConfig = getPageConfigFromPluto(pageTitle);
             int portletCount = portletList.size();
             Collection list = pageConfig.getPortletIds();
             
@@ -135,7 +135,7 @@
                 }
             }
         }else{
-            //TODO: that page is not there......should we create one with that name?  throw
an error?
+            log.warn("can't remove portlets from non-existent page " + pageTitle);
         }
     }
     
@@ -151,7 +151,7 @@
         } catch (Exception e) {
             //If we fall into here, the likely (but not only) cause is that we couldn't find
the
             //PortalContainerService in the Kernel.
-            e.printStackTrace();
+            log.error("Cannot get the portal container services", e);
         }
         return container;
     }
@@ -176,7 +176,6 @@
         RenderConfigService service = container.getRenderConfigService();
         
         PageConfig pageConfig = service.getPage(pageTitle);
-        
         return pageConfig;
     }
     
@@ -184,14 +183,20 @@
      * return true if Pluto contains a PageConfig with that name, else false
      */
     private boolean pageExists(String pageTitle){
-
-        PageConfig pageConfig = getPageConfigFromPluto(pageTitle);
-
-        //If the page does not exist, then the default page (Welcome) is returned by getPage
-        //Check to see if we got the page we requested, flag if we didn't and create a new
one 
-        boolean pageExists = (pageConfig.getName().equals(pageTitle));
+        if (pageTitle == null) return false;
+        
+        //Get the handle on pluto's rendering service
+        PortalContainerServices container = getPortalContainerServices();
+        RenderConfigService service = container.getRenderConfigService();
+        
+        List<PageConfig> pageConfigs = service.getPages();
+        for (PageConfig pageConfig : pageConfigs) {
+            if (pageTitle.equals(pageConfig.getName())) {
+                return true;
+            }
+        }
         
-        return pageExists;
+        return false;
     }
     
     /*
@@ -200,12 +205,9 @@
     private boolean pageIsEmpty(String pageTitle){
         if(pageExists(pageTitle)){
             PageConfig pageConfig = getPageConfigFromPluto(pageTitle);
-            int portletCount = pageConfig.getPortletIds().size();
-            if(portletCount==0)
-                return true;
-            else return false;
+            return pageConfig.getPortletIds().size() > 0 ? true : false;
         }else{
-            //TODO: that page is not there......should i throw an error?
+            log.debug("no pageConfig found for " + pageTitle);
             return true;
         }
     }
@@ -216,6 +218,14 @@
      * @see org.apache.geronimo.gbean.GBeanLifecycle#doStart()
      */
     public synchronized void doStart() throws Exception{
+        //Get the handle on the pluto service
+        PortalContainerServices container = getPortalContainerServices();
+        
+        // check to make sure that a portal driver has registered with the container services
+        if (container.getAdminConfiguration() == null) {
+            throw new RuntimeException ("No portal driver has been registered with the portal
container services");
+        }
+        
         //add the page if it doesn't exist yet
         if(!pageExists(pageTitle)){
             //create a PageConfig
@@ -234,13 +244,23 @@
      * @see org.apache.geronimo.gbean.GBeanLifecycle#doStop()
      */
     public synchronized void doStop() throws Exception{
-        //remove portlets from the page
-        removePortlets(pageTitle, portletList);
-        
-        //if the page has 0 portlets on it, then go ahead and remove it
-        if(pageIsEmpty(pageTitle)){
-            removePage(pageTitle);
+        try {
+            //remove portlets from the page
+            removePortlets(pageTitle, portletList);
+            
+            //if the page has 0 portlets on it, then go ahead and remove it
+            if(pageIsEmpty(pageTitle)){
+                removePage(pageTitle);
+            }
+        } catch (NullPointerException e) {
+            // during normal server shutdown the portal driver has been shut down before
+            // the admin console extensions.  the way that pluto is currently implemented
+            // is that when the portal driver shuts down it destroys all its services.
+            // this leads to an NPE when you try to use them.  currently there is no
+            // way to check to see if a service has been shut down.
+            log.debug("could not remove portlets for " + pageTitle, e);
         }
+        
         log.debug("Stopped AdminConsoleExtensionGBean for " + pageTitle);
     }
     



Mime
View raw message