View | Details | Raw Unified | Return to bug 267967
Collapse All | Expand All

(-)src/org/eclipse/jst/jsf/context/AbstractDelegatingFactory.java (-80 / +72 lines)
Lines 15-22 Link Here
15
import java.util.ArrayList;
15
import java.util.ArrayList;
16
import java.util.Arrays;
16
import java.util.Arrays;
17
import java.util.Collections;
17
import java.util.Collections;
18
import java.util.Iterator;
19
import java.util.List;
18
import java.util.List;
19
import java.util.concurrent.CopyOnWriteArrayList;
20
20
21
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.core.runtime.IAdaptable;
22
22
Lines 26-110 Link Here
26
 * Clients may extend this class.
26
 * Clients may extend this class.
27
 * 
27
 * 
28
 * @author cbateman
28
 * @author cbateman
29
 *
29
 * 
30
 */
30
 */
31
public abstract class AbstractDelegatingFactory implements IDelegatingFactory {
31
public abstract class AbstractDelegatingFactory implements IDelegatingFactory
32
{
33
34
    /* instance attributes */
32
35
33
	/* instance attributes */
36
    /**
34
	
37
     * the list of registered factory delegates
35
	/**
38
     */
36
	 * the list of registered factory delegates
39
    protected final CopyOnWriteArrayList<IAdaptable> _delegates;
37
	 */
40
38
	protected 	final List<IAdaptable>  _delegates;
41
    private final List<Class> _supportedDelegates;
39
	
42
40
	private 	final List<Class>		_supportedDelegates;
43
    /**
41
44
     * @param supportedDelegateTypes
42
	/**
45
     *            -- populates the list of classes used by the isValidDelegate
43
	 * @param supportedDelegateTypes -- populates the list of classes used
46
     *            contract
44
	 * by the isValidDelegate contract
47
     */
45
	 */
48
    protected AbstractDelegatingFactory(final Class[] supportedDelegateTypes)
46
	protected AbstractDelegatingFactory(Class[]  supportedDelegateTypes)
49
    {
47
	{
50
        _delegates = new CopyOnWriteArrayList<IAdaptable>();
48
		_delegates = new ArrayList<IAdaptable>();
51
49
		
52
        final List<Class> supportedTypes = new ArrayList<Class>();
50
		final List<Class> supportedTypes = new ArrayList<Class>();
53
        supportedTypes.addAll(Arrays.asList(supportedDelegateTypes));
51
		supportedTypes.addAll(Arrays.asList(supportedDelegateTypes));
54
        _supportedDelegates = Collections.unmodifiableList(supportedTypes);
52
		_supportedDelegates = Collections.unmodifiableList(supportedTypes);
55
    }
53
	}
56
54
57
    /**
55
	/**
58
     * @see org.eclipse.jst.jsf.context.IDelegatingFactory#addFactoryDelegate(org.eclipse.core.runtime.IAdaptable)
56
	 * @see org.eclipse.jst.jsf.context.IDelegatingFactory#addFactoryDelegate(org.eclipse.core.runtime.IAdaptable)
59
     */
57
	 */
60
    public final void addFactoryDelegate(final IAdaptable delegate)
58
	public final void addFactoryDelegate(IAdaptable delegate) 
61
    {
59
	{
62
        if (isValidDelegate(delegate))
60
		synchronized(_delegates)
63
        {
61
		{
64
            _delegates.addIfAbsent(delegate);
62
			
65
        }
63
			if (!_delegates.contains(delegate)
66
    }
64
					&& isValidDelegate(delegate))
67
65
			{
68
    /**
66
				_delegates.add(delegate);
69
     * @see org.eclipse.jst.jsf.context.IDelegatingFactory#removeFactoryDelegate(org.eclipse.core.runtime.IAdaptable)
67
			}
70
     */
68
		}
71
    public final boolean removeFactoryDelegate(final IAdaptable delegate)
69
	}
72
    {
70
73
        return _delegates.remove(delegate);
71
	/**
74
    }
72
	 * @see org.eclipse.jst.jsf.context.IDelegatingFactory#removeFactoryDelegate(org.eclipse.core.runtime.IAdaptable)
75
73
	 */
76
    /**
74
	public final boolean removeFactoryDelegate(IAdaptable delegate) 
77
     * @see org.eclipse.jst.jsf.context.IDelegatingFactory#getValidDelegateTypes()
75
	{
78
     */
76
		synchronized(_delegates)
79
    public final List<Class> getValidDelegateTypes()
77
		{
80
    {
78
			return _delegates.remove(delegate);
81
        return _supportedDelegates;
79
		}	
82
    }
80
	}
83
81
84
    /**
82
	/**
85
     * @see org.eclipse.jst.jsf.context.IDelegatingFactory#isValidDelegate(org.eclipse.core.runtime.IAdaptable)
83
	 * @see org.eclipse.jst.jsf.context.IDelegatingFactory#getValidDelegateTypes()
86
     */
84
	 */
87
    public final boolean isValidDelegate(final IAdaptable delegate)
85
	public final List<Class> getValidDelegateTypes() 
88
    {
86
	{
89
        for (final Class clazz : _supportedDelegates)
87
		return _supportedDelegates;
90
        {
88
	}
91
            // if the delegate supports one of the valid delegate classes
89
92
            // via adaptation, then it is a valid delegate
90
	/**
93
            if (delegate.getAdapter(clazz) != null)
91
	 * @see org.eclipse.jst.jsf.context.IDelegatingFactory#isValidDelegate(org.eclipse.core.runtime.IAdaptable)
94
            {
92
	 */
95
                return true;
93
	public final boolean isValidDelegate(IAdaptable delegate) 
96
            }
94
	{
97
        }
95
		for (final Iterator<Class> it = _supportedDelegates.iterator(); it.hasNext();)
98
96
		{
99
        // if no found, delegate is not supported
97
			final Class clazz = it.next();
100
        return false;
98
			
101
    }
99
			// if the delegate supports one of the valid delegate classes
100
			// via adaptation, then it is a valid delegate
101
			if (delegate.getAdapter(clazz) != null)
102
			{
103
				return true;
104
			}
105
		}
106
		
107
		// if no found, delegate is not supported
108
		return false;
109
	}
110
}
102
}
(-)src/org/eclipse/jst/jsf/designtime/resolver/StructuredDocumentSymbolResolverFactory.java (-21 / +47 lines)
Lines 12-17 Link Here
12
12
13
package org.eclipse.jst.jsf.designtime.resolver;
13
package org.eclipse.jst.jsf.designtime.resolver;
14
14
15
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.jst.jsf.context.AbstractDelegatingFactory;
16
import org.eclipse.jst.jsf.context.AbstractDelegatingFactory;
16
import org.eclipse.jst.jsf.context.IModelContext;
17
import org.eclipse.jst.jsf.context.IModelContext;
17
import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext;
18
import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext;
Lines 23-35 Link Here
23
 * Clients may not sub-class.
