Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0765dd48f8274ab9493ac8d2d79ebfaa7102c9c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*******************************************************************************
 * Copyright (c) 2006, 2008 Oracle Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Cameron Bateman/Oracle - initial API and implementation
 * 
 ********************************************************************************/

package org.eclipse.jst.jsf.context.symbol.source;

import java.util.List;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jst.jsf.common.JSFCommonPlugin;
import org.eclipse.jst.jsf.context.symbol.ISymbol;

/**
 * Must be sub-classed by all contextSymbolFactory extension point implementors
 * to create context configured symbols
 * 
 * <p><b>Provisional API - subject to change</b></p>
 * 
 * @author cbateman
 *
 */
public abstract class AbstractContextSymbolFactory
{
    /**
     * @param symbolName -- the symbol name
     * @param scope -- the scope of the symbol
     * @param context -- the context; must be supported (call supports(context))
     * @param problems -- populated with problems found during symbol construction.
     * @return a new ISymbol configured for the name, scope and context or null
     * if the arguments are invalid but some other reason a symbol cannot be created.
     * @throws IllegalArgumentException if this method is called with context
     * for which supports(context) == false or if scope does not conform
     * to exactly one of the ISymbolConstants.SYMBOL_SCOPE_* constants
     * @deprecated Use the new create method instead.
     */
    @Deprecated
    public final ISymbol  create(final String symbolName, final int scope, final IAdaptable context, final List problems)
    {
        if (!supports(context))
        {
            throw new IllegalArgumentException("Unsupported context"); //$NON-NLS-1$
        }
        else if (!ISymbolConstants.isValid(scope))
        {
            throw new IllegalArgumentException("Unsupported symbol constant:"+scope); //$NON-NLS-1$
        }

        try
        {
            return internalCreate(symbolName, scope, context, problems, null);
        }
        catch (final Exception e)
        {
            JSFCommonPlugin.log(e, "During execution of context symbol factory: "+this.getClass().getName()); //$NON-NLS-1$
            return null;
        }
    }

    /**
     * The same as create(symbolName, scope, context, problems), except it calls
     * the internalCreate with additionalInfo.  By default this has the same
     * effect.
     * 
     * @param symbolName
     * @param scope
     * @param context
     * @param problems
     * @param additionalInfo
     * @return the new Symbol
     */
    public final ISymbol  create(final String symbolName, final int scope, final IAdaptable context, final List problems, final IAdditionalContextSymbolInfo additionalInfo)
    {
        if (!supports(context))
        {
            throw new IllegalArgumentException("Unsupported context"); //$NON-NLS-1$
        }
        else if (!ISymbolConstants.isValid(scope))
        {
            throw new IllegalArgumentException("Unsupported symbol constant:"+scope); //$NON-NLS-1$
        }

        try
        {
            return internalCreate(symbolName, scope, context, problems, additionalInfo);
        }
        catch (final Exception e)
        {
            JSFCommonPlugin.log(e, "During execution of context symbol factory: "+this.getClass().getName()); //$NON-NLS-1$
            return null;
        }
    }


    /**
     * Use of this method is DISCOURAGED.  It is preferable to move functionality
     * to the new internalCreate method and have this one call it with null.
     * 
     * This method will eventually be deprecated and removed
     * 
     * @param symbolName
     * @param scope
     * @param context
     * @param problems -- see problems arg on create
     * @return a new ISymbol for the name, scope and context; may return null
     * @deprecated Use the new internalCreate instead.  Ignore the new
     * additionalInfo parameter if you do not need it.
     */
    @Deprecated
    protected ISymbol internalCreate(final String symbolName, final int scope, final IAdaptable context, final List problems)
    {
        // do nothing by default
        return null;
    }

    /**
     * NOTE: when migrating to this method, ensure that the other internalCreate
     * method in your implementation doesn't create inconsistent behaviour.
     * 
     * @param symbolName
     * @param scope
     * @param context Will conform to restrictions you set out in supports().
     * @param problems CURRENTLY IGNORED.
     * @param additionalInfo May be null
     * @since 3.0
     * @return a new ISymbol for the name, scope and context, but with the option
     * to also consult additionalInfo passed by the framework.  may return null.
     */
    protected ISymbol internalCreate(final String symbolName, final int scope, final IAdaptable context, final List problems, final IAdditionalContextSymbolInfo additionalInfo)
    {
        // by default, call the other internalCreate for backward compatibility.
        // implementers can override to do things with the additional info
        return internalCreate(symbolName, scope, context, problems);
    }

    /**
     * @param context
     * @return true if this factory supports the context
     */
    public abstract boolean  supports(IAdaptable context);
}

Back to the top