public class RefactoringPreferencesManager { /** Logger for this class. */ private final static ILogger s_log = LoggerController.createLogger(RefactoringPreferencesManager.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 RefactoringPreferenceBean _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 RefactoringPreferenceBean 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, RefactoringPreferenceBean.class.getClassLoader()); Iterator<?> it = doc.iterator(); if (it.hasNext()) { _prefs = (RefactoringPreferenceBean)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 RefactoringPreferenceBean(); } _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/refactoring/src/net/sourceforge/squirrel_sql/plugins/refactoring/prefs/RefactoringPreferencesManager.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 RefactoringPreferencesManager {
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(RefactoringPreferencesManager.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 RefactoringPreferenceBean _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 RefactoringPreferenceBean 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, RefactoringPreferenceBean.class.getClassLoader());            
58
            doc.load(prefFile, SQLScriptPreferenceBean.class.getClassLoader());            
59
            Iterator<?> it = doc.iterator();
59
            Iterator<?> it = doc.iterator();
60
            if (it.hasNext()) {
60
            if (it.hasNext()) {
61
                _prefs = (RefactoringPreferenceBean)it.next();
61
                _prefs = (SQLScriptPreferenceBean)it.next();
62
            }
62
            }
63
        } catch (FileNotFoundException ignore) {
63
        } catch (FileNotFoundException ignore) {
64
            s_log.info(USER_PREFS_FILE_NAME + " not found - will be created");
64
            s_log.info(USER_PREFS_FILE_NAME + " not found - will be created");
65
        } catch (Exception ex) {
65
        } catch (Exception ex) {
66
            s_log.error("Error occured reading from preferences file: "
66
            s_log.error("Error occured reading from preferences file: "
67
                    + USER_PREFS_FILE_NAME, ex);
67
                    + USER_PREFS_FILE_NAME, ex);
68
        }
68
        }
69
        if (_prefs == null) {
69
        if (_prefs == null) {
70
            _prefs = new RefactoringPreferenceBean();
70
            _prefs = new SQLScriptPreferenceBean();
71
        }
71
        }
72
        _prefs.setClientName(Version.getApplicationName() + "/" + plugin.getDescriptiveName());
72
        _prefs.setClientName(Version.getApplicationName() + "/" + plugin.getDescriptiveName());
73
        _prefs.setClientVersion(Version.getShortVersion() + "/" + plugin.getVersion())
73
        _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