Coverage Report - org.apache.tapestry.contrib.components.DumpObject
 
Classes in this File Line Coverage Branch Coverage Complexity
DumpObject
0%
0/14
0%
0/2
2.333
 
 1  
 // Copyright 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.components;
 16  
 
 17  
 import java.io.BufferedOutputStream;
 18  
 import java.io.CharArrayWriter;
 19  
 import java.io.ObjectOutputStream;
 20  
 
 21  
 import org.apache.tapestry.AbstractComponent;
 22  
 import org.apache.tapestry.IMarkupWriter;
 23  
 import org.apache.tapestry.IRequestCycle;
 24  
 import org.apache.tapestry.util.io.BinaryDumpOutputStream;
 25  
 
 26  
 /**
 27  
  * Used to dump out an object's serialized representation in a mix of hex and ascii. The output is
 28  
  * formatted for a fixed width font, typically should be enclosed in <pre> tags.
 29  
  * 
 30  
  * @see org.apache.tapestry.util.io.BinaryDumpOutputStream
 31  
  * @author Howard M. Lewis Ship
 32  
  * @since 4.0
 33  
  */
 34  
 
 35  0
 public abstract class DumpObject extends AbstractComponent
 36  
 {
 37  
     // Parameters:
 38  
 
 39  
     public abstract Object getObject();
 40  
 
 41  
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 42  
     {
 43  0
         if (cycle.isRewinding())
 44  0
             return;
 45  
 
 46  0
         String asText = convert(getObject());
 47  
 
 48  0
         writer.print(asText);
 49  0
     }
 50  
 
 51  
     String convert(Object object)
 52  
     {
 53  
         try
 54  
         {
 55  0
             CharArrayWriter writer = new CharArrayWriter();
 56  0
             BinaryDumpOutputStream bdos = new BinaryDumpOutputStream(writer);
 57  0
             ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(bdos));
 58  
 
 59  0
             oos.writeObject(object);
 60  
 
 61  0
             oos.close();
 62  
 
 63  0
             return writer.toString();
 64  
         }
 65  0
         catch (Exception ex)
 66  
         {
 67  0
             return ex.toString();
 68  
         }
 69  
     }
 70  
 }