gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / dispose / DisposeUtils.java @ 2501
History | View | Annotate | Download (3.19 KB)
1 | 802 | cordinyana | /**
|
---|---|---|---|
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 | 1191 | jjdelcerro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 802 | cordinyana | * 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 | 1191 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 802 | cordinyana | *
|
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 | 18 | cordinyana | package org.gvsig.tools.dispose; |
25 | |||
26 | 1191 | jjdelcerro | import org.slf4j.Logger; |
27 | import org.slf4j.LoggerFactory; |
||
28 | |||
29 | 1684 | fdiaz | import org.gvsig.tools.ToolsLocator; |
30 | |||
31 | 18 | cordinyana | /**
|
32 | * Dispose related utilities.
|
||
33 | 1191 | jjdelcerro | *
|
34 | 18 | cordinyana | * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
35 | */
|
||
36 | public class DisposeUtils { |
||
37 | |||
38 | 1191 | jjdelcerro | 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 | 1684 | fdiaz | * to dispose
|
45 | 1191 | jjdelcerro | */
|
46 | public static void dispose(Disposable disposable) { |
||
47 | 1684 | fdiaz | if (disposable != null) { |
48 | 1191 | jjdelcerro | disposable.dispose(); |
49 | } |
||
50 | } |
||
51 | |||
52 | 2349 | jjdelcerro | public static void dispose(Object obj) { |
53 | if (obj instanceof Disposable) { |
||
54 | ((Disposable)obj).dispose(); |
||
55 | } |
||
56 | } |
||
57 | |||
58 | 1684 | fdiaz | /**
|
59 | * @param disposable
|
||
60 | */
|
||
61 | 1191 | jjdelcerro | public static void disposeQuietly(Disposable disposable) { |
62 | 1684 | fdiaz | if (disposable != null) { |
63 | 1191 | jjdelcerro | try {
|
64 | disposable.dispose(); |
||
65 | } catch (Throwable th) { |
||
66 | logger.warn("Can't dispose", th);
|
||
67 | } |
||
68 | } |
||
69 | } |
||
70 | 1684 | fdiaz | |
71 | 2349 | jjdelcerro | 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 | 1684 | fdiaz | /**
|
82 | * @param disposable
|
||
83 | */
|
||
84 | 1448 | jjdelcerro | public static void bind(Disposable disposable) { |
85 | DisposableManager manager = ToolsLocator.getDisposableManager(); |
||
86 | 1684 | fdiaz | if (manager == null) { |
87 | logger.warn("Can't retrieve the disposable manager,");
|
||
88 | return;
|
||
89 | 1448 | jjdelcerro | } |
90 | manager.bind(disposable); |
||
91 | } |
||
92 | 1684 | fdiaz | |
93 | /**
|
||
94 | 2501 | fdiaz | * @param obj
|
95 | */
|
||
96 | public static void bind(Object obj) { |
||
97 | if(obj instanceof Disposable){ |
||
98 | DisposableManager manager = ToolsLocator.getDisposableManager(); |
||
99 | if (manager == null) { |
||
100 | logger.warn("Can't retrieve the disposable manager,");
|
||
101 | return;
|
||
102 | } |
||
103 | manager.bind((Disposable) obj); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | /**
|
||
108 | 1684 | fdiaz | * @param disposable
|
109 | * @return
|
||
110 | */
|
||
111 | public static boolean release(Disposable disposable) { |
||
112 | return ToolsLocator.getDisposableManager().release(disposable);
|
||
113 | } |
||
114 | |||
115 | 18 | cordinyana | } |