Skip to main content
summaryrefslogtreecommitdiffstats
blob: 219bd59768415529d2e601f98ccb95ee8e56a0a7 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/*******************************************************************************
 * Copyright (c) 2001, 2007 Oracle Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Oracle Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.validation.internal.appconfig;

import java.text.MessageFormat;
import java.util.Locale;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.jst.jsf.core.internal.JSFCorePlugin;
import org.eclipse.wst.validation.internal.core.Message;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;

/**
 * Factory for constructing diagnostic objects for AppConfig file validation
 * 
 * @author cbateman
 *
 */
public final class DiagnosticFactory 
{
    /**
     * Problem id
     */
    public final static int EL_EXPR_MUST_BE_IN_HASH_BRACES_ID = 0;
    
    /**
     * Problem id
     */
    public final static int SYNTAX_ERROR_IN_EL_ID = 1;
    
    /**
     * Problem id
     */
    public final static int CANNOT_FIND_CLASS_NAME_ID = 2;
    
    /**
     * Problem id
     */
    public final static int FULLY_QUALIFIED_NAME_MUST_BE_A_CLASS_ID = 3;
    
    /**
     * Problem id
     */
    public final static int CLASS_MUST_BE_INSTANCE_OF_ID = 4;
    
    /**
     * Problem id
     */
    public final static int CLASS_MUST_BE_CONCRETE_ID = 5;
    
    /**
     * TODO:
     */
    public final static int CLASS_MUST_HAVE_DEFAULT_OR_ADAPTER_CONSTRUCTOR_ID = 6;

    /**
     * Problem id
     */
    public final static int API_DEPRECATED_AFTER_VERSION_ID = 7;
    
    /**
     * Problem id
     */
    public final static int BEAN_PROPERTY_NOT_FOUND_ID = 8;
    
    /**
     * Problem id
     */
    public final static int MUST_BE_A_VALID_JAVA_IDENT_ID = 9;
    
    /**
     * Problem id
     */
    public final static int BEAN_SCOPE_NOT_VALID_ID = 10;
    
    /**
     * Problem id
     */
    public final static int MAP_ENTRIES_CAN_ONLY_BE_SET_ON_MAP_TYPE_ID = 11;
    
    /**
     * Problem id
     */
    public final static int LIST_ENTRIES_CAN_ONLY_BE_SET_ON_LIST_TYPE_ID = 12;
    
    /**
     * Problem id
     */
    public final static int API_NOT_AVAILABLE_BEFORE_VERSION_ID = 13;
    
    /**
     * Problem id
     */
    public final static int APP_CONFIG_IS_NEWER_THAN_JSF_VERSION_ID = 14;
    /**
     * Problem id
     */
    public final static int APP_CONFIG_IS_OLDER_THAN_JSF_VERSION_ID = 15;
    
    /**
     * Problem id
     */
    public final static int LOCALE_FORMAT_NOT_VALID_ID = 16;
    
