[151178] ValidateEdit
diff --git a/plugins/org.eclipse.wst.common.emf/workbench/org/eclipse/wst/common/internal/emf/ResourceSynchronizedIsLoadingAdapter.java b/plugins/org.eclipse.wst.common.emf/workbench/org/eclipse/wst/common/internal/emf/ResourceSynchronizedIsLoadingAdapter.java
new file mode 100644
index 0000000..f536105
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.emf/workbench/org/eclipse/wst/common/internal/emf/ResourceSynchronizedIsLoadingAdapter.java
@@ -0,0 +1,112 @@
+/*
+ * Created on Oct 26, 2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.eclipse.wst.common.internal.emf;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.jobs.ILock;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.wst.common.internal.emf.utilities.ResourceIsLoadingAdapter;
+
+
+
+
+
+/**
+ * The ResourceSynchronizedIsLoadingAdapter is used to synchronize the loading 
+ * of EMF resources. This is the Eclipse version of ResourceIsLoadingAdapter,
+ * and uses the Eclipse ILock technology to acquire a semaphore until the 
+ * Resource is loaded. the waitForResourceToLoad() method will pause until
+ * either (a) the Resource has loaded, the Adapter is notified, and the 
+ * semaphore is released or (b) the DELAY timeout is exceeded, which prevents
+ * full deadlock. 
+ * 
+ * @author mdelder 
+ */
+public class ResourceSynchronizedIsLoadingAdapter extends ResourceIsLoadingAdapter {
+    
+    private final ILock loadingLock;
+    
+    /**
+     * The delay is default to 5 minutes. This is the upward threshhold. The lock
+     * will wait up to DELAY milliseconds to acquire the lock, and bail if not. It 
+     * does not mean that it will wait DELAY milliseconds always. In general, the 
+     * wait should be almost instanteous -- just as long as document loading remains
+     * speedy. 
+     */
+    private static final long DELAY = 300000; 
+    
+    public ResourceSynchronizedIsLoadingAdapter() {
+        loadingLock = Platform.getJobManager().newLock();
+        if(loadingLock != null)
+            loadingLock.acquire();
+    }    
+    
+    
+    /* (non-Javadoc)
+     * @see com.ibm.wtp.internal.emf.utilities.ResourceIsLoadingAdapter#waitForResourceToLoad()
+     */
+    public void waitForResourceToLoad() { 
+        
+        if(loadingLock == null)
+            return;
+        
+        boolean lockAcquired = false;
+        try {
+            if( loadingLock != null ) 
+                if( !(lockAcquired = loadingLock.acquire(DELAY)) )  
+                    logWarning(); 
+        } catch (Throwable t) { 
+        } finally {
+            if(lockAcquired)
+                loadingLock.release();
+        }
+        
+    }
+    
+    
+    /**
+     * 
+     */
+    private void logWarning() { 
+        Notifier target = getTarget();
+        if(target == null || !(target instanceof Resource)) { 
+            Resource resource = (Resource) target;
+            System.err.println("[WARNING] Could not acquire Semaphore Lock for Resource: \""+resource.getURI() + "\" in " + getClass());
+        }
+        
+    }
+
+
+    /* (non-Javadoc)
+     * @see com.ibm.wtp.internal.emf.utilities.ResourceIsLoadingAdapter#notifyChanged(org.eclipse.emf.common.notify.Notification)
+     */
+    public void notifyChanged(Notification notification) { 
+
+		if (notification.getNotifier() != null) {		    
+			//listen for the remove of the loading adapter
+			if (isSetLoadedResourceNotification(notification)) {
+			    if(loadingLock != null)
+			        loadingLock.release();
+				removeIsLoadingSupport();  				
+			}
+		}         
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see com.ibm.wtp.internal.emf.utilities.ResourceIsLoadingAdapter#forceRelease()
+     */
+    public void forceRelease() { 
+        try {
+	        if(loadingLock != null && loadingLock.getDepth() > 0)
+	            loadingLock.release();
+        } catch(Throwable t) {}
+    }
+
+}
diff --git a/plugins/org.eclipse.wst.common.emf/workbench/org/eclipse/wst/common/internal/emf/ResourceSynchronizedIsLoadingAdapterFactory.java b/plugins/org.eclipse.wst.common.emf/workbench/org/eclipse/wst/common/internal/emf/ResourceSynchronizedIsLoadingAdapterFactory.java
new file mode 100644
index 0000000..b3d4495
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.emf/workbench/org/eclipse/wst/common/internal/emf/ResourceSynchronizedIsLoadingAdapterFactory.java
@@ -0,0 +1,28 @@
+/*
+ * Created on Oct 26, 2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.eclipse.wst.common.internal.emf;
+
+import org.eclipse.wst.common.internal.emf.utilities.ResourceIsLoadingAdapter;
+import org.eclipse.wst.common.internal.emf.utilities.ResourceIsLoadingAdapterFactory;
+
+
+/**
+ * @author mdelder
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class ResourceSynchronizedIsLoadingAdapterFactory extends ResourceIsLoadingAdapterFactory {
+
+    
+    /* (non-Javadoc)
+     * @see com.ibm.wtp.internal.emf.utilities.ResourceIsLoadingAdapterFactory#createResourceIsLoadingAdapter()
+     */
+    public ResourceIsLoadingAdapter createResourceIsLoadingAdapter() { 
+        return new ResourceSynchronizedIsLoadingAdapter();
+    }
+}
diff --git a/plugins/org.eclipse.wst.common.emf/workbench/org/eclipse/wst/common/internal/emf/plugin/EcoreUtilitiesPlugin.java b/plugins/org.eclipse.wst.common.emf/workbench/org/eclipse/wst/common/internal/emf/plugin/EcoreUtilitiesPlugin.java
index 0f04416..3b29f4a 100644
--- a/plugins/org.eclipse.wst.common.emf/workbench/org/eclipse/wst/common/internal/emf/plugin/EcoreUtilitiesPlugin.java
+++ b/plugins/org.eclipse.wst.common.emf/workbench/org/eclipse/wst/common/internal/emf/plugin/EcoreUtilitiesPlugin.java
@@ -17,7 +17,9 @@
 package org.eclipse.wst.common.internal.emf.plugin;
 
 import org.eclipse.core.runtime.Plugin;
