}
WonderlandServerIdentity id = (WonderlandServerIdentity) curId;
// create the response object, which will be populated below with
// any actions that are granted
ResourceMap grant = new ResourceMap();
// create a set of actions to schedule in a separate transaction
ResourceMap schedule = new ResourceMap();
// loop through each action set in the request, and generate
// an appropriate response
for (ActionMap set : request.values()) {
// get the resource this set pertains to
Resource resource = set.getResource();
// create a response set that we will append the granted
// permissions to
ActionMap grantSet = new ActionMap(resource);
grant.put(resource.getId(), grantSet);
// create a set of requests to schedule. We do not add the
// set immediately -- it will be added at the end if it
// is not empty
ActionMap scheduleSet = new ActionMap(resource);
// go through each action, and decider whether to grant or deny
// access, or if necessary, schedule for later
for (Action action : set.values()) {
// query the resource about this permission, and handle the
// result
switch (resource.request(id.getIdentity(), action)) {
case GRANT:
// access is granted, add to the response list
grantSet.put(action.getName(), action);
break;
case DENY:
// access is denied -- nothing to do
break;
case SCHEDULE:
// add to the set to schedule
scheduleSet.put(action.getName(), action);
break;
}
}
// if the schedule set is not empty, add it for scheduling
if (!scheduleSet.isEmpty()) {
schedule.put(resource.getId(), scheduleSet);
}
}
// determine if we can respond immediately
if (schedule.isEmpty()) {
// nothing to schedule, handle the response directly in
// this transaction
task.run(grant);
} else {
// schedule the request in a separate thread. First store