View Javadoc

1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3    Copyright (c) 2005, University of Innsbruck, Austria
4    This library is free software; you can redistribute it and/or modify it under
5    the terms of the GNU Lesser General Public License as published by the Free
6    Software Foundation; either version 2.1 of the License, or (at your option)
7    any later version.
8    This library is distributed in the hope that it will be useful, but WITHOUT
9    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11   details.
12   You should have received a copy of the GNU Lesser General Public License along
13   with this library; if not, write to the Free Software Foundation, Inc.,
14   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15   */
16  package org.deri.wsmo4j.factory;
17  
18  
19  import java.math.*;
20  import java.util.*;
21  
22  import org.omwg.ontology.*;
23  import org.wsmo.common.*;
24  import org.wsmo.factory.*;
25  
26  import com.ontotext.wsmo4j.ontology.*;
27  
28  
29  /**
30   * Interface or class description
31   *
32   * <pre>
33   * Created on Sep 5, 2005
34   * Committed by $Author$
35   * </pre>
36   *
37   * @author Holger Lausne (holger.lausen@deri.org)
38   *
39   * @version $Revision$ $Date$
40   */
41  public class DataFactoryImpl
42          implements DataFactory {
43  
44      /**
45       * contains the IRI of an wsml data type and the corresponding array of
46       * possible constuctors (SimpleTypes)
47       */
48      private HashMap <String, SimpleDataType[]> complexDataTypeConstructors = new HashMap  <String, SimpleDataType[]> ();
49      /**
50       * contains the iri of an wsml data tyoe and the coressponding java value
51       */
52      private HashMap <String, Class> complexDataTypeJavaMapping = new HashMap <String, Class> ();
53  
54      private HashMap <String, SimpleDataType> simpleDataTypes = new HashMap <String, SimpleDataType> ();
55  
56      private SimpleDataType decimal;
57  
58      private SimpleDataType integer;
59  
60      private SimpleDataType string;
61  
62      private WsmoFactory factory;
63      
64      public DataFactoryImpl() {
65          this(null);
66      }
67  
68      /**
69       * The DataFactory is initialised based on the supplied preferences. 
70       * The properties map can contain the factories to be used as Strings or as 
71       * instances. If a factory to use is only indicated as String, the constructor
72       * needs to create an instance of this given factory.
73       * 
74       * @param map
75       */
76      public DataFactoryImpl(Map map) {
77          if (map != null && map.containsKey(DATAFACTORY_WSMO_FACTORY)) {
78              factory = (WsmoFactory) map.get(DATAFACTORY_WSMO_FACTORY);
79          }
80          if (factory == null) {
81              factory = Factory.createWsmoFactory(null);
82          }
83  
84          decimal = new SimpleDataTypeImpl(factory.createIRI(WsmlDataType.WSML_DECIMAL));
85          integer = new SimpleDataTypeImpl(factory.createIRI(WsmlDataType.WSML_INTEGER));
86          string = new SimpleDataTypeImpl(factory.createIRI(WsmlDataType.WSML_STRING));
87  
88          simpleDataTypes.put(WsmlDataType.WSML_INTEGER, integer);
89          simpleDataTypes.put(WsmlDataType.WSML_STRING, string);
90          simpleDataTypes.put(WsmlDataType.WSML_DECIMAL, decimal);
91  
92          complexDataTypeConstructors.put(WsmlDataType.WSML_FLOAT,
93                                          new SimpleDataType[] {string});
94          complexDataTypeJavaMapping.put(WsmlDataType.WSML_FLOAT, Float.class);
95  
96          complexDataTypeConstructors.put(WsmlDataType.WSML_DOUBLE,
97                                          new SimpleDataType[] {string});
98          complexDataTypeJavaMapping.put(WsmlDataType.WSML_DOUBLE, Double.class);
99  
100         complexDataTypeConstructors.put(WsmlDataType.WSML_IRI,
101                                         new SimpleDataType[] {string});
102         complexDataTypeJavaMapping.put(WsmlDataType.WSML_IRI, String.class);
103 
104         complexDataTypeConstructors.put(WsmlDataType.WSML_SQNAME,
105                                         new SimpleDataType[] {string, string});
106         complexDataTypeJavaMapping.put(WsmlDataType.WSML_SQNAME, String[].class);
107 
108         complexDataTypeConstructors.put(WsmlDataType.WSML_BOOLEAN,
109                                         new SimpleDataType[] {string});
110         complexDataTypeJavaMapping.put(WsmlDataType.WSML_BOOLEAN, Boolean.class);
111 
112         complexDataTypeConstructors.put(WsmlDataType.WSML_DURATION,
113                                         new SimpleDataType[] {integer, integer, integer,
114                                         integer, integer, integer});
115         complexDataTypeJavaMapping.put(WsmlDataType.WSML_DURATION, String.class);
116 
117         //2 last are optional
118         complexDataTypeConstructors.put(WsmlDataType.WSML_DATETIME,
119                                         new SimpleDataType[] {integer, integer, integer,
120                                         integer, integer, decimal, integer, integer});
121         complexDataTypeJavaMapping.put(WsmlDataType.WSML_DATETIME, Calendar.class);
122 
123         //2 last are optional
124         complexDataTypeConstructors.put(WsmlDataType.WSML_TIME,
125                                         new SimpleDataType[] {integer, integer, decimal,
126                                         integer, integer});
127         complexDataTypeJavaMapping.put(WsmlDataType.WSML_TIME, Calendar.class);
128 
129         //2 last are optional
130         complexDataTypeConstructors.put(WsmlDataType.WSML_DATE,
131                                         new SimpleDataType[] {integer, integer, integer,
132                                         integer, integer});
133         complexDataTypeJavaMapping.put(WsmlDataType.WSML_DATE, Calendar.class);
134 
135         complexDataTypeConstructors.put(WsmlDataType.WSML_GYEARMONTH,
136                                         new SimpleDataType[] {integer, integer});
137         complexDataTypeJavaMapping.put(WsmlDataType.WSML_GYEARMONTH, Integer[].class);
138 
139         complexDataTypeConstructors.put(WsmlDataType.WSML_GMONTHDAY,
140                                         new SimpleDataType[] {integer, integer});
141         complexDataTypeJavaMapping.put(WsmlDataType.WSML_GMONTHDAY, Integer[].class);
142 
143         complexDataTypeConstructors.put(WsmlDataType.WSML_GYEAR,
144                                         new SimpleDataType[] {integer});
145         complexDataTypeJavaMapping.put(WsmlDataType.WSML_GYEAR, Integer.class);
146 
147         complexDataTypeConstructors.put(WsmlDataType.WSML_GDAY,
148                                         new SimpleDataType[] {integer});
149         complexDataTypeJavaMapping.put(WsmlDataType.WSML_GDAY, Integer.class);
150 
151         complexDataTypeConstructors.put(WsmlDataType.WSML_GMONTH,
152                                         new SimpleDataType[] {integer});
153         complexDataTypeJavaMapping.put(WsmlDataType.WSML_GMONTH, Integer.class);
154 
155         complexDataTypeConstructors.put(WsmlDataType.WSML_HEXBINARY,
156                                         new SimpleDataType[] {string});
157         complexDataTypeJavaMapping.put(WsmlDataType.WSML_GDAY, String.class);
158 
159         complexDataTypeConstructors.put(WsmlDataType.WSML_BASE64BINARY,
160                                         new SimpleDataType[] {string});
161         complexDataTypeJavaMapping.put(WsmlDataType.WSML_GDAY, String.class);
162     }
163 
164     public ComplexDataValue createDataValue(ComplexDataType type, SimpleDataValue argumentValues) {
165         return createDataValue(type, new SimpleDataValue[] {argumentValues});
166     }
167 
168     public ComplexDataValue createDataValue(ComplexDataType type, SimpleDataValue[] argumentValues) {
169         String typeIRIString = type.getIRI().toString();
170         //check correct arity
171         if (type.getArity() != argumentValues.length) {
172             if (!((typeIRIString.equals(WsmlDataType.WSML_DATE) ||
173                    typeIRIString.equals(WsmlDataType.WSML_DATETIME) ||
174                    typeIRIString.equals(WsmlDataType.WSML_TIME)) &&
175                   type.getArity() - 2 == argumentValues.length)) {
176                 throw new IllegalArgumentException("Data type " + typeIRIString +
177                         " must have " + type.getArity() + " number of arguments");
178             }
179         }
180         //check if data type is known
181         SimpleDataType[] types = complexDataTypeConstructors.get(typeIRIString);
182         if (types == null) {
183             throw new IllegalArgumentException("Data type" + type.getIRI().toString() +
184                                                " not supported!");
185         }
186         //check if arguments are of correct type
187         for (byte i = 0; i < argumentValues.length; i++) {
188             if (!argumentValues[i].getType().equals(types[i])) {
189                 throw new IllegalArgumentException("Wrong type of Argument for complex datatype " +
190                         typeIRIString + ": Found at position " + i + ": " +
191                         argumentValues[i].getType().getIRI() + " Expected: " + types[i].getIRI());
192             }
193         }
194         //finally pass to complexDataValueImpl
195         return new ComplexDataValueImpl(type, argumentValues);
196     }
197 
198     /**
199      *
200      * @param type
201      * @param value
202      * @return
203      */
204     public DataValue createDataValueFromJavaObject(WsmlDataType type, Object value) {
205         if (type instanceof SimpleDataType) {
206             if (type.getIRI().toString().equals(WsmlDataType.WSML_INTEGER)){
207                 return createWsmlInteger(value.toString());
208             }
209             else if (type.getIRI().toString().equals(WsmlDataType.WSML_DECIMAL)) {
210                 return createWsmlDecimal(value.toString());
211             }
212             else {
213                 return createWsmlString(value.toString());
214             }
215         }
216         else { //ComplexDataType
217             //check if correct java object is supplied:
218             Class javaType = complexDataTypeJavaMapping.get(type.getIRI().toString());
219             if (javaType == null) {
220                 throw new IllegalArgumentException("Data type" + type.getIRI().toString() +
221                         " not supported!");
222             }
223 
224             if (!javaType.isInstance(value)) {
225                 throw new IllegalArgumentException("Java value for type " + type.getIRI().toString() +
226                         " must be of type " + javaType + " (Found: " + value.getClass() + ")");
227             }
228             return new ComplexDataValueImpl((ComplexDataType)type,
229                                             createSimpleTypesFromJavaValue((ComplexDataType)type, value));
230         }
231 
232     }
233 
234     public SimpleDataValue createWsmlDecimal(BigDecimal value) {
235         return new SimpleDataValueImpl(simpleDataTypes.get(WsmlDataType.WSML_DECIMAL), value);
236     }
237 
238     public SimpleDataValue createWsmlInteger(BigInteger value) {
239         return new SimpleDataValueImpl( simpleDataTypes.get(WsmlDataType.WSML_INTEGER), value);
240     }
241 
242     public SimpleDataValue createWsmlString(String value) {
243         return new SimpleDataValueImpl( simpleDataTypes.get(WsmlDataType.WSML_STRING), value);
244     }
245 
246     public WsmlDataType createWsmlDataType(IRI typeIRI) {
247         return createWsmlDataType(typeIRI.toString());
248     }
249 
250     public WsmlDataType createWsmlDataType(String typeIRI) {
251         if (simpleDataTypes.get(typeIRI) != null) {
252             return simpleDataTypes.get(typeIRI);
253         }
254         SimpleDataType[] types = complexDataTypeConstructors.get(typeIRI);
255         if (types == null) {
256             throw new IllegalArgumentException("Given datatype: <" + typeIRI + "> not supprted");
257         }
258         IRI iri = factory.createIRI(typeIRI);
259         return new ComplexDataTypeImpl(iri, types);
260     }
261 
262     private SimpleDataValue[] createSimpleTypesFromJavaValue(ComplexDataType type, Object value) {
263         String typeIRI = type.getIRI().toString();
264         if (typeIRI.equals(WsmlDataType.WSML_FLOAT) ||
265             typeIRI.equals(WsmlDataType.WSML_DOUBLE) ||
266             typeIRI.equals(WsmlDataType.WSML_BOOLEAN)) {
267             return new SimpleDataValue[] {
268                     createWsmlString(value.toString())};
269         }
270         else if (typeIRI.equals(WsmlDataType.WSML_IRI)) {
271             return new SimpleDataValue[] {
272                     createWsmlString(value.toString())};
273         }
274         else if (typeIRI.equals(WsmlDataType.WSML_SQNAME)) {
275             String[] stringArray = (String[])value;
276             if (stringArray.length != 2) {
277                 throw new IllegalArgumentException("datatype " + typeIRI + " must have 2 strings as argument!");
278             }
279             return new SimpleDataValue[] {
280                     createWsmlString(stringArray[0]),
281                     createWsmlString(stringArray[1])};
282         }
283         else if (typeIRI.equals(WsmlDataType.WSML_DURATION)) {
284             //"-PnYn MnDTnH nMnS" lexical duration representation
285             return new SimpleDataValue[] {
286                     createWsmlString(value.toString())};
287         }
288         else if (typeIRI.equals(WsmlDataType.WSML_DATETIME)) {
289             Calendar cal = (Calendar)value;
290             
291             float seconds = cal.get(Calendar.SECOND) + cal.get(Calendar.MILLISECOND) / 1000f;
292             if (cal.isSet(Calendar.ZONE_OFFSET)) {
293                 int zoneOffSetHour = cal.getTimeZone().getRawOffset() / 1000 / 60;
294                 int zoneOffSetMinute = cal.get(Calendar.ZONE_OFFSET) / 1000 % 60;
295                 
296                 return new SimpleDataValue[] {
297                         createWsmlInteger(new BigInteger("" + cal.get(Calendar.YEAR))),
298                         createWsmlInteger(new BigInteger("" + (cal.get(Calendar.MONTH) + 1))),
299                         createWsmlInteger(new BigInteger("" + cal.get(Calendar.DAY_OF_MONTH))),
300                         createWsmlInteger(new BigInteger("" + cal.get(Calendar.HOUR_OF_DAY))),
301                         createWsmlInteger(new BigInteger("" + cal.get(Calendar.MINUTE))),
302                         createWsmlDecimal(new BigDecimal(String.valueOf(seconds))),
303                         createWsmlInteger(new BigInteger("" + zoneOffSetHour)),
304                         createWsmlInteger(new BigInteger("" + zoneOffSetMinute))};
305             }
306             else {
307                 return new SimpleDataValue[] {
308                         createWsmlInteger(new BigInteger("" + cal.get(Calendar.YEAR))),
309                         createWsmlInteger(new BigInteger("" + (cal.get(Calendar.MONTH) + 1))),
310                         createWsmlInteger(new BigInteger("" + cal.get(Calendar.DAY_OF_MONTH))),
311                         createWsmlInteger(new BigInteger("" + cal.get(Calendar.HOUR_OF_DAY))),
312                         createWsmlInteger(new BigInteger("" + cal.get(Calendar.MINUTE))),
313                         createWsmlDecimal(new BigDecimal(seconds))};
314             }
315         }
316         else if (typeIRI.equals(WsmlDataType.WSML_DATE)) {
317             Calendar cal = (Calendar)value;
318             if (cal.isSet(Calendar.ZONE_OFFSET)) {
319                 int zoneOffSetHour = cal.getTimeZone().getRawOffset() / 1000 / 60;
320                 int zoneOffSetMinute = cal.get(Calendar.ZONE_OFFSET) / 1000 % 60;
321                 return new SimpleDataValue[] {
322                         createWsmlInteger(new BigInteger("" + cal.get(Calendar.YEAR))),
323                         createWsmlInteger(new BigInteger("" + (cal.get(Calendar.MONTH) + 1))),
324                         createWsmlInteger(new BigInteger("" + cal.get(Calendar.DAY_OF_MONTH))),
325                         createWsmlInteger(new BigInteger("" + zoneOffSetHour)),
326                         createWsmlInteger(new BigInteger("" + zoneOffSetMinute))};
327             }
328             else {
329                 return new SimpleDataValue[] {
330                         createWsmlInteger(new BigInteger("" + cal.get(Calendar.YEAR))),
331                         createWsmlInteger(new BigInteger("" + (cal.get(Calendar.MONTH) + 1))),
332                         createWsmlInteger(new BigInteger("" + cal.get(Calendar.DAY_OF_MONTH)))};
333             }
334         }
335         else if (typeIRI.equals(WsmlDataType.WSML_TIME)) {
336             Calendar cal = (Calendar)value;
337             float seconds = cal.get(Calendar.SECOND) + cal.get(Calendar.MILLISECOND) / 1000f;
338             if (cal.isSet(Calendar.ZONE_OFFSET)) {
339                 int zoneOffSetHour = cal.getTimeZone().getRawOffset() / 1000 / 60;
340                 int zoneOffSetMinute = cal.get(Calendar.ZONE_OFFSET) / 1000 % 60;
341                 return new SimpleDataValue[] {
342                         createWsmlInteger(new BigInteger("" + cal.get(Calendar.HOUR_OF_DAY))),
343                         createWsmlInteger(new BigInteger("" + (cal.get(Calendar.MINUTE)))),
344                         createWsmlDecimal(new BigDecimal(seconds)),
345                         createWsmlInteger(new BigInteger("" + zoneOffSetHour)),
346                         createWsmlInteger(new BigInteger("" + zoneOffSetMinute))};
347             }
348             else {
349                 return new SimpleDataValue[] {
350                         createWsmlInteger(new BigInteger("" + cal.get(Calendar.HOUR_OF_DAY))),
351                         createWsmlInteger(new BigInteger("" + (cal.get(Calendar.MINUTE)))),
352                         createWsmlDecimal(new BigDecimal(seconds))};
353             }
354         }
355         else if (typeIRI.equals(WsmlDataType.WSML_GYEARMONTH)) {
356             Integer[] integer = (Integer[])value;
357             if (integer.length != 2) {
358                 throw new IllegalArgumentException("datatype " + typeIRI + " must have 2 Integers as argument!");
359             }
360             return new SimpleDataValue[] {
361                     createWsmlInteger(new BigInteger("" + integer[0])),
362                     createWsmlInteger(new BigInteger("" + integer[1]))};
363         }
364         else if (typeIRI.equals(WsmlDataType.WSML_GMONTHDAY)) {
365             Integer[] integer = (Integer[])value;
366             if (integer.length != 2) {
367                 throw new IllegalArgumentException("datatype " + typeIRI + " must have 2 Integers as argument!");
368             }
369             return new SimpleDataValue[] {
370                     createWsmlInteger(new BigInteger("" + integer[0])),
371                     createWsmlInteger(new BigInteger("" + integer[1]))};
372         }
373         else if (typeIRI.equals(WsmlDataType.WSML_GYEAR)) {
374             return new SimpleDataValue[] {
375                     createWsmlInteger(new BigInteger("" + value))};
376         }
377         else if (typeIRI.equals(WsmlDataType.WSML_GDAY)) {
378             return new SimpleDataValue[] {
379                     createWsmlInteger(new BigInteger("" + value))};
380         }
381         else if (typeIRI.equals(WsmlDataType.WSML_GMONTH)) {
382             return new SimpleDataValue[] {
383                     createWsmlInteger(new BigInteger("" + value))};
384         }
385         else if (typeIRI.equals(WsmlDataType.WSML_HEXBINARY)) {
386             return new SimpleDataValue[] {
387                     createWsmlString((String)value)};
388         }
389         else if (typeIRI.equals(WsmlDataType.WSML_BASE64BINARY)) {
390             return new SimpleDataValue[] {
391                     createWsmlString((String)value)};
392         }
393         else {
394             throw new UnsupportedOperationException("DataType " + typeIRI + " not supported!");
395         }
396     }
397 
398     public ComplexDataValue createWsmlBoolean(Boolean value) {
399         return (ComplexDataValue)createDataValueFromJavaObject(
400                 createWsmlDataType(WsmlDataType.WSML_BOOLEAN),
401                 value);
402     }
403 
404     public ComplexDataValue createWsmlBoolean(String value){
405         Boolean bValue = Boolean.valueOf(value);
406         return (ComplexDataValue)createDataValueFromJavaObject(
407                 createWsmlDataType(WsmlDataType.WSML_BOOLEAN),
408                 bValue);
409     }
410 
411 
412     public ComplexDataValue createWsmlDuration(int year, int month, int day, int hour, int minute, int second){
413         //"-PnYnMnDTnHnMnS"
414         //FIXME: this is ignoring the duartion value space and equivalence relation!
415         return (ComplexDataValue)createDataValueFromJavaObject(
416                 createWsmlDataType(WsmlDataType.WSML_DURATION),
417                 "P"+year+"Y"+month+"M"+day+"DT"+hour+"H"+minute+"M"+second+"S");
418     }
419 
420     public ComplexDataValue createWsmlDuration(String year, String month, String day, String hour, String minute, String second){
421         return (ComplexDataValue)createDataValueFromJavaObject(
422                 createWsmlDataType(WsmlDataType.WSML_DURATION),
423                 "P"+year+"Y"+month+"M"+day+"DT"+hour+"H"+minute+"M"+second+"S");
424     }
425 
426 
427     public ComplexDataValue createWsmlDateTime(Calendar value){
428         return (ComplexDataValue)createDataValueFromJavaObject(
429                 createWsmlDataType(WsmlDataType.WSML_DATETIME),
430                 value);
431     }
432 
433     public ComplexDataValue createWsmlDateTime(int year, int month, int day, int hour, int minute, int second, int tzHour, int tzMinute){
434         return createWsmlDateTime(year, month, day, hour, minute, (float)second, tzHour, tzMinute);
435     }
436     
437     public ComplexDataValue createWsmlDateTime(int year, int month, int day, int hour, int minute, float second, int tzHour, int tzMinute){
438         return createDataValue(
439                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_DATETIME),
440                 new SimpleDataValue[]{
441                     createWsmlInteger(year),
442                     createWsmlInteger(month),
443                     createWsmlInteger(day),
444                     createWsmlInteger(hour),
445                     createWsmlInteger(minute),
446                     createWsmlDecimal(new BigDecimal(String.valueOf(second))),
447                     createWsmlInteger(tzHour),
448                     createWsmlInteger(tzMinute),
449                 });
450     }
451 
452     public ComplexDataValue createWsmlDateTime(String year, String month, String day, String hour, String minute, String second, String tzHour, String tzMinute){
453         return createDataValue(
454                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_DATETIME),
455                 new SimpleDataValue[]{
456                     createWsmlInteger(year),
457                     createWsmlInteger(month),
458                     createWsmlInteger(day),
459                     createWsmlInteger(hour),
460                     createWsmlInteger(minute),
461                     createWsmlDecimal(new BigDecimal(second)),
462                     createWsmlInteger(tzHour),
463                     createWsmlInteger(tzMinute),
464                 });    
465     }
466 
467 
468     public ComplexDataValue createWsmlTime(Calendar value){
469         return (ComplexDataValue)createDataValueFromJavaObject(
470                 createWsmlDataType(WsmlDataType.WSML_TIME),
471                 value);    }
472 
473     public ComplexDataValue createWsmlTime(int hour, int minute, int second, int tzHour, int tzMinute){
474         return createWsmlTime( hour, minute, (float)second, tzHour, tzMinute);    
475     }
476     
477     public ComplexDataValue createWsmlTime(int hour, int minute, float second, int tzHour, int tzMinute){
478         return createDataValue(
479                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_TIME),
480                 new SimpleDataValue[]{
481                     createWsmlInteger(hour),
482                     createWsmlInteger(minute),
483                     createWsmlDecimal(new BigDecimal(second)),
484                     createWsmlInteger(tzHour),
485                     createWsmlInteger(tzMinute),
486                 });    
487     }
488 
489     public ComplexDataValue createWsmlTime(String hour, String minute, String second, String tzHour, String tzMinute){
490         return createDataValue(
491                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_TIME),
492                 new SimpleDataValue[]{
493                     createWsmlInteger(hour),
494                     createWsmlInteger(minute),
495                     createWsmlDecimal(new BigDecimal(second)),
496                     createWsmlInteger(tzHour),
497                     createWsmlInteger(tzMinute),
498                 }); 
499     }
500 
501 
502     public ComplexDataValue createWsmlDate(Calendar value){
503         return (ComplexDataValue)createDataValueFromJavaObject(
504                 createWsmlDataType(WsmlDataType.WSML_DATE),
505                 value);
506     }
507 
508     public ComplexDataValue createWsmlDate(int year, int month, int day, int tzHour, int tzMinute){
509         return createDataValue(
510                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_DATE),
511                 new SimpleDataValue[]{
512                     createWsmlInteger(year),
513                     createWsmlInteger(month),
514                     createWsmlInteger(day),
515                     createWsmlInteger(tzHour),
516                     createWsmlInteger(tzMinute),
517                 });  
518     }
519 
520     public ComplexDataValue createWsmlDate(String year, String month, String day, String tzHour, String tzMinute){
521         return createDataValue(
522                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_DATE),
523                 new SimpleDataValue[]{
524                     createWsmlInteger(year),
525                     createWsmlInteger(month),
526                     createWsmlInteger(day),
527                     createWsmlInteger(tzHour),
528                     createWsmlInteger(tzMinute),
529                 });  
530     }
531 
532 
533     public ComplexDataValue createWsmlGregorianYearMonth(int year, int month){
534         return createDataValue(
535                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_GYEARMONTH),
536                 new SimpleDataValue[]{
537                     createWsmlInteger(year),
538                     createWsmlInteger(month),
539                 });  
540     }
541 
542     public ComplexDataValue createWsmlGregorianYearMonth(String year, String month){
543         return createDataValue(
544                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_GYEARMONTH),
545                 new SimpleDataValue[]{
546                     createWsmlInteger(year),
547                     createWsmlInteger(month),
548                 });  
549     }
550 
551 
552     public ComplexDataValue createWsmlGregorianYear(int year){
553         return createDataValue(
554                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_GYEAR),
555                 new SimpleDataValue[]{
556                     createWsmlInteger(year),
557                 });  
558     }
559 
560     public ComplexDataValue createWsmlGregorianYear(String year){
561         return createDataValue(
562                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_GYEAR),
563                 new SimpleDataValue[]{
564                     createWsmlInteger(year),
565                 });  
566     }
567 
568 
569     public ComplexDataValue createWsmlGregorianMonthDay(int month, int day){
570         return createDataValue(
571                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_GMONTHDAY),
572                 new SimpleDataValue[]{
573                     createWsmlInteger(month),
574                     createWsmlInteger(day),
575                 });  
576     }
577 
578     public ComplexDataValue createWsmlGregorianMonthDay(String month, String day){
579         return createDataValue(
580                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_GMONTHDAY),
581                 new SimpleDataValue[]{
582                     createWsmlInteger(month),
583                     createWsmlInteger(day),
584                 });  
585     }
586 
587 
588     public ComplexDataValue createWsmlGregorianMonth(int month){
589         return createDataValue(
590                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_GMONTH),
591                 new SimpleDataValue[]{
592                     createWsmlInteger(month),
593                 });  
594     }
595 
596     public ComplexDataValue createWsmlGregorianMonth(String month){
597         return createDataValue(
598                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_GMONTH),
599                 new SimpleDataValue[]{
600                     createWsmlInteger(month),
601                 });  
602     }
603 
604 
605     public ComplexDataValue createWsmlGregorianDay(int day){
606         return createDataValue(
607                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_GDAY),
608                 new SimpleDataValue[]{
609                     createWsmlInteger(day),
610                 });  
611     }
612 
613     public ComplexDataValue createWsmlGregorianDay(String day){
614         return createDataValue(
615                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_GDAY),
616                 new SimpleDataValue[]{
617                     createWsmlInteger(day),
618                 });  
619     }
620     
621     public ComplexDataValue creatWsmlHexBinary(byte[] value){
622         return createDataValue(
623                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_HEXBINARY),
624                 new SimpleDataValue[]{
625                     createWsmlString(new String(value)),
626                 });  
627     }
628 
629     public ComplexDataValue createWsmlBase64Binary(byte[] value){
630         return createDataValue(
631                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_BASE64BINARY),
632                 new SimpleDataValue[]{
633                     createWsmlString(new String(value)),
634                 });  
635     }
636 
637     public SimpleDataValue createWsmlDecimal(String value){
638     	//FIXME we're just doing sanity checking and correction here, somewhere in
639     	//the calltrace an additional space is inserted after the sign of the decimal
640     	//number, even if the originally parsed expression didn't have a space
641     	value = value.replaceFirst("-\\s+", "-");
642         return createWsmlDecimal(new BigDecimal(value));  
643     }
644 
645     public SimpleDataValue createWsmlInteger(String value){
646         return createWsmlInteger(new BigInteger(value));
647     }
648 
649     public SimpleDataValue createWsmlInteger(int value){
650         return createWsmlInteger(new BigInteger(value+""));
651     }
652 
653     public ComplexDataValue createWsmlFloat(String value){
654         return createDataValue(
655                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_FLOAT),
656                 new SimpleDataValue[]{
657                     createWsmlString(value),
658                 });  
659     }
660 
661     public ComplexDataValue createWsmlFloat(Float value){
662         return (ComplexDataValue)createDataValueFromJavaObject(
663                 createWsmlDataType(WsmlDataType.WSML_FLOAT),
664                 value);  
665     }
666 
667     public ComplexDataValue createWsmlDouble(Double value){
668         return (ComplexDataValue)createDataValueFromJavaObject(
669                 createWsmlDataType(WsmlDataType.WSML_DOUBLE),
670                 value);     
671     }
672 
673     public ComplexDataValue createWsmlDouble(String value){
674         return createDataValue(
675                 (ComplexDataType)createWsmlDataType(WsmlDataType.WSML_DOUBLE),
676                 new SimpleDataValue[]{
677                     createWsmlString(value),
678                 }); 
679     }
680 
681 }
682 /*
683  * $Log$
684  * Revision 1.17  2007/09/04 08:18:06  lcekov
685  * DataTypeFactory.createWsmlTime must support milliseconds
686  * https://sourceforge.net/tracker/?func=detail&atid=665346&aid=1723466&group_id=113501
687  *
688  * Revision 1.16  2007/06/22 13:26:22  lcekov
689  * DataTypeFactory.createWsmlDateTime must support milliseconds
690  * https://sourceforge.net/tracker/?func=detail&atid=665346&aid=1723466&group_id=113501
691  *
692  * Revision 1.15  2007/06/22 12:35:09  lcekov
693  * DataTypeFactory.createWsmlDateTime must support milliseconds
694  * https://sourceforge.net/tracker/?func=detail&atid=665346&aid=1723466&group_id=113501
695  *
696  * Revision 1.14  2007/04/02 12:13:24  morcen
697  * Generics support added to wsmo-api, wsmo4j and wsmo-test
698  *
699  * Revision 1.13  2006/02/28 16:55:12  haselwanter
700  * Space-proofing the decimal creation.
701  *
702  * Revision 1.12  2006/01/09 14:18:43  nathaliest
703  * javadoc added
704  *
705  * Revision 1.11  2005/10/12 13:30:54  ohamano
706  * fix type determination for simple data types
707  *
708  * Revision 1.10  2005/09/30 11:56:12  alex_simov
709  * minor fixes
710  *
711  * Revision 1.9  2005/09/23 12:20:42  holgerlausen
712  * *** empty log message ***
713  *
714  * Revision 1.8  2005/09/17 08:50:53  vassil_momtchev
715  * constructor to accept map added
716  *
717  * Revision 1.7  2005/09/15 15:36:19  holgerlausen
718  * additional createXXX methods for data values and /some/ unit tests
719  *
720  * Revision 1.6  2005/09/12 12:10:53  marin_dimitrov
721  * added specific createXXX methods
722  *
723  * Revision 1.5  2005/09/12 12:05:53  marin_dimitrov
724  * added specific createXXX methods
725  *
726  * Revision 1.4  2005/09/09 15:51:41  marin_dimitrov
727  * formatting
728  *
729  * Revision 1.3  2005/09/09 10:00:15  holgerlausen
730  * fixed serializing problem eported by jan (for data types in relations)
731  *
732  * Revision 1.2  2005/09/08 15:16:27  holgerlausen
733  * fixes for parsing and serializing datatypes
734  *
735  * Revision 1.1  2005/09/06 18:34:14  holgerlausen
736  * added implementation of datatype factory
737  *
738  */