Clover coverage report - Code Coverage for tapestry-contrib release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:12:41 EDT
file stats: LOC: 364   Methods: 28
NCLOC: 210   Classes: 2
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ShowSpecification.java 0% 0% 0% 0%
coverage
 1   
 // Copyright 2004, 2005 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.tapestry.contrib.inspector;
 16   
 
 17   
 import java.util.ArrayList;
 18   
 import java.util.Collection;
 19   
 import java.util.Collections;
 20   
 import java.util.Comparator;
 21   
 import java.util.List;
 22   
 import java.util.Map;
 23   
 
 24   
 import org.apache.tapestry.BaseComponent;
 25   
 import org.apache.tapestry.IAsset;
 26   
 import org.apache.tapestry.IBinding;
 27   
 import org.apache.tapestry.IComponent;
 28   
 import org.apache.tapestry.event.PageEvent;
 29   
 import org.apache.tapestry.event.PageRenderListener;
 30   
 import org.apache.tapestry.spec.IBeanSpecification;
 31   
 import org.apache.tapestry.spec.IComponentSpecification;
 32   
 import org.apache.tapestry.spec.IContainedComponent;
 33   
 import org.apache.tapestry.spec.IParameterSpecification;
 34   
 
 35   
 /**
 36   
  *  Component of the {@link Inspector} page used to display
 37   
  *  the specification, parameters and bindings and assets of the inspected component.
 38   
  *
 39   
  *  @author Howard Lewis Ship
 40   
  *
 41   
  **/
 42   
 
 43   
 public abstract class ShowSpecification extends BaseComponent implements PageRenderListener
 44   
 {
 45   
     private IComponent _inspectedComponent;
 46   
     private IComponentSpecification _inspectedSpecification;
 47   
     private String _parameterName;
 48   
     private String _assetName;
 49   
     private List _sortedComponents;
 50   
     private IComponent _component;
 51   
     private List _assetNames;
 52   
     private List _formalParameterNames;
 53   
     private List _informalParameterNames;
 54   
     private List _sortedPropertyNames;
 55   
     private String _propertyName;
 56   
     private List _beanNames;
 57   
     private String _beanName;
 58   
     private IBeanSpecification _beanSpecification;
 59   
 
 60   
     private static class ComponentComparitor implements Comparator
 61   
     {
 62  0
         public int compare(Object left, Object right)
 63   
         {
 64  0
             IComponent leftComponent;
 65  0
             String leftId;
 66  0
             IComponent rightComponent;
 67  0
             String rightId;
 68   
 
 69  0
             if (left == right)
 70  0
                 return 0;
 71   
 
 72  0
             leftComponent = (IComponent) left;
 73  0
             rightComponent = (IComponent) right;
 74   
 
 75  0
             leftId = leftComponent.getId();
 76  0
             rightId = rightComponent.getId();
 77   
 
 78  0
             return leftId.compareTo(rightId);
 79   
         }
 80   
     }
 81   
 
 82   
     /**
 83   
      *  Clears all cached information about the component and such after
 84   
      *  each render (including the rewind phase render used to process
 85   
      *  the tab view).
 86   
      *
 87   
      *  @since 1.0.5
 88   
      *
 89   
      **/
 90   
 
 91  0
     public void pageEndRender(PageEvent event)
 92   
     {
 93  0
         _inspectedComponent = null;
 94  0
         _inspectedSpecification = null;
 95  0
         _parameterName = null;
 96  0
         _assetName = null;
 97  0
         _sortedComponents = null;
 98  0
         _component = null;
 99  0
         _assetNames = null;
 100  0
         _formalParameterNames = null;
 101  0
         _informalParameterNames = null;
 102  0
         _sortedPropertyNames = null;
 103  0
         _propertyName = null;
 104  0
         _beanNames = null;
 105  0
         _beanName = null;
 106  0
         _beanSpecification = null;
 107   
     }
 108   
 
 109   
     /**
 110   
      *  Gets the inspected component and specification from the {@link Inspector} page.
 111   
      *
 112   
      *  @since 1.0.5
 113   
      **/
 114   
 
 115  0
     public void pageBeginRender(PageEvent event)
 116   
     {
 117  0
         Inspector inspector = (Inspector) getPage();
 118   
 
 119  0
         _inspectedComponent = inspector.getInspectedComponent();
 120  0
         _inspectedSpecification = _inspectedComponent.getSpecification();
 121   
     }
 122   
 
 123  0
     public IComponent getInspectedComponent()
 124   
     {
 125  0
         return _inspectedComponent;
 126   
     }
 127   
 
 128  0
     public IComponentSpecification getInspectedSpecification()
 129   
     {
 130  0
         return _inspectedSpecification;
 131   
     }
 132   
 
 133   
     /**
 134   
      *  Returns a sorted list of formal parameter names.
 135   
      *
 136   
      **/
 137   
 
 138  0
     public List getFormalParameterNames()
 139   
     {
 140  0
         if (_formalParameterNames == null)
 141  0
             _formalParameterNames = sort(_inspectedSpecification.getParameterNames());
 142   
 
 143  0
         return _formalParameterNames;
 144   
     }
 145   
 
 146   
     /**
 147   
      *  Returns a sorted list of informal parameter names.  This is
 148   
      *  the list of all bindings, with the list of parameter names removed,
 149   
      *  sorted.
 150   
      *
 151   
      **/
 152   
 
 153  0
     public List getInformalParameterNames()
 154   
     {
 155  0
         if (_informalParameterNames != null)
 156  0
             return _informalParameterNames;
 157   
 
 158  0
         Collection names = _inspectedComponent.getBindingNames();
 159  0
         if (names != null && names.size() > 0)
 160   
         {
 161  0
             _informalParameterNames = new ArrayList(names);
 162   
 
 163   
             // Remove the names of any formal parameters.  This leaves
 164   
             // just the names of informal parameters (informal parameters
 165   
             // are any parameters/bindings that don't match a formal parameter
 166   
             // name).
 167   
 
 168  0
             names = _inspectedSpecification.getParameterNames();
 169  0
             if (names != null)
 170  0
                 _informalParameterNames.removeAll(names);
 171   
 
 172  0
             Collections.sort(_informalParameterNames);
 173   
         }
 174   
 
 175  0
         return _informalParameterNames;
 176   
     }
 177   
 
 178  0
     public String getParameterName()
 179   
     {
 180  0
         return _parameterName;
 181   
     }
 182   
 
 183  0
     public void setParameterName(String value)
 184   
     {
 185  0
         _parameterName = value;
 186   
     }
 187   
 
 188   
     /**
 189   
      *  Returns the {@link org.apache.tapestry.spec.ParameterSpecification} corresponding to
 190   
      *  the value of the parameterName property.
 191   
      *
 192   
      **/
 193   
 
 194  0
     public IParameterSpecification getParameterSpecification()
 195   
     {
 196  0
         return _inspectedSpecification.getParameter(_parameterName);
 197   
     }
 198   
 
 199   
     /**
 200   
      *  Returns the {@link IBinding} corresponding to the value of
 201   
      *  the parameterName property.
 202   
      *
 203   
      **/
 204   
 
 205  0
     public IBinding getBinding()
 206   
     {
 207  0
         return _inspectedComponent.getBinding(_parameterName);
 208   
     }
 209   
 
 210  0
     public void setAssetName(String value)
 211   
     {
 212  0
         _assetName = value;
 213   
     }
 214   
 
 215  0
     public String getAssetName()
 216   
     {
 217  0
         return _assetName;
 218   
     }
 219   
 
 220   
     /**
 221   
      *  Returns the {@link IAsset} corresponding to the value
 222   
      *  of the assetName property.
 223   
      *
 224   
      **/
 225   
 
 226  0
     public IAsset getAsset()
 227   
     {
 228  0
         return (IAsset) _inspectedComponent.getAssets().get(_assetName);
 229   
     }
 230   
 
 231   
     /**
 232   
      *  Returns a sorted list of asset names, or null if the
 233   
      *  component contains no assets.
 234   
      *
 235   
      **/
 236   
 
 237  0
     public List getAssetNames()
 238   
     {
 239  0
         if (_assetNames == null)
 240  0
             _assetNames = sort(_inspectedComponent.getAssets().keySet());
 241   
 
 242  0
         return _assetNames;
 243   
     }
 244   
 
 245  0
     public List getSortedComponents()
 246   
     {
 247  0
         if (_sortedComponents != null)
 248  0
             return _sortedComponents;
 249   
 
 250  0
         Inspector inspector = (Inspector) getPage();
 251  0
         IComponent inspectedComponent = inspector.getInspectedComponent();
 252   
 
 253   
         // Get a Map of the components and simply return null if there
 254   
         // are none.
 255   
 
 256  0
         Map components = inspectedComponent.getComponents();
 257   
 
 258  0
         _sortedComponents = new ArrayList(components.values());
 259   
 
 260  0
         Collections.sort(_sortedComponents, new ComponentComparitor());
 261   
 
 262  0
         return _sortedComponents;
 263   
     }
 264   
 
 265  0
     public void setComponent(IComponent value)
 266   
     {
 267  0
         _component = value;
 268   
     }
 269   
 
 270  0
     public IComponent getComponent()
 271   
     {
 272  0
         return _component;
 273   
     }
 274   
 
 275   
     /**
 276   
      *  Returns the type of the component, as specified in the container's
 277   
      *  specification (i.e., the component alias if known).
 278   
      *
 279   
      **/
 280   
 
 281  0
     public String getComponentType()
 282   
     {
 283  0
         IComponent container = _component.getContainer();
 284   
 
 285  0
         IComponentSpecification containerSpecification = container.getSpecification();
 286   
 
 287  0
         String id = _component.getId();
 288  0
         IContainedComponent contained = containerSpecification.getComponent(id);
 289   
 
 290   
         // Temporary:  An implicit component will not be in the containing
 291   
         // component's specification as a ContainedComponent.
 292   
 
 293  0
         if (contained == null)
 294  0
             return null;
 295   
 
 296  0
         return contained.getType();
 297   
     }
 298   
 
 299   
     /**
 300   
      *  Returns a list of the properties for the component
 301   
      *  (from its specification), or null if the component
 302   
      *  has no properties.
 303   
      *
 304   
      **/
 305   
 
 306  0
     public List getSortedPropertyNames()
 307   
     {
 308  0
         if (_sortedPropertyNames == null)
 309  0
             _sortedPropertyNames = sort(_inspectedSpecification.getPropertyNames());
 310   
 
 311  0
         return _sortedPropertyNames;
 312   
     }
 313   
 
 314  0
     public void setPropertyName(String value)
 315   
     {
 316  0
         _propertyName = value;
 317   
     }
 318   
 
 319  0
     public String getPropertyName()
 320   
     {
 321  0
         return _propertyName;
 322   
     }
 323   
 
 324  0
     public String getPropertyValue()
 325   
     {
 326  0
         return _inspectedSpecification.getProperty(_propertyName);
 327   
     }
 328   
 
 329  0
     public List getBeanNames()
 330   
     {
 331  0
         if (_beanNames == null)
 332  0
             _beanNames = sort(_inspectedSpecification.getBeanNames());
 333   
 
 334  0
         return _beanNames;
 335   
     }
 336   
 
 337  0
     public void setBeanName(String value)
 338   
     {
 339  0
         _beanName = value;
 340  0
         _beanSpecification = _inspectedSpecification.getBeanSpecification(_beanName);
 341   
     }
 342   
 
 343  0
     public String getBeanName()
 344   
     {
 345  0
         return _beanName;
 346   
     }
 347   
 
 348  0
     public IBeanSpecification getBeanSpecification()
 349   
     {
 350  0
         return _beanSpecification;
 351   
     }
 352   
 
 353  0
     private List sort(Collection c)
 354   
     {
 355  0
         if (c == null || c.size() == 0)
 356  0
             return null;
 357   
 
 358  0
         List result = new ArrayList(c);
 359   
 
 360  0
         Collections.sort(result);
 361   
 
 362  0
         return result;
 363   
     }
 364   
 }