portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wea...@apache.org
Subject cvs commit: jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletregsitry PortletRegistryComponent.java PortletRegistryComponentImpl.java
Date Sat, 06 Mar 2004 19:05:09 GMT
weaver      2004/03/06 11:05:09

  Modified:    components/registry/src/java/org/apache/jetspeed/components/portletregsitry
                        PortletRegistryComponent.java
                        PortletRegistryComponentImpl.java
  Log:
  Added defensive programming to the PortletRegistryCompnent.
  
  getPortletByUniqueIdentifer() and getPortletByUniqueName() will
  throw IllegalStateExceptions immediately if portlet def found is not null
  AND it that portlet definition has no associated portlet application.  This will
  give us a more precise and fail-fast environment.
  
  Revision  Changes    Path
  1.4       +9 -0      jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletregsitry/PortletRegistryComponent.java
  
  Index: PortletRegistryComponent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletregsitry/PortletRegistryComponent.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PortletRegistryComponent.java	2 Mar 2004 02:01:19 -0000	1.3
  +++ PortletRegistryComponent.java	6 Mar 2004 19:05:09 -0000	1.4
  @@ -119,6 +119,10 @@
        * on the returned <code>PortletEntityInstance</code>
        * @param ident Unique id for this portlet
        * @return Portlet matching this unique id.
  +     * @throws java.lang.IllegalStateException If <code>PortletDefinitionComposite
