wangting
2024-09-27 a3e87f78ee262ca9bb7d9b0c997639d5f3295890
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
package com.vci.client.ui.exception;
 
import java.util.Locale;
 
import com.vci.common.exception.LocaleCommonDisplay;
import com.vci.common.exception.VciException;
import com.vci.corba.common.VCIError;
import com.vci.mw.InvocationUtility;
 
public class ClientExceptionHandler {
 
    private static ClientExceptionHandler instance = null;
    
    private ClientExceptionHandler() {
        
    }
    
    public static synchronized ClientExceptionHandler getInstance() {
        if (instance == null) {
            instance = new ClientExceptionHandler();
        }
        
        return instance;
    }
 
    public VCIError getClientString(VCIError vciError, String fileName) {
        VciException exp = new VciException(vciError.code,
                vciError.messages);
        String str = LocaleCommonDisplay.getI18nString(exp, fileName,
                getClientLocale());
        vciError.code = str;
        return vciError;
    }
      
    /**
     * 获取国际化的错误提示信息,将其设置到PLMError的key中
     * @param plmError
     * @return
     */
    public VCIError getLocalString(VCIError vciError, String fileName) {
        VciException exp = new VciException(vciError.code, vciError.messages);
        String str = LocaleCommonDisplay.getI18nString(exp, fileName, getClientLocale());
        vciError.code = str;
        return vciError;
    }
    
    private Locale getClientLocale() {
        Locale locale = null; 
        try {
            if (InvocationUtility.getInvocation() == null) {
                return Locale.getDefault();
            }
            String language = InvocationUtility.getInvocation().language;
            if (language == null || language.trim().equals("")) {
                language = Locale.getDefault().getLanguage();
            }
            
            String country = InvocationUtility.getInvocation().country;
            if (country == null || country.trim().equals("")) {
                country = Locale.getDefault().getCountry();
            }
            locale = new Locale(language, country);
        } catch (Exception e) {
            e.printStackTrace();
            locale = Locale.getDefault();
        }
        
        
        return locale;
    }
}