{
throw new SecurityViolationException("err.rpc.eventVisibility",
new Object[]{member.getName(), metaclass.getName()});
}
Event event = (Event)member;
Object[] args = new Object[nArgCount + 1];
if (arguments != null)
{
for (int k = 0; k < nArgCount; ++k)
{
args[k + 1] = instanceFactory.instantiate(arguments[k]);
}
}
if (event.isStatic())
{
args[0] = metaclass;
if (arguments == null)
{
int nEventArgCount = event.getArgumentCount();
if (event.isVarArg())
{
--nEventArgCount;
}
for (int k = 0; k < nEventArgCount; ++k)
{
args[k + 1] = instanceFactory.instantiate(tobj.getValue(event.getArgument(k).getName()));
}
if (event.isVarArg())
{
int nArg = nEventArgCount;
for (PropertyIterator itr = tobj.getIterator(); itr.hasNext();)
{
itr.next();
Argument arg = event.findArgument(itr.getName());
if (arg == null || arg == event.getArgument(nEventArgCount))
{
args[++nArg] = new Pair(Symbol.define(itr.getName()), instanceFactory.instantiate(itr.getValue()));
}
}
}
}
// Allow auditing of static events
identityMap.put(tobj, null);
}
else
{
args[0] = instanceFactory.instantiate(tobj);
}
eventArray[i] = event;
argArray[i] = args;
eventMap.put(tobj, event);
}
Lookup diffMap = null;
// Instantiate the transfer objects from the instance filters
if (bInstanceFilter)
{
diffMap = new HashTab();
for (int i = 0; i < nFilterCount; ++i)
{
m_context.setTransient(bTransient);
TransferObject tobj = request.getFilter(i);
Object instances = tobj.findValue("instances");
if (instances != null)
{
List instanceList = (List)instances;
int nCount = instanceList.size();
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;
}