/** * The way to calculate the cache is the follow: * loop on the current element against an array list * that has the cache. It is the copy of the original cache. * When an current element is found in the cache, it is removed * from the cache copy. At the end the remained element * in the cache are the deleted ones. */ bool CacheSyncSource::fillItemModifications() { // all the current items keys list Enumeration* items = (Enumeration*)getAllItemList(); if (!items) { LOG.error("Error in fillItemModification"); return false; } // all the action are done on the copy so we can delete // the element found. The remained are the deleted by the user. Enumeration& e = cache->getProperties(); ArrayList cacheCopy; while(e.hasMoreElement()) { cacheCopy.add(*e.getNextElement()); } //if (e) { // delete e; //} StringBuffer* key; KeyValuePair* kvp; ArrayListEnumeration *newitems = new ArrayListEnumeration(), *moditems = new ArrayListEnumeration(); if (items) { while(items->hasMoreElement()) { key = (StringBuffer*)items->getNextElement(); int size = cacheCopy.size(); bool foundnew = true; for (int i = 0; i < size; i++) { kvp = (KeyValuePair*)(cacheCopy[i]); if (strcmp(kvp->getKey(), key->c_str()) == 0) { foundnew = false; // see if it is updated. StringBuffer sign = getItemSignature(*key); if (sign != kvp->getValue()) { // there is an update. if equal nothing to do... moditems->add(*key); } cacheCopy.removeElementAt(i); break; } } if (foundnew) { newitems->add(*key); } } } newKeys = newitems; updatedKeys = moditems; deletedKeys = new ArrayListEnumeration(cacheCopy); delete items; return true; }