1 22 package org.jboss.invocation.unified.marshall; 23 24 import org.jboss.invocation.Invocation; 25 import org.jboss.invocation.MarshalledInvocation; 26 import org.jboss.logging.Logger; 27 import org.jboss.remoting.InvocationRequest; 28 import org.jboss.remoting.marshal.serializable.SerializableMarshaller; 29 import org.jboss.remoting.marshal.Marshaller; 30 import org.jboss.remoting.marshal.MarshallerDecorator; 31 import org.jboss.tm.TransactionPropagationContextFactory; 32 import org.jboss.tm.TransactionPropagationContextUtil; 33 34 import javax.transaction.SystemException ; 35 import java.io.IOException ; 36 import java.io.OutputStream ; 37 38 45 public class InvocationMarshaller extends SerializableMarshaller implements MarshallerDecorator 46 { 47 public final static String DATATYPE = "invocation"; 48 49 private static final Logger log = Logger.getLogger(InvocationMarshaller.class); 50 51 63 public void write(Object dataObject, OutputStream output) throws IOException 64 { 65 66 super.write(addDecoration(dataObject), output); 67 } 68 69 public Object addDecoration(Object dataObject) throws IOException { 70 if(dataObject instanceof InvocationRequest) 71 { 72 InvocationRequest remoteInv = (InvocationRequest) dataObject; 73 74 if(remoteInv.getParameter() instanceof Invocation) 75 { 76 Invocation inv = (Invocation) remoteInv.getParameter(); 77 78 MarshalledInvocation marshInv = new MarshalledInvocation(inv); 79 80 if(inv != null) 81 { 82 86 try 87 { 88 marshInv.setTransactionPropagationContext(getTransactionPropagationContext()); 89 } 90 catch(SystemException e) 91 { 92 log.error("Error setting transaction propagation context.", e); 93 throw new IOException ("Error setting transaction context. Message: " + e.getMessage()); 94 } 95 96 remoteInv.setParameter(marshInv); 98 } 99 else 100 { 101 log.error("Attempting to marshall Invocation but is null. Can not proceed."); 103 throw new IOException ("Can not process data object due to the InvocationRequest's parameter being null."); 104 } 105 106 } 107 } 108 return dataObject; 109 } 110 111 public Object getTransactionPropagationContext() 112 throws SystemException 113 { 114 TransactionPropagationContextFactory tpcFactory = TransactionPropagationContextUtil.getTPCFactoryClientSide(); 115 return (tpcFactory == null) ? null : tpcFactory.getTransactionPropagationContext(); 116 } 117 118 public Marshaller cloneMarshaller() throws CloneNotSupportedException 119 { 120 return new InvocationMarshaller(); 121 } 122 123 } | Popular Tags |