| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 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 | |
|
| 29 | |
|
| 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 | |
|
| 60 | |
|
| 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 | |
} |