else
{
int nActionCount = getActionCount();
final int nArgOffset = 7; // number of non-vararg arguments
Object[] args = new Object[Math.max(nActionCount, 1) + nArgOffset];
Lookup posMap = new IdentityHashTab(64);
Lookup urlMap = new IdentityHashTab(64);
String sEventURL = getURL(m_metaclass);
String sURLPrefix = sEventURL + "$";
// When updating the event generator invocation code,
// also update the plugin action compilation validation
args[0] = this;
args[1] = getArguments(true);
args[2] = getVariables();
args[3] = getPrivilege();
if (m_accessAttribute == null)
{
args[4] = null;
}
else if (m_bStatic)
{
if (m_accessAttribute.isStatic())
{
args[4] = Primitive.createInteger(m_accessAttribute.getOrdinal());
}
else
{
args[4] = null;
}
}
else
{
args[4] = Primitive.createInteger(
(m_accessAttribute.isStatic()) ?
-1 -m_accessAttribute.getOrdinal() :
m_accessAttribute.getOrdinal());
}
args[5] = Boolean.valueOf(getArgumentCount() == 0 && "delete".equals(m_sName));
byte nTransactionMode = ((getSymbol() == Symbol.CREATE || getSymbol() == Symbol.UPDATE) &&
getArgumentCount() == 0) ? TX_SUPPORTED : getTransactionMode();
args[6] = Primitive.createInteger(nTransactionMode);
m_bTransient = (nTransactionMode != TX_SUPPORTED);
for (int i = 0; i < nActionCount; ++i)
{
Action action = getAction(i);
Object condition = action.getCondition();
String sURL;
Object body;
if (action.getDeclarator() != null)
{
sURL = getURL(action.getDeclarator()) + "$" + action.getFullName();
}
else
{
sURL = sURLPrefix + action.getFullName();
}
if (action.getMethod() == null)
{
body = action.getBody();
if (body == null)
{
body = EMPTY_BODY;
}
}
else
{
body = Pair.list(Pair.list(Pair.quote(new JavaAction(action)),
(action.getType() == Action.AROUND) ? Symbol.CALL_NEXT : EMPTY_CLOSURE));
}
Lookup map = action.getTextPositionMap();
if (map != null)
{
for (Lookup.Iterator itr = map.iterator(); itr.hasNext();)
{
itr.next();
posMap.put(itr.getKey(), itr.getValue());
urlMap.put(itr.getValue(), sURL);
}
}
if (condition != null)
{
Compiler.setPosURLs(condition, sURL + "$condition", posMap, urlMap);
}
Boolean grouped = Boolean.FALSE;
// Set grouped for all but the first action in a group
if (action.getGroupName() != null)
{
if (action.getType() == Action.BEFORE)
{
for (int k = i - 1; k >= 0; --k)
{
if (action.getGroupName().equals(getAction(k).getGroupName()))
{
grouped = Boolean.TRUE;
break;
}
}
}
else
{
for (int k = i + 1; k < nActionCount; ++k)
{
if (action.getGroupName().equals(getAction(k).getGroupName()))
{
grouped = Boolean.TRUE;
break;
}
}
}
}
args[i + nArgOffset] = new Pair(action.getTypeSymbol(), new Pair(grouped, new Pair(condition, body)));
action.setBody(null);
action.setTextPositionMap(null);
}
// Ensure there is a main action
if (nActionCount == 0 || ((Pair)args[args.length - 1]).getHead() != Symbol.MAIN)
{
if (nActionCount > 0)
{
Object[] argsSaved = args;
args = new Object[args.length + 1];
System.arraycopy(argsSaved, 0, args, 0, argsSaved.length);
}
args[args.length - 1] = new Pair(Symbol.MAIN, new Pair(Boolean.FALSE, new Pair(Boolean.TRUE, EMPTY_BODY)));
}
try
{
// Invoke the sys:generate-event macro that generates the ECA code and compile the result
Pair code = (Pair)machine.invoke((Function)machine.getGlobalEnvironment().getVariable(Symbol.SYS_GENERATE_EVENT), args);
TextPosition pos = new TextPosition(0, 0);
posMap.put(code, pos);
urlMap.put(pos, sEventURL);
for (Pair pair = code; pair != null; pair = pair.getNext())
{
if (pair.getHead() instanceof Pair && !posMap.contains(pair.getHead()))
{
pos = new TextPosition(0, 0);
posMap.put(pair.getHead(), pos);
urlMap.put(pos, sEventURL);
}
}
m_function = new Compiler().compile(code, posMap, urlMap, machine, false);
}