+import org.eclipse.wst.common.internal.emf.ResourceSynchronizedIsLoadingAdapterFactory;
 import org.eclipse.wst.common.internal.emf.resource.RendererFactory;
+import org.eclipse.wst.common.internal.emf.utilities.ResourceIsLoadingAdapterFactory;
 import org.osgi.framework.BundleContext;
 
 /**
@@ -46,5 +48,7 @@
 		RendererFactory.setDefaultHandler(PluginRendererFactoryDefaultHandler.INSTANCE);
 		PackageURIMapReader reader = new PackageURIMapReader();
 		reader.processExtensions();
+		//use a synchronized loading adapter factory
+		ResourceIsLoadingAdapterFactory.INSTANCE = new ResourceSynchronizedIsLoadingAdapterFactory();
 	}
 }
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/CompatibilityXMIResourceImpl.java b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/CompatibilityXMIResourceImpl.java
index 4bb6d7a..2419be7 100644
--- a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/CompatibilityXMIResourceImpl.java
+++ b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/CompatibilityXMIResourceImpl.java
@@ -14,6 +14,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.InternalEObject;
@@ -22,6 +23,8 @@
 import org.eclipse.emf.ecore.xmi.XMLSave;
 import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
 import org.eclipse.wst.common.internal.emf.utilities.IDUtil;
+import org.eclipse.wst.common.internal.emf.utilities.ResourceIsLoadingAdapter;
+import org.eclipse.wst.common.internal.emf.utilities.ResourceIsLoadingAdapterFactory;
 
 
 public class CompatibilityXMIResourceImpl extends XMIResourceImpl implements CompatibilityXMIResource {
@@ -234,4 +237,102 @@
 			idToEObjectMap.remove(eObjectToIDMap.remove(eObject));
 		}
 	}
+	
+	public void load(Map options) throws IOException {
+
+        ResourceIsLoadingAdapter adapter = null;
+        if (isLoaded) {
+            adapter = ResourceIsLoadingAdapter.findAdapter(this);
+            if (adapter != null) 
+                adapter.waitForResourceToLoad();
+            return;
+        }
+        synchronized (this) {            
+            adapter = ResourceIsLoadingAdapter.findAdapter(this);
+            if (adapter == null && !isLoaded) 
+                addSynchronizationLoadingAdapter();
+        }
+        if(adapter != null)
+            adapter.waitForResourceToLoad();
+        else {
+            try {
+                super.load(options);
+            } catch(IOException ioe) {
+                removeLoadingSynchronizationAdapter();
+                throw ioe;
+            } catch(RuntimeException re) {
+                removeLoadingSynchronizationAdapter();
+                throw re;
+            } catch(Error e) {
+                removeLoadingSynchronizationAdapter();
+                throw e;
+            }
+        }
+    }
+	
+	  /**
+     * 
+     */
+    private void addSynchronizationLoadingAdapter() {
+        if (ResourceIsLoadingAdapter.findAdapter(this) == null)
+            eAdapters().add(ResourceIsLoadingAdapterFactory.INSTANCE.createResourceIsLoadingAdapter());
+    }
+
+    /**
+     * 
+     */
+    private void removeLoadingSynchronizationAdapter() {
+        ResourceIsLoadingAdapter adapter = ResourceIsLoadingAdapter.findAdapter(this);
+        if (adapter != null) {
+            adapter.forceRelease();
+            eAdapters().remove(adapter);
+        }
+    }
+
+    /**
+     * Case 1: LOAD RESOURCE FROM DISK this.isLoaded == false AND isLoaded ==
+     * true (which means we entered the load() method, but have not completed
+     * the load), and we're loading from a resource on disk, then we add the
+     * adapter Case 2: RESOURCE CREATION (NOT A LOAD) Case 4: RESOURCE CREATION,
+     * UNLOADED, NEW CONTENTS (NOT A LOAD) Resource is created but not from a
+     * resource on disk, so contents is null AND not empty, so no adapter: THIS
+     * IS NOT A LOAD Case 3: RESOURCE HAS BEEN UNLOADED, BEING RELOADED FROM
+     * DISK Contents is NOT null, but it is Empty and the resource is being
+     * loaded from disk. We must add the adapter.
+     * 
+     */
+    public boolean isResourceBeingLoaded(boolean isLoaded) {
+        return (!this.isLoaded && isLoaded) && (contents == null || contents.isEmpty());
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.eclipse.emf.ecore.resource.Resource#getContents()
+     */
+    public EList getContents() {
+        waitForResourceToLoadIfNecessary();
+        return super.getContents();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.eclipse.emf.ecore.resource.impl.ResourceImpl#isLoaded()
+     */
+    public boolean isLoaded() {
+        waitForResourceToLoadIfNecessary();
+        return super.isLoaded();
+    }
+
+    /**
+     * 
+     */
+    protected final void waitForResourceToLoadIfNecessary() {
+        ResourceIsLoadingAdapter loadingAdapter = ResourceIsLoadingAdapter.findAdapter(this);
+        if (loadingAdapter != null) loadingAdapter.waitForResourceToLoad();
+    }
+
+
+
 }
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/EMF2DOMAdapterImpl.java b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/EMF2DOMAdapterImpl.java
index c73886f..12ba6c5 100644
--- a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/EMF2DOMAdapterImpl.java
+++ b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/EMF2DOMAdapterImpl.java
@@ -406,7 +406,7 @@
 		}
 
 		// Remove any remaining adapters.
