Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=199480.
diff --git a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/resource/TestLifecycleListener.java b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/resource/TestLifecycleListener.java
new file mode 100644
index 0000000..aa1fdae
--- /dev/null
+++ b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/resource/TestLifecycleListener.java
@@ -0,0 +1,217 @@
+package org.eclipse.jst.jsf.core.tests.resource;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent;
+import org.eclipse.jst.jsf.common.internal.resource.IResourceLifecycleListener;
+import org.eclipse.jst.jsf.common.internal.resource.LifecycleListener;
+import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent.EventType;
+import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent.ReasonType;
+import org.eclipse.jst.jsf.core.tests.TestsPlugin;
+import org.eclipse.jst.jsf.test.util.JSFTestUtil;
+import org.eclipse.jst.jsf.test.util.WebProjectTestEnvironment;
+
+public class TestLifecycleListener extends TestCase 
+{
+    private WebProjectTestEnvironment _webProjectTestEnv;
+    private IResource                 _res;
+    
+    @Override
+    protected void setUp() throws Exception 
+    {
+        super.setUp();
+        
+        JSFTestUtil.setValidationEnabled(false);
+
+        _webProjectTestEnv = new WebProjectTestEnvironment(
+                getClass().getName()+"_" + getName());
+        _webProjectTestEnv.createProject(false);
+        assertNotNull(_webProjectTestEnv);
+        assertNotNull(_webProjectTestEnv.getTestProject());
+        assertTrue(_webProjectTestEnv.getTestProject().isAccessible());
+
+        _res = _webProjectTestEnv.loadResourceInWebRoot(TestsPlugin.getDefault().getBundle()
+                , "/testfiles/jsps/testdata1.jsp.data", "/testdata1.jsp");
+    }
+
+    private void testInaccessibleCondition(IResource res, Runnable runnable, ReasonType reason)
+    {
+        assertTrue(res.isAccessible());
+
+        LifecycleListener testListener = new LifecycleListener(res);
+        MockListener mockListener = new MockListener();
+        testListener.addListener(mockListener);
+
+        runnable.run();
+
+        mockListener.assertAcceptedResourceInaccessible(res, reason);
+        assertFalse(res.isAccessible());
+
+        testListener.removeListener(mockListener);
+        testListener.dispose();
+    }
+
+    public void testProjectClosedForProject() throws Exception
+    {
+        Runnable runnable = new Runnable()
+        {
+            public void run() 
+            {
+                // now close the project
+                try {
+                    _webProjectTestEnv.getTestProject().close(null);
+                } catch (CoreException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+
+        };
+        testInaccessibleCondition(_webProjectTestEnv.getTestProject(), runnable,  ReasonType.RESOURCE_PROJECT_CLOSED);
+    }
+
+    public void testProjectClosedForContainedResource() throws Exception
+    {
+        Runnable runnable = new Runnable()
+        {
+            public void run()
+            {
+                // now close the project
+                try {
+                    _webProjectTestEnv.getTestProject().close(null);
+                } catch (CoreException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        };
+        testInaccessibleCondition(_res, runnable,  ReasonType.RESOURCE_PROJECT_CLOSED);
+    }
+
+    public void testProjectDeletedForProject() throws Exception
+    {
+        Runnable runnable = new Runnable()
+        {
+            public void run()
+            {
+                // now delete the project
+                try {
+                    _webProjectTestEnv.getTestProject().delete(true, null);
+                } catch (CoreException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        };
+        testInaccessibleCondition(_webProjectTestEnv.getTestProject(), runnable,  ReasonType.RESOURCE_DELETED);
+    }
+
+    public void testProjectDeletedForContainedResource() throws Exception
+    {
+        Runnable runnable = new Runnable()
+        {
+            public void run()
+            {
+                // now delete the project
+                try {
+                    _webProjectTestEnv.getTestProject().delete(true, null);
+                } catch (CoreException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        };
+        testInaccessibleCondition(_res, runnable,  ReasonType.RESOURCE_PROJECT_DELETED);
+    }
+
+    public void testResourceDeleted() throws Exception
+    {
+        Runnable runnable = new Runnable()
+        {
+            public void run()
+            {
+                // now delete the resource
+                try {
+                    _res.delete(true, null);
+                } catch (CoreException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        };
+        testInaccessibleCondition(_res, runnable,  ReasonType.RESOURCE_DELETED);
+    }
+
+    public void testDisposeAfterEvent() throws Exception
+    {
+        LifecycleListener testListener = new LifecycleListener(_res);
+        MockListenerThatDoesDispose mockListener = new MockListenerThatDoesDispose();
+        testListener.addListener(mockListener);
+
+        _res.delete(true, null);
+        
+        assertTrue(testListener.isDisposed());
+        
+        boolean caughtAssertion = false;
+        try
+        {
+            testListener.addListener(mockListener);
+        }
+        catch (IllegalStateException ae)
+        {
+            caughtAssertion = true;
+        }
+        
+        assertTrue(caughtAssertion);
+    }
+
+    private class MockListener implements IResourceLifecycleListener
+    {
+        private List<ResourceLifecycleEvent>   acceptedEvents = 
+            new ArrayList<ResourceLifecycleEvent>();
+
+        public EventResult acceptEvent(ResourceLifecycleEvent event) 
+        {
+            acceptedEvents.add(event);
+            return new EventResult();
+        }
+
+        public void assertAcceptedResourceInaccessible(final IResource res, final ReasonType  reason)
+        {
+            for (ResourceLifecycleEvent event : acceptedEvents)
+            {
+                if (event.getEventType() == EventType.RESOURCE_INACCESSIBLE
+                        && event.getAffectedResource() == res)
+                {
+                    if (reason == event.getReasonType())
+                    {
+                        return;
+                    }
+                    else
+                    {
+                        System.out.printf("Expected event found with different result: %s instead of %s", event.getReasonType().toString(), reason.toString());
+                    }
+                }
+            }
+
+            // if we get to here then we have failed to find the expected
+            // event
+            fail("Expected to find RESOURCE_INACCESSIBLE event for resource: "+res.toString());
+        }
+    }
+    
+    /**
+     * A mock object that tests the disposeAfterEvent flag.
+     * @author cbateman
+     *
+     */
+    private class MockListenerThatDoesDispose implements IResourceLifecycleListener
+    {
+        public EventResult acceptEvent(ResourceLifecycleEvent event) 
+        {
+            EventResult result = new EventResult();
+            result.setDisposeAfterEvent(true);
+            return result;
+        }
+    }
+}
diff --git a/jsf/tests/org.eclipse.jst.jsf.designtime.tests/src/org/eclipse/jst/jsf/designtime/tests/TestJSPModelProcessor.java b/jsf/tests/org.eclipse.jst.jsf.designtime.tests/src/org/eclipse/jst/jsf/designtime/tests/TestJSPModelProcessor.java
index 1de6302..0b8621b 100644
--- a/jsf/tests/org.eclipse.jst.jsf.designtime.tests/src/org/eclipse/jst/jsf/designtime/tests/TestJSPModelProcessor.java
+++ b/jsf/tests/org.eclipse.jst.jsf.designtime.tests/src/org/eclipse/jst/jsf/designtime/tests/TestJSPModelProcessor.java
@@ -19,11 +19,12 @@
 
 public class TestJSPModelProcessor extends TestCase 
 {
-    private IFile _testJSP1;
-    private JSFFacetedTestEnvironment _jsfFactedTestEnvironment;
 
-    @Override
-    protected void setUp() throws Exception {
+	private IFile _testJSP1;
+	private JSFFacetedTestEnvironment _jsfFactedTestEnvironment;
+
+	@Override
+	protected void setUp() throws Exception {
         super.setUp();
         JSFTestUtil.setValidationEnabled(false);
         JSFTestUtil.setInternetProxyPreferences(true, "www-proxy.us.oracle.com","80");
@@ -33,151 +34,143 @@
         projectTestEnvironment.createProject(false);
 
         JDTTestEnvironment jdtTestEnvironment = 
-            new JDTTestEnvironment(projectTestEnvironment);
+        	new JDTTestEnvironment(projectTestEnvironment);
 
         final TestFileResource input = new TestFileResource();
         input.load(DesignTimeTestsPlugin.getDefault().getBundle(), 
-                "/testdata/bundle1.resources.data");
+        		"/testdata/bundle1.resources.data");
         jdtTestEnvironment.addResourceFile("src"
-                , new ByteArrayInputStream(input.toBytes())
-                , "bundles", "bundle1.properties");
+        		, new ByteArrayInputStream(input.toBytes())
+        		, "bundles", "bundle1.properties");
         
         IResource res = projectTestEnvironment.loadResourceInWebRoot(DesignTimeTestsPlugin.getDefault().getBundle()
-                , "/testdata/testdata1.jsp.data", "testdata1.jsp");
+        		, "/testdata/testdata1.jsp.data", "testdata1.jsp");
         _testJSP1 = (IFile) res;
 
         _jsfFactedTestEnvironment = new JSFFacetedTestEnvironment(projectTestEnvironment);
-        _jsfFactedTestEnvironment.initialize(IJSFCoreConstants.FACET_VERSION_1_1);    
-    }
+        _jsfFactedTestEnvironment.initialize(IJSFCoreConstants.FACET_VERSION_1_1);	
+	}
 
-    @Override
-    protected void tearDown() throws Exception {
-    }
+	@Override
+	protected void tearDown() throws Exception {
+	}
 
-    public void testGetAndDispose() throws Exception
-    {
-        JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
-        assertNotNull(processor);
-        assertEquals(1, processor.getRefCount());
-        JSPModelProcessor.dispose(_testJSP1);
-        assertEquals(0, processor.getRefCount());
-    }
+	public void testGetAndDispose() throws Exception
+	{
+		JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
+		assertNotNull(processor);
+		assertEquals(1, processor.getRefCount());
+		JSPModelProcessor.dispose(_testJSP1);
+		assertEquals(0, processor.getRefCount());
+	}
+	
+	public void testGetAndDisposeMultiple() throws Exception
+	{
+		JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
+		assertNotNull(processor);
+		assertEquals(1, processor.getRefCount());
+		
+		// get again
+		processor = JSPModelProcessor.get(_testJSP1);
+		assertEquals(2, processor.getRefCount());
+		// and again
+		processor = JSPModelProcessor.get(_testJSP1);
+		assertEquals(3, processor.getRefCount());
+		// and dispose once
+		JSPModelProcessor.dispose(_testJSP1);
+		assertEquals(2, processor.getRefCount());
 
-    public void testGetAndDisposeMultiple() throws Exception
-    {
-        JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
-        assertNotNull(processor);
-        assertEquals(1, processor.getRefCount());
+		// and reacquire
+		processor = JSPModelProcessor.get(_testJSP1);
+		assertEquals(3, processor.getRefCount());
 
-        // get again
-        processor = JSPModelProcessor.get(_testJSP1);
-        assertEquals(2, processor.getRefCount());
-        // and again
-        processor = JSPModelProcessor.get(_testJSP1);
-        assertEquals(3, processor.getRefCount());
-        // and dispose once
-        JSPModelProcessor.dispose(_testJSP1);
-        assertEquals(2, processor.getRefCount());
+		// dispose twice
+		JSPModelProcessor.dispose(_testJSP1);
+		JSPModelProcessor.dispose(_testJSP1);
+		assertEquals(1, processor.getRefCount());
 
-        // and reacquire
-        processor = JSPModelProcessor.get(_testJSP1);
-        assertEquals(3, processor.getRefCount());
+		// one final dispose
+		JSPModelProcessor.dispose(_testJSP1);
+		assertEquals(0, processor.getRefCount());
+		
+		// exceed by one
+		JSPModelProcessor.dispose(_testJSP1);
+		assertEquals(0, processor.getRefCount());
+		
+		// acquire
+		processor = JSPModelProcessor.get(_testJSP1);
+		assertEquals(1, processor.getRefCount());
 
-        // dispose twice
-        JSPModelProcessor.dispose(_testJSP1);
-        JSPModelProcessor.dispose(_testJSP1);
-        assertEquals(1, processor.getRefCount());
+		// dispose single reference
+		JSPModelProcessor.dispose(_testJSP1);
+		assertEquals(0, processor.getRefCount());
+	}
 
-        // one final dispose
-        JSPModelProcessor.dispose(_testJSP1);
-        assertEquals(0, processor.getRefCount());
+	public void testGetMapForScope() throws Exception
+	{
+		// if we not refreshed yet, then should be no symbols
+		JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
+		assertNotNull(processor);
+		
+		try
+		{
+			Map<Object, ISymbol> scopeMap = 
+				processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_REQUEST_STRING);
+			assertTrue(scopeMap.isEmpty());
+			
+			scopeMap = 
+				processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_SESSION_STRING);
+			assertTrue(scopeMap.isEmpty());
+	
+			scopeMap = 
+				processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_APPLICATION_STRING);
+			assertTrue(scopeMap.isEmpty());
+	
+			scopeMap = 
+				processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_NONE_STRING);
+			assertTrue(scopeMap.isEmpty());
+		}
+		finally
+		{
+			JSPModelProcessor.dispose(_testJSP1);
+			assertEquals(0, processor.getRefCount());
+		}
+	}
+	
+	public void testRefreshAndGet() throws Exception
+	{
+		// if we not refreshed yet, then should be no symbols
+		JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
+		assertNotNull(processor);
+		
+		try
+		{
+			Map<Object, ISymbol> scopeMap = 
+				processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_REQUEST_STRING);
+			assertTrue(scopeMap.isEmpty());
+			
+			processor.refresh(false);
+			
+			// after refresh we should have a symbol for the loadBundle and the dataTable
+			scopeMap = 
+				processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_REQUEST_STRING);
+			assertFalse(scopeMap.isEmpty());
+			assertEquals(2, scopeMap.size());
+		}
+		finally
+		{
+			JSPModelProcessor.dispose(_testJSP1);
+			assertEquals(0, processor.getRefCount());
+		}
+	}
 
-        // exceed by one
-        JSPModelProcessor.dispose(_testJSP1);
-        assertEquals(0, processor.getRefCount());
-
-        // acquire
-        processor = JSPModelProcessor.get(_testJSP1);
-        assertEquals(1, processor.getRefCount());
-
-        // dispose single reference
-        JSPModelProcessor.dispose(_testJSP1);
-        assertEquals(0, processor.getRefCount());
-    }
-
-    public void testGetMapForScope() throws Exception
-    {
-        // if we not refreshed yet, then should be no symbols
-        JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
-        assertNotNull(processor);
-
-        try
-        {
-            Map<Object, ISymbol> scopeMap = 
-                processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_REQUEST_STRING);
-            assertTrue(scopeMap.isEmpty());
-
-            scopeMap = 
-                processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_SESSION_STRING);
-            assertTrue(scopeMap.isEmpty());
-
-            scopeMap = 
-                processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_APPLICATION_STRING);
-            assertTrue(scopeMap.isEmpty());
-
-            scopeMap = 
-                processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_NONE_STRING);
-            assertTrue(scopeMap.isEmpty());
-        }
-        finally
-        {
-            JSPModelProcessor.dispose(_testJSP1);
-            assertEquals(0, processor.getRefCount());
-        }
-    }
-
-    public void testRefreshAndGet() throws Exception
-    {
-        // if we not refreshed yet, then should be no symbols
-        JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
-        assertNotNull(processor);
-
-        try
-        {
-            Map<Object, ISymbol> scopeMap = 
-                processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_REQUEST_STRING);
-            assertTrue(scopeMap.isEmpty());
-
-            processor.refresh(false);
-
-            // after refresh we should have a symbol for the loadBundle and the dataTable
-            scopeMap = 
-                processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_REQUEST_STRING);
-            assertFalse(scopeMap.isEmpty());
-            assertEquals(2, scopeMap.size());
-        }
-        finally
-        {
-            JSPModelProcessor.dispose(_testJSP1);
-            assertEquals(0, processor.getRefCount());
-        }
-    }
-
-    public void testFileDeletion_RegressionBug199480() throws Exception
-    {
-        // Regression for bug 199480
-        // ensure that the deletion of a resource with a JSPModelProcessor
-        // on it without an editor close event is still disposed of due
-        // to the resource change event.
-        // if we not refreshed yet, then should be no symbols
-        JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
-        assertNotNull(processor);
-
-        _testJSP1.delete(true, null);
-        // file is deleted, so the processor should dispose itself on the 
-        // resource change event
-        assertTrue(processor.isDisposed());
-        assertEquals(0, processor.getRefCount());
-        processor.refresh(true);
-    }
+	public void testFileDeletion() throws Exception
+	{
+		// if we not refreshed yet, then should be no symbols
+		JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
+		assertNotNull(processor);
+		
+		_testJSP1.delete(true, null);
+		processor.refresh(true);
+	}
 }