Coverage Report - org.apache.tapestry5.corelib.internal.ComponentActionSink
 
Classes in this File Line Coverage Branch Coverage Complexity
ComponentActionSink
88%
14/16
N/A
0
 
 1  
 // Copyright 2008, 2009 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.tapestry5.corelib.internal;
 16  
 
 17  
 import org.apache.tapestry5.ComponentAction;
 18  
 import org.apache.tapestry5.ioc.internal.util.Defense;
 19  
 import org.apache.tapestry5.runtime.Component;
 20  
 import org.apache.tapestry5.services.ClientDataEncoder;
 21  
 import org.apache.tapestry5.services.ClientDataSink;
 22  
 import org.slf4j.Logger;
 23  
 
 24  
 import java.io.IOException;
 25  
 import java.io.ObjectOutputStream;
 26  
 
 27  
 /**
 28  
  * Used to collection component actions, with the ultimate goal being the creation of a MIME-encoded string of the
 29  
  * serialization of those actions.
 30  
  */
 31  
 public class ComponentActionSink
 32  
 {
 33  
     private final Logger logger;
 34  
 
 35  
     private final ObjectOutputStream stream;
 36  
 
 37  
     private final ClientDataSink sink;
 38  
 
 39  
     public ComponentActionSink(Logger logger, ClientDataEncoder encoder)
 40  376
     {
 41  376
         this.logger = logger;
 42  
 
 43  376
         sink = encoder.createSink();
 44  
 
 45  376
         stream = sink.getObjectOutputStream();
 46  376
     }
 47  
 
 48  
     public <T> void store(T component, ComponentAction<T> action)
 49  
     {
 50  3792
         Component castComponent = Defense.cast(component, Component.class, "component");
 51  3792
         Defense.notNull(action, "action");
 52  
 
 53  3792
         String completeId = castComponent.getComponentResources().getCompleteId();
 54  
 
 55  3792
         logger.debug("Storing action: {} {}", completeId, action);
 56  
 
 57  
         try
 58  
         {
 59  
             // Writing the complete id is not very efficient, but the GZip filter
 60  
             // should help out there.
 61  3792
             stream.writeUTF(completeId);
 62  3792
             stream.writeObject(action);
 63  
         }
 64  0
         catch (IOException ex)
 65  
         {
 66  0
             throw new RuntimeException(InternalMessages.componentActionNotSerializable(completeId, ex), ex);
 67  3792
         }
 68  3792
     }
 69  
 
 70  
 
 71  
     public String getClientData()
 72  
     {
 73  374
         return sink.getClientData();
 74  
     }
 75  
 }