24
 * Clients may not sub-class.
24
 * 
25
 * 
25
 * @author cbateman
26
 * @author cbateman
26
 *
27
 * 
27
 */
28
 */
28
public final class StructuredDocumentSymbolResolverFactory extends
29
public final class StructuredDocumentSymbolResolverFactory extends
29
        AbstractDelegatingFactory implements IStructuredDocumentSymbolResolverFactory
30
        AbstractDelegatingFactory implements
31
        IStructuredDocumentSymbolResolverFactory
30
{
32
{
31
    private static StructuredDocumentSymbolResolverFactory INSTANCE;
33
    private static StructuredDocumentSymbolResolverFactory INSTANCE;
32
    
34
33
    /**
35
    /**
34
     * @return the singleton factory instance
36
     * @return the singleton factory instance
35
     */
37
     */
Lines 38-83 Link Here
38
        if (INSTANCE == null)
40
        if (INSTANCE == null)
39
        {
41
        {
40
            // no delegates supported
42
            // no delegates supported
41
            INSTANCE = new StructuredDocumentSymbolResolverFactory(new Class[0]);
43
            INSTANCE = new StructuredDocumentSymbolResolverFactory(new Class[]
44
            { IStructuredDocumentSymbolResolverFactory.class });
42
        }
45
        }
43
        
46
44
        return INSTANCE;
47
        return INSTANCE;
45
    }
48
    }
46
    
49
47
    private StructuredDocumentSymbolResolverFactory(Class[] supportedDelegateTypes) 
50
    private StructuredDocumentSymbolResolverFactory(
51
            Class[] supportedDelegateTypes)
48
    {
52
    {
49
        super(supportedDelegateTypes);
53
        super(supportedDelegateTypes);
54
        for (final IAdaptable delegate : SymbolContextResolverReader
55
                .getAllHandlers())
56
        {
57
            addFactoryDelegate(delegate);
58
        }
50
    }
59
    }
51
60
52
    /**
61
    /**
53
     * @param context
62
     * @param context
54
     * @return a new instance of symbol resolver for context
63
     * @return a new instance of symbol resolver for context
55
     */
64
     */
