Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/AbstractDelegatingFactory.java18
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/StructuredDocumentContextResolverFactory.java180
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/structureddocument/internal/impl/StructuredDocumentContextFactory.java93
3 files changed, 149 insertions, 142 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/AbstractDelegatingFactory.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/AbstractDelegatingFactory.java
index 2a88ad6c0..69fac24b9 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/AbstractDelegatingFactory.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/AbstractDelegatingFactory.java
@@ -16,6 +16,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -108,7 +109,10 @@ public abstract class AbstractDelegatingFactory implements IDelegatingFactory
*/
public final boolean removeFactoryDelegate(final IAdaptable delegate)
{
- return _delegates.remove(delegate);
+ synchronized(_delegates)
+ {
+ return _delegates.remove(delegate);
+ }
}
/**
@@ -137,4 +141,16 @@ public abstract class AbstractDelegatingFactory implements IDelegatingFactory
// if no found, delegate is not supported
return false;
}
+
+ /**
+ * @return an iterator to _delegates which is retrieved in a synchronized block to protect against
+ * access during sorting.
+ */
+ protected final Iterator<IAdaptable> getDelegatesIterator()
+ {
+ synchronized(_delegates)
+ {
+ return _delegates.iterator();
+ }
+ }
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/StructuredDocumentContextResolverFactory.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/StructuredDocumentContextResolverFactory.java
index a12d3a92d..b05e6e628 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/StructuredDocumentContextResolverFactory.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/StructuredDocumentContextResolverFactory.java
@@ -13,6 +13,8 @@
package org.eclipse.jst.jsf.context.resolver.structureddocument.internal.impl;
+import java.util.Iterator;
+
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jst.jsf.context.AbstractDelegatingFactory;
import org.eclipse.jst.jsf.context.resolver.structureddocument.IDOMContextResolver;
@@ -91,28 +93,27 @@ IStructuredDocumentContextResolverFactory, IStructuredDocumentContextResolverFac
private IDOMContextResolver delegateGetDOMResolver(
final IStructuredDocumentContext context)
{
- synchronized (_delegates)
+ Iterator<IAdaptable> it = getDelegatesIterator();
+ while (it.hasNext())
{
- for (final IAdaptable adaptable : _delegates)
- {
+ IAdaptable adapter = it.next();
- final IStructuredDocumentContextResolverFactory delegateFactory = (IStructuredDocumentContextResolverFactory) adaptable
- .getAdapter(IStructuredDocumentContextResolverFactory.class);
+ final IStructuredDocumentContextResolverFactory delegateFactory = (IStructuredDocumentContextResolverFactory) adapter
+ .getAdapter(IStructuredDocumentContextResolverFactory.class);
- if (delegateFactory != null)
- {
- final IDOMContextResolver contextResolver = delegateFactory
- .getDOMContextResolver(context);
+ if (delegateFactory != null)
+ {
+ final IDOMContextResolver contextResolver = delegateFactory
+ .getDOMContextResolver(context);
- if (contextResolver != null)
- {
- return contextResolver;
- }
+ if (contextResolver != null)
+ {
+ return contextResolver;
}
}
-
- return null;
}
+
+ return null;
}
/**
@@ -145,23 +146,22 @@ IStructuredDocumentContextResolverFactory, IStructuredDocumentContextResolverFac
private ITextRegionContextResolver delegateGetTextRegionResolver(
final IStructuredDocumentContext context)
{
- synchronized (_delegates)
+ Iterator<IAdaptable> it = getDelegatesIterator();
+ while (it.hasNext())
{
- for (final Object element : _delegates)
- {
- final IStructuredDocumentContextResolverFactory delegateFactory = (IStructuredDocumentContextResolverFactory) ((IAdaptable) element)
- .getAdapter(IStructuredDocumentContextResolverFactory.class);
- final ITextRegionContextResolver contextResolver = delegateFactory
- .getTextRegionResolver(context);
+ IAdaptable adapter = it.next();
+ final IStructuredDocumentContextResolverFactory delegateFactory = (IStructuredDocumentContextResolverFactory) (adapter)
+ .getAdapter(IStructuredDocumentContextResolverFactory.class);
+ final ITextRegionContextResolver contextResolver = delegateFactory
+ .getTextRegionResolver(context);
- if (contextResolver != null)
- {
- return contextResolver;
- }
+ if (contextResolver != null)
+ {
+ return contextResolver;
}
-
- return null;
}
+
+ return null;
}
public IWorkspaceContextResolver getWorkspaceContextResolver(
@@ -192,23 +192,22 @@ IStructuredDocumentContextResolverFactory, IStructuredDocumentContextResolverFac
private IWorkspaceContextResolver delegateGetWorkspaceContextResolver(
final IStructuredDocumentContext context)
{
- synchronized (_delegates)
+ Iterator<IAdaptable> it = getDelegatesIterator();
+ while (it.hasNext())
{
- for (final Object element : _delegates)
- {
- final IStructuredDocumentContextResolverFactory delegateFactory = (IStructuredDocumentContextResolverFactory) ((IAdaptable) element)
- .getAdapter(IStructuredDocumentContextResolverFactory.class);
- final IWorkspaceContextResolver contextResolver = delegateFactory
- .getWorkspaceContextResolver(context);
+ IAdaptable adapter = it.next();
+ final IStructuredDocumentContextResolverFactory delegateFactory = (IStructuredDocumentContextResolverFactory) (adapter)
+ .getAdapter(IStructuredDocumentContextResolverFactory.class);
+ final IWorkspaceContextResolver contextResolver = delegateFactory
+ .getWorkspaceContextResolver(context);
- if (contextResolver != null)
- {
- return contextResolver;
- }
+ if (contextResolver != null)
+ {
+ return contextResolver;
}
-
- return null;
}
+
+ return null;
}
public ITaglibContextResolver getTaglibContextResolver(
@@ -249,28 +248,27 @@ IStructuredDocumentContextResolverFactory, IStructuredDocumentContextResolverFac
private ITaglibContextResolver delegateGetTaglibContextResolver(
final IStructuredDocumentContext context)
{
- synchronized (_delegates)
+ Iterator<IAdaptable> it = getDelegatesIterator();
+ while (it.hasNext())
{
- for (final IAdaptable adapter : _delegates)
+ IAdaptable adapter = it.next();
+ final IStructuredDocumentContextResolverFactory delegateFactory =
+ (IStructuredDocumentContextResolverFactory) adapter
+ .getAdapter(IStructuredDocumentContextResolverFactory.class);
+
+ if (delegateFactory != null)
{
- final IStructuredDocumentContextResolverFactory delegateFactory =
- (IStructuredDocumentContextResolverFactory) adapter
- .getAdapter(IStructuredDocumentContextResolverFactory.class);
+ final ITaglibContextResolver contextResolver = delegateFactory
+ .getTaglibContextResolver(context);
- if (delegateFactory != null)
+ if (contextResolver != null)
{
- final ITaglibContextResolver contextResolver = delegateFactory
- .getTaglibContextResolver(context);
-
- if (contextResolver != null)
- {
- return contextResolver;
- }
+ return contextResolver;
}
}
-
- return null;
}
+
+ return null;
}
public IMetadataContextResolver getMetadataContextResolver(
@@ -300,50 +298,48 @@ IStructuredDocumentContextResolverFactory, IStructuredDocumentContextResolverFac
private IMetadataContextResolver delegateGetMetadataContextResolver(
final IStructuredDocumentContext context)
{
- synchronized (_delegates)
+ Iterator<IAdaptable> it = getDelegatesIterator();
+ while (it.hasNext())
{
- for (final Object element : _delegates)
- {
- final IStructuredDocumentContextResolverFactory delegateFactory = (IStructuredDocumentContextResolverFactory) ((IAdaptable) element)
- .getAdapter(IStructuredDocumentContextResolverFactory.class);
- final IMetadataContextResolver contextResolver = delegateFactory
- .getMetadataContextResolver(context);
+ IAdaptable adapter = it.next();
+ final IStructuredDocumentContextResolverFactory delegateFactory = (IStructuredDocumentContextResolverFactory) (adapter)
+ .getAdapter(IStructuredDocumentContextResolverFactory.class);
+ final IMetadataContextResolver contextResolver = delegateFactory
+ .getMetadataContextResolver(context);
- if (contextResolver != null)
- {
- return contextResolver;
- }
+ if (contextResolver != null)
+ {
+ return contextResolver;
}
-
- return null;
}
+
+ return null;
}
public <T> T getResolver(final IStructuredDocumentContext context, final Class<T> clazz) {
{
- synchronized (_delegates)
- {
- for (final IAdaptable adapter : _delegates)
- {
- final IStructuredDocumentContextResolverFactory delegateFactory =
- (IStructuredDocumentContextResolverFactory) adapter
- .getAdapter(IStructuredDocumentContextResolverFactory.class);
-
- if (delegateFactory != null
- && delegateFactory instanceof IStructuredDocumentContextResolverFactory2)
- {
- final IStructuredDocumentContextResolverFactory2 contextResolverFactory = (IStructuredDocumentContextResolverFactory2)delegateFactory;
- final T contextResolver = contextResolverFactory.getResolver(context, clazz);
- if (contextResolver != null)
- {
- return contextResolver;
- }
- }
- }
-
- return null;
- }
- }
+ Iterator<IAdaptable> it = getDelegatesIterator();
+ while (it.hasNext())
+ {
+ IAdaptable adapter = it.next();
+ final IStructuredDocumentContextResolverFactory delegateFactory =
+ (IStructuredDocumentContextResolverFactory) adapter
+ .getAdapter(IStructuredDocumentContextResolverFactory.class);
+
+ if (delegateFactory != null
+ && delegateFactory instanceof IStructuredDocumentContextResolverFactory2)
+ {
+ final IStructuredDocumentContextResolverFactory2 contextResolverFactory = (IStructuredDocumentContextResolverFactory2)delegateFactory;
+ final T contextResolver = contextResolverFactory.getResolver(context, clazz);
+ if (contextResolver != null)
+ {
+ return contextResolver;
+ }
+ }
+ }
+
+ return null;
+ }
}
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/structureddocument/internal/impl/StructuredDocumentContextFactory.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/structureddocument/internal/impl/StructuredDocumentContextFactory.java
index 89f24f622..989fd8364 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/structureddocument/internal/impl/StructuredDocumentContextFactory.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/structureddocument/internal/impl/StructuredDocumentContextFactory.java
@@ -109,21 +109,20 @@ public class StructuredDocumentContextFactory extends AbstractStructuredDocument
private IStructuredDocumentContext delegateGetContext(ITextViewer textViewer, int documentPosition)
{
- synchronized(_delegates)
+ final Iterator it = getDelegatesIterator();
+
+ while (it.hasNext())
{
- for (final Iterator it = _delegates.iterator(); it.hasNext();)
+ IStructuredDocumentContextFactory delegateFactory = (IStructuredDocumentContextFactory) ((IAdaptable) it.next()).getAdapter(IStructuredDocumentContextFactory.class);
+ IStructuredDocumentContext context = delegateFactory.getContext(textViewer, documentPosition);
+
+ if (context != null)
{
- IStructuredDocumentContextFactory delegateFactory = (IStructuredDocumentContextFactory) ((IAdaptable) it.next()).getAdapter(IStructuredDocumentContextFactory.class);
- IStructuredDocumentContext context = delegateFactory.getContext(textViewer, documentPosition);
-
- if (context != null)
- {
- return context;
- }
+ return context;
}
-
- return null;
}
+
+ return null;
}
/**
@@ -144,21 +143,20 @@ public class StructuredDocumentContextFactory extends AbstractStructuredDocument
private IStructuredDocumentContext delegateGetContext(IDocument document, int documentPosition)
{
- synchronized(_delegates)
- {
- for (final Iterator it = _delegates.iterator(); it.hasNext();)
+ final Iterator it = getDelegatesIterator();
+
+ while (it.hasNext())
+ {
+ IStructuredDocumentContextFactory delegateFactory = (IStructuredDocumentContextFactory) ((IAdaptable) it.next()).getAdapter(IStructuredDocumentContextFactory.class);
+ IStructuredDocumentContext context = delegateFactory.getContext(document, documentPosition);
+
+ if (context != null)
{
- IStructuredDocumentContextFactory delegateFactory = (IStructuredDocumentContextFactory) ((IAdaptable) it.next()).getAdapter(IStructuredDocumentContextFactory.class);
- IStructuredDocumentContext context = delegateFactory.getContext(document, documentPosition);
-
- if (context != null)
- {
- return context;
- }
+ return context;
}
-
- return null;
}
+
+ return null;
}
public IStructuredDocumentContext getContext(IDocument document, Node node)
@@ -201,21 +199,20 @@ public class StructuredDocumentContextFactory extends AbstractStructuredDocument
private IStructuredDocumentContext delegateGetContext(IDocument document, Node node)
{
- synchronized(_delegates)
+ final Iterator it = getDelegatesIterator();
+
+ while (it.hasNext())
{
- for (final Iterator it = _delegates.iterator(); it.hasNext();)
+ IStructuredDocumentContextFactory delegateFactory = (IStructuredDocumentContextFactory) ((IAdaptable) it.next()).getAdapter(IStructuredDocumentContextFactory.class);
+ IStructuredDocumentContext context = delegateFactory.getContext(document, node);
+
+ if (context != null)
{
- IStructuredDocumentContextFactory delegateFactory = (IStructuredDocumentContextFactory) ((IAdaptable) it.next()).getAdapter(IStructuredDocumentContextFactory.class);
- IStructuredDocumentContext context = delegateFactory.getContext(document, node);
-
- if (context != null)
- {
- return context;
- }
+ return context;
}
-
- return null;
}
+
+ return null;
}
public IStructuredDocumentContext getContext(Element element)
@@ -245,26 +242,24 @@ public class StructuredDocumentContextFactory extends AbstractStructuredDocument
return null;
}
- private IStructuredDocumentContext delegateGetContext(Element element) {
- synchronized(_delegates)
+ private IStructuredDocumentContext delegateGetContext(Element element)
+ {
+ final Iterator it = getDelegatesIterator();
+
+ while (it.hasNext())
{
- for (final Iterator it = _delegates.iterator(); it.hasNext();)
+ IStructuredDocumentContextFactory2 delegateFactory = (IStructuredDocumentContextFactory2) ((IAdaptable) it.next()).getAdapter(IStructuredDocumentContextFactory2.class);
+ if (delegateFactory != null)
{
- IStructuredDocumentContextFactory2 delegateFactory = (IStructuredDocumentContextFactory2) ((IAdaptable) it.next()).getAdapter(IStructuredDocumentContextFactory2.class);
- if (delegateFactory != null)
+ IStructuredDocumentContext context = delegateFactory.getContext(element);
+
+ if (context != null)
{
- IStructuredDocumentContext context = delegateFactory.getContext(element);
-
- if (context != null)
- {
- return context;
- }
+ return context;
}
}
-
- return null;
}
+
+ return null;
}
-
-
}

Back to the top