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: 185   Methods: 9
NCLOC: 116   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
ShowEngine.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.io.ByteArrayOutputStream;
 18   
 import java.io.CharArrayWriter;
 19   
 import java.io.IOException;
 20   
 import java.io.ObjectOutputStream;
 21   
 import java.io.OutputStream;
 22   
 
 23   
 import org.apache.hivemind.ApplicationRuntimeException;
 24   
 import org.apache.tapestry.BaseComponent;
 25   
 import org.apache.tapestry.IMarkupWriter;
 26   
 import org.apache.tapestry.IRender;
 27   
 import org.apache.tapestry.IRequestCycle;
 28   
 import org.apache.tapestry.Tapestry;
 29   
 import org.apache.tapestry.event.PageDetachListener;
 30   
 import org.apache.tapestry.event.PageEvent;
 31   
 import org.apache.tapestry.util.io.BinaryDumpOutputStream;
 32   
 
 33   
 /**
 34   
  *  Component of the {@link Inspector} page used to display
 35   
  *  the properties of the {@link org.apache.tapestry.IEngine} as well as a serialized view of it.
 36   
  *  Also, the {@link org.apache.tapestry.request.RequestContext} is dumped out.
 37   
  *
 38   
  *
 39   
  *  @author Howard Lewis Ship
 40   
  *
 41   
  **/
 42   
 
 43   
 public abstract class ShowEngine extends BaseComponent implements PageDetachListener
 44   
 {
 45   
     private byte[] serializedEngine;
 46   
 
 47  0
     public void pageDetached(PageEvent event)
 48   
     {
 49  0
         serializedEngine = null;
 50   
     }
 51   
 
 52   
     /**
 53   
      *  Workaround for OGNL limitation --- OGNL can't dereference
 54   
      *  past class instances.
 55   
      * 
 56   
      *  @since 2.2
 57   
      * 
 58   
      **/
 59   
 
 60  0
     public String getEngineClassName()
 61   
     {
 62  0
         return getPage().getEngine().getClass().getName();
 63   
     }
 64   
 
 65  0
     private byte[] getSerializedEngine()
 66   
     {
 67  0
         if (serializedEngine == null)
 68  0
             buildSerializedEngine();
 69   
 
 70  0
         return serializedEngine;
 71   
     }
 72   
 
 73  0
     private void buildSerializedEngine()
 74   
     {
 75  0
         ByteArrayOutputStream bos = null;
 76  0
         ObjectOutputStream oos = null;
 77   
 
 78  0
         try
 79   
         {
 80  0
             bos = new ByteArrayOutputStream();
 81  0
             oos = new ObjectOutputStream(bos);
 82   
 
 83   
             // Write the application object to the stream.
 84   
 
 85  0
             oos.writeObject(getPage().getEngine());
 86   
 
 87   
             // Extract the application as an array of bytes.
 88   
 
 89  0
             serializedEngine = bos.toByteArray();
 90   
         }
 91   
         catch (IOException ex)
 92   
         {
 93  0
             throw new ApplicationRuntimeException(
 94   
                 Tapestry.getMessage("ShowEngine.could-not-serialize"),
 95   
                 ex);
 96   
         }
 97   
         finally
 98   
         {
 99  0
             close(oos);
 100  0
             close(bos);
 101   
         }
 102   
 
 103   
         // It would be nice to deserialize the application object now, but in
 104   
         // practice, that fails due to class loader problems.
 105   
     }
 106   
 
 107  0
     private void close(OutputStream stream)
 108   
     {
 109  0
         if (stream == null)
 110  0
             return;
 111   
 
 112  0
         try
 113   
         {
 114  0
             stream.close();
 115   
         }
 116   
         catch (IOException ex)
 117   
         {
 118   
             // Ignore.
 119   
         }
 120   
     }
 121   
 
 122  0
     public int getEngineByteCount()
 123   
     {
 124  0
         return getSerializedEngine().length;
 125   
     }
 126   
 
 127  0
     public IRender getEngineDumpDelegate()
 128   
     {
 129  0
         return new IRender()
 130   
         {
 131  0
             public void render(IMarkupWriter writer, IRequestCycle cycle)
 132   
             {
 133  0
                 dumpSerializedEngine(writer);
 134   
             }
 135   
         };
 136   
     }
 137   
 
 138  0
     private void dumpSerializedEngine(IMarkupWriter responseWriter)
 139   
     {
 140  0
         CharArrayWriter writer = null;
 141  0
         BinaryDumpOutputStream bos = null;
 142   
 
 143  0
         try
 144   
         {
 145   
             // Because IReponseWriter doesn't implement the
 146   
             // java.io.Writer interface, we have to buffer this
 147   
             // stuff then pack it in all at once.  Kind of a waste!
 148   
 
 149  0
             writer = new CharArrayWriter();
 150   
 
 151  0
             bos = new BinaryDumpOutputStream(writer);
 152  0
             bos.setBytesPerLine(32);
 153   
 
 154  0
             bos.write(getSerializedEngine());
 155  0
             bos.close();
 156   
 
 157  0
             responseWriter.print(writer.toString());
 158   
         }
 159   
         catch (IOException ex)
 160   
         {
 161   
             // Ignore.
 162   
         }
 163   
         finally
 164   
         {
 165  0
             if (bos != null)
 166   
             {
 167  0
                 try
 168   
                 {
 169  0
                     bos.close();
 170   
                 }
 171   
                 catch (IOException ex)
 172   
                 {
 173   
                     // Ignore.
 174   
                 }
 175   
             }
 176   
 
 177  0
             if (writer != null)
 178   
             {
 179  0
                 writer.reset();
 180  0
                 writer.close();
 181   
             }
 182   
         }
 183   
     }
 184   
 
 185   
 }