[190548] roll back content model changes relating to soft references
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/modelquery/ModelQueryAdapterFactoryForJSP.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/modelquery/ModelQueryAdapterFactoryForJSP.java
index 94eae29..efa71fa 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/modelquery/ModelQueryAdapterFactoryForJSP.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/modelquery/ModelQueryAdapterFactoryForJSP.java
@@ -90,7 +90,7 @@
ModelQuery modelQuery = createModelQuery(model, resolver);
modelQuery.setEditMode(ModelQuery.EDIT_MODE_UNCONSTRAINED);
- modelQueryAdapterImpl = new JSPModelQueryAdapterImpl(CMDocumentCache.getInstance(), modelQuery, resolver);
+ modelQueryAdapterImpl = new JSPModelQueryAdapterImpl(new CMDocumentCache(), modelQuery, resolver);
}
}
}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/modelquery/ModelQueryAdapterFactoryForHTML.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/modelquery/ModelQueryAdapterFactoryForHTML.java
index 3efcb7e..c9dc850 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/modelquery/ModelQueryAdapterFactoryForHTML.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/modelquery/ModelQueryAdapterFactoryForHTML.java
@@ -192,9 +192,10 @@
if (baseLocation != null || resolver != null) {
idResolver = new XMLCatalogIdResolver(baseLocation, resolver);
}
- ModelQuery modelQuery = new HTMLModelQueryImpl(CMDocumentCache.getInstance(), idResolver);
+ CMDocumentCache documentCache = new CMDocumentCache();
+ ModelQuery modelQuery = new HTMLModelQueryImpl(documentCache, idResolver);
modelQuery.setEditMode(ModelQuery.EDIT_MODE_UNCONSTRAINED);
- modelQueryAdapter = new ModelQueryAdapterImpl(CMDocumentCache.getInstance(), modelQuery, idResolver);
+ modelQueryAdapter = new ModelQueryAdapterImpl(documentCache, modelQuery, idResolver);
}
}
return modelQueryAdapter;
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/CMDocumentManagerImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/CMDocumentManagerImpl.java
index f6df03e..c4cbfc4 100644
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/CMDocumentManagerImpl.java
+++ b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/CMDocumentManagerImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002,2007 IBM Corporation and others.
+ * Copyright (c) 2002, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -19,7 +19,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.wst.xml.core.internal.Logger;
@@ -32,6 +31,7 @@
import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentReferenceProvider;
import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache;
+
/**
*
*/
@@ -42,7 +42,6 @@
protected List listenerList = new Vector();
protected Hashtable propertyTable = new Hashtable();
protected Hashtable publicIdTable = new Hashtable();
- static final boolean DEBUG_MANAGER = Boolean.valueOf(Platform.getDebugOption("org.eclipse.wst.xml.core/debug/cmdocumentmanager")).booleanValue(); //$NON-NLS-1$
public CMDocumentManagerImpl(CMDocumentCache cmDocumentCache, CMDocumentReferenceProvider cmDocumentReferenceProvider)
@@ -160,7 +159,7 @@
if (getPropertyEnabled(PROPERTY_AUTO_LOAD))
{
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=136399
-
+
if (getPropertyEnabled(PROPERTY_PERFORM_URI_RESOLUTION))
{
resolvedURI = lookupOrCreateResolvedURI(publicId, systemId);
@@ -264,27 +263,16 @@
CMDocument result = null;
if (resolvedURI != null && resolvedURI.length() > 0)
{
- // try to get from cache
- result = cmDocumentCache.getCMDocument(resolvedURI);
- if(result == null){
- if (DEBUG_MANAGER)
- System.out.println("CMDocumentManager building " + resolvedURI + "[" + type + "]");
- // TODO... pass the TYPE thru to the CMDocumentBuilder
- result = ContentModelManager.getInstance().createCMDocument(resolvedURI, type);
-
- // load the annotation files for the document
- if (result != null && publicId != null)
- {
- AnnotationUtility.loadAnnotationsForGrammar(publicId, result);
- }
- }
- else {
- if (DEBUG_MANAGER)
- System.out.println("CMDocumentManager retrieving cached document " + resolvedURI + "[" + type + "]");
- }
+ // TODO... pass the TYPE thru to the CMDocumentBuilder
+ result = ContentModelManager.getInstance().createCMDocument(resolvedURI, type);
}
if (result != null)
{
+ // load the annotation files for the document
+ if (publicId != null)
+ {
+ AnnotationUtility.loadAnnotationsForGrammar(publicId, result);
+ }
cmDocumentCache.putCMDocument(resolvedURI, result);
}
else
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCache.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCache.java
index 43ea14e..670ff53 100644
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCache.java
+++ b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCache.java
@@ -12,231 +12,192 @@
*******************************************************************************/
package org.eclipse.wst.xml.core.internal.contentmodel.util;
-import java.lang.ref.SoftReference;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
+import java.util.Vector;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
+
+
/**
- * A singleton cache of CMDocuments. Because of the CM
+ *
*/
-public class CMDocumentCache {
- class CacheEntry {
- String uri;
- int status = STATUS_NOT_LOADED;
- float progress;
- private SoftReference cmDocumentReference;
+public class CMDocumentCache
+{
+ public static final int STATUS_NOT_LOADED = 0;
+ public static final int STATUS_LOADING = 2;
+ public static final int STATUS_LOADED = 3;
+ public static final int STATUS_ERROR = 4;
- CacheEntry(String uri) {
- this.uri = uri;
- }
+ protected class Entry
+ {
+ public String uri;
+ public int status = STATUS_NOT_LOADED;
+ public float progress;
+ public CMDocument cmDocument;
- CacheEntry(String uri, int status, CMDocument document) {
- this.uri = uri;
- this.status = status;
- this.cmDocumentReference = new SoftReference(document);
- }
+ public Entry(String uri)
+ {
+ this.uri = uri;
+ }
- CMDocument getCMDocument() {
- if (cmDocumentReference == null)
- return null;
- return (CMDocument) cmDocumentReference.get();
- }
+ public Entry(String uri, int status, CMDocument cmDocument)
+ {
+ this.uri = uri;
+ this.status = status;
+ this.cmDocument = cmDocument;
+ }
+ }
- public void setCMDocument(CMDocument document) {
- cmDocumentReference = new SoftReference(document);
- }
- }
-
- public static final int STATUS_NOT_LOADED = 0;
-
- public static final int STATUS_LOADING = 2;
-
- public static final int STATUS_LOADED = 3;
-
- public static final int STATUS_ERROR = 4;
-
- static final boolean DEBUG_CACHE = Boolean.valueOf(Platform.getDebugOption("org.eclipse.wst.xml.core/debug/cmdocumentcache")).booleanValue(); //$NON-NLS-1$
-
- private static CMDocumentCache SHARED_INSTANCE = new CMDocumentCache();
-
- public static CMDocumentCache getInstance() {
- return SHARED_INSTANCE;
- }
-
- Map fSavedDocuments = new HashMap();
-
- protected Hashtable fCachetable;
- protected List listenerList = new ArrayList();
-
- private CMDocumentCache() {
- fCachetable = new Hashtable();
- }
-
- public void addListener(CMDocumentCacheListener listener) {
- listenerList.add(listener);
- }
-
- /**
- *
- */
- public void clear() {
- synchronized (fCachetable) {
- fCachetable.clear();
- }
- notifyCacheCleared();
- }
-
- /**
- *
- */
- public CMDocument getCMDocument(String grammarURI) {
- CMDocument result = null;
- boolean cachedDocumentWasRemoved = false;
- if (grammarURI != null) {
- CacheEntry entry = null;
- synchronized (fCachetable) {
- entry = (CacheEntry) fCachetable.get(grammarURI);
- if (entry != null) {
- result = entry.getCMDocument();
- cachedDocumentWasRemoved = ((entry.status == STATUS_LOADED) && (result == null));
- }
- }
-
- if (cachedDocumentWasRemoved) {
- if (DEBUG_CACHE)
- System.out.println("CMDocumentCache hit on reclaimed document " + grammarURI);
- /* a previously loaded document has been reclaimed, */
- notifyCacheUpdated(grammarURI, entry.status, STATUS_NOT_LOADED, result);
- /* wait until after notification to actually remove the entry */
- synchronized (fCachetable) {
- fCachetable.remove(grammarURI);
- }
- }
- else if (DEBUG_CACHE && entry != null) {
- System.out.println("CMDocumentCache hit on " + grammarURI);
- }
- }
- else if (DEBUG_CACHE) {
- System.out.println("CMDocumentCache miss on " + grammarURI);
- }
- return result;
- }
-
- public synchronized List getCMDocuments() {
- List list = new ArrayList();
- for (Iterator i = fCachetable.values().iterator(); i.hasNext();) {
- CacheEntry entry = (CacheEntry) i.next();
- CMDocument document = entry.getCMDocument();
- if (document != null) {
- list.add(document);
- }
- }
- return list;
- }
-
- /**
- *
- */
- public int getStatus(String grammarURI) {
- int result = STATUS_NOT_LOADED;
- boolean cacheDocumentWasRemoved = false;
- if (grammarURI != null) {
- CacheEntry entry = null;
- synchronized (fCachetable) {
- entry = (CacheEntry) fCachetable.get(grammarURI);
- if (entry != null) {
- cacheDocumentWasRemoved = ((entry.status == STATUS_LOADED) && (entry.getCMDocument() == null));
- }
- }
-
- if (cacheDocumentWasRemoved) {
- /* a previously loaded document has been reclaimed, */
- notifyCacheUpdated(grammarURI, entry.status, STATUS_NOT_LOADED, null);
- /* wait until after notification to actually update the entry */
- entry.status = STATUS_NOT_LOADED;
- }
- if (entry != null) {
- result = entry.status;
- }
- }
- return result;
- }
+ protected Hashtable hashtable;
+ protected List listenerList = new Vector();
- /**
- * Gets a corresponding CacheEntry for the given grammarURI, creating one
- * if needed. Assumes that fCachetable is locked.
- *
- * @param grammarURI
- * @return
- */
- CacheEntry lookupOrCreate(String grammarURI) {
- CacheEntry entry = null;
- entry = (CacheEntry) fCachetable.get(grammarURI);
- if (entry == null) {
- entry = new CacheEntry(grammarURI);
- fCachetable.put(grammarURI, entry);
- }
- return entry;
- }
+ /**
+ * temporarily public until caching problem is solved
+ */
+ public CMDocumentCache()
+ {
+ hashtable = new Hashtable();
+ }
- /**
- *
- */
- protected void notifyCacheCleared() {
- CMDocumentCacheListener[] listeners = (CMDocumentCacheListener[]) listenerList.toArray(new CMDocumentCacheListener[0]);
- for (int i = 0; i < listeners.length; i++) {
- listeners[i].cacheCleared(this);
- }
- }
+ public void addListener(CMDocumentCacheListener listener)
+ {
+ listenerList.add(listener);
+ }
- /**
- *
- */
- protected void notifyCacheUpdated(String uri, int oldStatus, int newStatus, CMDocument cmDocument) {
- CMDocumentCacheListener[] listeners = (CMDocumentCacheListener[]) listenerList.toArray(new CMDocumentCacheListener[0]);
- for (int i = 0; i < listeners.length; i++) {
- listeners[i].cacheUpdated(this, uri, oldStatus, newStatus, cmDocument);
- }
- }
+ public void removeListener(CMDocumentCacheListener listener)
+ {
+ listenerList.remove(listener);
+ }
- /**
- *
- */
- public void putCMDocument(String grammarURI, CMDocument cmDocument) {
- if (grammarURI != null && cmDocument != null) {
- CacheEntry entry = null;
- int oldStatus = STATUS_NOT_LOADED;
- synchronized (fCachetable) {
- entry = lookupOrCreate(grammarURI);
- oldStatus = entry.status;
- entry.status = STATUS_LOADED;
- entry.setCMDocument(cmDocument);
- }
- notifyCacheUpdated(grammarURI, oldStatus, entry.status, cmDocument);
- }
- }
+ /**
+ *
+ */
+ public CMDocument getCMDocument(String grammarURI)
+ {
+ CMDocument result = null;
+ if (grammarURI != null)
+ {
+ Entry entry = (Entry)hashtable.get(grammarURI);
+ if (entry != null)
+ {
+ result = entry.cmDocument;
+ }
+ }
+ return result;
+ }
- public void removeListener(CMDocumentCacheListener listener) {
- listenerList.remove(listener);
- }
+ /**
+ *
+ */
+ public int getStatus(String grammarURI)
+ {
+ int result = STATUS_NOT_LOADED;
+ if (grammarURI != null)
+ {
+ Entry entry = (Entry)hashtable.get(grammarURI);
+ if (entry != null)
+ {
+ result = entry.status;
+ }
+
+ }
+ return result;
+ }
+
+ /**
+ *
+ */
+ protected Entry lookupOrCreate(String grammarURI)
+ {
+ Entry entry = (Entry)hashtable.get(grammarURI);
+ if (entry == null)
+ {
+ entry = new Entry(grammarURI);
+ hashtable.put(grammarURI, entry);
+ }
+ return entry;
+ }
- /**
- *
- */
- public void setStatus(String grammarURI, int status) {
- if (grammarURI != null) {
- CacheEntry entry = lookupOrCreate(grammarURI);
- int oldStatus = entry.status;
- entry.status = status;
- notifyCacheUpdated(grammarURI, oldStatus, entry.status, entry.getCMDocument());
- }
- }
+
+ /**
+ *
+ */
+ public void putCMDocument(String grammarURI, CMDocument cmDocument)
+ {
+ if (grammarURI != null && cmDocument != null)
+ {
+ Entry entry = lookupOrCreate(grammarURI);
+ int oldStatus = entry.status;
+ entry.status = STATUS_LOADED;
+ entry.cmDocument = cmDocument;
+ notifyCacheUpdated(grammarURI, oldStatus, entry.status, entry.cmDocument);
+ }
+ }
+
+ /**
+ *
+ */
+ public void setStatus(String grammarURI, int status)
+ {
+ if (grammarURI != null)
+ {
+ Entry entry = lookupOrCreate(grammarURI);
+ int oldStatus = entry.status;
+ entry.status = status;
+ notifyCacheUpdated(grammarURI, oldStatus, entry.status, entry.cmDocument);
+ }
+ }
+
+ /**
+ *
+ */
+ public void clear()
+ {
+ hashtable.clear();
+ notifyCacheCleared();
+ }
+
+ /**
+ *
+ */
+ protected void notifyCacheUpdated(String uri, int oldStatus, int newStatus, CMDocument cmDocument)
+ {
+ List list = new Vector();
+ list.addAll(listenerList);
+ for (Iterator i = list.iterator(); i.hasNext(); )
+ {
+ CMDocumentCacheListener listener = (CMDocumentCacheListener)i.next();
+ listener.cacheUpdated(this, uri, oldStatus, newStatus, cmDocument);
+ }
+ }
+
+ /**
+ *
+ */
+ protected void notifyCacheCleared()
+ {
+ List list = new Vector();
+ list.addAll(listenerList);
+ for (Iterator i = list.iterator(); i.hasNext(); )
+ {
+ CMDocumentCacheListener listener = (CMDocumentCacheListener)i.next();
+ listener.cacheCleared(this);
+ }
+ }
+
+ public List getCMDocuments()
+ {
+ List list = new ArrayList();
+ for (Iterator i = hashtable.values().iterator(); i.hasNext(); )
+ {
+ Entry entry = (Entry)i.next();
+ list.add(entry.cmDocument);
+ }
+ return list;
+ }
}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryAdapterFactoryForXML.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryAdapterFactoryForXML.java
index e710fd4..b02377f 100644
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryAdapterFactoryForXML.java
+++ b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryAdapterFactoryForXML.java
@@ -163,6 +163,7 @@
if (org.eclipse.wst.sse.core.internal.util.Debug.displayInfo)
System.out.println("----------------ModelQueryAdapterFactoryForXML... baseLocation : " + baseLocation); //$NON-NLS-1$
+ CMDocumentCache cmDocumentCache = new CMDocumentCache();
ModelQuery modelQuery = null;
URIResolver idResolver = null;
@@ -172,7 +173,7 @@
if (baseLocation != null || resolver != null) {
idResolver = new XMLCatalogIdResolver(baseLocation, resolver);
}
- modelQuery = new XMLModelQueryImpl(CMDocumentCache.getInstance(), idResolver);
+ modelQuery = new XMLModelQueryImpl(cmDocumentCache, idResolver);
// cs todo...
// for now we create a CMDocumentCache on a 'per editor' basis
@@ -183,7 +184,7 @@
if (documentManager != null) {
configureDocumentManager(documentManager);
}
- modelQueryAdapterImpl = new ModelQueryAdapterImpl(CMDocumentCache.getInstance(), modelQuery, idResolver);
+ modelQueryAdapterImpl = new ModelQueryAdapterImpl(cmDocumentCache, modelQuery, idResolver);
}
}
return modelQueryAdapterImpl;