Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / dispose / DisposeUtils.java @ 1684

History | View | Annotate | Download (2.4 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA 02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.dispose;
25

    
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28

    
29
import org.gvsig.tools.ToolsLocator;
30

    
31
/**
32
 * Dispose related utilities.
33
 *
34
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
35
 */
36
public class DisposeUtils {
37

    
38
    private static final Logger logger = LoggerFactory.getLogger(DisposeUtils.class);
39

    
40
    /**
41
     * Disposes a {@link Disposable} object, checking if it is null.
42
     *
43
     * @param disposable
44
     *            to dispose
45
     */
46
    public static void dispose(Disposable disposable) {
47
        if (disposable != null) {
48
            disposable.dispose();
49
        }
50
    }
51

    
52
    /**
53
     * @param disposable
54
     */
55
    public static void disposeQuietly(Disposable disposable) {
56
        if (disposable != null) {
57
            try {
58
                disposable.dispose();
59
            } catch (Throwable th) {
60
                logger.warn("Can't dispose", th);
61
            }
62
        }
63
    }
64

    
65
    /**
66
     * @param disposable
67
     */
68
    public static void bind(Disposable disposable) {
69
        DisposableManager manager = ToolsLocator.getDisposableManager();
70
        if (manager == null) {
71
            logger.warn("Can't retrieve the disposable manager,");
72
            return;
73
        }
74
        manager.bind(disposable);
75
    }
76

    
77
    /**
78
     * @param disposable
79
     * @return
80
     */
81
    public static boolean release(Disposable disposable) {
82
        return ToolsLocator.getDisposableManager().release(disposable);
83
    }
84

    
85
}