    /**
     * @return message indicating text that should be EL was
     * not found sorrounded in #{} values
     */
    public static IMessage create_EL_EXPR_MUST_BE_IN_HASH_BRACES()
    {
        return new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
                Messages.EL_EXPR_MUST_BE_IN_HASH_BRACES_ID,
                null, EL_EXPR_MUST_BE_IN_HASH_BRACES_ID);
    }
    
    /**
     * @return message indicating that EL was found that
     * was empty or did not parse
     */
    public static IMessage create_SYNTAX_ERROR_IN_EL()
    {
        return new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
                Messages.SYNTAX_ERROR_IN_EL_ID,
                null, SYNTAX_ERROR_IN_EL_ID);
    }
    
    /**
     * @param className
     * @return message indicating that className can't be found as 
     * a valid fully qualified class name
     */
    public static IMessage create_CANNOT_FIND_CLASS_NAME(final String className)
    {
        return new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
                MessageFormat.format(Messages.CANNOT_FIND_CLASS_NAME_ID,new Object[]{className}),
                null, CANNOT_FIND_CLASS_NAME_ID);
    }
    
    /**
     * @param fullyQualifiedName
     * @return the error message for a fullyQualifiedName that resolves to a type
     * that is not a class (i.e. an interface or enum) but is expected to be
     */
    public static IMessage create_FULLY_QUALIFIED_NAME_MUST_BE_A_CLASS(final String fullyQualifiedName)
    {
        return new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
                MessageFormat.format(Messages.FULLY_QUALIFIED_NAME_MUST_BE_A_CLASS_ID
                        ,new Object[]{fullyQualifiedName})
                        ,null, FULLY_QUALIFIED_NAME_MUST_BE_A_CLASS_ID);
    }

    /**
     * @param className
     * @param extensionType 
     * @param expectedSuper
     * @return an error when a class name must be of type expectedSuper
     */
    public static IMessage create_CLASS_MUST_BE_INSTANCE_OF(final String className, 
                                                            final String extensionType,
                                                            final String expectedSuper)
    {
        return new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
                MessageFormat.format(Messages.CLASS_MUST_BE_INSTANCE_OF_ID
                        ,new Object[]{className, extensionType, expectedSuper})
                        ,null, CLASS_MUST_BE_INSTANCE_OF_ID);
    }
    
    
    /**
     * @param className
     * @return error indicating that className must specify a class
     * that is concrete
     */
    public static IMessage create_CLASS_MUST_BE_CONCRETE(final String className)
    {
        return new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
                MessageFormat.format(Messages.CLASS_MUST_BE_CONCRETE_ID
                        ,new Object[]{className})
                        ,null, CLASS_MUST_BE_CONCRETE_ID);
    }
    
    /**
     * @param apiName -- name of deprecated API
     * @param afterVersion -- version after which deprecation is effective
     * @param useInstead -- name of API to use instead
     * @return an error indicating the use of a deprecated API
     */
    public static IMessage create_API_DEPRECATED_AFTER_VERSION_ID(final String apiName, final String afterVersion, final String useInstead)
    {
        return new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
                MessageFormat.format(Messages.API_DEPRECATED_AFTER_VERSION_ID
                        ,new Object[]{apiName, afterVersion, useInstead})
                        ,null, API_DEPRECATED_AFTER_VERSION_ID);
    }
    
    /**
     * @param propertyName
     * @param beanClassName
     * @return an error indicating that the propertyName was not
     * found on beanClassName
     */
    public static IMessage create_BEAN_PROPERTY_NOT_FOUND(final String propertyName, final String beanClassName)
    {
        return new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
                MessageFormat.format(Messages.BEAN_PROPERTY_NOT_FOUND_ID
                        ,new Object[]{propertyName, beanClassName})
                        ,null, BEAN_PROPERTY_NOT_FOUND_ID);
            
    }
    
    
    /**
     * @param nameOfId
     * @return an error indicating that some id must be a valid
     * Java identifier
     */
    public static IMessage create_MUST_BE_A_VALID_JAVA_IDENT(final String nameOfId)
    {
        return new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
            MessageFormat.format(Messages.MUST_BE_A_VALID_JAVA_IDENT_ID
                ,new Object[]{nameOfId})
                ,null, MUST_BE_A_VALID_JAVA_IDENT_ID);    
    }
    
    /**
     * @return an error indicating an invalid bean scope enum value
     */
    public static IMessage create_BEAN_SCOPE_NOT_VALID()
    {
        return new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
            Messages.BEAN_SCOPE_NOT_VALID_ID
            , null, BEAN_SCOPE_NOT_VALID_ID);    
    }
    
    /**
     * @param targetName 
     * @return an error indicating that a map entry is being set on a target
     * object that is not a java.util.Map
     */
    public static IMessage create_MAP_ENTRIES_CAN_ONLY_BE_SET_ON_MAP_TYPE(String targetName)
    {
        return new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
            MessageFormat.format(Messages.MAP_ENTRIES_CAN_ONLY_BE_SET_ON_MAP_TYPE_ID,
                                 new Object[]{targetName}),
            null, MAP_ENTRIES_CAN_ONLY_BE_SET_ON_MAP_TYPE_ID);
    }

    /**
     * @param targetName 
     * @return an error indicating that a list entry is being set on a target
     * object that is not a java.util.List
     */
    public static IMessage create_LIST_ENTRIES_CAN_ONLY_BE_SET_ON_LIST_TYPE(String targetName)
    {
        return new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
            MessageFormat.format(Messages.LIST_ENTRIES_CAN_ONLY_BE_SET_ON_LIST_TYPE_ID,
                                 new Object[]{targetName}),
            null, LIST_ENTRIES_CAN_ONLY_BE_SET_ON_LIST_TYPE_ID);
    }
    
    /**
     * @param apiName
     * @param beforeVersion
     * @param useInstead
     * @return a diagnostic indicating that an API is being used that is not yet
     * available in the current JSF version.
     */
    public static IMessage create_API_NOT_AVAILABLE_BEFORE_VERSION(final String apiName, final String beforeVersion, final String useInstead)
    {
        return new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
            MessageFormat.format(Messages.API_NOT_AVAILABLE_BEFORE_VERSION_ID
                ,new Object[]{apiName, beforeVersion, useInstead})
                ,null, API_NOT_AVAILABLE_BEFORE_VERSION_ID);
    }
    
    /**
     * @param file
     * @return a diagnostic indicating that the app config model in use is too
     * new for the selected JSF runtime version.
     */
    public static IMessage create_APP_CONFIG_IS_NEWER_THAN_JSF_VERSION(IFile file)
    {
        final IMessage message = new MyLocalizedMessage(IMessage.HIGH_SEVERITY,
            Messages.APP_CONFIG_IS_NEWER_THAN_JSF_VERSION_ID
                ,null, APP_CONFIG_IS_NEWER_THAN_JSF_VERSION_ID);
        message.setTargetObject(file);
        return message;
    }
    
    /**
     * @param file
     * @param appConfigVersion 
     * @param projectVersion 
     * @return a diagnostic indicating that the app config model in use is older
     * than the selected JSF runtime version.
     */
    public static IMessage create_APP_CONFIG_IS_OLDER_THAN_JSF_VERSION(IFile file, String appConfigVersion, String projectVersion)
    {
        final IMessage message = new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
            MessageFormat.format(
                Messages.APP_CONFIG_IS_OLDER_THAN_JSF_VERSION_ID,
                    new Object[] {appConfigVersion, projectVersion})
            ,null, APP_CONFIG_IS_OLDER_THAN_JSF_VERSION_ID);
        message.setTargetObject(file);
        return message;
    }
    
    /**
     * @return a diagnostic indicating that the locale format does
     * not match what is expected
     */
    public static IMessage create_LOCALE_FORMAT_NOT_VALID()
    {
        IMessage message = new MyLocalizedMessage(IMessage.NORMAL_SEVERITY,
                    Messages.LOCALE_FORMAT_NOT_VALID_ID
                ,null, LOCALE_FORMAT_NOT_VALID_ID);
        return message;
    }
    
    /**
     * Customized localizable message for app config validation
     * @author cbateman
     *
     */
    static class MyLocalizedMessage extends Message implements ILocalizedMessage
    {
        private final String _message;
        private final int    _errorCode;

        /**
         * @param severity
         * @param messageText
         * @param targetObject
         * @param errorCode 
         */
        public MyLocalizedMessage(int severity, String messageText, IResource targetObject, int errorCode) {
            this(severity, messageText, (Object) targetObject, errorCode);
        }

        /**
         * @param severity
         * @param messageText
         * @param targetObject
         * @param errorCode 
         */
        private MyLocalizedMessage(int severity, String messageText, Object targetObject, int errorCode) {
            super(JSFCorePlugin.getDefault().getBundle().getSymbolicName(), severity, 
                    messageText);
            _message = messageText;
            setTargetObject(targetObject);
            _errorCode = errorCode;
        }

        /**
         * @return the localized message
         */
        public String getLocalizedMessage() {
            return _message;
        }

        /**
         * @see org.eclipse.wst.validation.internal.core.Message#getText()
         */
        public String getText() {
            return getLocalizedMessage();
        }

        /**
         * @see org.eclipse.wst.validation.internal.core.Message#getText(java.lang.ClassLoader)
         */
        public String getText(ClassLoader cl) {
            return getLocalizedMessage();
        }

        /**
         * @see org.eclipse.wst.validation.internal.core.Message#getText(java.util.Locale)
         */
        public String getText(Locale l) {
            return getLocalizedMessage();
        }

        public String getText(Locale l, ClassLoader cl) {
            return getLocalizedMessage();
        }

        /**
         * @return the error code related to this message
         */
        public int getErrorCode() {
            return _errorCode;
        }


        /**
         * @param offset
         * @return true if this message applies to document offset
         */
        public boolean appliesTo(int offset)
        {
            return (offset >= getOffset() && offset < getOffset()+getLength());
        }
    }
}

Back to the top