gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / observer / BaseNotification.java @ 3086
History | View | Annotate | Download (1.85 KB)
1 | 1108 | jjdelcerro | package org.gvsig.tools.observer; |
---|---|---|---|
2 | |||
3 | 3086 | jjdelcerro | import org.apache.commons.lang3.builder.ToStringBuilder; |
4 | |||
5 | 1108 | jjdelcerro | public class BaseNotification implements Notification { |
6 | |||
7 | private final String type; |
||
8 | protected Object[] values; |
||
9 | protected boolean canceled = false; |
||
10 | 3010 | jjdelcerro | private boolean aborted; |
11 | 1108 | jjdelcerro | |
12 | public BaseNotification(String type, int values) { |
||
13 | this.type = type;
|
||
14 | this.values = new Object[values]; |
||
15 | } |
||
16 | |||
17 | public BaseNotification(String type, Object[] values) { |
||
18 | this.type = type;
|
||
19 | this.values = values;
|
||
20 | } |
||
21 | |||
22 | 2530 | jjdelcerro | @Override
|
23 | 1108 | jjdelcerro | public String getType() { |
24 | return this.type; |
||
25 | } |
||
26 | |||
27 | 2530 | jjdelcerro | @Override
|
28 | 1155 | jjdelcerro | public boolean isOfType(String type) { |
29 | return type.equalsIgnoreCase(this.type); |
||
30 | } |
||
31 | |||
32 | 2530 | jjdelcerro | @Override
|
33 | 1108 | jjdelcerro | public Object getValue() { |
34 | 2530 | jjdelcerro | if( this.values==null ) { |
35 | return null; |
||
36 | } |
||
37 | 1108 | jjdelcerro | return this.values[0]; |
38 | } |
||
39 | |||
40 | 2530 | jjdelcerro | @Override
|
41 | 1108 | jjdelcerro | public Object getValue(int n) { |
42 | 2530 | jjdelcerro | if( this.values==null ) { |
43 | return null; |
||
44 | } |
||
45 | 1108 | jjdelcerro | return this.values[n]; |
46 | } |
||
47 | |||
48 | 2530 | jjdelcerro | @Override
|
49 | 1108 | jjdelcerro | public void setValue(Object value) { |
50 | this.values[0] = value; |
||
51 | } |
||
52 | |||
53 | 2530 | jjdelcerro | @Override
|
54 | 1108 | jjdelcerro | public void setValue(int n, Object value) { |
55 | this.values[n] = value;
|
||
56 | } |
||
57 | |||
58 | 2530 | jjdelcerro | @Override
|
59 | 1108 | jjdelcerro | public boolean isCanceled() { |
60 | return this.canceled; |
||
61 | } |
||
62 | |||
63 | 2530 | jjdelcerro | @Override
|
64 | 1108 | jjdelcerro | public void cancel() { |
65 | this.canceled = true; |
||
66 | } |
||
67 | 3010 | jjdelcerro | |
68 | @Override
|
||
69 | public boolean isAborted() { |
||
70 | return this.aborted; |
||
71 | } |
||
72 | |||
73 | @Override
|
||
74 | public void abort() { |
||
75 | this.aborted = true; |
||
76 | } |
||
77 | 3086 | jjdelcerro | |
78 | @Override
|
||
79 | public String toString() { |
||
80 | try {
|
||
81 | ToStringBuilder builder = new ToStringBuilder(this); |
||
82 | builder.append("type", type);
|
||
83 | builder.append("values", values);
|
||
84 | return builder.build();
|
||
85 | } catch(Throwable th) { |
||
86 | return super.toString(); |
||
87 | } |
||
88 | } |
||
89 | |||
90 | 1108 | jjdelcerro | } |