[302199] [translation] JSPTranslationAdapterFactory becoming a singleton was a bad idea
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslationAdapterFactory.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslationAdapterFactory.java index b8af1b1..52cac51 100644 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslationAdapterFactory.java +++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslationAdapterFactory.java
@@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.jst.jsp.core.internal.java; -import java.util.HashMap; - import org.eclipse.core.runtime.Platform; import org.eclipse.wst.sse.core.internal.provisional.AbstractAdapterFactory; import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; @@ -26,68 +24,47 @@ * */ public class JSPTranslationAdapterFactory extends AbstractAdapterFactory { + + /** the adapter associated with this factory */ + private JSPTranslationAdapter fAdapter = null; + // for debugging static final boolean DEBUG = Boolean.valueOf(Platform.getDebugOption("org.eclipse.jst.jsp.core/debug/jsptranslation")).booleanValue(); //$NON-NLS-1$; - private static final JSPTranslationAdapterFactory DEFAULT = new JSPTranslationAdapterFactory(); - - /** - * <code>{@link HashMap}<{@link String}, {@link JSPTranslationAdapter}></code> - * <ul><li>key - location of JSP file</li> - * <li>value - adapter associated with file at base location</li></ul> - */ - private HashMap fAdapters = null; - - protected JSPTranslationAdapterFactory() { + public JSPTranslationAdapterFactory() { super(IJSPTranslation.class, true); - this.fAdapters = new HashMap(); - } - - /** - * @return Singleton instance of the {@link JSPTranslationAdapterFactory} - */ - public static JSPTranslationAdapterFactory getDefault() { - return DEFAULT; } - /** - * <p>If an adapter for the model associated with the given <code>target</code> - * already exists then the model is updated for that adapter and returned, - * else a new adapter is created for the model associated with the given - * <code>target</code> and that new adapter is returned</p> - * - * @param target get {@link JSPTranslationAdapter} for model associated with this {@link INodeNotifier} - * - * @return {@link JSPTranslationAdapter} assoicated with the model for the given <code>target</code> - * - * @see org.eclipse.wst.sse.core.internal.provisional.AbstractAdapterFactory#createAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier) - */ + protected INodeAdapter createAdapter(INodeNotifier target) { - JSPTranslationAdapter adapter = null; - if (target instanceof IDOMNode) { + if (target instanceof IDOMNode && fAdapter == null) { /* attempt to load externalized translator and create adapter from it * else create new adapter */ IDOMModel model = ((IDOMNode) target).getModel(); - adapter = (JSPTranslationAdapter)this.fAdapters.get(model.getBaseLocation()); - if(adapter == null) { - JSPTranslator translator = JSPTranslatorPersister.getPersistedTranslator(model); - if(translator != null) { - adapter = new JSPTranslationAdapter(model, translator); - } else { - adapter= new JSPTranslationAdapter(model); - } - - if(DEBUG) { - System.out.println("(+) JSPTranslationAdapterFactory [" + this + "] created adapter: " + adapter); //$NON-NLS-1$ //$NON-NLS-2$ - } - - this.fAdapters.put(model.getBaseLocation(), adapter); + JSPTranslator translator = JSPTranslatorPersister.getPersistedTranslator(model); + if(translator != null) { + fAdapter = new JSPTranslationAdapter(model, translator); } else { - adapter.setXMLModel(model); + fAdapter= new JSPTranslationAdapter(model); } - + + if(DEBUG) { + System.out.println("(+) JSPTranslationAdapterFactory [" + this + "] created adapter: " + fAdapter); //$NON-NLS-1$ //$NON-NLS-2$ + } } - return adapter; + return fAdapter; + } + + + public void release() { + if(fAdapter != null) { + if(DEBUG) { + System.out.println("(-) JSPTranslationAdapterFactory [" + this + "] releasing adapter: " + fAdapter); //$NON-NLS-1$ //$NON-NLS-2$ + } + fAdapter.release(); + } + + super.release(); } }
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/modelhandler/ModelHandlerForJSP.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/modelhandler/ModelHandlerForJSP.java index 181bb92..aa74637 100644 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/modelhandler/ModelHandlerForJSP.java +++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/modelhandler/ModelHandlerForJSP.java
@@ -103,7 +103,7 @@ // } // } if (factory == null) { - factory = JSPTranslationAdapterFactory.getDefault(); + factory = new JSPTranslationAdapterFactory(); } sm.getFactoryRegistry().addFactory(factory);