gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / dynobject / exception / DynFieldRequiredValueException.java @ 1860
History | View | Annotate | Download (2.7 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.dynobject.exception; |
25 |
|
26 |
import org.gvsig.tools.ToolsLocator; |
27 |
import org.gvsig.tools.dynobject.DynClass; |
28 |
import org.gvsig.tools.dynobject.DynField; |
29 |
import org.gvsig.tools.dynobject.DynObject; |
30 |
import org.gvsig.tools.dynobject.DynStruct; |
31 |
|
32 |
public class DynFieldRequiredValueException extends DynFieldValidateException { |
33 |
|
34 |
/**
|
35 |
*
|
36 |
*/
|
37 |
private static final long serialVersionUID = -7813629748228774775L; |
38 |
private final static String MESSAGE_FORMAT = |
39 |
"Field '%(fieldText)': Value required.";
|
40 |
private final static String MESSAGE_KEY = |
41 |
"_Field_XfieldTextX_Value_required";
|
42 |
|
43 |
public DynFieldRequiredValueException(DynField field, Object value) { |
44 |
super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
|
45 |
|
46 |
setValue("field", field.getName());
|
47 |
setValue("fieldText", translate(field.getName()));
|
48 |
setValue(value); |
49 |
} |
50 |
|
51 |
private String translate(String name) { |
52 |
return ToolsLocator.getI18nManager().getTranslation(name);
|
53 |
} |
54 |
|
55 |
private void setValue(Object value) { |
56 |
try {
|
57 |
if (value instanceof DynObject) { |
58 |
setValue("value", ((DynObject) value).getDynClass().getName());
|
59 |
return;
|
60 |
} else if (value instanceof DynClass) { |
61 |
setValue("value", ((DynClass) value).getName());
|
62 |
return;
|
63 |
} else if (value instanceof DynStruct) { |
64 |
setValue("value", ((DynStruct) value).getName());
|
65 |
return;
|
66 |
} |
67 |
if (value == null) { |
68 |
setValue("value", "null"); |
69 |
} else {
|
70 |
setValue("value", value.toString());
|
71 |
} |
72 |
} catch (Exception e) { |
73 |
setValue("value", "(unknow)"); |
74 |
} |
75 |
} |
76 |
|
77 |
public DynField getDynField() {
|
78 |
return (DynField) this.values().get("field"); |
79 |
} |
80 |
|
81 |
public String getDynFieldName() { |
82 |
return this.getDynField().getName(); |
83 |
} |
84 |
|
85 |
public Object getValueOfException() { |
86 |
return this.values().get("value"); |
87 |
} |
88 |
|
89 |
} |