for (NewObject newObject : new ArrayList<NewObject>(newObjects)) {
if(!newObject.processed){
DataSource source = DataSourceManager.getSourceByPrototype(newObject.object.getPrototype());
if (!("Array".equals(source.getId()) || "Object".equals(source.getId()))){
Persistable rootQuery = ObjectId.idForObject(source,"").getTarget();
Function postMethod = (Function) ScriptableObject.getProperty((Persistable) rootQuery, "post");
if(postMethod instanceof Method)
((Method)postMethod).call(PersevereContextFactory.getContext(), GlobalData.getGlobalScope(), rootQuery, new Object[]{newObject.object}, true);
else
postMethod.call(PersevereContextFactory.getContext(), GlobalData.getGlobalScope(), rootQuery, new Object[]{newObject.object});
Method onSave = (Method) ScriptableObject.getProperty(newObject.object, "onSave");
onSave.call(PersevereContextFactory.getContext(), GlobalData.getGlobalScope(), newObject.object, new Object[0], true);
}
newObject.processed = true;
}