Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libTools / src / org / gvsig / tools / dynobject / impl / DefaultDynField.java @ 25791

History | View | Annotate | Download (3.11 KB)

1
package org.gvsig.tools.dynobject.impl;
2

    
3
import org.gvsig.tools.dynobject.DynField;
4
import org.gvsig.tools.dynobject.DynObjectValueItem;
5

    
6
public class DefaultDynField implements DynField {
7
        private String name;
8
        private String description;
9

    
10
        private int dataType;
11

    
12
        private Object defaultValue;
13

    
14
        private int typeOfAvailableValues;
15
        private DynObjectValueItem[] availableValues;
16
        private Object minValue;
17
        private Object maxValue;
18
        private boolean mandatory;
19
        private boolean persistent;
20

    
21
        public DefaultDynField(String name) {
22
                this.name = name;
23
                this.dataType = 0;
24
                this.defaultValue = null;
25
                this.persistent = false;
26
                this.mandatory = false;
27
                this.typeOfAvailableValues = DynField.SINGLE;
28
        }
29

    
30
        public String getName() {
31
                return name;
32
        }
33

    
34
        public DynField setDescription(String description) {
35
                this.description = description;
36
                return this;
37
        }
38

    
39
        public String getDescription() {
40
                return description;
41
        }
42

    
43
        public DynField setType(int dataType) {
44
                this.dataType = dataType;
45
                return this;
46
        }
47

    
48
        public int getType() {
49
                return dataType;
50
        }
51

    
52
        public DynField setDefaultValue(Object defaultValue) {
53
                this.defaultValue = defaultValue;
54
                return this;
55
        }
56

    
57
        public Object getDefaultValue() {
58
                return defaultValue;
59
        }
60

    
61
        public int getTheTypeOfAvailableValues() {
62
                return typeOfAvailableValues;
63
        }
64

    
65
        public DynField setAvailableValues(DynObjectValueItem[] availableValues) {
66
                this.availableValues = availableValues;
67
                return this;
68
        }
69

    
70
        public DynObjectValueItem[] getAvailableValues() {
71
                return availableValues;
72
        }
73

    
74
        public DynField setMinValue(Object minValue) {
75
                this.minValue = minValue;
76
                return this;
77
        }
78

    
79
        public Object getMinValue() {
80
                return minValue;
81
        }
82

    
83
        public DynField setMaxValue(Object maxValue) {
84
                this.maxValue = maxValue;
85
                return this;
86
        }
87

    
88
        public Object getMaxValue() {
89
                return maxValue;
90
        }
91

    
92
        public Object coerce(Object value) {
93
                return value; // FIXME: Falta por comprobar los tipos
94
        }
95

    
96
        public boolean isMandatory() {
97
                return this.mandatory;
98
        }
99

    
100
        public boolean isPersistent() {
101
                return this.persistent;
102
        }
103

    
104
        public DynField setMandatory(boolean mandatory) {
105
                this.mandatory = mandatory;
106
                return this;
107
        }
108

    
109
        public DynField setPersistent(boolean persistent) {
110
                this.persistent = persistent;
111
                return this;
112
        }
113

    
114
        public DynField setTheTypeOfAvailableValues(int type) {
115
                if (type == DynField.SINGLE || type == DynField.RANGE
116
                                || type == DynField.CHOICE) {
117
                this.typeOfAvailableValues = type;
118
                } else {
119
                        // FIXME
120
                        throw new IllegalArgumentException();
121
                }
122
                return this;
123
        }
124

    
125

    
126
    public boolean equals(Object obj) {
127
        if (this == obj) {
128
            return true;
129
        }
130
        if (obj instanceof DynField) {
131
            return name.equals(((DynField) obj).getName());
132
        }
133
        return false;
134
    }
135

    
136
    public String toString() {
137
        return "name: ".concat(getName()) + ", description: "
138
                + getDescription() + ", type: " + Integer.toString(getType())
139
                + ", minValue: " + getMinValue() + ", maxValue: "
140
                + getMaxValue() + ", mandatory?:" + isMandatory()
141
                + ", persistent?: " + isPersistent() + ", default value: "
142
                + getDefaultValue();
143
    }
144
}