OSDN Git Service

4d8536913e648c0526d037317776556f3e3a9448
[mikumikustudio/MikuMikuStudio.git] / src / com / jmex / xml / types / SchemaString.java
1 /**
2  * SchemaString.java
3  *
4  * This file was generated by XMLSpy 2007sp2 Enterprise Edition.
5  *
6  * YOU SHOULD NOT MODIFY THIS FILE, BECAUSE IT WILL BE
7  * OVERWRITTEN WHEN YOU RE-RUN CODE GENERATION.
8  *
9  * Refer to the XMLSpy Documentation for further details.
10  * http://www.altova.com/xmlspy
11  */
12
13
14 package com.jmex.xml.types;
15
16 import java.math.BigDecimal;
17 import java.math.BigInteger;
18
19 public class SchemaString implements SchemaTypeNumber, SchemaTypeCalendar {
20   protected String value;
21   protected boolean isempty;
22   protected boolean isnull;
23
24   // construction
25   public SchemaString() {
26     setEmpty();
27   }
28
29   public SchemaString(SchemaString newvalue) {
30     value = newvalue.value;
31     isempty = newvalue.isempty;
32     isnull = newvalue.isnull;
33   }
34
35   public SchemaString(String newvalue) {
36     setValue( newvalue );
37   }
38
39   public SchemaString(SchemaType newvalue) {
40     assign( newvalue );
41   }
42
43   public SchemaString(SchemaTypeNumber newvalue) {
44     assign( (SchemaType)newvalue );
45   }
46
47   public SchemaString(SchemaTypeCalendar newvalue) {
48     assign( (SchemaType)newvalue );
49   }
50
51   // getValue, setValue
52   public String getValue() {
53     return value;
54   }
55
56   public void setValue(String newvalue) {
57     if( newvalue == null ) {
58       isempty = true;
59       isnull = true;
60       value = "";
61       return;
62     }
63     value = newvalue;
64     isempty = (value.length()==0);
65   }
66
67   public void parse(String newvalue) {
68     if( newvalue == null )
69       setNull();
70     else if( newvalue.length() == 0)
71       setEmpty();
72     else
73       setValue(newvalue);
74   }
75
76   public void assign(SchemaType newvalue) {
77     if( newvalue == null || newvalue.isNull() )
78       setNull();
79     else if( newvalue.isEmpty() )
80       setEmpty();
81     else {
82       value = newvalue.toString();
83       isempty = (value.length()==0);
84       isnull = false;
85     }
86   }
87
88   public void setNull() {
89     isnull = true;
90     isempty = true;
91     value = "";
92   }
93
94   public void setEmpty() {
95     isnull = false;
96     isempty = true;
97     value = "";
98   }
99
100   // further
101   public int hashCode() {
102     return value.hashCode();
103   }
104
105   public boolean equals(Object obj) {
106     if (! (obj instanceof SchemaString))
107       return false;
108     return value.equals( ( (SchemaString) obj).value);
109   }
110
111   public Object clone() {
112     if ( isnull ) {
113       SchemaString result = new SchemaString();
114       result.setNull();
115       return result;
116     }
117     else if ( isempty ) 
118       return new SchemaString();
119     return new SchemaString( new String( value ) );
120   }
121
122   public String toString() {
123     if( isempty || isnull )
124       return "";
125     return value;
126   }
127
128   public int length() {
129     return value.length();
130   }
131
132   public boolean booleanValue() {
133     if( value==null || value.length()==0 || value.compareToIgnoreCase("false")==0 )
134       return false;
135     if (isValueNumeric())
136       return bigDecimalValue().compareTo(BigDecimal.valueOf(0)) != 0;
137     return true;
138   }
139
140   public boolean isEmpty() {
141     return isempty;
142   }
143
144   public boolean isNull() {
145     return isnull;
146   }
147
148   public int compareTo(Object obj) {
149     return compareTo( (SchemaString) obj);
150   }
151
152   public int compareTo(SchemaString obj) {
153     return value.compareTo(obj.value);
154   }
155
156   public boolean isValueNumeric() {
157     try {
158       BigDecimal tmp = new BigDecimal(value.trim());
159     }
160     catch (NumberFormatException e) {
161       return false;
162     }
163     return true;
164   }
165
166   // ---------- interface SchemaTypeNumber ----------
167   public int numericType() {
168     return NUMERIC_VALUE_BIGDECIMAL;
169   }
170
171   public int intValue() {
172     if( isnull || isempty || value.length() == 0)
173       return 0;
174     try {
175       return Integer.parseInt(value);
176     } catch( NumberFormatException e ) {
177       throw new ValuesNotConvertableException( this, new SchemaInt( 0 ) );
178     }
179   }
180
181   public long longValue() {
182     if( isnull || isempty || value.length() == 0)
183       return 0;
184     try {
185       return Long.parseLong(value);
186     } catch( NumberFormatException e ) {
187       throw new ValuesNotConvertableException( this, new SchemaLong( 0 ) );
188     }
189   }
190
191   public BigInteger bigIntegerValue() {
192     if( isnull || isempty || value.length() == 0)
193       return new BigInteger( "0" );
194     try {
195       return new BigInteger(value.trim());
196     } catch( NumberFormatException e ) {
197       throw new ValuesNotConvertableException( this, new SchemaInteger( 0 ) );
198     }
199   }
200
201   public float floatValue() {
202     if( isnull || isempty || value.length() == 0)
203       return 0;
204     try {
205       return Float.parseFloat(value);
206     } catch( NumberFormatException e ) {
207       throw new ValuesNotConvertableException( this, new SchemaFloat( 0 ) );
208     }
209   }
210
211   public double doubleValue() {
212     if( isnull || isempty || value.length() == 0)
213       return 0.0;
214     try {
215       return Double.parseDouble(value);
216     } catch( NumberFormatException e ) {
217       throw new ValuesNotConvertableException( this, new SchemaDouble( 0 ) );
218     }
219   }
220
221   public BigDecimal bigDecimalValue() {
222     if( isnull || isempty || value.length() == 0)
223       return new BigDecimal( 0 );
224     try {
225       return new BigDecimal(value.trim());
226     } catch( NumberFormatException e ) {
227       throw new ValuesNotConvertableException( this, new SchemaDecimal( 0 ) );
228     }
229   }
230
231   // ---------- interface SchemaTypeCalendar ----------
232   public int calendarType() {
233     return CALENDAR_VALUE_UNDEFINED;
234   }
235
236   public SchemaDuration durationValue() {
237     try {
238       return new SchemaDuration(value);
239     } catch( StringParseException e ) {
240       throw new ValuesNotConvertableException( this, new SchemaDuration( "PT" ) );
241     }
242   }
243
244   public SchemaDateTime dateTimeValue() {
245     try {
246       return new SchemaDateTime(value);
247     } catch( StringParseException e ) {
248       throw new ValuesNotConvertableException( this, new SchemaDateTime( "2003-08-06T00:00:00" ) );
249     }
250   }
251
252   public SchemaDate dateValue() {
253     try {
254       return new SchemaDate(value);
255     }
256     catch (StringParseException e) {
257       throw new ValuesNotConvertableException(this, new SchemaDate("2003-08-06"));
258     }
259   }
260
261   public SchemaTime timeValue() {
262     try {
263       return new SchemaTime(value);
264     }
265     catch (StringParseException e) {
266       throw new ValuesNotConvertableException(this, new SchemaTime("00:00:00"));
267     }
268   }
269
270 }