Clover coverage report - Code Coverage for tapestry-contrib release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:55:19 EDT
file stats: LOC: 330   Methods: 25
NCLOC: 193   Classes: 2
 
 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.PageBeginRenderListener;
 29    import org.apache.tapestry.event.PageEndRenderListener;
 30    import org.apache.tapestry.event.PageEvent;
 31    import org.apache.tapestry.spec.IBeanSpecification;
 32    import org.apache.tapestry.spec.IComponentSpecification;
 33    import org.apache.tapestry.spec.IParameterSpecification;
 34   
 35    /**
 36    * Component of the {@link Inspector} page used to display the specification, parameters and
 37    * bindings and assets of the inspected component.
 38    *
 39    * @author Howard Lewis Ship
 40    */
 41   
 42    public abstract class ShowSpecification extends BaseComponent implements PageBeginRenderListener,
 43    PageEndRenderListener
 44    {
 45    private IComponent _inspectedComponent;
 46   
 47    private IComponentSpecification _inspectedSpecification;
 48   
 49    private String _parameterName;
 50   
 51    private String _assetName;
 52   
 53    private List _sortedComponents;
 54   
 55    private List _assetNames;
 56   
 57    private List _formalParameterNames;
 58   
 59    private List _informalParameterNames;
 60   
 61    private List _sortedPropertyNames;
 62   
 63    private String _propertyName;
 64   
 65    private List _beanNames;
 66   
 67    private String _beanName;
 68   
 69    private IBeanSpecification _beanSpecification;
 70   
 71    private static class ComponentComparitor implements Comparator
 72    {
 73  0 public int compare(Object left, Object right)
 74    {
 75  0 IComponent leftComponent;
 76  0 String leftId;
 77  0 IComponent rightComponent;
 78  0 String rightId;
 79   
 80  0 if (left == right)
 81  0 return 0;
 82   
 83  0 leftComponent = (IComponent) left;
 84  0 rightComponent = (IComponent) right;
 85   
 86  0 leftId = leftComponent.getId();
 87  0 rightId = rightComponent.getId();
 88   
 89  0 return leftId.compareTo(rightId);
 90    }
 91    }
 92   
 93    /**
 94    * Clears all cached information about the component and such after each render (including the
 95    * rewind phase render used to process the tab view).
 96    *
 97    * @since 1.0.5
 98    */
 99   
 100  0 public void pageEndRender(PageEvent event)
 101    {
 102  0 _inspectedComponent = null;
 103  0 _inspectedSpecification = null;
 104  0 _parameterName = null;
 105  0 _assetName = null;
 106  0 _sortedComponents = null;
 107  0 _assetNames = null;
 108  0 _formalParameterNames = null;
 109  0 _informalParameterNames = null;
 110  0 _sortedPropertyNames = null;
 111  0 _propertyName = null;
 112  0 _beanNames = null;
 113  0 _beanName = null;
 114  0 _beanSpecification = null;
 115    }
 116   
 117    /**
 118    * Gets the inspected component and specification from the {@link Inspector} page.
 119    *
 120    * @since 1.0.5
 121    */
 122   
 123  0 public void pageBeginRender(PageEvent event)
 124    {
 125  0 Inspector inspector = (Inspector) getPage();
 126   
 127  0 _inspectedComponent = inspector.getInspectedComponent();
 128  0 _inspectedSpecification = _inspectedComponent.getSpecification();
 129    }
 130   
 131  0 public IComponent getInspectedComponent()
 132    {
 133  0 return _inspectedComponent;
 134    }
 135   
 136  0 public IComponentSpecification getInspectedSpecification()
 137    {
 138  0 return _inspectedSpecification;
 139    }
 140   
 141    /**
 142    * Returns a sorted list of formal parameter names.
 143    */
 144   
 145  0 public List getFormalParameterNames()
 146    {
 147  0 if (_formalParameterNames == null)
 148  0 _formalParameterNames = sort(_inspectedSpecification.getParameterNames());
 149   
 150  0 return _formalParameterNames;
 151    }
 152   
 153    /**
 154    * Returns a sorted list of informal parameter names. This is the list of all bindings, with the
 155    * list of parameter names removed, sorted.
 156    */
 157   
 158  0 public List getInformalParameterNames()
 159    {
 160  0 if (_informalParameterNames != null)
 161  0 return _informalParameterNames;
 162   
 163  0 Collection names = _inspectedComponent.getBindingNames();
 164  0 if (names != null && names.size() > 0)
 165    {
 166  0 _informalParameterNames = new ArrayList(names);
 167   
 168    // Remove the names of any formal parameters. This leaves
 169    // just the names of informal parameters (informal parameters
 170    // are any parameters/bindings that don't match a formal parameter
 171    // name).
 172   
 173  0 names = _inspectedSpecification.getParameterNames();
 174  0 if (names != null)
 175  0 _informalParameterNames.removeAll(names);
 176   
 177  0 Collections.sort(_informalParameterNames);
 178    }
 179   
 180  0 return _informalParameterNames;
 181    }
 182   
 183  0 public String getParameterName()
 184    {
 185  0 return _parameterName;
 186    }
 187   
 188  0 public void setParameterName(String value)
 189    {
 190  0 _parameterName = value;
 191    }
 192   
 193    /**
 194    * Returns the {@link org.apache.tapestry.spec.ParameterSpecification} corresponding to the
 195    * value of the parameterName property.
 196    */
 197   
 198  0 public IParameterSpecification getParameterSpecification()
 199    {
 200  0 return _inspectedSpecification.getParameter(_parameterName);
 201    }
 202   
 203    /**
 204    * Returns the {@link IBinding} corresponding to the value of the parameterName property.
 205    */
 206   
 207  0 public IBinding getBinding()
 208    {
 209  0 return _inspectedComponent.getBinding(_parameterName);
 210    }
 211   
 212  0 public void setAssetName(String value)
 213    {
 214  0 _assetName = value;
 215    }
 216   
 217  0 public String getAssetName()
 218    {
 219  0 return _assetName;
 220    }
 221   
 222    /**
 223    * Returns the {@link IAsset} corresponding to the value of the assetName property.
 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 component contains no assets.
 233    */
 234   
 235  0 public List getAssetNames()
 236    {
 237  0 if (_assetNames == null)
 238  0 _assetNames = sort(_inspectedComponent.getAssets().keySet());
 239   
 240  0 return _assetNames;
 241    }
 242   
 243  0 public List getSortedComponents()
 244    {
 245  0 if (_sortedComponents != null)
 246  0 return _sortedComponents;
 247   
 248  0 Inspector inspector = (Inspector) getPage();
 249  0 IComponent inspectedComponent = inspector.getInspectedComponent();
 250   
 251    // Get a Map of the components and simply return null if there
 252    // are none.
 253   
 254  0 Map components = inspectedComponent.getComponents();
 255   
 256  0 _sortedComponents = new ArrayList(components.values());
 257   
 258  0 Collections.sort(_sortedComponents, new ComponentComparitor());
 259   
 260  0 return _sortedComponents;
 261    }
 262   
 263    public abstract void setCurrentComponent(IComponent value);
 264   
 265    public abstract IComponent getCurrentComponent();
 266   
 267    /**
 268    * Returns a list of the properties for the component (from its specification), or null if the
 269    * component has no properties.
 270    */
 271   
 272  0 public List getSortedPropertyNames()
 273    {
 274  0 if (_sortedPropertyNames == null)
 275  0 _sortedPropertyNames = sort(_inspectedSpecification.getPropertyNames());
 276   
 277  0 return _sortedPropertyNames;
 278    }
 279   
 280  0 public void setPropertyName(String value)
 281    {
 282  0 _propertyName = value;
 283    }
 284   
 285  0 public String getPropertyName()
 286    {
 287  0 return _propertyName;
 288    }
 289   
 290  0 public String getPropertyValue()
 291    {
 292  0 return _inspectedSpecification.getProperty(_propertyName);
 293    }
 294   
 295  0 public List getBeanNames()
 296    {
 297  0 if (_beanNames == null)
 298  0 _beanNames = sort(_inspectedSpecification.getBeanNames());
 299   
 300  0 return _beanNames;
 301    }
 302   
 303  0 public void setBeanName(String value)
 304    {
 305  0 _beanName = value;
 306  0 _beanSpecification = _inspectedSpecification.getBeanSpecification(_beanName);
 307    }
 308   
 309  0 public String getBeanName()
 310    {
 311  0 return _beanName;
 312    }
 313   
 314  0 public IBeanSpecification getBeanSpecification()
 315    {
 316  0 return _beanSpecification;
 317    }
 318   
 319  0 private List sort(Collection c)
 320    {
 321  0 if (c == null || c.size() == 0)
 322  0 return null;
 323   
 324  0 List result = new ArrayList(c);
 325   
 326  0 Collections.sort(result);
 327   
 328  0 return result;
 329    }
 330    }