56
    public ISymbolContextResolver getSymbolContextResolver(IModelContext context) {
65
    public ISymbolContextResolver getSymbolContextResolver(IModelContext context)
57
        ISymbolContextResolver  resolver = internalGetSymbolContextResolver(context);
66
    {
58
        
67
        ISymbolContextResolver resolver = delegateGetSymbolContextResolver(context);
68
59
        if (resolver == null)
69
        if (resolver == null)
60
        {
70
        {
61
            resolver = delegateGetSymbolContextResolver(context);
71
            resolver = internalGetSymbolContextResolver(context);
62
        }
72
        }
63
        
73
64
        return resolver;
74
        return resolver;
65
    }
75
    }
66
    
76
67
    private ISymbolContextResolver internalGetSymbolContextResolver(IModelContext context)
77
    private ISymbolContextResolver internalGetSymbolContextResolver(
78
            IModelContext context)
68
    {
79
    {
69
        if (context instanceof IStructuredDocumentContext &&
80
        if (context instanceof IStructuredDocumentContext
70
                ((IStructuredDocumentContext)context).getStructuredDocument() instanceof IStructuredDocument)
81
                && ((IStructuredDocumentContext) context)
82
                        .getStructuredDocument() instanceof IStructuredDocument)
71
        {
83
        {
72
            return new SymbolContextResolver((IStructuredDocumentContext) context);
84
            return new SymbolContextResolver(
85
                    (IStructuredDocumentContext) context);
73
        }
86
        }
74
        
87
75
        return null;
88
        return null;
76
    }
89
    }
77
    
90
78
    private ISymbolContextResolver delegateGetSymbolContextResolver(IModelContext context)
91
    private ISymbolContextResolver delegateGetSymbolContextResolver(
92
            IModelContext context)
79
    {
93
    {
80
        // no delegates currently supported
94
        for (final IAdaptable adaptable : _delegates)
95
        {
96
            final IStructuredDocumentSymbolResolverFactory delegateFactory = 
97
                (IStructuredDocumentSymbolResolverFactory) adaptable
98
                    .getAdapter(IStructuredDocumentSymbolResolverFactory.class);
99
            ISymbolContextResolver symbolContextResolver = delegateFactory
100
                    .getSymbolContextResolver(context);
101
102
            if (symbolContextResolver != null)
103
            {
104
                return symbolContextResolver;
105
            }
106
        }
81
        return null;
107
        return null;
82
    }
108
    }
83
}
109
}
(-)plugin.xml (+1 lines)
Lines 13-18 Link Here
13
   <extension-point id="viewhandler" name="%extension-point.name.6" schema="schema/viewhandler.exsd"/>
13
   <extension-point id="viewhandler" name="%extension-point.name.6" schema="schema/viewhandler.exsd"/>
14
   <extension-point id="customViewMapper" name="%extension-point.name.7" schema="schema/customViewMapper.exsd"/>
14
   <extension-point id="customViewMapper" name="%extension-point.name.7" schema="schema/customViewMapper.exsd"/>
15
   <extension-point id="jsfFacetConfiguration" name="%extension-point.name.11" schema="schema/jsfFacetConfiguration.exsd"/>
15
   <extension-point id="jsfFacetConfiguration" name="%extension-point.name.11" schema="schema/jsfFacetConfiguration.exsd"/>
16
   <extension-point id="symbolContextResolverFactory" name="%extension-point.name.12" schema="schema/symbolContextResolverFactory.exsd"/>
16
17
17
   <extension point="org.eclipse.emf.ecore.generated_package">
18
   <extension point="org.eclipse.emf.ecore.generated_package">
18
    	<package 
19
    	<package 
