Coverage report

  %line %branch
org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl
0% 
0% 

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 package org.apache.jetspeed.om.portlet.impl;
 19  
 
 20  
 import java.io.Serializable;
 21  
 import java.util.ArrayList;
 22  
 import java.util.Collection;
 23  
 import java.util.Collections;
 24  
 import java.util.HashMap;
 25  
 import java.util.Iterator;
 26  
 import java.util.List;
 27  
 import java.util.Map;
 28  
 
 29  
 import javax.portlet.PortletMode;
 30  
 import javax.portlet.WindowState;
 31  
 
 32  
 import org.apache.jetspeed.JetspeedActions;
 33  
 import org.apache.jetspeed.om.common.GenericMetadata;
 34  
 import org.apache.jetspeed.om.common.JetspeedServiceReference;
 35  
 import org.apache.jetspeed.om.common.Support;
 36  
 import org.apache.jetspeed.om.common.UserAttribute;
 37  
 import org.apache.jetspeed.om.common.UserAttributeRef;
 38  
 import org.apache.jetspeed.om.common.portlet.CustomPortletMode;
 39  
 import org.apache.jetspeed.om.common.portlet.CustomWindowState;
 40  
 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
 41  
 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 42  
 import org.apache.jetspeed.om.impl.UserAttributeImpl;
 43  
 import org.apache.jetspeed.util.JetspeedLongObjectID;
 44  
 import org.apache.pluto.om.common.ObjectID;
 45  
 import org.apache.pluto.om.portlet.PortletDefinition;
 46  
 import org.apache.pluto.om.portlet.PortletDefinitionList;
 47  
 import org.apache.pluto.om.servlet.WebApplicationDefinition;
 48  
 
 49  
 /**
 50  
  *
 51  
  * @author <a href="mailto:paulsp@apache.org">Paul Spencer</a>
 52  
  * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
 53  
  * @version $Id: PortletApplicationDefinitionImpl.java 553014 2007-07-03 23:10:53Z ate $
 54  
  * @since 1.0
 55  
  */
 56  
 public class PortletApplicationDefinitionImpl implements MutablePortletApplication, Serializable, Support
 57  
 { 
 58  
     /**
 59  
      * Unique id of the application.  This serves as the primary key in database
 60  
      * and in any caching of this object.
 61  
      */
 62  
     private Long id;
 63  
     
 64  
     private JetspeedLongObjectID oid;
 65  
     
 66  
     /** Holds value of property name. */
 67  
     private String name;
 68  
 
 69  
     /** Holds value of property version. */
 70  
     private String version;
 71  
 
 72  
     /** Holds the optional application identifier from the portlet.xml */
 73  
     private String applicationIdentifier;
 74  
 
 75  
     /** WebApplication property */
 76  
     private transient WebApplicationDefinition webApplication;
 77  
     /** PK of this Portlet Application's Web Application */
 78  
     protected long webApplicationId;
 79  
     
 80  
     /** Metadata property */
 81  0
     private Collection metadataFields = null;
 82  
 
 83  
     /** Metadata property */
 84  0
     private Collection services = new ArrayList();
 85  
     
 86  
     /** Description */
 87  
     private String description;
 88  
 
 89  
     private Collection portlets;
 90  
 
 91  
     /** User attribute refs collection. */
 92  
     private Collection userAttributeRefs;
 93  
     
 94  
     /** User attributes collection. */
 95  
     private Collection userAttributes;
 96  
     
 97  0
     private PortletDefinitionListImpl listWrapper = new PortletDefinitionListImpl();
 98  
 
 99  0
     private int applicationType = MutablePortletApplication.WEBAPP;
 100  
     
 101  0
     private String checksum = "0";
 102  0
     private long checksumLong = -1;
 103  
     
 104  
     private List customPortletModes;
 105  
     private List customWindowStates;
 106  
     
 107  0
     private String jetspeedSecurityConstraint = null;
 108  
     
 109  
     private transient Map supportedCustomModes;
 110  
     private transient Map supportedCustomStates;
 111  
     private transient Map mappedCustomModes;
 112  
     private transient Map mappedCustomStates;    
 113  
     private transient Collection supportedPortletModes;
 114  
     private transient Collection supportedWindowStates;
 115  
     
 116  
     /** Creates a new instance of BaseApplication */
 117  
     public PortletApplicationDefinitionImpl()
 118  0
     {
 119  0
         portlets = new ArrayList();
 120  0
         userAttributes = new ArrayList();        
 121  0
         userAttributeRefs = new ArrayList();
 122  0
         customPortletModes = new ArrayList();
 123  0
         customWindowStates = new ArrayList();
 124  0
     }
 125  
 
 126  
     /**
 127  
      * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getId()
 128  
      */
 129  
     public ObjectID getId()
 130  
     {
 131  0
         if ( oid == null && id != class="keyword">null )
 132  
         {
 133  0
             oid = new JetspeedLongObjectID(id);
 134  
         }
 135  0
         return oid;
 136  
     }
 137  
 
 138  
     /**
 139  
      * @see org.apache.jetspeed.om.common.Application#getName()
 140  
      */
 141  
     public String getName()
 142  
     {
 143  0
         return this.name;
 144  
     }
 145  
 
 146  
     /**
 147  
      * @see org.apache.jetspeed.om.common.Application#setName(String)
 148  
      */
 149  
     public void setName(String name)
 150  
     {
 151  0
         this.name = name;
 152  0
     }
 153  
 
 154  
     /**
 155  
      * @see org.apache.jetspeed.om.common.Application#getVersion()
 156  
      */
 157  
     public String getVersion()
 158  
     {
 159  0
         return this.version;
 160  
     }
 161  
 
 162  
     /**
 163  
      * @see org.apache.jetspeed.om.common.Application#setVersion(String)
 164  
      */
 165  
     public void setVersion(String version)
 166  
     {
 167  0
         this.version = version;
 168  0
     }
 169  
 
 170  
     /**
 171  
      * @return
 172  
      */
 173  
     public WebApplicationDefinition getWebApplicationDefinition()
 174  
     {
 175  0
         return webApplication;
 176  
     }
 177  
 
 178  
     /**
 179  
      * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getPortletDefinitionList()
 180  
      */
 181  
     public PortletDefinitionList getPortletDefinitionList()
 182  
     {
 183  0
         return new PortletDefinitionListImpl(portlets);
 184  
     }
 185  
 
 186  
     /**
 187  
      * @return
 188  
      */
 189  
     public String getDescription()
 190  
     {
 191  0
         return description;
 192  
     }
 193  
 
 194  
     /**
 195  
      * @param string
 196  
      */
 197  
     public void setDescription(String string)
 198  
     {
 199  0
         description = string;
 200  0
     }
 201  
 
 202  
     /**
 203  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setWebApplicationDefinition(org.apache.pluto.om.servlet.WebApplicationDefinition)
 204  
      */
 205  
     public void setWebApplicationDefinition(WebApplicationDefinition wad)
 206  
     {
 207  0
         this.webApplication = wad;
 208  
 
 209  0
     }
 210  
 
 211  
     /**
 212  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#addPortletDefinition(org.apache.pluto.om.portlet.PortletDefinition)
 213  
      */
 214  
     public void addPortletDefinition(PortletDefinition pd)
 215  
     {
 216  0
        ((PortletDefinitionComposite) pd).setPortletApplicationDefinition(this);
 217  0
         portlets.add(pd);
 218  0
     }
 219  
 
 220  
     /**
 221  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getPortletDefinitions()
 222  
      */
 223  
     public Collection getPortletDefinitions()
 224  
     {
 225  0
         return portlets;
 226  
     }
 227  
 
 228  
     /**
 229  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getPortletDefinitionByName(java.lang.String)
 230  
      */
 231  
     public PortletDefinition getPortletDefinitionByName(String name)
 232  
     {
 233  0
     	listWrapper.setInnerCollection(portlets);
 234  0
         return listWrapper.get(name);
 235  
     }
 236  
 
 237  
     /**
 238  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setPortletDefinitionList(org.apache.pluto.om.portlet.PortletDefinitionList)
 239  
      */
 240  
     public void setPortletDefinitionList(PortletDefinitionList portlets)
 241  
     {
 242  0
         this.portlets = ((PortletDefinitionListImpl) portlets).getInnerCollection();
 243  0
     }
 244  
 
 245  
     /** 
 246  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setUserAttributeRefs(java.util.Collection)
 247  
      */
 248  
     public void setUserAttributeRefs(Collection userAttributeRefs)
 249  
     {
 250  0
         this.userAttributeRefs = userAttributeRefs;
 251  0
     }
 252  
 
 253  
     /** 
 254  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getUserAttributeRefs()
 255  
      */
 256  
     public Collection getUserAttributeRefs()
 257  
     {
 258  0
         return this.userAttributeRefs;
 259  
     }
 260  
 
 261  
     /** 
 262  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#addUserAttributeRef(org.apache.jetspeed.om.common.UserAttributeRef)
 263  
      */
 264  
     public void addUserAttributeRef(UserAttributeRef userAttributeRef)
 265  
     {
 266  0
         userAttributeRefs.add(userAttributeRef);
 267  0
     }
 268  
 
 269  
     /** 
 270  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#addUserAttribute(org.apache.jetspeed.om.common.UserAttribute)
 271  
      */
 272  
     public void addUserAttribute(UserAttribute userAttribute)
 273  
     {
 274  0
         userAttributes.add(userAttribute);
 275  0
     }
 276  
     
 277  
     /** 
 278  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#addUserAttribute(java.lang.String, java.lang.String)
 279  
      */
 280  
     public void addUserAttribute(String userName, String description)
 281  
     {
 282  0
         UserAttributeImpl userAttribute = new UserAttributeImpl();
 283  0
         userAttribute.setName(userName);
 284  0
         userAttribute.setDescription(description);
 285  0
         userAttributes.add(userAttribute);
 286  0
     }
 287  
     
 288  
     /** 
 289  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setUserAttributes(java.util.Collection)
 290  
      */
 291  
     public void setUserAttributes(Collection userAttributes)
 292  
     {
 293  0
         this.userAttributes = userAttributes;
 294  0
     }
 295  
 
 296  
     /** 
 297  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getUserAttributes()
 298  
      */
 299  
     public Collection getUserAttributes()
 300  
     {
 301  0
         return this.userAttributes;
 302  
     }
 303  
 
 304  
     /**
 305  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setApplicationIdentifier(java.lang.String)
 306  
      */
 307  
     public void setApplicationIdentifier(String applicationIdentifier)
 308  
     {
 309  0
         this.applicationIdentifier = applicationIdentifier;
 310  0
     }
 311  
 
 312  
     /**
 313  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getApplicationIdentifier()
 314  
      */
 315  
     public String getApplicationIdentifier()
 316  
     {
 317  0
         return this.applicationIdentifier;
 318  
     }
 319  
 
 320  
     /**
 321  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setApplicationType(int)
 322  
      */
 323  
     public void setApplicationType(int type)
 324  
     {
 325  0
         this.applicationType = type;
 326  0
     }
 327  
 
 328  
     /**
 329  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getApplicationType()
 330  
      */
 331  
     public int getApplicationType()
 332  
     {
 333  0
         return applicationType;
 334  
     }
 335  
 
 336  
     /**
 337  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getMetadata()
 338  
      */
 339  
     public GenericMetadata getMetadata()
 340  
     {
 341  0
     	if(metadataFields == null)
 342  
         {
 343  0
             metadataFields = new ArrayList();
 344  
         }
 345  
     	
 346  0
     	GenericMetadata metadata = new PortletApplicationMetadataImpl();
 347  0
     	metadata.setFields(metadataFields);
 348  
         
 349  0
         return metadata;
 350  
     }
 351  
 
 352  
     /**
 353  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setMetadata(org.apache.jetspeed.om.common.GenericMetadata)
 354  
      */
 355  
     public void setMetadata(GenericMetadata metadata)
 356  
     {
 357  0
         this.metadataFields = metadata.getFields();     
 358  0
     }
 359  
 
 360  
     /**
 361  
      * @return
 362  
      */
 363  
     protected Collection getMetadataFields()
 364  
     {
 365  0
         return metadataFields;
 366  
     }
 367  
 
 368  
     /**
 369  
      * @param collection
 370  
      */
 371  
     protected void setMetadataFields(Collection metadataFields)
 372  
     {
 373  0
         this.metadataFields = metadataFields;
 374  0
     }
 375  
 
 376  
     /* (non-Javadoc)
 377  
      * @see org.apache.jetspeed.om.common.portlet.PortletApplication#getJetspeedServices()
 378  
      */
 379  
     public Collection getJetspeedServices()
 380  
     {
 381  0
         return services;
 382  
     }
 383  
     
 384  
     /* (non-Javadoc)
 385  
      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#addJetspeedService(org.apache.jetspeed.om.common.JetspeedServiceReference)
 386  
      */
 387  
     public void addJetspeedService(JetspeedServiceReference service)
 388  
     {
 389  0
         services.add(service);
 390  0
     }
 391  
 
 392  
     public long getChecksum()
 393  
     {
 394  0
         if(checksumLong == -1)
 395  
         {
 396  0
             checksumLong = Long.parseLong(checksum);
 397  
         }
 398  0
         return checksumLong;
 399  
     }
 400  
     
 401  
     public void setChecksum(long checksum)
 402  
     {
 403  0
         this.checksumLong = checksum;
 404  0
         this.checksum = Long.toString(checksum);
 405  0
     }
 406  
     
 407  
     /* (non-Javadoc)
 408  
      * @see org.apache.jetspeed.om.common.Support#postLoad(java.lang.Object)
 409  
      */
 410  
     public void postLoad(Object parameter) throws Exception
 411  
     {
 412  0
         Iterator portletDefinitions = getPortletDefinitions().iterator();
 413  0
         while (portletDefinitions.hasNext())
 414  
         {
 415  0
             ((Support) portletDefinitions.next()).postLoad(this);
 416  
         }
 417  0
     }
 418  
 
 419  
     public Collection getCustomPortletModes()
 420  
     {
 421  0
         return customPortletModes;
 422  
     }
 423  
     
 424  
     public void addCustomPortletMode(CustomPortletMode customPortletMode)
 425  
     {
 426  
         // clear transient cache
 427  0
         supportedPortletModes = null;
 428  0
         supportedCustomModes = null;
 429  0
         mappedCustomModes = null;
 430  
         
 431  0
         if ( !customPortletModes.contains(customPortletMode) )
 432  
         {
 433  0
             customPortletModes.add(customPortletMode);
 434  
         }
 435  0
     }
 436  
     
 437  
     public void setCustomPortletModes(Collection customPortletModes)
 438  
     {
 439  
         // clear transient cache
 440  0
         supportedPortletModes = null;
 441  0
         supportedCustomModes = null;
 442  0
         mappedCustomModes = null;
 443  
 
 444  0
         this.customPortletModes.clear();
 445  
         
 446  0
         if ( customPortletModes != null )
 447  
         {
 448  0
             this.customPortletModes.addAll(customPortletModes);
 449  
         }
 450  0
     }
 451  
     
 452  
     public PortletMode getMappedPortletMode(PortletMode mode)
 453  
     {
 454  0
         if ( JetspeedActions.getStandardPortletModes().contains(mode) )
 455  
         {
 456  0
             return mode;
 457  
         }
 458  0
         else if ( getSupportedPortletModes().contains(mode) )
 459  
         {
 460  0
             return (PortletMode)mappedCustomModes.get(mode);
 461  
         }
 462  0
         return null;
 463  
     }
 464  
     
 465  
     public PortletMode getCustomPortletMode(PortletMode mode)
 466  
     {
 467  0
         if (JetspeedActions.getStandardPortletModes().contains(mode))
 468  
         {
 469  0
             return mode;
 470  
         }
 471  0
         else if (JetspeedActions.getExtendedPortletModes().contains(mode))
 472  
         {
 473  
             // make sure transient cache is setup
 474  0
             getSupportedPortletModes();
 475  0
             return (PortletMode)supportedCustomModes.get(mode);
 476  
         }
 477  0
         return null;            
 478  
     }
 479  
     
 480  
     public Collection getSupportedPortletModes()
 481  
     {
 482  0
         if ( supportedPortletModes == null )
 483  
         {
 484  0
             ArrayList list = new ArrayList(JetspeedActions.getStandardPortletModes());
 485  0
             supportedCustomModes = new HashMap();
 486  0
             mappedCustomModes = new HashMap();
 487  
             
 488  0
             if ( customPortletModes.size() > 0 )
 489  
             {
 490  0
                 Iterator iter = customPortletModes.iterator();
 491  0
                 while ( iter.hasNext() )
 492  
                 {
 493  0
                     CustomPortletMode customMode = (CustomPortletMode)iter.next();
 494  0
                     if ( !list.contains(customMode.getCustomMode()) && JetspeedActions.getExtendedPortletModes().contains(customMode.getMappedMode()) )
 495  
                     {
 496  0
                         list.add(customMode.getCustomMode());
 497  0
                         supportedCustomModes.put(customMode.getMappedMode(), customMode.getCustomMode());
 498  0
                         mappedCustomModes.put(customMode.getCustomMode(), customMode.getMappedMode());
 499  
                     }
 500  0
                 }
 501  
             }
 502  0
             supportedPortletModes = Collections.unmodifiableCollection(list);
 503  
         }
 504  0
         return supportedPortletModes;
 505  
     }
 506  
     
 507  
     public Collection getCustomWindowStates()
 508  
     {
 509  0
         return customWindowStates;
 510  
     }
 511  
     
 512  
     public void addCustomWindowState(CustomWindowState customWindowState)
 513  
     {
 514  
         // clear transient cache
 515  0
         supportedWindowStates = null;
 516  0
         supportedCustomStates = null;
 517  0
         mappedCustomStates = null;
 518  
         
 519  0
         if ( !customWindowStates.contains(customWindowState) )
 520  
         {
 521  0
             customWindowStates.add(customWindowState);
 522  
         }
 523  0
     }
 524  
     
 525  
     public void setCustomWindowStates(Collection customWindowStates)
 526  
     {
 527  
         // clear transient cache
 528  0
         supportedWindowStates = null;
 529  0
         supportedCustomStates = null;
 530  0
         mappedCustomStates = null;
 531  
 
 532  0
         this.customWindowStates.clear();
 533  
 
 534  0
         if ( customWindowStates != null )
 535  
         {
 536  0
             this.customWindowStates.addAll(customWindowStates);
 537  
         }
 538  0
     }
 539  
     
 540  
     public WindowState getMappedWindowState(WindowState state)
 541  
     {
 542  0
         if (JetspeedActions.getStandardWindowStates().contains(state) )
 543  
         {
 544  0
             return state;
 545  
         }
 546  0
         else if ( getSupportedWindowStates().contains(state) )
 547  
         {
 548  0
             return (WindowState)mappedCustomStates.get(state);
 549  
         }
 550  0
         return null;
 551  
     }
 552  
     
 553  
     public WindowState getCustomWindowState(WindowState state)
 554  
     {
 555  0
         if (JetspeedActions.getStandardWindowStates().contains(state))
 556  
         {
 557  0
             return state;
 558  
         }
 559  0
         else if (JetspeedActions.getExtendedWindowStates().contains(state))
 560  
         {
 561  
             // make sure transient cache is setup
 562  0
             getSupportedWindowStates();
 563  0
             return (WindowState)supportedCustomStates.get(state);
 564  
         }
 565  0
         return null;            
 566  
     }
 567  
     
 568  
     public Collection getSupportedWindowStates()
 569  
     {
 570  0
         if ( supportedWindowStates == null )
 571  
         {
 572  0
             ArrayList list = new ArrayList(JetspeedActions.getStandardWindowStates());
 573  0
             supportedCustomStates = new HashMap();
 574  0
             mappedCustomStates = new HashMap();
 575  
             
 576  0
             if ( customWindowStates.size() > 0 )
 577  
             {
 578  0
                 Iterator iter = customWindowStates.iterator();
 579  0
                 while ( iter.hasNext() )
 580  
                 {
 581  0
                     CustomWindowState customState = (CustomWindowState)iter.next();
 582  0
                     if ( !list.contains(customState.getCustomState()) && JetspeedActions.getExtendedWindowStates().contains(customState.getMappedState()) )
 583  
                     {
 584  0
                         list.add(customState.getCustomState());
 585  0
                         supportedCustomStates.put(customState.getMappedState(),customState.getCustomState());
 586  0
                         mappedCustomStates.put(customState.getCustomState(),customState.getMappedState());
 587  
                     }
 588  0
                 }
 589  
             }
 590  0
             supportedWindowStates = Collections.unmodifiableCollection(list);
 591  
         }
 592  0
         return supportedWindowStates;
 593  
     }
 594  
 
 595  
     /* (non-Javadoc)
 596  
      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#getJetspeedSecurityConstraint()
 597  
      */
 598  
     public String getJetspeedSecurityConstraint()
 599  
     {
 600  0
         return this.jetspeedSecurityConstraint;
 601  
     }
 602  
 
 603  
     /* (non-Javadoc)
 604  
      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#setJetspeedSecurityConstraint(java.lang.String)
 605  
      */
 606  
     public void setJetspeedSecurityConstraint(String constraint)
 607  
     {
 608  0
         this.jetspeedSecurityConstraint = constraint;
 609  0
     }
 610  
     
 611  
     public boolean isLayoutApplication()
 612  
     {
 613  0
         if (this.getMetadata() != null)
 614  
         {
 615  0
             Collection c = this.getMetadata().getFields("layout-app");
 616  0
             if (c != null)
 617  
             {
 618  0
                 if (!c.isEmpty())
 619  
                 {
 620  0
                    return true;
 621  
                 }
 622  
             }
 623  
         }
 624  0
         return false;
 625  
      }
 626  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.