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 @ 2349

History | View | Annotate | Download (2.81 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
    public static void dispose(Object obj) {
53
        if (obj instanceof Disposable) {
54
            ((Disposable)obj).dispose();
55
        }
56
    }
57

    
58
    /**
59
     * @param disposable
60
     */
61
    public static void disposeQuietly(Disposable disposable) {
62
        if (disposable != null) {
63
            try {
64
                disposable.dispose();
65
            } catch (Throwable th) {
66
                logger.warn("Can't dispose", th);
67
            }
68
        }
69
    }
70

    
71
    public static void disposeQuietly(Object obj) {
72
        if (obj instanceof Disposable) {
73
            try {
74
                ((Disposable)obj).dispose();
75
            } catch (Throwable th) {
76
                logger.warn("Can't dispose", th);
77
            }
78
        }
79
    }
80

    
81
    /**
82
     * @param disposable
83
     */
84
    public static void bind(Disposable disposable) {
85
        DisposableManager manager = ToolsLocator.getDisposableManager();
86
        if (manager == null) {
87
            logger.warn("Can't retrieve the disposable manager,");
88
            return;
89
        }
90
        manager.bind(disposable);
91
    }
92

    
93
    /**
94
     * @param disposable
95
     * @return
96
     */
97
    public static boolean release(Disposable disposable) {
98
        return ToolsLocator.getDisposableManager().release(disposable);
99
    }
100

    
101
}