-		for (; i < mofChildren.size();) {
+		for (; i < mofChildren.size(); i++) {
 			removeMOFValue((EObject) mofChildren.get(i), map);
 		}
 
@@ -802,13 +802,15 @@
 
 		EMF2DOMAdapter adapter = primGetExistingAdapter(node);
 
-		if (adapter != null && adapter.isMOFProxy()) {
-			removeDOMAdapter(node, adapter);
-			adapter.getTarget().eAdapters().remove(adapter);
-			adapter = null;
-		}
-
-		if (adapter == null) {
+		if (adapter != null) {
+			if (adapter.isMOFProxy() || adapter.getTarget() == null) {
+				removeDOMAdapter(node, adapter);
+				if (adapter.getTarget() != null) {
+					adapter.getTarget().eAdapters().remove(adapter);
+				}
+				adapter = null;
+			}
+		} else {
 			adapter = primCreateAdapter(node, childMap);
 		}
 		return adapter;
diff --git a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/ReferencedResource.java b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/ReferencedResource.java
index fc8ceaf..4aafc23 100644
--- a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/ReferencedResource.java
+++ b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/ReferencedResource.java
@@ -18,6 +18,18 @@
 	public static final String DELETED_ERROR_MSG = "This resource has been deleted and can no longer be used."; //$NON-NLS-1$
 
 	public static final int RESOURCE_WAS_SAVED = 601;
+	
+	/**
+	 * A flag used to indicate a ReferencedResource is about
+	 * to save.
+	 */
+	public static final int RESOURCE_ABOUT_TO_SAVE = 602;
+	
+	/**
+	 * A flag used to indicate a ReferencedResource has failed
+	 * to save.
+	 */
+	public static final int RESOURCE_SAVE_FAILED = 603;
 
 	/**
 	 * Access this resource for read only. This call increments the use read count of this resource.
diff --git a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/ReferencedXMIResourceImpl.java b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/ReferencedXMIResourceImpl.java
index bf429d7..df07748 100644
--- a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/ReferencedXMIResourceImpl.java
+++ b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/ReferencedXMIResourceImpl.java
@@ -25,6 +25,7 @@
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.jem.util.logger.proxy.Logger;
 import org.eclipse.wst.common.internal.emf.utilities.IDUtil;
 
 public class ReferencedXMIResourceImpl extends CompatibilityXMIResourceImpl implements ReferencedResource {
@@ -337,25 +338,48 @@
 	 * @see Resource#save(Object)
 	 */
 	public void save(Map options) throws IOException {
-		super.save(options);
-		notifySaved();
+		notifyAboutToSave();
+        try {
+            super.save(options);
+        } catch (Exception e) {
+            notifySaveFailed();
+            if (e instanceof IOException)
+                throw (IOException) e;
+            else
+                Logger.getLogger().write(e);
+        }
+        notifySaved();
 	}
 
 	protected void notifySaved() {
+		notifySaveEvent(RESOURCE_WAS_SAVED);
+	}
+	
+	protected void notifyAboutToSave() {
+        notifySaveEvent(RESOURCE_ABOUT_TO_SAVE);
+    }
+	
+	protected void notifySaveFailed() {
+        notifySaveEvent(RESOURCE_SAVE_FAILED);
+    }
+	
+	private void notifySaveEvent(int eventType) {
 		if (eNotificationRequired()) {
-			Notification notification = new NotificationImpl(RESOURCE_WAS_SAVED, this, this) {
-				public Object getNotifier() {
-					return ReferencedXMIResourceImpl.this;
-				}
-
-				public int getFeatureID(Class expectedClass) {
-					return RESOURCE_WAS_SAVED;
-				}
+		  Notification notification =
+			new NotificationImpl(eventType, this, this)
+			{
+			  public Object getNotifier()
+			  {
+				return ReferencedXMIResourceImpl.this;
+			  }
+			  public int getFeatureID(Class expectedClass)
+			  {
+				return eventType;
+			  }
 			};
 			eNotify(notification);
 		}
-	}
-	
+	}	
 
 	/**
 	 * @see com.ibm.etools.emf.workbench.ReferencedResource#wasReverted()
@@ -374,10 +398,4 @@
 	  }
 
 
-	public void eNotify(Notification notification) {
-		synchronized (eAdapters()) {
-			super.eNotify(notification);
-		}
-	}
-
 }
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/TranslatorResourceImpl.java b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/TranslatorResourceImpl.java
index a75f792..1fa8f5f 100644
--- a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/TranslatorResourceImpl.java
+++ b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/TranslatorResourceImpl.java
@@ -24,6 +24,7 @@
 import org.eclipse.emf.ecore.InternalEObject;
 import org.eclipse.emf.ecore.impl.ENotificationImpl;
 import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
+import org.eclipse.jem.util.logger.proxy.Logger;
 import org.eclipse.wst.common.internal.emf.utilities.StringUtil;
 import org.xml.sax.EntityResolver;
 
@@ -149,16 +150,24 @@
 	}
 
 	public void save(Map options) throws IOException {
-		if (renderer.useStreamsForIO()) {
-			super.save(options);
-		}
-		else {
-			// we cast to OutputStream, in preparation for 3.2 code base,
-			// where this doSave call is ambiguous with just "null". 
-			doSave((OutputStream) null, options);
-			notifySaved();
-		}
-	}
+        if (renderer.useStreamsForIO()) {
+            super.save(options);
+        } else {
+            notifyAboutToSave();
+            try {
+                doSave((OutputStream)null, options);
+                notifySaved();
+            } catch (Exception e) {
+                 notifySaveFailed();
+                if (e instanceof IOException)
+                    throw (IOException) e;
+                else
+                    Logger.getLogger().write(e);
+            }
+            notifySaved();
+        }
+    }
+
 
 	/**
 	 * @see com.ibm.etools.xmi.helpers.CompatibilityXMIResourceImpl#doSave(OutputStream,
@@ -224,6 +233,7 @@
 	}
 
 	public EList getContents() {
+		waitForResourceToLoadIfNecessary();
 		if (contents == null) {
 			initializeContents();
 		}
diff --git a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/XMLEncoderDecoder.java b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/XMLEncoderDecoder.java
index 9f46962..7898757 100644
--- a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/XMLEncoderDecoder.java
+++ b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/resource/XMLEncoderDecoder.java
@@ -35,7 +35,7 @@
 	 * 16-bit encodings this will be 0xFFFF. Characters that are not printable will be escaped using
 	 * character references.
 	 */
-	private int _lastPrintable = 0x7E;
+	private int _lastPrintable = 0xFFFE;
 
 	protected static XMLEncoderDecoder _singleton;
 
diff --git a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/utilities/ExtendedEcoreUtil.java b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/utilities/ExtendedEcoreUtil.java
index 891f4f5..8489833 100644
--- a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/utilities/ExtendedEcoreUtil.java
+++ b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/utilities/ExtendedEcoreUtil.java
@@ -13,6 +13,7 @@
 import java.util.List;
 
 import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.impl.BasicNotifierImpl.EAdapterList;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.emf.common.util.WrappedException;
 import org.eclipse.emf.ecore.EAttribute;
@@ -172,16 +173,15 @@
 	   */
 	  public static Adapter getAdapter(EObject anObject, List adapters, Object type) {
 
-		synchronized (adapters) {
-
-			for (int i = 0, size = adapters.size(); i < size; ++i) {
-				Adapter adapter = (Adapter) adapters.get(i);
-				if (adapter.isAdapterForType(type)) {
+		  	Object [] adaptArray = ((EAdapterList)adapters).data();
+		  	if (adaptArray == null) return null;
+			for (int i = 0; i < adaptArray.length; i++) {
+				Adapter adapter = (Adapter) adaptArray[i];
+				if (adapter != null && adapter.isAdapterForType(type)) {
 					return adapter;
 				}
 			}
 			return null;
-		}
 	}
 
 	/**
diff --git a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/utilities/ResourceIsLoadingAdapter.java b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/utilities/ResourceIsLoadingAdapter.java
new file mode 100644
index 0000000..3d47574
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/utilities/ResourceIsLoadingAdapter.java
@@ -0,0 +1,103 @@
+/*
+ * Created on Oct 26, 2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.eclipse.wst.common.internal.emf.utilities;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+
+/**
+ * @author mdelder
+ */
+public class ResourceIsLoadingAdapter extends AdapterImpl implements Adapter {
+
+    private static final Class RESOURCE_IS_LOADING_ADAPTER_CLASS = ResourceIsLoadingAdapter.class;
+
+    public ResourceIsLoadingAdapter() {
+    }
+
+    public static ResourceIsLoadingAdapter findAdapter(Resource aResource) {
+        ResourceIsLoadingAdapter adapter = null;
+        //System.out.println("ResourceIsLoadingAdapter Synchronizing on " + aResource);
+        
+        /* Synchronize on the Resource (which will be the target of 
+         * the ResourceIsLoadingAdapter in the list, if it exists).
+         * 
+         * removeIsLoadingSupport() will coordinate with this 
+         * synchronization.
+         */
+        synchronized (aResource) {
+            adapter = (ResourceIsLoadingAdapter) EcoreUtil.getAdapter(aResource.eAdapters(), ResourceIsLoadingAdapter.class);
+        }
+        return adapter;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.eclipse.emf.common.notify.Adapter#notifyChanged(org.eclipse.emf.common.notify.Notification)
+     */
+    public void notifyChanged(Notification notification) {
+
+        if (notification.getNotifier() != null) {
+
+            // listen for the remove of the loading adapter
+            if (isSetLoadedResourceNotification(notification)) removeIsLoadingSupport();
+        }
+    }
+
+    /**
+     * Default implementation is a no-op.
+     */
+    public void waitForResourceToLoad() {
+
+    }
+
+    /**
+     * @param notification
+     * @return
+     */
+    protected boolean isSetLoadedResourceNotification(Notification notification) {
+        return notification.getFeatureID(null) == Resource.RESOURCE__IS_LOADED && notification.getEventType() == Notification.SET;
+    }
+
+    protected void removeIsLoadingSupport() {
+
+        /* Synchronize on the target of the Adapter. If 
+         * the list of adapters is searched for a 
+         * ResourceIsLoadingAdapter using the 
+         * ResourceIsLoadingAdapter.findAdapter() API, then
+         * the access to remove the Adapter using this method 
+         * will be coordinated.  
+         */
+        if (getTarget() != null) {
+            //System.out.println("ResourceIsLoadingAdapter Synchronizing on " + getTarget());
+            synchronized (getTarget()) {
+                getTarget().eAdapters().remove(this);
+            }
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.eclipse.emf.common.notify.Adapter#isAdapterForType(java.lang.Object)
+     */
+    public boolean isAdapterForType(Object type) {
+        return type == RESOURCE_IS_LOADING_ADAPTER_CLASS;
+    }
+
+    /**
+     * 
+     */
+    public void forceRelease() {
+
+    }
+
+}
diff --git a/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/utilities/ResourceIsLoadingAdapterFactory.java b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/utilities/ResourceIsLoadingAdapterFactory.java
new file mode 100644
index 0000000..0723342
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.emf/wtpemf/org/eclipse/wst/common/internal/emf/utilities/ResourceIsLoadingAdapterFactory.java
@@ -0,0 +1,22 @@
+/*
+ * Created on Oct 26, 2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.eclipse.wst.common.internal.emf.utilities;
+
+
+/**
+ * @author mdelder
+ * 
+ */
+public class ResourceIsLoadingAdapterFactory {
+
+    public static ResourceIsLoadingAdapterFactory INSTANCE = new ResourceIsLoadingAdapterFactory();
+         
+    public ResourceIsLoadingAdapter createResourceIsLoadingAdapter() {
+        return new ResourceIsLoadingAdapter();
+    }
+    
+}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/schema/editModel.exsd b/plugins/org.eclipse.wst.common.emfworkbench.integration/schema/editModel.exsd
index 3a103a7..14743b2 100644
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/schema/editModel.exsd
+++ b/plugins/org.eclipse.wst.common.emfworkbench.integration/schema/editModel.exsd
@@ -103,6 +103,23 @@
          </attribute>

       </complexType>

    </element>

+   

+   <element name="resourceExtension">

+      <annotation>

+         <documentation>

+            This allows registration of files for autoloading according to file extension.

+         </documentation>

+      </annotation>

+      <complexType>

+         <attribute name="name" type="string">

+            <annotation>

+               <documentation>

+                  The file extension itself (&quot;myxmi&quot;)

+               </documentation>

+            </annotation>

+         </attribute>

+      </complexType>

+   </element>

 

    <annotation>

       <appInfo>

diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper.java
index dda3581..bc9f27a 100644
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper.java
+++ b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper.java
@@ -21,10 +21,11 @@
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.jobs.ILock;
 import org.eclipse.emf.common.notify.Adapter;
 import org.eclipse.emf.common.notify.Notification;
 import org.eclipse.emf.common.notify.Notifier;
@@ -39,6 +40,7 @@
 import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase;
 import org.eclipse.jem.util.emf.workbench.WorkbenchURIConverter;
+import org.eclipse.jem.util.logger.proxy.Logger;
 import org.eclipse.jem.util.plugin.JEMUtilPlugin;
 import org.eclipse.wst.common.internal.emf.resource.ReferencedResource;
 import org.eclipse.wst.common.internal.emf.resource.ReferencedXMIFactoryImpl;
@@ -70,9 +72,11 @@
 	 */
 	private static class FileAdapter extends AdapterImpl {
 		public static final Object ADAPTER_KEY = FileAdapter.class.getName();
+		private static final long delay = 6000;
 		private IFile file;
 		private long synchronizationStamp;
 		protected ResourceSet previousResourceSet;
+		private ILock saveLock;
 		public static final int FILE_NOT_LOADED = 0;
 		public static final int FILE_INACCESSIBLE = -1;
 
@@ -91,13 +95,60 @@
 					else
 						handleUnloaded();
 					break;
-				case ReferencedResource.RESOURCE_WAS_SAVED :
-					handleSaved();
-					break;
+				case ReferencedResource.RESOURCE_ABOUT_TO_SAVE:
+	                handleAboutToSave();
+	                break;
+	            case ReferencedResource.RESOURCE_WAS_SAVED:
+	                handleSaved();
+	                break;
+	            case ReferencedResource.RESOURCE_SAVE_FAILED:
+	                handleSaveFailed();
+	                break;
 				case Resource.RESOURCE__URI :
 					handleURIChanged();
 			}
 		}
+		
+		private void handleSaveFailed() {
+            releaseSaveLock();
+
+        }
+
+        private void handleAboutToSave() {
+            aquireSaveLock();
+        }
+
+        private void aquireSaveLock() {
+  /*          System.out.println("FileName: " + getFile().getName());
+            System.out.println("aquiredSaveLock: " + Thread.currentThread().getName());
+            System.out.println("Depth" + getSaveLock().getDepth());
+            System.out.println();*/
+            getSaveLock().acquire();
+
+        }
+
+        private boolean aquireSaveLock(long delay) throws InterruptedException {
+/*            System.out.println("FileName: " + getFile().getName());
+            System.out.println("aquiredSaveLock with delay: " + Thread.currentThread().getName());
+            System.out.println("Depth" + getSaveLock().getDepth());
+            System.out.println();*/
+            return getSaveLock().acquire(delay);
+
+        }
+
+        private void releaseSaveLock() {
+    /*        System.out.println("FileName: " + getFile().getName());
+            System.out.println("releasedSaveLock: " + Thread.currentThread().getName());
+            System.out.println("Depth" + getSaveLock().getDepth());*/
+            getSaveLock().release();
+
+        }
+
+        private ILock getSaveLock() {
+            if (saveLock == null)
+                saveLock = Platform.getJobManager().newLock();
+            return saveLock;
+        }
 
 		/**
 		 *  
@@ -153,15 +204,35 @@
 		 * @see ReferencedResource#isConsistent()
 		 */
 		public boolean isConsistent() {
-			if (getFile() == null || !getFile().isAccessible())
+			//This checks for the case where the resource hasn't finished saving fo the first time
+			if(!getResource().isLoaded())
 				return true;
-			if (!getFile().isSynchronized(IResource.DEPTH_ZERO))
-				return false;
-			if (synchronizationStamp == FILE_NOT_LOADED)
-				return true;
-			return synchronizationStamp == computeModificationStamp(getFile());
+            boolean hasLocked = false;
+            try {
+                hasLocked = aquireSaveLock(delay);
+            } catch (InterruptedException e) {
+                Logger.getLogger().write(e);
+            }
+            boolean result = false;
+            try {
 
-		}
+                if (getFile() == null || !getFile().isAccessible())
+                    result = true;
+                else {
+                    if (!getFile().isSynchronized(IFile.DEPTH_ZERO))
+                        result = false;
+                    else {
+                        result = synchronizationStamp == computeModificationStamp(getFile());
+                    }
+                }
+            } catch (Exception e) {
+                Logger.getLogger().write(e);
+            } finally {
+                if (hasLocked)
+                    releaseSaveLock();
+            }
+            return result;
+        }
 
 		public void cacheSynchronizationStamp() {
 			setSynchronizationStamp(computeModificationStamp(getFile()));
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelRegistry.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelRegistry.java
index 4666cd3..0733b32 100644
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelRegistry.java
+++ b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelRegistry.java
@@ -46,6 +46,8 @@
 	
 
 	public static final String EDIT_MODEL_ELEMENT = "editModel"; //$NON-NLS-1$
+	public static final String EDIT_MODEL_RESOURCE_EXTENSION = "resourceExtension"; //$NON-NLS-1$
+	public static final String EDIT_MODEL_RESOURCE_EXTENSION_NAME = "name"; //$NON-NLS-1$
 	public static final String EDIT_MODEL_ID_ATTR = "editModelID"; //$NON-NLS-1$
 	public static final String FACTORY_CLASS_ATTR = "factoryClass"; //$NON-NLS-1$
 	public static final String PARENT_MODEL_ATTR = "parentModelID"; //$NON-NLS-1$
@@ -107,7 +109,7 @@
 	public Collection getEditModelResources(String editModelID) {
 		Collection resources = new TreeSet();
 
-		EditModelInfo nextEditModelInfo = (EditModelInfo) factoryConfigurations.get(editModelID);
+		EditModelInfo nextEditModelInfo = getEditModelInfoById(editModelID);
 
 		String parentModelID = null;
 		Map visitedEditModels = new HashMap();
@@ -117,7 +119,7 @@
 				throw new IllegalStateException(EMFWorkbenchEditResourceHandler.getString(EMFWorkbenchEditResourceHandler.EditModelRegistry_ERROR_0, new Object[]{editModelID}));
 			visitedEditModels.put(parentModelID, null);
 			resources.addAll(getAllEditModelResources(parentModelID));
-			nextEditModelInfo = (EditModelInfo) factoryConfigurations.get(parentModelID);
+			nextEditModelInfo = getEditModelInfoById(parentModelID);
 		}
 
 		/* Get the resources for the actual edit model id */
@@ -126,6 +128,30 @@
 		return resources;
 	}
 	
+	public Collection getEditModelExtensions(String editModelID) { 
+		Collection extensions = new TreeSet();
+		
+		EditModelInfo nextEditModelInfo = getEditModelInfoById(editModelID);
+
+		String parentModelID = null;
+		Map visitedEditModels = new HashMap();
+		/* collect the resources from the parents */
+		while(nextEditModelInfo != null && (parentModelID = nextEditModelInfo.getParentModelID()) != null) {
+			if(visitedEditModels.containsKey(parentModelID)) 
+				throw new IllegalStateException(EMFWorkbenchEditResourceHandler.getString(EMFWorkbenchEditResourceHandler.EditModelRegistry_ERROR_0,new Object [] {editModelID})); 
+			else 
+				visitedEditModels.put(parentModelID, null);
+			
+			extensions.addAll(getAllEditModelExtensions(parentModelID));
+			nextEditModelInfo = getEditModelInfoById(parentModelID);
+		}
+		
+		/* Get the resources for the actual edit model id */
+		extensions.addAll(getAllEditModelExtensions(editModelID));
+		
+		return extensions;
+	}
+	
 	public IEditModelFactory findEditModelFactoryByKey(Object editModelID) {
 		IEditModelFactory factory = null;
 		EditModelInfo editMdlInfo = (EditModelInfo) factoryConfigurations.get(editModelID);
@@ -166,10 +192,20 @@
 		resources.addAll(getExtendedEditModelResources(editModelID));
 		return resources;
 	}
+	
+	protected Collection getAllEditModelExtensions(String editModelID) {
+		Collection resources = new ArrayList();
+		resources.addAll(getLocalEditModelExtensions(editModelID));
+		return resources;
+	}
 
-	protected Collection getLocalEditModelResources(String editModelID) {
-		EditModelInfo editMdlInfo = (EditModelInfo) factoryConfigurations.get(editModelID);
-		return (editMdlInfo != null) ? editMdlInfo.getEditModelResources() : Collections.EMPTY_LIST;
+	protected Collection getLocalEditModelResources(String editModelID) { 
+		EditModelInfo editMdlInfo = getEditModelInfoById(editModelID);
+  		return (editMdlInfo != null) ? editMdlInfo.getEditModelResources() : Collections.EMPTY_LIST; 
+	}
+	protected Collection getLocalEditModelExtensions(String editModelID) { 
+		EditModelInfo editMdlInfo = getEditModelInfoById(editModelID);
+  		return (editMdlInfo != null) ? editMdlInfo.getEditModelExtensions() : Collections.EMPTY_LIST; 
 	}
 
 	protected Collection getExtendedEditModelResources(String editModelID) {
@@ -185,7 +221,7 @@
 	 */
 	protected IEditModelFactory getEditModelFactoryByKey(Object editModelID) {
 		IEditModelFactory factory = null;
-		EditModelInfo editMdlInfo = (EditModelInfo) factoryConfigurations.get(editModelID);
+		EditModelInfo editMdlInfo = getEditModelInfoById(editModelID);
 		if (editMdlInfo != null)
 			factory = editMdlInfo.getEditModelFactory();
 		else
@@ -194,7 +230,27 @@
 		return factory;
 	}
 	
-	
+	/**
+     * @param editModelID
+     * @return
+     */
+    protected EditModelInfo getEditModelInfoById(Object editModelID) {
+        waitForInitializationIfNecessary();
+        return (EditModelInfo) factoryConfigurations.get(editModelID);
+    }
+    
+    /**
+     * If we are not initialized, block until the INSTANCE is released ( from getInstance())
+     */
+    private void waitForInitializationIfNecessary() {
+        /* We only need to acquire the semaphore (INSTANCE), we do not need 
+         * to execute anything in this block. If the Registry is not initailized,
+         * then it will block until the semaphore is released (from getInstance()),
+         * and then release it and return immediately. 
+         */
+		if(!isInitialized()) 
+		    synchronized(INSTANCE) { }
+    }
 
 	public class EditModelInfo {
 
@@ -203,6 +259,7 @@
 
 		private IEditModelFactory factory = null;
 		private List editModelResources = null;
+		private List editModelExtensions = null;
 
 		private String parentModelID = null;
 
@@ -223,20 +280,26 @@
 		}
 
 		public IEditModelFactory getEditModelFactory() {
+//			 Do not block if the factory is not null
 			if (this.factory == null) {
-				if (this.configurationElement != null) {
-					try {
-						this.factory = (IEditModelFactory) this.configurationElement.createExecutableExtension(FACTORY_CLASS_ATTR);
-						String loadUnknownResourceAsReadOnly = this.configurationElement.getAttribute(LOAD_UNKNOWN_RESOURCES_ATTR);
-						Boolean value = loadUnknownResourceAsReadOnly != null ? Boolean.valueOf(loadUnknownResourceAsReadOnly) : Boolean.FALSE;
-						this.factory.setLoadKnownResourcesAsReadOnly(value.booleanValue());
-						discardConfigurationElementIfNecessary();
-					} catch (CoreException e) {
-						Logger.getLogger(EMFWorkbenchEditPlugin.ID).logError(e);
+			  synchronized (this) {
+			      // another thread could have already initialized the factory
+			      // while this thread was waiting to enter the sync block
+			      if(this.factory == null) {
+					if (this.configurationElement != null) {
+						try {
+							this.factory = (IEditModelFactory) this.configurationElement.createExecutableExtension(FACTORY_CLASS_ATTR);
+							Boolean value = Boolean.valueOf(this.configurationElement.getAttribute(LOAD_UNKNOWN_RESOURCES_ATTR));
+							this.factory.setLoadKnownResourcesAsReadOnly(value.booleanValue());
+							discardConfigurationElementIfNecessary();
+						} catch (CoreException e) {
+							Logger.getLogger(EMFWorkbenchEditPlugin.ID).logError(e);
+						}
+					} else {
+						Logger.getLogger().logError(EMFWorkbenchEditResourceHandler.EditModelRegistry_ERROR_1);
 					}
-				} else {
-					Logger.getLogger().logError(EMFWorkbenchEditResourceHandler.EditModelRegistry_ERROR_1);
-				}
+			      }
+			    }
 			}
 			return this.factory;
 		}
@@ -249,9 +312,19 @@
 					editModelResources = new ArrayList();
 
 					IConfigurationElement[] resources = configurationElement.getChildren(EditModelResource.EDIT_MODEL_RESOURCE_ELEMENT);
-					for (int j = 0; j < resources.length; j++)
+					for (int j = 0; j < resources.length; j++) {
 						editModelResources.add(new EditModelResource(resources[j]));
-
+					}
+					IConfigurationElement[] resExtensions = configurationElement.getChildren(EDIT_MODEL_RESOURCE_EXTENSION);
+					if (resExtensions == null || resExtensions.length == 0) {
+						editModelExtensions = Collections.EMPTY_LIST;
+					} else {
+						editModelExtensions = new ArrayList();
+						for (int i = 0; i < resExtensions.length; i++) {
+							String extension = resExtensions[i].getAttribute(EDIT_MODEL_RESOURCE_EXTENSION_NAME);
+							editModelExtensions.add(extension);
+						}
+					}
 					discardConfigurationElementIfNecessary();
 				} else {
 					editModelResources = Collections.EMPTY_LIST;
@@ -276,6 +349,12 @@
 		public String getParentModelID() {
 			return parentModelID;
 		}
+		
+		public List getEditModelExtensions() {
+			/* this method is guarded */
+			initializeResources();
+			return editModelExtensions;
+		}
 
 	}
 	/**
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModel.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModel.java
index 5e55303..e9c39da 100644
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModel.java
+++ b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModel.java
@@ -45,6 +45,7 @@
 import org.eclipse.jem.internal.util.emf.workbench.nls.EMFWorkbenchResourceHandler;
 import org.eclipse.jem.util.emf.workbench.ResourceSetWorkbenchSynchronizer;
 import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase;
+import org.eclipse.jem.util.logger.proxy.Logger;
 import org.eclipse.wst.common.frameworks.internal.ISaveHandler;
 import org.eclipse.wst.common.frameworks.internal.SaveFailedException;
 import org.eclipse.wst.common.frameworks.internal.SaveHandlerHeadless;
@@ -81,6 +82,8 @@
 	private final boolean readOnly;
 	// These are the current resource uris we need to track
 	protected List knownResourceUris;
+	//These are the current resource extensions to track
+	protected List knownResourceExtensions;
 	// This is a subset of the known resource uris, which we have requested be autoloaded
 	protected List preloadResourceUris;
 	// This is a map of identifiers to resources that we need to listen to in order to listen for
@@ -208,6 +211,10 @@
 				URI uri = (URI) preloadResourceUris.get(i);
 				sync.disableAutoload(uri);
 			}
+			for (int i = 0; i < knownResourceExtensions.size(); i++) {
+				String ext = (String) knownResourceExtensions.get(i);
+				sync.disableAutoload(ext);
+			}
 		}
 	}
 
@@ -533,18 +540,33 @@
 			res = (EditModelResource) iter.next();
 			addEditModelResource(res);
 		}
-
+		Collection resourceExtensions = EditModelRegistry.getInstance().getEditModelExtensions(getEditModelID());
+		if (resourceExtensions.isEmpty()) {
+			knownResourceExtensions = Collections.EMPTY_LIST;
+		} else {
+			knownResourceExtensions.addAll(resourceExtensions);
+			Iterator it = resourceExtensions.iterator();
+			ResourceSetWorkbenchEditSynchronizer sync = (ResourceSetWorkbenchEditSynchronizer) getEmfContext().getResourceSet().getSynchronizer();
+			while (it.hasNext()) {
+				String extension = (String)iter.next();
+				sync.enableAutoload(extension);
+			}
+		}
 	}
 
 	private void addEditModelResource(EditModelResource res) {
 		boolean enabled = false;
-		if (res.isCore()) {
-			enabled = true;
-		} else {
-			IEnablementIdentifier identifier = res.getEnablementIdentifier(getProject());
-			registerInterest(identifier, res);
-			enabled = identifier.isEnabled();
-		}
+		try {
+			if (res.isCore()) {
+				enabled = true;
+			} else {
+				IEnablementIdentifier identifier = res.getEnablementIdentifier(getProject());
+				registerInterest(identifier, res);
+				enabled = identifier.isEnabled();
+			}
+		} catch(RuntimeException re) {
+	        Logger.getLogger().logWarning(re);
+	    } 
 		if (enabled) {
 			URI uri = res.getURI();
 			knownResourceUris.add(uri);
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ResourceSetWorkbenchEditSynchronizer.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ResourceSetWorkbenchEditSynchronizer.java
index aaf902e..14e1cbc 100644
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ResourceSetWorkbenchEditSynchronizer.java
+++ b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ResourceSetWorkbenchEditSynchronizer.java
@@ -64,7 +64,7 @@
 	protected List deferredLoadResources = new ArrayList();
 
 	protected List autoloadResourcesURIs = new ArrayList();
-
+	protected List autoloadResourcesExts = new ArrayList();
 
 
 	/**
@@ -233,7 +233,12 @@
 	 */
 	protected boolean addedResource(IFile aFile) {
 		//Process resource as a refresh.
-		return processResource(aFile, false);
+		URI uri = URI.createPlatformResourceURI(aFile.getFullPath().toString());
+		if ((autoloadResourcesURIs.contains(uri)) || (autoloadResourcesExts.contains(aFile.getFileExtension()))) {
+			deferredLoadResources.add(uri);
+			return true;
+		}
+		return false;
 	}
 
 	protected boolean processResource(IFile aFile, boolean isRemove) {
@@ -252,8 +257,6 @@
 				deferredRemoveResources.add(resource);
 			else if (resource.isLoaded() && !(WorkbenchResourceHelper.isReferencedResource(resource) && WorkbenchResourceHelper.isConsistent((ReferencedResource)resource)))
 				deferredUnloadResources.add(resource);
-			else if (autoloadResourcesURIs.contains(resource.getURI()))
-				deferredLoadResources.add(resource.getURI());
 		}
 		return false;
 	}
@@ -379,5 +382,12 @@
 	protected void initialize() {
 		getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.POST_CHANGE);
 	}
+	public void enableAutoload(String extension) {
+		autoloadResourcesExts.add(extension);
+		
+	}
+	public void disableAutoload(String extension) {
+		autoloadResourcesExts.remove(extension);
+	}
 
 }
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidatorImpl.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidatorImpl.java
index fa3b4f2..729443f 100644
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidatorImpl.java
+++ b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidatorImpl.java
@@ -72,11 +72,11 @@
 	 * they would like to refresh with the contents on disk if we are dirty.
 	 */
 	public void checkActivation(ResourceStateValidatorPresenter presenter) throws CoreException {
-		//checkConsistency(presenter);
+		checkConsistency(presenter);
 	}
 
 	public void lostActivation(ResourceStateValidatorPresenter presenter) throws CoreException {
-		//checkConsistency(presenter);
+		checkConsistency(presenter);
 	}
 
 	public boolean checkSave(ResourceStateValidatorPresenter presenter) throws CoreException {
@@ -329,8 +329,8 @@
 		Object ctx = presenter != null ? presenter.getValidateEditContext() : null;
 		IStatus result = ResourcesPlugin.getWorkspace().validateEdit(files, ctx);
 		cacheValidateState(result, roResources, nonResROFiles);
-//		if (!result.isOK())
-//			checkConsistency(presenter);
+		if (!result.isOK())
+			checkConsistency(presenter);
 		return result;
 	}
 
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleStructuralModel.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleStructuralModel.java
index 5065f9a..2bbcc72 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleStructuralModel.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/ModuleStructuralModel.java
@@ -18,9 +18,12 @@
 import java.util.List;
 import java.util.Map;
 
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRunnable;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Status;
@@ -32,10 +35,13 @@
 import org.eclipse.wst.common.componentcore.internal.impl.ResourceTreeRoot;
 import org.eclipse.wst.common.componentcore.internal.impl.WTPModulesResource;
 import org.eclipse.wst.common.componentcore.internal.impl.WTPModulesResourceFactory;
+import org.eclipse.wst.common.frameworks.internal.SaveFailedException;
 import org.eclipse.wst.common.internal.emf.resource.ReferencedResource;
 import org.eclipse.wst.common.internal.emf.resource.TranslatorResource;
 import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext;
 import org.eclipse.wst.common.internal.emfworkbench.integration.EditModel;
+import org.eclipse.wst.common.internal.emfworkbench.validateedit.ResourceStateValidator;
+import org.eclipse.wst.common.internal.emfworkbench.validateedit.ResourceStateValidatorPresenter;
 import org.eclipse.wst.common.project.facet.core.internal.FacetedProjectNature;
 /**
  * Manages the underlying Module Structural Metamodel.
@@ -177,6 +183,19 @@
 	public WTPModulesResource  makeWTPModulesResource() {
 		return (WTPModulesResource) createResource(WTPModulesResourceFactory.WTP_MODULES_URI_OBJ);
 	}
+	protected void runSaveOperation(IWorkspaceRunnable runnable, IProgressMonitor monitor) throws SaveFailedException {
+		try {
+			ResourcesPlugin.getWorkspace().run(runnable, null,IWorkspace.AVOID_UPDATE,monitor);
+		} catch (CoreException e) {
+			throw new SaveFailedException(e);
+		}
+	}
+	/**
+	 * @see ResourceStateValidator#checkActivation(ResourceStateValidatorPresenter)
+	 */
+	public void checkActivation(ResourceStateValidatorPresenter presenter) throws CoreException {
+		// Do nothing for now...
+	}
 	/**
 	 * Subclasses can override - by default this will return the first resource referenced by the
 	 * known resource URIs for this EditModel
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ComponentImplRegistryReader.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ComponentImplRegistryReader.java
index fff13c5..4f92654 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ComponentImplRegistryReader.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ComponentImplRegistryReader.java
@@ -115,6 +115,7 @@
 	protected IComponentImplFactory findFactoryForProject(IProject project){
 		try {
 			IFacetedProject facetedProject = ProjectFacetsManager.create(project);
+			if (facetedProject == null) return null;
 			Iterator keys = descriptors.keySet().iterator();
 			while (keys.hasNext()) {
 				String typeID = (String) keys.next();