4 * This file was generated by XMLSpy 2007sp2 Enterprise Edition.
6 * YOU SHOULD NOT MODIFY THIS FILE, BECAUSE IT WILL BE
7 * OVERWRITTEN WHEN YOU RE-RUN CODE GENERATION.
9 * Refer to the XMLSpy Documentation for further details.
10 * http://www.altova.com/xmlspy
14 package com.jmex.xml.types;
16 import java.math.BigDecimal;
17 import java.math.BigInteger;
19 public class SchemaString implements SchemaTypeNumber, SchemaTypeCalendar {
20 protected String value;
21 protected boolean isempty;
22 protected boolean isnull;
25 public SchemaString() {
29 public SchemaString(SchemaString newvalue) {
30 value = newvalue.value;
31 isempty = newvalue.isempty;
32 isnull = newvalue.isnull;
35 public SchemaString(String newvalue) {
39 public SchemaString(SchemaType newvalue) {
43 public SchemaString(SchemaTypeNumber newvalue) {
44 assign( (SchemaType)newvalue );
47 public SchemaString(SchemaTypeCalendar newvalue) {
48 assign( (SchemaType)newvalue );
52 public String getValue() {
56 public void setValue(String newvalue) {
57 if( newvalue == null ) {
64 isempty = (value.length()==0);
67 public void parse(String newvalue) {
68 if( newvalue == null )
70 else if( newvalue.length() == 0)
76 public void assign(SchemaType newvalue) {
77 if( newvalue == null || newvalue.isNull() )
79 else if( newvalue.isEmpty() )
82 value = newvalue.toString();
83 isempty = (value.length()==0);
88 public void setNull() {
94 public void setEmpty() {
101 public int hashCode() {
102 return value.hashCode();
105 public boolean equals(Object obj) {
106 if (! (obj instanceof SchemaString))
108 return value.equals( ( (SchemaString) obj).value);
111 public Object clone() {
113 SchemaString result = new SchemaString();
118 return new SchemaString();
119 return new SchemaString( new String( value ) );
122 public String toString() {
123 if( isempty || isnull )
128 public int length() {
129 return value.length();
132 public boolean booleanValue() {
133 if( value==null || value.length()==0 || value.compareToIgnoreCase("false")==0 )
135 if (isValueNumeric())
136 return bigDecimalValue().compareTo(BigDecimal.valueOf(0)) != 0;
140 public boolean isEmpty() {
144 public boolean isNull() {
148 public int compareTo(Object obj) {
149 return compareTo( (SchemaString) obj);
152 public int compareTo(SchemaString obj) {
153 return value.compareTo(obj.value);
156 public boolean isValueNumeric() {
158 BigDecimal tmp = new BigDecimal(value.trim());
160 catch (NumberFormatException e) {
166 // ---------- interface SchemaTypeNumber ----------
167 public int numericType() {
168 return NUMERIC_VALUE_BIGDECIMAL;
171 public int intValue() {
172 if( isnull || isempty || value.length() == 0)
175 return Integer.parseInt(value);
176 } catch( NumberFormatException e ) {
177 throw new ValuesNotConvertableException( this, new SchemaInt( 0 ) );
181 public long longValue() {
182 if( isnull || isempty || value.length() == 0)
185 return Long.parseLong(value);
186 } catch( NumberFormatException e ) {
187 throw new ValuesNotConvertableException( this, new SchemaLong( 0 ) );
191 public BigInteger bigIntegerValue() {
192 if( isnull || isempty || value.length() == 0)
193 return new BigInteger( "0" );
195 return new BigInteger(value.trim());
196 } catch( NumberFormatException e ) {
197 throw new ValuesNotConvertableException( this, new SchemaInteger( 0 ) );
201 public float floatValue() {
202 if( isnull || isempty || value.length() == 0)
205 return Float.parseFloat(value);
206 } catch( NumberFormatException e ) {
207 throw new ValuesNotConvertableException( this, new SchemaFloat( 0 ) );
211 public double doubleValue() {
212 if( isnull || isempty || value.length() == 0)
215 return Double.parseDouble(value);
216 } catch( NumberFormatException e ) {
217 throw new ValuesNotConvertableException( this, new SchemaDouble( 0 ) );
221 public BigDecimal bigDecimalValue() {
222 if( isnull || isempty || value.length() == 0)
223 return new BigDecimal( 0 );
225 return new BigDecimal(value.trim());
226 } catch( NumberFormatException e ) {
227 throw new ValuesNotConvertableException( this, new SchemaDecimal( 0 ) );
231 // ---------- interface SchemaTypeCalendar ----------
232 public int calendarType() {
233 return CALENDAR_VALUE_UNDEFINED;
236 public SchemaDuration durationValue() {
238 return new SchemaDuration(value);
239 } catch( StringParseException e ) {
240 throw new ValuesNotConvertableException( this, new SchemaDuration( "PT" ) );
244 public SchemaDateTime dateTimeValue() {
246 return new SchemaDateTime(value);
247 } catch( StringParseException e ) {
248 throw new ValuesNotConvertableException( this, new SchemaDateTime( "2003-08-06T00:00:00" ) );
252 public SchemaDate dateValue() {
254 return new SchemaDate(value);
256 catch (StringParseException e) {
257 throw new ValuesNotConvertableException(this, new SchemaDate("2003-08-06"));
261 public SchemaTime timeValue() {
263 return new SchemaTime(value);
265 catch (StringParseException e) {
266 throw new ValuesNotConvertableException(this, new SchemaTime("00:00:00"));