### Eclipse Workspace Patch 1.0 #P org.eclipse.jpt.core Index: src/org/eclipse/jpt/core/internal/GenericJpaFile.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaFile.java,v retrieving revision 1.8 diff -u -r1.8 GenericJpaFile.java --- src/org/eclipse/jpt/core/internal/GenericJpaFile.java 25 Apr 2008 20:15:04 -0000 1.8 +++ src/org/eclipse/jpt/core/internal/GenericJpaFile.java 12 May 2008 19:43:22 -0000 @@ -9,10 +9,10 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal; -import java.util.HashMap; +import java.util.Hashtable; import java.util.Iterator; -import java.util.Map; import java.util.Set; + import org.eclipse.core.resources.IFile; import org.eclipse.jdt.core.ElementChangedEvent; import org.eclipse.jpt.core.JpaFile; @@ -35,15 +35,15 @@ protected final ResourceModel resourceModel; /** - * The context model root node represented by this JPA file + * The context model root nodes represented by this JPA file */ - protected final Map rootStructureNodes; + protected final Hashtable rootStructureNodes; public GenericJpaFile(JpaProject jpaProject, IFile file, ResourceModel resourceModel) { super(jpaProject); this.file = file; this.resourceModel = resourceModel; - this.rootStructureNodes = new HashMap(); + this.rootStructureNodes = new Hashtable(); } @Override @@ -71,17 +71,22 @@ public int rootStructureNodesSize() { return this.rootStructureNodes.size(); } - + + // TODO move events outside of 'synchronized' block? + // need fireItemReplaced(String, Object, Object) for Collection? public void addRootStructureNode(Object key, JpaStructureNode rootStructureNode) { - if (this.rootStructureNodes.get(key) == rootStructureNode) { - return; - } - if (this.rootStructureNodes.containsKey(key)) { - JpaStructureNode removedStructureNode = this.rootStructureNodes.remove(key); - fireItemRemoved(JpaFile.ROOT_STRUCTURE_NODES_COLLECTION, removedStructureNode); + synchronized (this.rootStructureNodes) { + JpaStructureNode node = this.rootStructureNodes.get(key); + if (node == rootStructureNode) { + return; // no duplicates + } + if (node != null) { + this.rootStructureNodes.remove(key); + this.fireItemRemoved(JpaFile.ROOT_STRUCTURE_NODES_COLLECTION, node); + } + this.rootStructureNodes.put(key, rootStructureNode); + this.fireItemAdded(JpaFile.ROOT_STRUCTURE_NODES_COLLECTION, rootStructureNode); } - this.rootStructureNodes.put(key, rootStructureNode); - fireItemAdded(JpaFile.ROOT_STRUCTURE_NODES_COLLECTION, rootStructureNode); } public void removeRootStructureNode(Object key) { @@ -99,16 +104,19 @@ return null; } + protected Iterator rootStructureNodeKeys() { + return new CloneIterator(this.rootStructureNodes.keySet()); + } + public String getResourceType() { return getResourceModel().getResourceType(); } public void dispose() { getResourceModel().dispose(); - - Set keys = this.rootStructureNodes.keySet(); - for (Object key : keys) { - removeRootStructureNode(key); + + for (Iterator stream = this.rootStructureNodeKeys(); stream.hasNext(); ) { + this.removeRootStructureNode(stream.next()); } } @@ -123,4 +131,5 @@ sb.append(getResourceType()); sb.append(")"); } + }