Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 169   Methods: 7
NCLOC: 83   Classes: 1
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
Script.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.html;
 16   
 
 17   
 import java.util.HashMap;
 18   
 import java.util.Iterator;
 19   
 import java.util.Map;
 20   
 
 21   
 import org.apache.hivemind.ApplicationRuntimeException;
 22   
 import org.apache.hivemind.Resource;
 23   
 import org.apache.tapestry.AbstractComponent;
 24   
 import org.apache.tapestry.IBinding;
 25   
 import org.apache.tapestry.IEngine;
 26   
 import org.apache.tapestry.IMarkupWriter;
 27   
 import org.apache.tapestry.IRequestCycle;
 28   
 import org.apache.tapestry.IScript;
 29   
 import org.apache.tapestry.PageRenderSupport;
 30   
 import org.apache.tapestry.Tapestry;
 31   
 import org.apache.tapestry.TapestryUtils;
 32   
 import org.apache.tapestry.engine.IScriptSource;
 33   
 
 34   
 /**
 35   
  * Works with the {@link Body}component to add a script (and perhaps some initialization) to the
 36   
  * HTML response. [ <a href="../../../../../ComponentReference/Script.html">Component Reference
 37   
  * </a>]
 38   
  * 
 39   
  * @author Howard Lewis Ship
 40   
  */
 41   
 
 42   
 public abstract class Script extends AbstractComponent
 43   
 {
 44   
     private Map _baseSymbols;
 45   
 
 46   
     /**
 47   
      * A Map of input and output symbols visible to the body of the Script.
 48   
      * 
 49   
      * @since 2.2
 50   
      */
 51   
 
 52   
     private Map _symbols;
 53   
 
 54   
     /**
 55   
      * Constructs the symbols {@link Map}. This starts with the contents of the symbols parameter
 56   
      * (if specified) to which is added any informal parameters. If both a symbols parameter and
 57   
      * informal parameters are bound, then a copy of the symbols parameter's value is made (that is,
 58   
      * the {@link Map}provided by the symbols parameter is read, but not modified).
 59   
      */
 60   
 
 61  0
     private Map getInputSymbols()
 62   
     {
 63  0
         Map result = new HashMap();
 64   
 
 65  0
         if (_baseSymbols != null)
 66  0
             result.putAll(_baseSymbols);
 67   
 
 68   
         // Now, iterate through all the binding names (which includes both
 69   
         // formal and informal parmeters). Skip the formal ones and
 70   
         // access the informal ones.
 71   
 
 72  0
         Iterator i = getBindingNames().iterator();
 73  0
         while (i.hasNext())
 74   
         {
 75  0
             String bindingName = (String) i.next();
 76   
 
 77   
             // Skip formal parameters
 78   
 
 79  0
             if (getSpecification().getParameter(bindingName) != null)
 80  0
                 continue;
 81   
 
 82  0
             IBinding binding = getBinding(bindingName);
 83   
 
 84  0
             Object value = binding.getObject();
 85   
 
 86  0
             result.put(bindingName, value);
 87   
         }
 88   
 
 89  0
         return result;
 90   
     }
 91   
 
 92   
     /**
 93   
      * Gets the {@link IScript}for the correct script.
 94   
      */
 95   
 
 96  0
     private IScript getParsedScript(IRequestCycle cycle)
 97   
     {
 98  0
         String scriptPath = getScriptPath();
 99   
 
 100  0
         if (scriptPath == null)
 101  0
             throw Tapestry.createRequiredParameterException(this, "scriptPath");
 102   
 
 103  0
         IEngine engine = cycle.getEngine();
 104  0
         IScriptSource source = engine.getScriptSource();
 105   
 
 106   
         // If the script path is relative, it should be relative to the Script component's
 107   
         // container (i.e., relative to a page in the application).
 108   
 
 109  0
         Resource rootLocation = getContainer().getSpecification().getSpecificationLocation();
 110  0
         Resource scriptLocation = rootLocation.getRelativeResource(scriptPath);
 111   
 
 112  0
         try
 113   
         {
 114  0
             return source.getScript(scriptLocation);
 115   
         }
 116   
         catch (RuntimeException ex)
 117   
         {
 118  0
             throw new ApplicationRuntimeException(ex.getMessage(), this, null, ex);
 119   
         }
 120   
 
 121   
     }
 122   
 
 123  0
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 124   
     {
 125  0
         if (!cycle.isRewinding())
 126   
         {
 127  0
             PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
 128   
 
 129  0
             _symbols = getInputSymbols();
 130   
 
 131  0
             getParsedScript(cycle).execute(cycle, pageRenderSupport, _symbols);
 132   
         }
 133   
 
 134   
         // Render the body of the Script;
 135  0
         renderBody(writer, cycle);
 136   
     }
 137   
 
 138   
     public abstract String getScriptPath();
 139   
 
 140  0
     public Map getBaseSymbols()
 141   
     {
 142  0
         return _baseSymbols;
 143   
     }
 144   
 
 145  0
     public void setBaseSymbols(Map baseSymbols)
 146   
     {
 147  0
         _baseSymbols = baseSymbols;
 148   
     }
 149   
 
 150   
     /**
 151   
      * Returns the complete set of symbols (input and output) from the script execution. This is
 152   
      * visible to the body of the Script, but is cleared after the Script finishes rendering.
 153   
      * 
 154   
      * @since 2.2
 155   
      */
 156   
 
 157  0
     public Map getSymbols()
 158   
     {
 159  0
         return _symbols;
 160   
     }
 161   
 
 162  0
     protected void cleanupAfterRender(IRequestCycle cycle)
 163   
     {
 164  0
         _symbols = null;
 165   
 
 166  0
         super.cleanupAfterRender(cycle);
 167   
     }
 168   
 
 169   
 }