for (int k = 0; k < nCount; ++k)
{
tobj = (TransferObject)instanceList.get(k);
Instance inst = instanceFactory.instantiate(tobj);
instanceList.set(k, inst);
if (inst != null)
{
diffMap.put(inst, tobj);
}
}
}
}
}
instanceFactory.complete();
instanceFactory = null;
GenericServer.auditRequest(identityMap, eventMap, m_context);
identityMap = null;
Object[] resultArray = new Object[nInvocationCount << 1];
// Unset the pending event flag on the request argument instances
for (int i = 0; i < nInvocationCount; ++i)
{
Object[] args = argArray[i];
Object obj = args[0];
if (obj instanceof Instance)
{
Instance instance = (Instance)obj;
if (args.length == 1 && eventArray[i].getName().equals(instance.getPendingEventName()))
{
resultArray[i << 1] = instance;
}
instance.suspendEvent();
}
}
m_context.setTransient(false);
uow.invokePendingEvents(false, false);
// Invoke the events and accumulate the results
for (int i = 0; i < nInvocationCount; ++i)
{
TransferObject tobj = request.getObject(i);
Event event = eventArray[i];
Pair attributes = EMPTY_PAIR;
Object[] args = argArray[i];
Object obj = args[0];
int nAttrIndex = -1;
m_context.setTransient(event.isTransient(bTransient));
if (event.getArgumentCount() != 0)
{
Argument arg = event.findArgument("attributes");
if (arg != null)
{
nAttrIndex = arg.getOrdinal() + 1;
Object value = args[nAttrIndex];
attributes = (value instanceof Pair) ? (Pair)value : null;
}
}
if (nAttrIndex < 0)
{
Object value = tobj.findValue("attributes", EMPTY_PAIR);
if (value != EMPTY_PAIR)
{
nAttrIndex = 0;
attributes = (Pair)value;
}
}
if (event.isStatic() && m_context.isProtected() && m_context.isSecure())
{
Metaclass metaclass = event.getMetaclass();
Argument result = event.getResult();
if (result != null && !result.getType().isPrimitive())
{
metaclass = (Metaclass)result.getType();
}
if (nAttrIndex > 0)
{
Pair security = metaclass.checkReadAccess(attributes, m_context.getPrivilegeSet());
if (security != null)
{
args[nAttrIndex] = Pair.nconc(security, attributes);
}
}
metaclass.checkExpressionAccess(findArg(event, "where", args, tobj), m_context.getPrivilegeSet());
metaclass.checkOrderByAccess(findArg(event, "orderBy", args, tobj), m_context.getPrivilegeSet());
}
boolean bInvoked = false;
boolean bDeleted = false;
m_context.setUnitOfWork(uow);
m_context.setTransient(event.isTransient(bTransient));
if (obj instanceof Instance)
{
Instance instance = (Instance)obj;
UnitOfWork instanceUOW = instance.getUnitOfWork();
// Use the instance UoW
if (!event.isStatic() && instanceUOW != null && instanceUOW != uow)
{
m_context.setUnitOfWork(instanceUOW);
}
bInvoked = instance.invokeSuspendedEvent();
bDeleted = (instance.getState() == Instance.DELETED);
if (nAttrIndex <= 0)
{
Attribute attribute = instance.getMetaclass().findAttribute("attributes");
if (attribute != null && !attribute.isStatic())
{
attributes = (Pair)instance.getValue(attribute.getOrdinal());
}
}
}
if (resultArray[i << 1] == null)
{
if (!bDeleted)
{
resultArray[i << 1] = event.invoke(args, m_context.getMachine());
}
}
else
{
if (!bInvoked && !bDeleted)
{
event.invoke(args, m_context.getMachine());
}
eventArray[i] = null;
}
resultArray[(i << 1) + 1] = attributes;
}
// Pre-commit all units of work in the context
for (int i = m_context.getUnitOfWorkCount() - 1; i >= 0; i--)
{
UnitOfWork work = m_context.getUnitOfWork(i);
m_context.setUnitOfWork(work);
if (work.isTransient())
{
work.invokePendingEvents(true, false);
work.computeHiddenness();
work.accumulateChanges();
}
else
{
work.commit(false);
}
}
m_context.setUnitOfWork(uow);
// Transfer the results into the response object.
// This is done as a separate step after the commit
// so that the objects are in the correct state (e.g. with OIDs).
Response response = new Response();
identityMap = new HashTab();
for (int i = 0; i < nInvocationCount; ++i)
{
Object result = resultArray[i << 1];
Pair attributes = request.getInvocation(i).getAttributes();
int nTF = RPCUtil.TF_HIDDEN;
if (attributes == null)
{
attributes = (Pair)resultArray[(i << 1) + 1];
if (attributes == EMPTY_PAIR)
{
attributes = null;
nTF |= RPCUtil.TF_READABLE;
}
}
else if (m_context.isProtected() && m_context.isSecure())
{
if (result instanceof Instance)
{
Instance instance = (Instance)result;
instance.invoke("load", Pair.nconc(instance.getMetaclass()
.checkReadAccess(attributes, m_context.getPrivilegeSet()), attributes));
}
else if (result instanceof InstanceList)
{
InstanceList list = (InstanceList)result;
Lookup classMap = new HashTab(4);
for (int k = 0, n = list.size(); k < n; ++k)
{
Instance instance = list.getInstance(k);
Metaclass metaclass = instance.getMetaclass();
Pair all = (Pair)classMap.get(metaclass);
if (all == null)
{
all = Pair.nconc(metaclass.checkReadAccess(
attributes, m_context.getPrivilegeSet()), attributes);
classMap.put(metaclass, all);
}
instance.invoke("load", all);
}
}
nTF |= RPCUtil.TF_READABLE;
}
response.addResult(RPCUtil.transfer(result, attributes,
(eventArray[i] == null) ? diffMap : null, identityMap, nTF));
}
// Apply the change filters
for (int i = 0; i < nFilterCount; ++i)
{
TransferObject tobj = request.getFilter(i);
Metaclass metaclass = metadata.getMetaclass(tobj.getClassName());
Lookup map = m_context.getClassChangeMap(metaclass);
Object instances = tobj.findValue("instances");
Pair attributes = (Pair)tobj.findValue("attributes");
Pair all = attributes;
List eventList = new ArrayList();
if (m_context.isProtected() && m_context.isSecure())
{
all = Pair.nconc(metaclass.checkReadAccess(attributes, m_context.getPrivilegeSet()), attributes);
}
if (instances != null)
{
List instanceList = (List)instances;
int nCount = instanceList.size();
for (int k = 0; k < nCount; ++k)
{
Instance instance = (Instance)instanceList.get(k);
Object state = map.get(instance);
if (state != null)
{
instance.invoke("load", all);
eventList.add(transferEvent(instance, ((Integer)state).byteValue(),
attributes, diffMap, identityMap));
}
else
{
eventList.add(null);
}
}
}
else
{
for (Lookup.Iterator itr = map.iterator(); itr.hasNext();)
{
Instance instance = (Instance)itr.next();
instance.invoke("load", all);
TransferObject obj = transferEvent(instance, ((Integer)itr.getValue()).byteValue(),
attributes, diffMap, identityMap);
if (obj != null)