### Eclipse Workspace Patch 1.0 #P org.eclipse.jst.jsf.common Index: src/org/eclipse/jst/jsf/context/AbstractDelegatingFactory.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jsf/components/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/AbstractDelegatingFactory.java,v retrieving revision 1.3 diff -u -r1.3 AbstractDelegatingFactory.java --- src/org/eclipse/jst/jsf/context/AbstractDelegatingFactory.java 23 May 2007 16:48:00 -0000 1.3 +++ src/org/eclipse/jst/jsf/context/AbstractDelegatingFactory.java 4 May 2009 22:44:17 -0000 @@ -15,8 +15,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Iterator; import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; import org.eclipse.core.runtime.IAdaptable; @@ -26,85 +26,77 @@ * Clients may extend this class. * * @author cbateman - * + * */ -public abstract class AbstractDelegatingFactory implements IDelegatingFactory { +public abstract class AbstractDelegatingFactory implements IDelegatingFactory +{ + + /* instance attributes */ - /* instance attributes */ - - /** - * the list of registered factory delegates - */ - protected final List _delegates; - - private final List _supportedDelegates; - - /** - * @param supportedDelegateTypes -- populates the list of classes used - * by the isValidDelegate contract - */ - protected AbstractDelegatingFactory(Class[] supportedDelegateTypes) - { - _delegates = new ArrayList(); - - final List supportedTypes = new ArrayList(); - supportedTypes.addAll(Arrays.asList(supportedDelegateTypes)); - _supportedDelegates = Collections.unmodifiableList(supportedTypes); - } - - /** - * @see org.eclipse.jst.jsf.context.IDelegatingFactory#addFactoryDelegate(org.eclipse.core.runtime.IAdaptable) - */ - public final void addFactoryDelegate(IAdaptable delegate) - { - synchronized(_delegates) - { - - if (!_delegates.contains(delegate) - && isValidDelegate(delegate)) - { - _delegates.add(delegate); - } - } - } - - /** - * @see org.eclipse.jst.jsf.context.IDelegatingFactory#removeFactoryDelegate(org.eclipse.core.runtime.IAdaptable) - */ - public final boolean removeFactoryDelegate(IAdaptable delegate) - { - synchronized(_delegates) - { - return _delegates.remove(delegate); - } - } - - /** - * @see org.eclipse.jst.jsf.context.IDelegatingFactory#getValidDelegateTypes() - */ - public final List getValidDelegateTypes() - { - return _supportedDelegates; - } - - /** - * @see org.eclipse.jst.jsf.context.IDelegatingFactory#isValidDelegate(org.eclipse.core.runtime.IAdaptable) - */ - public final boolean isValidDelegate(IAdaptable delegate) - { - for (final Iterator it = _supportedDelegates.iterator(); it.hasNext();) - { - final Class clazz = it.next(); - - // if the delegate supports one of the valid delegate classes - // via adaptation, then it is a valid delegate - if (delegate.getAdapter(clazz) != null) - { - return true; - } - } - - // if no found, delegate is not supported - return false; - } + /** + * the list of registered factory delegates + */ + protected final CopyOnWriteArrayList _delegates; + + private final List _supportedDelegates; + + /** + * @param supportedDelegateTypes + * -- populates the list of classes used by the isValidDelegate + * contract + */ + protected AbstractDelegatingFactory(final Class[] supportedDelegateTypes) + { + _delegates = new CopyOnWriteArrayList(); + + final List supportedTypes = new ArrayList(); + supportedTypes.addAll(Arrays.asList(supportedDelegateTypes)); + _supportedDelegates = Collections.unmodifiableList(supportedTypes); + } + + /** + * @see org.eclipse.jst.jsf.context.IDelegatingFactory#addFactoryDelegate(org.eclipse.core.runtime.IAdaptable) + */ + public final void addFactoryDelegate(final IAdaptable delegate) + { + if (isValidDelegate(delegate)) + { + _delegates.addIfAbsent(delegate); + } + } + + /** + * @see org.eclipse.jst.jsf.context.IDelegatingFactory#removeFactoryDelegate(org.eclipse.core.runtime.IAdaptable) + */ + public final boolean removeFactoryDelegate(final IAdaptable delegate) + { + return _delegates.remove(delegate); + } + + /** + * @see org.eclipse.jst.jsf.context.IDelegatingFactory#getValidDelegateTypes() + */ + public final List getValidDelegateTypes() + { + return _supportedDelegates; + } + + /** + * @see org.eclipse.jst.jsf.context.IDelegatingFactory#isValidDelegate(org.eclipse.core.runtime.IAdaptable) + */ + public final boolean isValidDelegate(final IAdaptable delegate) + { + for (final Class clazz : _supportedDelegates) + { + // if the delegate supports one of the valid delegate classes + // via adaptation, then it is a valid delegate + if (delegate.getAdapter(clazz) != null) + { + return true; + } + } + + // if no found, delegate is not supported + return false; + } } #P org.eclipse.jst.jsf.core Index: src/org/eclipse/jst/jsf/designtime/resolver/StructuredDocumentSymbolResolverFactory.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jsf/components/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/resolver/StructuredDocumentSymbolResolverFactory.java,v retrieving revision 1.4 diff -u -r1.4 StructuredDocumentSymbolResolverFactory.java --- src/org/eclipse/jst/jsf/designtime/resolver/StructuredDocumentSymbolResolverFactory.java 12 Feb 2008 07:57:34 -0000 1.4 +++ src/org/eclipse/jst/jsf/designtime/resolver/StructuredDocumentSymbolResolverFactory.java 4 May 2009 22:44:18 -0000 @@ -12,6 +12,7 @@ package org.eclipse.jst.jsf.designtime.resolver; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jst.jsf.context.AbstractDelegatingFactory; import org.eclipse.jst.jsf.context.IModelContext; import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext; @@ -23,13 +24,14 @@ * Clients may not sub-class. * * @author cbateman - * + * */ public final class StructuredDocumentSymbolResolverFactory extends - AbstractDelegatingFactory implements IStructuredDocumentSymbolResolverFactory + AbstractDelegatingFactory implements + IStructuredDocumentSymbolResolverFactory { private static StructuredDocumentSymbolResolverFactory INSTANCE; - + /** * @return the singleton factory instance */ @@ -38,46 +40,70 @@ if (INSTANCE == null) { // no delegates supported - INSTANCE = new StructuredDocumentSymbolResolverFactory(new Class[0]); + INSTANCE = new StructuredDocumentSymbolResolverFactory(new Class[] + { IStructuredDocumentSymbolResolverFactory.class }); } - + return INSTANCE; } - - private StructuredDocumentSymbolResolverFactory(Class[] supportedDelegateTypes) + + private StructuredDocumentSymbolResolverFactory( + Class[] supportedDelegateTypes) { super(supportedDelegateTypes); + for (final IAdaptable delegate : SymbolContextResolverReader + .getAllHandlers()) + { + addFactoryDelegate(delegate); + } } /** * @param context * @return a new instance of symbol resolver for context */ - public ISymbolContextResolver getSymbolContextResolver(IModelContext context) { - ISymbolContextResolver resolver = internalGetSymbolContextResolver(context); - + public ISymbolContextResolver getSymbolContextResolver(IModelContext context) + { + ISymbolContextResolver resolver = delegateGetSymbolContextResolver(context); + if (resolver == null) { - resolver = delegateGetSymbolContextResolver(context); + resolver = internalGetSymbolContextResolver(context); } - + return resolver; } - - private ISymbolContextResolver internalGetSymbolContextResolver(IModelContext context) + + private ISymbolContextResolver internalGetSymbolContextResolver( + IModelContext context) { - if (context instanceof IStructuredDocumentContext && - ((IStructuredDocumentContext)context).getStructuredDocument() instanceof IStructuredDocument) + if (context instanceof IStructuredDocumentContext + && ((IStructuredDocumentContext) context) + .getStructuredDocument() instanceof IStructuredDocument) { - return new SymbolContextResolver((IStructuredDocumentContext) context); + return new SymbolContextResolver( + (IStructuredDocumentContext) context); } - + return null; } - - private ISymbolContextResolver delegateGetSymbolContextResolver(IModelContext context) + + private ISymbolContextResolver delegateGetSymbolContextResolver( + IModelContext context) { - // no delegates currently supported + for (final IAdaptable adaptable : _delegates) + { + final IStructuredDocumentSymbolResolverFactory delegateFactory = + (IStructuredDocumentSymbolResolverFactory) adaptable + .getAdapter(IStructuredDocumentSymbolResolverFactory.class); + ISymbolContextResolver symbolContextResolver = delegateFactory + .getSymbolContextResolver(context); + + if (symbolContextResolver != null) + { + return symbolContextResolver; + } + } return null; } } Index: plugin.xml =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jsf/components/jsf/plugins/org.eclipse.jst.jsf.core/plugin.xml,v retrieving revision 1.36 diff -u -r1.36 plugin.xml --- plugin.xml 30 Apr 2009 00:25:24 -0000 1.36 +++ plugin.xml 4 May 2009 22:44:18 -0000 @@ -13,6 +13,7 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PROVISIONAL API -- Subject to change + +Use to add symbol factory delegates that get called before the SymbolContextResolver. + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + Index: src/org/eclipse/jst/jsf/designtime/resolver/SymbolContextResolverReader.java =================================================================== RCS file: src/org/eclipse/jst/jsf/designtime/resolver/SymbolContextResolverReader.java diff -N src/org/eclipse/jst/jsf/designtime/resolver/SymbolContextResolverReader.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jst/jsf/designtime/resolver/SymbolContextResolverReader.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,68 @@ +package org.eclipse.jst.jsf.designtime.resolver; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; + +/*package*/ class SymbolContextResolverReader +{ + private static List _handlers = null; + + /** + * @return all available handers for the ext-pt. List is not + * modifiable + */ + public static synchronized List getAllHandlers() { + if (_handlers == null) { + _handlers = readAllHandlers(); + } + return Collections.unmodifiableList(_handlers); + } + + private static List readAllHandlers() + { + final List result = new ArrayList(); + final IExtensionPoint extensionPoint = Platform.getExtensionRegistry() + .getExtensionPoint(JSFCorePlugin.PLUGIN_ID, + "symbolContextResolverFactory"); //$NON-NLS-1$ + final IExtension[] extensions = extensionPoint.getExtensions(); + + for (final IExtension ext : extensions) + { + final IConfigurationElement[] elementEditElement = ext + .getConfigurationElements(); + + for (final IConfigurationElement configurationElement : elementEditElement) + { + final IConfigurationElement element = configurationElement; + if (element.getName().equals( + "symbolFactoryDelegate")) //$NON-NLS-1$ + { + try + { + final IAdaptable factory = (IAdaptable) configurationElement + .createExecutableExtension("class"); //$NON-NLS-1$ + if (factory != null) + { + result.add(factory); + } + + } catch (final CoreException e) + { + JSFCorePlugin.log("Problem loading element edit extension for "+element.toString(), e); //$NON-NLS-1$ + } + } + } + } + return result; + } + +}