package org.jboss.invocation.pooled.interfaces;
import org.jboss.invocation.Invocation;
import org.jboss.invocation.InvocationType;
import org.jboss.invocation.MarshalledInvocation;
import org.jboss.invocation.MarshalledValue;
import javax.transaction.Transaction;
import java.io.IOException;
import java.lang.reflect.Method;
import java.security.Principal;
import java.util.HashMap;
import java.util.Iterator;
public class PooledMarshalledInvocation
extends MarshalledInvocation
implements java.io.Externalizable
{
static final long serialVersionUID = -728630295444149842L;
private transient Transaction tx;
private transient Object credential;
private transient Principal principal;
private transient Object enterpriseContext;
private transient Object id;
private transient PooledMarshalledValue pooledMarshalledArgs;
public PooledMarshalledInvocation()
{
}
public PooledMarshalledInvocation(Invocation invocation)
{
this.payload = invocation.payload;
this.as_is_payload = invocation.as_is_payload;
this.method = invocation.getMethod();
this.objectName = invocation.getObjectName();
this.args = invocation.getArguments();
this.invocationType = invocation.getType();
}
public PooledMarshalledInvocation(
Object id,
Method m,
Object[] args,
Transaction tx,
Principal identity,
Object credential)
{
super(id, m, args, tx, identity, credential);
}
public Object getEnterpriseContext()
{
return enterpriseContext;
}
public void setEnterpriseContext(Object enterpriseContext)
{
this.enterpriseContext = enterpriseContext;
}
public Object getId()
{
if (id == null) id = super.getId();
return id;
}
public void setId(Object id)
{
super.setId(id);
this.id = id;
}
public void setTransaction(Transaction tx)
{
super.setTransaction(tx);
this.tx = tx;
}
public Transaction getTransaction()
{
if (tx == null) tx = super.getTransaction();
return this.tx;
}
public Object getCredential()
{
if (credential == null) credential = super.getCredential();
return credential;
}
public void setCredential(Object credential)
{
super.setCredential(credential);
this.credential = credential;
}
public Principal getPrincipal()
{
if (principal == null) principal = super.getPrincipal();
return principal;
}
public void setPrincipal(Principal principal)
{
super.setPrincipal(principal);
this.principal = principal;
}
public Object[] getArguments()
{
if (this.args == null)
{
try
{
this.args = (Object[]) pooledMarshalledArgs.get();
}
catch (Exception e)
{
e.printStackTrace();
}
}
return args;
}
public void writeExternal(java.io.ObjectOutput out)
throws IOException
{
out.writeObject(invocationType);
out.writeObject(tpc);
long methodHash = calculateHash(this.method);
out.writeLong(methodHash);
out.writeInt(((Integer)this.objectName).intValue());
out.writeObject(new PooledMarshalledValue(this.args));
if (payload == null)
out.writeInt(0);
else
{
out.writeInt(payload.size());
Iterator keys = payload.keySet().iterator();
while (keys.hasNext())
{
Object currentKey = keys.next();
out.writeObject(currentKey);
out.writeObject(new MarshalledValue(payload.get(currentKey)));
}
}
if (as_is_payload == null)
out.writeInt(0);
else
{
out.writeInt(as_is_payload.size());
Iterator keys = as_is_payload.keySet().iterator();
while (keys.hasNext())
{
Object currentKey = keys.next();
out.writeObject(currentKey);
out.writeObject(as_is_payload.get(currentKey));
}
}
}
public void readExternal(java.io.ObjectInput in)
throws IOException, ClassNotFoundException
{
invocationType = (InvocationType)in.readObject();
tpc = in.readObject();
this.methodHash = in.readLong();
this.objectName = new Integer(in.readInt());
pooledMarshalledArgs = (PooledMarshalledValue) in.readObject();
int payloadSize = in.readInt();
if (payloadSize > 0)
{
payload = new HashMap();
for (int i = 0; i < payloadSize; i++)
{
Object key = in.readObject();
Object value = in.readObject();
payload.put(key, value);
}
}
int as_is_payloadSize = in.readInt();
if (as_is_payloadSize > 0)
{
as_is_payload = new HashMap();
for (int i = 0; i < as_is_payloadSize; i++)
{
Object key = in.readObject();
Object value = in.readObject();
as_is_payload.put(key, value);
}
}
}
}