!= null</code> AND
  +     *  <code>PortletDefinitionComposite.getPortletApplicationDefinition() ==  null</code>.
  +     * The reason for this is that every PortletDefinition is required to
  +     * have a parent PortletApplicationDefinition
        */
       PortletDefinitionComposite getPortletDefinitionByIndetifier(String ident);
       /**
  @@ -134,6 +138,11 @@
        * on the returned <code>PortletEntityInstance</code> 
        * @param name portlets unique name.  
        * @return Portlet that matches the unique name 
  +     * @throws java.lang.IllegalStateException If <code>PortletDefinitionComposite
!= null</code> AND
  +     *  <code>PortletDefinitionComposite.getPortletApplicationDefinition() ==  null</code>.
  +     * The reason for this is that every PortletDefinition is required to
  +     * have a parent PortletApplicationDefinition
  +     * 
        */
       PortletDefinitionComposite getPortletDefinitionByUniqueName(String name);
    
  
  
  
  1.6       +78 -76    jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletregsitry/PortletRegistryComponentImpl.java
  
  Index: PortletRegistryComponentImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletregsitry/PortletRegistryComponentImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PortletRegistryComponentImpl.java	4 Mar 2004 21:21:36 -0000	1.5
  +++ PortletRegistryComponentImpl.java	6 Mar 2004 19:05:09 -0000	1.6
  @@ -58,7 +58,8 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.Locale;
  -
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   import org.apache.jetspeed.components.persistence.store.Filter;
   import org.apache.jetspeed.components.persistence.store.PersistenceStore;
   import org.apache.jetspeed.components.persistence.store.PersistenceStoreContainer;
  @@ -82,46 +83,37 @@
    * Component for accessing the Portlet registry.
    * </p>
    * 
  - *  <table border="1">
  - *    <tr>
  - *     <th>Configuration Key</th>
  - *     <th>Optional?</th>
  - *     <th>Default</th>
  - *     <th>Description</th>
  - *    </tr>
  - *    <tr>
  - *     <td>
  - *      persistence.store.name
  - *     </td>
  - *     <td>
  - *      true 
  - *     </td>
  - *     <td>
  - *      jetspeed
  - *     </td>
  - *     <td>
  - *      Name of the persistence store that will be  
  - *      used for persistence operations.
  - *     </td>
  - *    </tr>
  - *   </table>
  - *
  -
  - * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
  + * <table border="1">
  + * <tr>
  + * <th>Configuration Key</th>
  + * <th>Optional?</th>
  + * <th>Default</th>
  + * <th>Description</th>
  + * </tr>
  + * <tr>
  + * <td>persistence.store.name</td>
  + * <td>true</td>
  + * <td>jetspeed</td>
  + * <td>Name of the persistence store that will be used for persistence operations.</td>
  + * </tr>
  + * </table>
  + * 
  + * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
    * @version $ $
  - *
  + *  
    */
   public class PortletRegistryComponentImpl implements org.apache.jetspeed.components.portletregsitry.PortletRegistryComponent
   {
  -
  +    private static final Log log = LogFactory.getLog(PortletRegistryComponentImpl.class);
       protected static final String KEY_STORE_NAME = "persistence.store.name";
       private PersistenceStoreContainer storeContainer;
       private String jetspeedStoreName;
       private Class portletDefClass;
       private Class portletAppClass;
   
  +
       /**
  -     * 
  +     *  
        */
       public PortletRegistryComponentImpl(PersistenceStoreContainer storeContainer, String
keyStoreName) throws RegistryException
       {
  @@ -129,34 +121,30 @@
           {
               throw new IllegalArgumentException("storeContainer cannot be null for PortletRegistryComponentImpl");
           }
  -
           this.storeContainer = storeContainer;
  -
           jetspeedStoreName = keyStoreName;
  -
           portletDefClass = PortletDefinitionImpl.class;
           portletAppClass = PortletApplicationDefinitionImpl.class;
  -
       }
   
  -    /** 
  +    /**
        * <p>
        * createLanguage
        * </p>
        * 
  -     * @see org.apache.jetspeed.registry.PortletRegistryComponentImpl#createLanguage(java.util.Locale,
java.lang.String, java.lang.String, java.lang.String, java.util.Collection)
  +     * @see org.apache.jetspeed.registry.PortletRegistryComponentImpl#createLanguage(java.util.Locale,
java.lang.String,
  +     *      java.lang.String, java.lang.String, java.util.Collection)
        * @param locale
        * @param title
        * @param shortTitle
        * @param description
        * @param keywords
  -     * @return
  -     * @throws RegistryException
  +     * @return @throws
  +     *         RegistryException
        */
       public Language createLanguage(Locale locale, String title, String shortTitle, String
description, Collection keywords)
  -        throws RegistryException
  +    throws RegistryException
       {
  -
           try
           {
               MutableLanguage lc = new LanguageImpl();
  @@ -164,17 +152,15 @@
               lc.setTitle(title);
               lc.setShortTitle(shortTitle);
               lc.setKeywords(keywords);
  -
               return lc;
           }
           catch (Exception e)
           {
               throw new RegistryException("Unable to create language object.");
           }
  -
       }
   
  -    /** 
  +    /**
        * <p>
        * getAllPortletDefinitions
        * </p>
  @@ -194,7 +180,7 @@
           return storeContainer.getStoreForThread(jetspeedStoreName);
       }
   
  -    /** 
  +    /**
        * <p>
        * getPortletApplication
        * </p>
  @@ -221,7 +207,7 @@
           }
       }
   
  -    /** 
  +    /**
        * <p>
        * getPortletApplication
        * </p>
  @@ -240,7 +226,7 @@
           return (MutablePortletApplication) store.getObjectByQuery(query);
       }
   
  -    /** 
  +    /**
        * <p>
        * getPortletApplicationByIndetifier
        * </p>
  @@ -259,7 +245,7 @@
           return (MutablePortletApplication) store.getObjectByQuery(query);
       }
   
  -    /** 
  +    /**
        * <p>
        * getPortletApplications
        * </p>
  @@ -274,7 +260,7 @@
           return new ArrayList(store.getExtent(portletAppClass));
       }
   
  -    /** 
  +    /**
        * <p>
        * getPortletDefinitionByIndetifier
        * </p>
  @@ -290,10 +276,24 @@
           Filter filter = store.newFilter();
           filter.addEqualTo("portletIdentifier", ident);
           Object query = store.newQuery(portletDefClass, filter);
  -        return getStoreableInstance((PortletDefinitionComposite) store.getObjectByQuery(query));
  +        PortletDefinitionComposite portlet = (PortletDefinitionComposite) store.getObjectByQuery(query);
  +        if (portlet != null)
  +        {
  +            if (portlet.getPortletApplicationDefinition() == null)
  +            {
  +                final String msg = "getPortletDefinitionByIdentifier() returned a PortletDefinition
that has no parent PortletApplication.";
  +                log.error(msg);
  +                throw new IllegalStateException(msg);
  +            }
  +            return getStoreableInstance(portlet);
  +        }
  +        else
  +        {
  +            return null;
  +        }
       }
   
  -    /** 
  +    /**
        * <p>
        * getPortletDefinitionByUniqueName
        * </p>
  @@ -306,29 +306,40 @@
       {
           PersistenceStore store = getPersistenceStore();
           prepareTransaction(store);
  -    
  +
           //parse out names
           int split = name.indexOf("::");
           if (split < 1)
           {
               throw new IllegalArgumentException(
  -                "The unique portlet name, \"" + name + "\";  is not well formed.  No \"::\"
delimiter was found.");
  +            "The unique portlet name, \"" + name + "\";  is not well formed.  No \"::\"
delimiter was found.");
           }
  -    
           String appName = name.substring(0, split);
           String portletName = name.substring((split + 2), name.length());
  -    
  +
           // build filter
           Filter filter = store.newFilter();
           filter.addEqualTo("app.name", appName);
           filter.addEqualTo("name", portletName);
           Object query = store.newQuery(portletDefClass, filter);
  -        PortletDefinitionComposite pdc = (PortletDefinitionComposite) store.getObjectByQuery(query);
  -    
  -        return getStoreableInstance(pdc);
  +        PortletDefinitionComposite portlet = (PortletDefinitionComposite) store.getObjectByQuery(query);
  +        if (portlet != null)
  +        {
  +            if (portlet.getPortletApplicationDefinition() == null)
  +            {
  +                final String msg = "getPortletDefinitionByUniqueName() returned a PortletDefinition
that has no parent PortletApplication.";
  +                log.error(msg);
  +                throw new IllegalStateException(msg);
  +            }
  +            return getStoreableInstance(portlet);
  +        }
  +        else
  +        {
  +            return null;
  +        }
       }
   
  -    /** 
  +    /**
        * <p>
        * portletApplicationExists
        * </p>
  @@ -342,7 +353,7 @@
           return getPortletApplicationByIndetifier(appIentity) != null;
       }
   
  -    /** 
  +    /**
        * <p>
        * portletDefinitionExists
        * </p>
  @@ -356,23 +367,23 @@
           return getPortletDefinitionByIndetifier(portletIndentity) != null;
       }
   
  -    /** 
  +    /**
        * <p>
        * portletDefinitionExists
        * </p>
        * 
  -     * @see org.apache.jetspeed.registry.PortletRegistryComponentImpl#portletDefinitionExists(java.lang.String,
org.apache.jetspeed.om.common.portlet.MutablePortletApplication)
  +     * @see org.apache.jetspeed.registry.PortletRegistryComponentImpl#portletDefinitionExists(java.lang.String,
  +     *      org.apache.jetspeed.om.common.portlet.MutablePortletApplication)
        * @param portletName
        * @param app
        * @return
        */
       public boolean portletDefinitionExists(String portletName, MutablePortletApplication
app)
       {
  -
           return getPortletDefinitionByUniqueName(app.getName() + "::" + portletName) !=
null;
       }
   
  -    /** 
  +    /**
        * <p>
        * registerPortletApplication
        * </p>
  @@ -385,7 +396,6 @@
       {
           PersistenceStore store = getPersistenceStore();
           prepareTransaction(store);
  -
           try
           {
               store.makePersistent(newApp);
  @@ -395,10 +405,9 @@
           {
               throw new RegistryException("Unable to lock PortletApplicaiton for makePersistent:
" + e.toString(), e);
           }
  -
       }
   
  -    /** 
  +    /**
        * <p>
        * removeApplication
        * </p>
  @@ -411,29 +420,25 @@
       {
           PersistenceStore store = getPersistenceStore();
           prepareTransaction(store);
  -
           try
  -        {   
  +        {
               Iterator portlets = app.getPortletDefinitionList().iterator();
  -            while(portlets.hasNext())
  +            while (portlets.hasNext())
               {
                   // portlets are getting cascade deleted but
                   // content type and langs asocciated are not
                   store.deletePersistent(portlets.next());
               }
               store.deletePersistent(app);
  -            
               store.getTransaction().checkpoint();
           }
           catch (LockFailedException e)
           {
               throw new RegistryException("Unable to lock PortletApplication for deletion:
" + e.toString(), e);
  -
           }
  -
       }
   
  -    /** 
  +    /**
        * <p>
        * updatePortletApplication
        * </p>
  @@ -455,7 +460,6 @@
           {
               throw new RegistryException("Unable to lock PortletApplicaiton for update:
" + e.toString(), e);
           }
  -
       }
   
       public PortletDefinitionComposite getStoreableInstance(PortletDefinitionComposite portlet)
  @@ -468,7 +472,5 @@
           {
               return null;
           }
  -
       }
  -
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message