(-)plugin.properties (+2 lines)
Lines 42-44 Link Here
42
42
43
noOpLibraryProviderWarning = Library configuration is disabled. Further classpath changes may be required later.
43
noOpLibraryProviderWarning = Library configuration is disabled. Further classpath changes may be required later.
44
noOpLibraryProviderMessage = This facet requires JSF implementation library to be present on project classpath. By disabling library configuration, user takes on responsibility of configuring classpath appropriately via alternate means.
44
noOpLibraryProviderMessage = This facet requires JSF implementation library to be present on project classpath. By disabling library configuration, user takes on responsibility of configuring classpath appropriately via alternate means.
45
46
extension-point.name.12 = Symbol Context Resolver Factory Delegate
(-)schema/symbolContextResolverFactory.exsd (+104 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.jst.jsf.core" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.jst.jsf.core" id="symbolContextResolverFactory" name="Symbol Context Resolver Factory Delegate"/>
7
      </appInfo>
8
      <documentation>
9
         [Enter description of this extension point.]
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appInfo>
16
            <meta.element />
17
         </appInfo>
18
      </annotation>
19
      <complexType>
20
         <choice>
21
            <element ref="symbolFactoryDelegate"/>
22
         </choice>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appInfo>
43
                  <meta.attribute translatable="true"/>
44
               </appInfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49
50
   <element name="symbolFactoryDelegate">
51
      <complexType>
52
         <attribute name="class" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  PROVISIONAL API  -- Subject to change
56
57
Use to add symbol factory delegates that get called before the SymbolContextResolver.
58
               </documentation>
59
               <appInfo>
60
                  <meta.attribute kind="java" basedOn="org.eclipse.jst.jsf.designtime.resolver.AbstractStructuredDocumentSymbolResolverFactory:org.eclipse.core.runtime.IAdaptable"/>
61
               </appInfo>
62
            </annotation>
63
         </attribute>
64
      </complexType>
65
   </element>
66
67
   <annotation>
68
      <appInfo>
69
         <meta.section type="since"/>
70
      </appInfo>
71
      <documentation>
72
         [Enter the first release in which this extension point appears.]
73
      </documentation>
74
   </annotation>
75
76
   <annotation>
77
      <appInfo>
78
         <meta.section type="examples"/>
79
      </appInfo>
80
      <documentation>
81
         [Enter extension point usage example here.]
82
      </documentation>
83
   </annotation>
84
85
   <annotation>
86
      <appInfo>
87
         <meta.section type="apiinfo"/>
88
      </appInfo>
89
      <documentation>
90
         [Enter API information here.]
91
      </documentation>
92
   </annotation>
93
94
   <annotation>
95
      <appInfo>
96
         <meta.section type="implementation"/>
97
      </appInfo>
98
      <documentation>
99
         [Enter information about supplied implementation of this extension point.]
100
      </documentation>
101
   </annotation>
102
103
104
</schema>
(-)src/org/eclipse/jst/jsf/designtime/resolver/SymbolContextResolverReader.java (+68 lines)
Added Link Here
1
package org.eclipse.jst.jsf.designtime.resolver;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.List;
6
7
import org.eclipse.core.runtime.CoreException;
8
import org.eclipse.core.runtime.IAdaptable;
9
import org.eclipse.core.runtime.IConfigurationElement;
10
import org.eclipse.core.runtime.IExtension;
11
import org.eclipse.core.runtime.IExtensionPoint;
12
import org.eclipse.core.runtime.Platform;
13
import org.eclipse.jst.jsf.core.internal.JSFCorePlugin;
14
15
/*package*/ class SymbolContextResolverReader
16
{
17
    private static List<IAdaptable> _handlers = null;
18
19
    /**
20
     * @return all available handers for the ext-pt.  List is not
21
     * modifiable
22
     */
23
    public static synchronized List<IAdaptable> getAllHandlers() {
24
        if (_handlers == null) {
25
            _handlers = readAllHandlers();
26
        }
27
        return Collections.unmodifiableList(_handlers);
28
    }
29
30
    private static List<IAdaptable> readAllHandlers()
31
    {
32
        final List<IAdaptable> result = new ArrayList<IAdaptable>();
33
        final IExtensionPoint extensionPoint = Platform.getExtensionRegistry()
34
                .getExtensionPoint(JSFCorePlugin.PLUGIN_ID,
35
                        "symbolContextResolverFactory"); //$NON-NLS-1$
36
        final IExtension[] extensions = extensionPoint.getExtensions();
37
38
        for (final IExtension ext : extensions)
39
        {
40
            final IConfigurationElement[] elementEditElement = ext
41
                    .getConfigurationElements();
42
43
            for (final IConfigurationElement configurationElement : elementEditElement)
44
            {
45
                final IConfigurationElement element = configurationElement;
46
                if (element.getName().equals(
47
                        "symbolFactoryDelegate")) //$NON-NLS-1$
48
                {
49
                    try
50
                    {
51
                        final IAdaptable factory = (IAdaptable) configurationElement
52
                                .createExecutableExtension("class"); //$NON-NLS-1$
53
                        if (factory != null)
54
                        {
55
                            result.add(factory);
56
                        }
57
                        
58
                    } catch (final CoreException e)
59
                    {
60
                        JSFCorePlugin.log("Problem loading element edit extension for "+element.toString(), e); //$NON-NLS-1$
61
                    }
62
                }
63
            }
64
        }
65
        return result;
66
    }
67
68
}

Return to bug 267967