* @throws QuickFixException if a definition can't be compiled.
*/
@Override
public void updateLoaded(DefDescriptor<?> loading) throws QuickFixException, ClientOutOfSyncException {
ContextService contextService = Aura.getContextService();
AuraContext context;
MasterDefRegistry mdr;
Set<DefDescriptor<?>> loaded = Sets.newHashSet();
Set<DefDescriptor<?>> prev = Sets.newHashSet();
Set<DefDescriptor<?>> remove = null;
contextService.assertEstablished();
context = contextService.getCurrentContext();
mdr = context.getDefRegistry();
if (context.getPreloadedDefinitions() == null) {
//
// TODO (optimize): we could reverse this set randomly to try
// to sanitize the list in opposite directions. No need to be
// exact (hard to test though).
//
for (Map.Entry<DefDescriptor<?>, String> entry : context.getClientLoaded().entrySet()) {
DefDescriptor<?> descriptor = entry.getKey();
if (loaded.contains(descriptor)) {
context.dropLoaded(descriptor);
} else {
// validate the uid.
String uid = entry.getValue();
String tuid = null;
QuickFixException qfe = null;
if (uid == null) {
// If we are given a null, bounce out.
throw new ClientOutOfSyncException(descriptor + ": missing UID ");
}
try {
tuid = mdr.getUid(uid, descriptor);
} catch (QuickFixException broke) {
//
// See note above. This is how we enforce precedence of ClientOutOfSyncException
//
qfe = broke;
}
if (!uid.equals(tuid)) {
throw new ClientOutOfSyncException(descriptor + ": mismatched UIDs " + uid + " != " + tuid);
}
if (qfe != null) {
throw qfe;
}
Set<DefDescriptor<?>> deps = mdr.getDependencies(uid);
loaded.addAll(deps);
for (DefDescriptor<?> x : prev) {
if (deps.contains(x)) {
if (remove == null) {
remove = Sets.newHashSet();
}
remove.add(x);
}
}
prev.add(descriptor);
}
}
context.setPreloadedDefinitions(loaded);
} else {
loaded = context.getPreloadedDefinitions();
}
if (remove != null) {
for (DefDescriptor<?> x : remove) {
context.dropLoaded(x);
}
}
//
// Now make sure that our current definition is somewhere there
// If this fails, we will throw an exception, and all will be
// well.
//
if (loading != null && !loaded.contains(loading) && !context.getLoaded().containsKey(loading)) {
String uid = mdr.getUid(null, loading);
if (uid == null) {
throw new DefinitionNotFoundException(loading, null);
} else {
context.addLoaded(loading, uid);
}
}
}