public class PreferencesManager { /** Logger for this class. */ private final static ILogger s_log = LoggerController.createLogger(PreferencesManager.class); /** Name of preferences file. */ private static final String USER_PREFS_FILE_NAME = "prefs.xml"; /** Folder to store user settings in. */ private static File _userSettingsFolder; private static MSSQLPreferenceBean _prefs = null; private static IPlugin plugin = null; public static void initialize(IPlugin thePlugin) throws PluginException { plugin = thePlugin; // Folder to store user settings. try { _userSettingsFolder = plugin.getPluginUserSettingsFolder(); } catch (IOException ex) { throw new PluginException(ex); } loadPrefs(); } public static MSSQLPreferenceBean getPreferences() { return _prefs; } public static void unload() { savePrefs(); } /** * Save preferences to disk. */ public static void savePrefs() { try { XMLBeanWriter wtr = new XMLBeanWriter(_prefs); wtr.save(new File(_userSettingsFolder, USER_PREFS_FILE_NAME)); } catch (Exception ex) { s_log.error("Error occured writing to preferences file: " + USER_PREFS_FILE_NAME, ex); } } /** * Load from preferences file. */ private static void loadPrefs() { try { XMLBeanReader doc = new XMLBeanReader(); File prefFile = PreferenceUtil.getPreferenceFileToReadFrom(plugin); doc.load(prefFile, MSSQLPreferenceBean.class.getClassLoader()); Iterator<?> it = doc.iterator(); if (it.hasNext()) { _prefs = (MSSQLPreferenceBean)it.next(); } } catch (FileNotFoundException ignore) { s_log.info(USER_PREFS_FILE_NAME + " not found - will be created"); } catch (Exception ex) { s_log.error("Error occured reading from preferences file: " + USER_PREFS_FILE_NAME, ex); } if (_prefs == null) { _prefs = new MSSQLPreferenceBean(); } _prefs.setClientName(Version.getApplicationName() + "/" + plugin.getDescriptiveName()); _prefs.setClientVersion(Version.getShortVersion() + "/" + plugin.getVersion())
public class SQLScriptPreferencesManager { /** Logger for this class. */ private final static ILogger s_log = LoggerController.createLogger(SQLScriptPreferencesManager.class); /** Name of preferences file. */ private static final String USER_PREFS_FILE_NAME = "prefs.xml"; /** Folder to store user settings in. */ private static File _userSettingsFolder; private static SQLScriptPreferenceBean _prefs = null; private static IPlugin plugin = null; public static void initialize(IPlugin thePlugin) throws PluginException { plugin = thePlugin; // Folder to store user settings. try { _userSettingsFolder = plugin.getPluginUserSettingsFolder(); } catch (IOException ex) { throw new PluginException(ex); } loadPrefs(); } public static SQLScriptPreferenceBean getPreferences() { return _prefs; } public static void unload() { savePrefs(); } /** * Save preferences to disk. */ public static void savePrefs() { try { XMLBeanWriter wtr = new XMLBeanWriter(_prefs); wtr.save(new File(_userSettingsFolder, USER_PREFS_FILE_NAME)); } catch (Exception ex) { s_log.error("Error occured writing to preferences file: " + USER_PREFS_FILE_NAME, ex); } } /** * Load from preferences file. */ private static void loadPrefs() { try { XMLBeanReader doc = new XMLBeanReader(); File prefFile = PreferenceUtil.getPreferenceFileToReadFrom(plugin); doc.load(prefFile, SQLScriptPreferenceBean.class.getClassLoader()); Iterator<?> it = doc.iterator(); if (it.hasNext()) { _prefs = (SQLScriptPreferenceBean)it.next(); } } catch (FileNotFoundException ignore) { s_log.info(USER_PREFS_FILE_NAME + " not found - will be created"); } catch (Exception ex) { s_log.error("Error occured reading from preferences file: " + USER_PREFS_FILE_NAME, ex); } if (_prefs == null) { _prefs = new SQLScriptPreferenceBean(); } _prefs.setClientName(Version.getApplicationName() + "/" + plugin.getDescriptiveName()); _prefs.setClientVersion(Version.getShortVersion() + "/" + plugin.getVersion())
Clone fragments detected by clone detection tool
File path: /sql12/plugins/mssql/src/net/sourceforge/squirrel_sql/plugins/mssql/prefs/PreferencesManager.java File path: /sql12/plugins/sqlscript/src/net/sourceforge/squirrel_sql/plugins/sqlscript/prefs/SQLScriptPreferencesManager.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class PreferencesManager {
1
public class SQLScriptPreferencesManager {
2
    /** Logger for this class. */
2
    /** Logger for this class. */
3
    private final static ILogger s_log = 
3
    private final static ILogger s_log = 
4
        LoggerController.createLogger(PreferencesManager.class);
4
        LoggerController.createLogger(SQLScriptPreferencesManager.class);
5
    
5
    
6
    /** Name of preferences file. */
6
    /** Name of preferences file. */
7
    private static final String USER_PREFS_FILE_NAME = "prefs.xml";    
7
    private static final String USER_PREFS_FILE_NAME = "prefs.xml";    
8
    
8
    
9
    /** Folder to store user settings in. */
9
    /** Folder to store user settings in. */
10
    private static File _userSettingsFolder;
10
    private static File _userSettingsFolder;
11
    
11
    
12
    private static MSSQLPreferenceBean _prefs = null;
12
    private static SQLScriptPreferenceBean _prefs = null;
13
    
13
    
14
    private static IPlugin plugin = null;
14
    private static IPlugin plugin = null;
15
    
15
    
16
    public static void initialize(IPlugin thePlugin) throws PluginException {
16
    public static void initialize(IPlugin thePlugin) throws PluginException {
17
        plugin = thePlugin;
17
        plugin = thePlugin;
18
        
18
        
19
        // Folder to store user settings.
19
        // Folder to store user settings.
20
        try {
20
        try {
21
            _userSettingsFolder = plugin.getPluginUserSettingsFolder();
21
            _userSettingsFolder = plugin.getPluginUserSettingsFolder();
22
        } catch (IOException ex) {
22
        } catch (IOException ex) {
23
            throw new PluginException(ex);
23
            throw new PluginException(ex);
24
        }        
24
        }        
25
        
25
        
26
        loadPrefs();
26
        loadPrefs();
27
    }
27
    }
28
    
28
    
29
    public static MSSQLPreferenceBean getPreferences() {
29
    public static SQLScriptPreferenceBean getPreferences() {
30
        return _prefs;
30
        return _prefs;
31
    }
31
    }
32
    
32
    
33
    public static void unload() {
33
    public static void unload() {
34
        savePrefs();
34
        savePrefs();
35
    }
35
    }
36
    
36
    
37
    /**
37
    /**
38
     * Save preferences to disk.
38
     * Save preferences to disk.
39
     */
39
     */
40
    public static void savePrefs() {
40
    public static void savePrefs() {
41
        try {
41
        try {
42
            XMLBeanWriter wtr = new XMLBeanWriter(_prefs);
42
            XMLBeanWriter wtr = new XMLBeanWriter(_prefs);
43
            wtr.save(new File(_userSettingsFolder, USER_PREFS_FILE_NAME));
43
            wtr.save(new File(_userSettingsFolder, USER_PREFS_FILE_NAME));
44
        } catch (Exception ex) {
44
        } catch (Exception ex) {
45
            s_log.error("Error occured writing to preferences file: "
45
            s_log.error("Error occured writing to preferences file: "
46
                    + USER_PREFS_FILE_NAME, ex);
46
                    + USER_PREFS_FILE_NAME, ex);
47
        }
47
        }
48
    }
48
    }
49
    /**
49
    /**
50
     * Load from preferences file.
50
     * Load from preferences file.
51
     */
51
     */
52
    private static void loadPrefs() {
52
    private static void loadPrefs() {
53
        try {
53
        try {
54
            XMLBeanReader doc = new XMLBeanReader();
54
            XMLBeanReader doc = new XMLBeanReader();
55
            
55
            
56
            File prefFile = PreferenceUtil.getPreferenceFileToReadFrom(plugin);
56
            File prefFile = PreferenceUtil.getPreferenceFileToReadFrom(plugin);
57
            
57
            
58
            doc.load(prefFile, MSSQLPreferenceBean.class.getClassLoader());
58
            doc.load(prefFile, SQLScriptPreferenceBean.class.getClassLoader());
59
                        
59
            
60
            Iterator<?> it = doc.iterator();
60
            Iterator<?> it = doc.iterator();
61
            if (it.hasNext()) {
61
            if (it.hasNext()) {
62
                _prefs = (MSSQLPreferenceBean)it.next();
62
                _prefs = (SQLScriptPreferenceBean)it.next();
63
            }
63
            }
64
        } catch (FileNotFoundException ignore) {
64
        } catch (FileNotFoundException ignore) {
65
            s_log.info(USER_PREFS_FILE_NAME + " not found - will be created");
65
            s_log.info(USER_PREFS_FILE_NAME + " not found - will be created");
66
        } catch (Exception ex) {
66
        } catch (Exception ex) {
67
            s_log.error("Error occured reading from preferences file: "
67
            s_log.error("Error occured reading from preferences file: "
68
                    + USER_PREFS_FILE_NAME, ex);
68
                    + USER_PREFS_FILE_NAME, ex);
69
        }
69
        }
70
        if (_prefs == null) {
70
        if (_prefs == null) {
71
            _prefs = new MSSQLPreferenceBean();
71
            _prefs = new SQLScriptPreferenceBean();
72
        }
72
        }
73
        _prefs.setClientName(Version.getApplicationName() + "/" + plugin.getDescriptiveName());
73
        _prefs.setClientName(Version.getApplicationName() + "/" + plugin.getDescriptiveName());
74
        _prefs.setClientVersion(Version.getShortVersion() + "/" + plugin.getVersion())
74
        _prefs.setClientVersion(Version.getShortVersion() + "/" + plugin.getVersion())
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0