+ /**
+ * Checks the given identities for changes since the last check.
+ *
+ * @param ownIdentity
+ * The own identity trusting the given identities
+ * @param trustedIdentities
+ * The trusted identities
+ */
+ private void checkTrustedIdentities(OwnIdentity ownIdentity, Map<String, Identity> trustedIdentities) {
+
+ @SuppressWarnings("hiding")
+ Map<String, Identity> currentTrustedIdentities = new HashMap<String, Identity>();
+ synchronized (syncObject) {
+ if (this.currentTrustedIdentities.containsKey(ownIdentity)) {
+ for (Identity identity : this.currentTrustedIdentities.get(ownIdentity)) {
+ currentTrustedIdentities.put(identity.getId(), identity);
+ }
+ }
+ }
+
+ /* find new identities. */
+ for (Identity currentIdentity : trustedIdentities.values()) {
+ if (!currentTrustedIdentities.containsKey(currentIdentity.getId())) {
+ identityListenerManager.fireIdentityAdded(ownIdentity, currentIdentity);
+ }
+ }
+
+ /* find removed identities. */
+ for (Identity oldIdentity : currentTrustedIdentities.values()) {
+ if (!trustedIdentities.containsKey(oldIdentity.getId())) {
+ identityListenerManager.fireIdentityRemoved(ownIdentity, oldIdentity);
+ }
+ }
+
+ /* check for changes in the contexts. */
+ for (Identity oldIdentity : currentTrustedIdentities.values()) {
+ if (!trustedIdentities.containsKey(oldIdentity.getId())) {
+ continue;
+ }
+ Identity newIdentity = trustedIdentities.get(oldIdentity.getId());
+ Set<String> oldContexts = oldIdentity.getContexts();
+ Set<String> newContexts = newIdentity.getContexts();
+ if (oldContexts.size() != newContexts.size()) {
+ identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity);
+ continue;
+ }
+ boolean changed = false;
+ for (String oldContext : oldContexts) {
+ if (!newContexts.contains(oldContext)) {
+ identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity);
+ changed = true;
+ break;
+ }
+ }
+ if (changed) {
+ continue;
+ }
+ Map<String, String> oldProperties = oldIdentity.getProperties();
+ Map<String, String> newProperties = newIdentity.getProperties();
+ if (oldProperties.size() != newProperties.size()) {
+ identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity);
+ continue;
+ }
+ for (Entry<String, String> oldProperty : oldProperties.entrySet()) {
+ if (!newProperties.containsKey(oldProperty.getKey()) || !newProperties.get(oldProperty.getKey()).equals(oldProperty.getValue())) {
+ identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity);
+ break;
+ }
+ }
+ }
+
+ synchronized (syncObject) {
+ this.currentTrustedIdentities.put(ownIdentity, trustedIdentities.values());
+ }
+
+ }
+