DataType.java
0001 /*
0002  *  DataType.java
0003  *
0004  *  Niraj Aswani, 09/March/07
0005  *
0006  *  $Id: DataType.html,v 1.0 2007/03/09 16:13:01 niraj Exp $
0007  */
0008 package gate.creole.ontology;
0009 
0010 import gate.util.GateRuntimeException;
0011 
0012 import java.util.HashMap;
0013 import java.util.Locale;
0014 
0015 import javax.xml.datatype.DatatypeConfigurationException;
0016 import javax.xml.datatype.DatatypeFactory;
0017 import javax.xml.datatype.XMLGregorianCalendar;
0018 
0019 /**
0020  * This class provides a list of datatypes, supported by the ontology
0021  * API.
0022  
0023  @author Niraj Aswani
0024  */
0025 public class DataType {
0026   /**
0027    * for each datatype, there exists a XML Schema URI in ontology which
0028    * is used to denote the specific datatype. For example to denote the
0029    * boolean datatype one would have to use
0030    * "http://www.w3.org/2001/XMLSchema#boolean".
0031    
0032    */
0033   // protected OURI xmlSchemaURI;
0034   protected String xmlSchemaURIString;
0035 
0036   static DatatypeFactory datatypeFactory = null;
0037   static {
0038     try {
0039       datatypeFactory = DatatypeFactory.newInstance();
0040     }
0041     catch(DatatypeConfigurationException e) {
0042       throw new GateRuntimeException(
0043               "could not initialize data type factory :\n", e);
0044     }
0045   }
0046 
0047   /**
0048    * Constructor
0049    
0050    @param xmlSchemaURI for each datatype, there exists a XML Schema
0051    *          URI in ontology which is used to denote the specific
0052    *          datatype. For example to denote the boolean datatype one
0053    *          would have to use
0054    *          "http://www.w3.org/2001/XMLSchema#boolean".
0055    */
0056   public DataType(OURI xmlSchemaURI) {
0057     // this.xmlSchemaURI = xmlSchemaURI;
0058     this.xmlSchemaURIString = xmlSchemaURI.toString();
0059   }
0060 
0061   public DataType(String xmlSchemaURIString) {
0062     this.xmlSchemaURIString = xmlSchemaURIString;
0063     // TODO: make checks here, the schema URI really must be one of
0064     // those
0065     // defined in the standard!
0066   }
0067 
0068   public boolean isStringDataType() {
0069     return this.xmlSchemaURIString
0070             .equals("http://www.w3.org/2001/XMLSchema#string");
0071   }
0072 
0073   /**
0074    * denotes the "http://www.w3.org/2001/XMLSchema#boolean" datatype.
0075    */
0076   public static DataType getBooleanDataType() {
0077     try {
0078       return new BooleanDT("http://www.w3.org/2001/XMLSchema#boolean");
0079     }
0080     catch(InvalidURIException iue) {
0081       return null;
0082     }
0083   }
0084 
0085   /**
0086    * denotes the "http://www.w3.org/2001/XMLSchema#byte" datatype.
0087    */
0088   public static DataType getByteDataType() {
0089     try {
0090       return new ByteDT("http://www.w3.org/2001/XMLSchema#byte");
0091     }
0092     catch(InvalidURIException iue) {
0093       return null;
0094     }
0095   }
0096 
0097   /**
0098    * denotes the "http://www.w3.org/2001/XMLSchema#date" datatype.
0099    */
0100   public static DataType getDateDataType() {
0101     try {
0102       return new DateDT("http://www.w3.org/2001/XMLSchema#date");
0103     }
0104     catch(InvalidURIException iue) {
0105       return null;
0106     }
0107   }
0108 
0109   /**
0110    * denotes the "http://www.w3.org/2001/XMLSchema#decimal" datatype.
0111    */
0112   public static DataType getDecimalDataType() {
0113     try {
0114       return new DoubleDT("http://www.w3.org/2001/XMLSchema#decimal");
0115     }
0116     catch(InvalidURIException iue) {
0117       return null;
0118     }
0119   }
0120 
0121   /**
0122    * denotes the "http://www.w3.org/2001/XMLSchema#double" datatype.
0123    */
0124   public static DataType getDoubleDataType() {
0125     try {
0126       return new DoubleDT("http://www.w3.org/2001/XMLSchema#double");
0127     }
0128     catch(InvalidURIException iue) {
0129       return null;
0130     }
0131   }
0132 
0133   /**
0134    * denotes the "http://www.w3.org/2001/XMLSchema#duration" datatype.
0135    */
0136   public static DataType getDurationDataType() {
0137     try {
0138       return new LongDT("http://www.w3.org/2001/XMLSchema#duration");
0139     }
0140     catch(InvalidURIException iue) {
0141       return null;
0142     }
0143   }
0144 
0145   /**
0146    * denotes the "http://www.w3.org/2001/XMLSchema#float" datatype.
0147    */
0148   public static DataType getFloatDataType() {
0149     try {
0150       return new FloatDT("http://www.w3.org/2001/XMLSchema#float");
0151     }
0152     catch(InvalidURIException iue) {
0153       return null;
0154     }
0155   }
0156 
0157   /**
0158    * denotes the "http://www.w3.org/2001/XMLSchema#int" datatype.
0159    */
0160   public static DataType getIntDataType() {
0161     try {
0162       return new IntegerDT("http://www.w3.org/2001/XMLSchema#int");
0163     }
0164     catch(InvalidURIException iue) {
0165       return null;
0166     }
0167   }
0168 
0169   /**
0170    * denotes the "http://www.w3.org/2001/XMLSchema#integer" datatype.
0171    */
0172   public static DataType getIntegerDataType() {
0173     try {
0174       return new IntegerDT("http://www.w3.org/2001/XMLSchema#integer");
0175     }
0176     catch(InvalidURIException iue) {
0177       return null;
0178     }
0179   }
0180 
0181   /**
0182    * denotes the "http://www.w3.org/2001/XMLSchema#long" datatype.
0183    */
0184   public static DataType getLongDataType() {
0185     try {
0186       return new LongDT("http://www.w3.org/2001/XMLSchema#long");
0187     }
0188     catch(InvalidURIException iue) {
0189       return null;
0190     }
0191   }
0192 
0193   /**
0194    * denotes the "http://www.w3.org/2001/XMLSchema#negativeInteger"
0195    * datatype.
0196    */
0197   public static DataType getNegativeIntegerDataType() {
0198     try {
0199       return new NegativeIntegerDT(
0200               "http://www.w3.org/2001/XMLSchema#negativeInteger");
0201     }
0202     catch(InvalidURIException iue) {
0203       return null;
0204     }
0205   }
0206 
0207   /**
0208    * denotes the "http://www.w3.org/2001/XMLSchema#nonNegativeInteger"
0209    * datatype.
0210    */
0211   public static DataType getNonNegativeIntegerDataType() {
0212     try {
0213       return new NonNegativeIntegerDT(
0214               "http://www.w3.org/2001/XMLSchema#nonNegativeInteger");
0215     }
0216     catch(InvalidURIException iue) {
0217       return null;
0218     }
0219   }
0220 
0221   /**
0222    * denotes the "http://www.w3.org/2001/XMLSchema#nonPositiveInteger"
0223    * datatype.
0224    */
0225   public static DataType getNonPositiveIntegerDataType() {
0226     try {
0227       return new NegativeIntegerDT(
0228               "http://www.w3.org/2001/XMLSchema#nonPositiveInteger");
0229     }
0230     catch(InvalidURIException iue) {
0231       return null;
0232     }
0233   }
0234 
0235   /**
0236    * denotes the "http://www.w3.org/2001/XMLSchema#positiveInteger"
0237    * datatype.
0238    */
0239   public static DataType getPositiveIntegerDataType() {
0240     try {
0241       return new NonNegativeIntegerDT(
0242               "http://www.w3.org/2001/XMLSchema#positiveInteger");
0243     }
0244     catch(InvalidURIException iue) {
0245       return null;
0246     }
0247   }
0248 
0249   /**
0250    * denotes the "http://www.w3.org/2001/XMLSchema#short" datatype.
0251    */
0252   public static DataType getShortDataType() {
0253     try {
0254       return new ShortDT("http://www.w3.org/2001/XMLSchema#short");
0255     }
0256     catch(InvalidURIException iue) {
0257       return null;
0258     }
0259   }
0260 
0261   /**
0262    * denotes the "http://www.w3.org/2001/XMLSchema#string" datatype.
0263    */
0264   public static DataType getStringDataType() {
0265     try {
0266       return new DataType("http://www.w3.org/2001/XMLSchema#string");
0267     }
0268     catch(InvalidURIException iue) {
0269       return null;
0270     }
0271   }
0272 
0273   /**
0274    * denotes the "http://www.w3.org/2001/XMLSchema#time" datatype.
0275    */
0276   public static DataType getTimeDataType() {
0277     try {
0278       return new TimeDT("http://www.w3.org/2001/XMLSchema#time");
0279     }
0280     catch(InvalidURIException iue) {
0281       return null;
0282     }
0283   }
0284 
0285   /**
0286    * denotes the "http://www.w3.org/2001/XMLSchema#dateTime" datatype.
0287    */
0288   public static DataType getDateTimeDataType() {
0289     try {
0290       return new DateTimeDT(
0291               "http://www.w3.org/2001/XMLSchema#dateTime");
0292     }
0293     catch(InvalidURIException iue) {
0294       return null;
0295     }
0296   }
0297 
0298   /**
0299    * denotes the "http://www.w3.org/2001/XMLSchema#unsignedByte"
0300    * datatype.
0301    */
0302   public static DataType getUnsignedByteDataType() {
0303     try {
0304       return new UnsignedByteDT(
0305               "http://www.w3.org/2001/XMLSchema#unsignedByte");
0306     }
0307     catch(InvalidURIException iue) {
0308       return null;
0309     }
0310   }
0311 
0312   /**
0313    * denotes the "http://www.w3.org/2001/XMLSchema#unsignedInt"
0314    * datatype.
0315    */
0316   public static DataType getUnsignedIntDataType() {
0317     try {
0318       return new NonNegativeIntegerDT(
0319               "http://www.w3.org/2001/XMLSchema#unsignedInt");
0320     }
0321     catch(InvalidURIException iue) {
0322       return null;
0323     }
0324   }
0325 
0326   /**
0327    * denotes the "http://www.w3.org/2001/XMLSchema#unsignedLong"
0328    * datatype.
0329    */
0330   public static DataType getUnsignedLongDataType() {
0331     try {
0332       return new UnsignedLongDT(
0333               "http://www.w3.org/2001/XMLSchema#unsignedLong");
0334     }
0335     catch(InvalidURIException iue) {
0336       return null;
0337     }
0338   }
0339 
0340   /**
0341    * denotes the "http://www.w3.org/2001/XMLSchema#unsignedShort"
0342    * datatype.
0343    */
0344   public static DataType getUnsignedShortDataType() {
0345     try {
0346       return new UnsignedShortDT(
0347               "http://www.w3.org/2001/XMLSchema#unsignedShort");
0348     }
0349     catch(InvalidURIException iue) {
0350       return null;
0351     }
0352   }
0353 
0354   @Deprecated
0355   public OURI getXmlSchemaURI() {
0356     return new URI(xmlSchemaURIString, false);
0357   }
0358 
0359   public String getXmlSchemaURIString() {
0360     return xmlSchemaURIString;
0361   }
0362 
0363   /**
0364    * Compares if the two objects are same, i.e. if their string
0365    * representations are identical.
0366    */
0367   public boolean equals(Object o) {
0368     if(instanceof DataType) {
0369       DataType dt = (DataType)o;
0370       // return
0371       // this.xmlSchemaURI.getNameSpace().equals(dt.xmlSchemaURI.getNameSpace())
0372       // &&
0373       // this.xmlSchemaURI.getResourceName().equals(dt.xmlSchemaURI.getResourceName());
0374       return this.getXmlSchemaURIString().equals(dt.getXmlSchemaURIString());
0375     }
0376     return false;
0377   }
0378 
0379   /**
0380    * Checks whether the provided value is a valid value for the datatype
0381    * (e.g. if the datatype is integer, parsing a string value into
0382    * integer causes the exception or not.
0383    
0384    @param value
0385    @return true, if the provided value can be parsed correctly into
0386    *         the datatype, otherwise - false.
0387    */
0388   public boolean isValidValue(String value) {
0389     return true;
0390   }
0391 
0392   /**
0393    * Map containing uri and respective instance of datatypes
0394    */
0395   private static HashMap<String, DataType> datatypeMap = new HashMap<String, DataType>();
0396   static {
0397     datatypeMap.put("http://www.w3.org/2001/XMLSchema#boolean", DataType
0398             .getBooleanDataType());
0399     datatypeMap.put("http://www.w3.org/2001/XMLSchema#byte", DataType
0400             .getByteDataType());
0401     datatypeMap.put("http://www.w3.org/2001/XMLSchema#date", DataType
0402             .getDateDataType());
0403     datatypeMap.put("http://www.w3.org/2001/XMLSchema#decimal", DataType
0404             .getDecimalDataType());
0405     datatypeMap.put("http://www.w3.org/2001/XMLSchema#double", DataType
0406             .getDoubleDataType());
0407     datatypeMap.put("http://www.w3.org/2001/XMLSchema#duration", DataType
0408             .getDurationDataType());
0409     datatypeMap.put("http://www.w3.org/2001/XMLSchema#float", DataType
0410             .getFloatDataType());
0411     datatypeMap.put("http://www.w3.org/2001/XMLSchema#int", DataType
0412             .getIntDataType());
0413     datatypeMap.put("http://www.w3.org/2001/XMLSchema#integer", DataType
0414             .getIntegerDataType());
0415     datatypeMap.put("http://www.w3.org/2001/XMLSchema#long", DataType
0416             .getLongDataType());
0417     datatypeMap.put("http://www.w3.org/2001/XMLSchema#negativeInteger",
0418             DataType.getNegativeIntegerDataType());
0419     datatypeMap.put("http://www.w3.org/2001/XMLSchema#nonNegativeInteger",
0420             DataType.getNonNegativeIntegerDataType());
0421     datatypeMap.put("http://www.w3.org/2001/XMLSchema#nonPositiveInteger",
0422             DataType.getNonPositiveIntegerDataType());
0423     datatypeMap.put("http://www.w3.org/2001/XMLSchema#positiveInteger",
0424             DataType.getPositiveIntegerDataType());
0425     datatypeMap.put("http://www.w3.org/2001/XMLSchema#short", DataType
0426             .getShortDataType());
0427     datatypeMap.put("http://www.w3.org/2001/XMLSchema#string", DataType
0428             .getStringDataType());
0429     datatypeMap.put("http://www.w3.org/2001/XMLSchema#time", DataType
0430             .getTimeDataType());
0431     datatypeMap.put("http://www.w3.org/2001/XMLSchema#unsignedByte", DataType
0432             .getUnsignedByteDataType());
0433     datatypeMap.put("http://www.w3.org/2001/XMLSchema#unsignedInt", DataType
0434             .getUnsignedIntDataType());
0435     datatypeMap.put("http://www.w3.org/2001/XMLSchema#unsignedLong", DataType
0436             .getUnsignedLongDataType());
0437     datatypeMap.put("http://www.w3.org/2001/XMLSchema#unsignedShort", DataType
0438             .getUnsignedShortDataType());
0439     datatypeMap.put("http://www.w3.org/2001/XMLSchema#dateTime", DataType
0440             .getDateTimeDataType());
0441 
0442   }
0443 
0444   /**
0445    * Map containing language codes and their respective locales
0446    */
0447   private static HashMap<String, Locale> localsMap = new HashMap<String, Locale>();
0448   static {
0449     localsMap.put("aa", OConstants.AFAR);
0450     localsMap.put("ab", OConstants.ABKHAZIAN);
0451     localsMap.put("af", OConstants.AFRIKAANS);
0452     localsMap.put("am", OConstants.AMHARIC);
0453     localsMap.put("ar", OConstants.ARABIC);
0454     localsMap.put("as", OConstants.ASSAMESE);
0455     localsMap.put("ay", OConstants.AYMARA);
0456     localsMap.put("az", OConstants.AZERBAIJANI);
0457     localsMap.put("ba", OConstants.BASHKIR);
0458     localsMap.put("be", OConstants.BYELORUSSIAN);
0459     localsMap.put("bg", OConstants.BULGARIAN);
0460     localsMap.put("bh", OConstants.BIHARI);
0461     localsMap.put("bi", OConstants.BISLAMA);
0462     localsMap.put("bn", OConstants.BENGALI);
0463     localsMap.put("bo", OConstants.TIBETAN);
0464     localsMap.put("br", OConstants.BRETON);
0465     localsMap.put("ca", OConstants.CATALAN);
0466     localsMap.put("co", OConstants.CORSICAN);
0467     localsMap.put("cs", OConstants.CZECH);
0468     localsMap.put("cy", OConstants.WELSH);
0469     localsMap.put("da", OConstants.DANISH);
0470     localsMap.put("de", OConstants.GERMAN);
0471     localsMap.put("dz", OConstants.BHUTANI);
0472     localsMap.put("el", OConstants.GREEK);
0473     localsMap.put("en", OConstants.ENGLISH);
0474     localsMap.put("eo", OConstants.ESPERANTO);
0475     localsMap.put("es", OConstants.SPANISH);
0476     localsMap.put("et", OConstants.ESTONIAN);
0477     localsMap.put("eu", OConstants.BASQUE);
0478     localsMap.put("fa", OConstants.PERSIAN);
0479     localsMap.put("fi", OConstants.FINNISH);
0480     localsMap.put("fj", OConstants.FIJI);
0481     localsMap.put("fo", OConstants.FAROESE);
0482     localsMap.put("fr", OConstants.FRENCH);
0483     localsMap.put("fy", OConstants.FRISIAN);
0484     localsMap.put("ga", OConstants.IRISH);
0485     localsMap.put("gd", OConstants.SCOTS);
0486     localsMap.put("gl", OConstants.GALICIAN);
0487     localsMap.put("gn", OConstants.GUARANI);
0488     localsMap.put("gu", OConstants.GUJARATI);
0489     localsMap.put("ha", OConstants.HAUSA);
0490     localsMap.put("he", OConstants.HEBREW);
0491     localsMap.put("hi", OConstants.HINDI);
0492     localsMap.put("hr", OConstants.CROATIAN);
0493     localsMap.put("hu", OConstants.HUNGARIAN);
0494     localsMap.put("hy", OConstants.ARMENIAN);
0495     localsMap.put("ia", OConstants.INTERLINGUA);
0496     localsMap.put("id", OConstants.INDONESIAN);
0497     localsMap.put("ie", OConstants.INTERLINGUE);
0498     localsMap.put("ik", OConstants.INUPIAK);
0499     localsMap.put("is", OConstants.ICELANDIC);
0500     localsMap.put("it", OConstants.ITALIAN);
0501     localsMap.put("iu", OConstants.INUKTITUT);
0502     localsMap.put("ja", OConstants.JAPANESE);
0503     localsMap.put("jw", OConstants.JAVANESE);
0504     localsMap.put("ka", OConstants.GEORGIAN);
0505     localsMap.put("kk", OConstants.KAZAKH);
0506     localsMap.put("kl", OConstants.GREENLANDIC);
0507     localsMap.put("km", OConstants.CAMBODIAN);
0508     localsMap.put("kn", OConstants.KANNADA);
0509     localsMap.put("ko", OConstants.KOREAN);
0510     localsMap.put("ks", OConstants.KASHMIRI);
0511     localsMap.put("ku", OConstants.KURDISH);
0512     localsMap.put("ky", OConstants.KIRGHIZ);
0513     localsMap.put("la", OConstants.LATIN);
0514     localsMap.put("ln", OConstants.LINGALA);
0515     localsMap.put("lo", OConstants.LAOTHIAN);
0516     localsMap.put("lt", OConstants.LITHUANIAN);
0517     localsMap.put("lv", OConstants.LATVIAN);
0518     localsMap.put("mg", OConstants.MALAGASY);
0519     localsMap.put("mi", OConstants.MAORI);
0520     localsMap.put("mk", OConstants.MACEDONIAN);
0521     localsMap.put("ml", OConstants.MALAYALAM);
0522     localsMap.put("mn", OConstants.MONGOLIAN);
0523     localsMap.put("mo", OConstants.MOLDAVIAN);
0524     localsMap.put("mr", OConstants.MARATHI);
0525     localsMap.put("ms", OConstants.MALAY);
0526     localsMap.put("mt", OConstants.MALTESE);
0527     localsMap.put("my", OConstants.BURMESE);
0528     localsMap.put("na", OConstants.NAURU);
0529     localsMap.put("ne", OConstants.NEPALI);
0530     localsMap.put("nl", OConstants.DUTCH);
0531     localsMap.put("no", OConstants.NORWEGIAN);
0532     localsMap.put("oc", OConstants.OCCITAN);
0533     localsMap.put("om", OConstants.OROMO);
0534     localsMap.put("or", OConstants.ORIYA);
0535     localsMap.put("pa", OConstants.PUNJABI);
0536     localsMap.put("pl", OConstants.POLISH);
0537     localsMap.put("ps", OConstants.PASHTO);
0538     localsMap.put("pt", OConstants.PORTUGUESE);
0539     localsMap.put("qu", OConstants.QUECHUA);
0540     localsMap.put("rm", OConstants.RHAETO_ROMANCE);
0541     localsMap.put("rn", OConstants.KIRUNDI);
0542     localsMap.put("ro", OConstants.ROMANIAN);
0543     localsMap.put("ru", OConstants.RUSSIAN);
0544     localsMap.put("rw", OConstants.KINYARWANDA);
0545     localsMap.put("sa", OConstants.SANSKRIT);
0546     localsMap.put("sd", OConstants.SINDHI);
0547     localsMap.put("sg", OConstants.SANGHO);
0548     localsMap.put("sh", OConstants.SERBO_CROATIAN);
0549     localsMap.put("si", OConstants.SINHALESE);
0550     localsMap.put("sk", OConstants.SLOVAK);
0551     localsMap.put("sl", OConstants.SLOVENIAN);
0552     localsMap.put("sm", OConstants.SAMOAN);
0553     localsMap.put("sn", OConstants.SHONA);
0554     localsMap.put("so", OConstants.SOMALI);
0555     localsMap.put("sq", OConstants.ALBANIAN);
0556     localsMap.put("sr", OConstants.SERBIAN);
0557     localsMap.put("ss", OConstants.SISWATI);
0558     localsMap.put("st", OConstants.SESOTHO);
0559     localsMap.put("su", OConstants.SUNDANESE);
0560     localsMap.put("sv", OConstants.SWEDISH);
0561     localsMap.put("sw", OConstants.SWAHILI);
0562     localsMap.put("ta", OConstants.TAMIL);
0563     localsMap.put("te", OConstants.TELUGU);
0564     localsMap.put("tg", OConstants.TAJIK);
0565     localsMap.put("th", OConstants.THAI);
0566     localsMap.put("ti", OConstants.TIGRINYA);
0567     localsMap.put("tk", OConstants.TURKMEN);
0568     localsMap.put("tl", OConstants.TAGALOG);
0569     localsMap.put("tn", OConstants.SETSWANA);
0570     localsMap.put("to", OConstants.TONGA);
0571     localsMap.put("tr", OConstants.TURKISH);
0572     localsMap.put("ts", OConstants.TSONGA);
0573     localsMap.put("tt", OConstants.TATAR);
0574     localsMap.put("tw", OConstants.TWI);
0575     localsMap.put("ug", OConstants.UIGHUR);
0576     localsMap.put("uk", OConstants.UKRAINIAN);
0577     localsMap.put("ur", OConstants.URDU);
0578     localsMap.put("uz", OConstants.UZBEK);
0579     localsMap.put("vi", OConstants.VIETNAMESE);
0580     localsMap.put("vo", OConstants.VOLAPUK);
0581     localsMap.put("wo", OConstants.WOLOF);
0582     localsMap.put("xh", OConstants.XHOSA);
0583     localsMap.put("yi", OConstants.YIDDISH);
0584     localsMap.put("yo", OConstants.YORUBA);
0585     localsMap.put("za", OConstants.ZHUANG);
0586     localsMap.put("zh", OConstants.CHINESE);
0587     localsMap.put("zu", OConstants.ZULU);
0588   }
0589 
0590   /**
0591    * Gets the respective datatype for the given datatype URI. If the URI
0592    * is invalid, the method returns null.
0593    
0594    @param datatypeURI
0595    @return
0596    */
0597   public static DataType getDataType(String datatypeURI) {
0598     return datatypeMap.get(datatypeURI);
0599   }
0600 
0601   /**
0602    * Gets the respective locale for the given 2 character language code.
0603    * If the code doesn't match, the method returns null.
0604    
0605    @param languageCode
0606    @return
0607    */
0608   public static Locale getLocale(String languageCode) {
0609     if(languageCode == nullreturn null;
0610     return localsMap.get(languageCode.toLowerCase());
0611   }
0612 
0613 }
0614 
0615 /**
0616  * Boolean DataType
0617  
0618  @author niraj
0619  */
0620 class BooleanDT extends DataType {
0621   public BooleanDT(OURI xmlSchemaURI) {
0622     super(xmlSchemaURI);
0623   }
0624   public BooleanDT(String xmlSchemaURIString) {
0625     super(xmlSchemaURIString);
0626   }
0627 
0628   /**
0629    * A Method to validate the boolean value
0630    */
0631   public boolean isValidValue(String value) {
0632     try {
0633       if((Boolean.parseBoolean(value"").equalsIgnoreCase(value))
0634         return true;
0635       return false;
0636     }
0637     catch(Exception e) {
0638       return false;
0639     }
0640   }
0641 }
0642 
0643 /**
0644  * Byte DataType
0645  
0646  @author niraj
0647  
0648  */
0649 class ByteDT extends DataType {
0650   public ByteDT(OURI xmlSchemaURI) {
0651     super(xmlSchemaURI);
0652   }
0653   public ByteDT(String xmlSchemaURIString) {
0654     super(xmlSchemaURIString);
0655   }
0656 
0657   /**
0658    * Methods check if the value is valid for the datatype
0659    */
0660   public boolean isValidValue(String value) {
0661     try {
0662       if((Byte.parseByte(value"").equalsIgnoreCase(value)) return true;
0663       ;
0664       return false;
0665     }
0666     catch(Exception e) {
0667       return false;
0668     }
0669   }
0670 }
0671 
0672 /**
0673  * Double Datatype
0674  
0675  @author niraj
0676  
0677  */
0678 class DoubleDT extends DataType {
0679   public DoubleDT(OURI xmlSchemaURI) {
0680     super(xmlSchemaURI);
0681   }
0682   public DoubleDT(String xmlSchemaURIString) {
0683     super(xmlSchemaURIString);
0684   }
0685 
0686   /**
0687    * Methods check if the value is valid for the datatype
0688    */
0689   public boolean isValidValue(String value) {
0690     try {
0691       Double.parseDouble(value);
0692       return true;
0693     }
0694     catch(Exception e) {
0695       return false;
0696     }
0697   }
0698 }
0699 
0700 class DateDT extends DataType {
0701   public DateDT(OURI xmlSchemaURI) {
0702     super(xmlSchemaURI);
0703   }
0704   public DateDT(String xmlSchemaURIString) {
0705     super(xmlSchemaURIString);
0706   }
0707 
0708   /**
0709    * Methods check if the value is valid for the datatype
0710    */
0711   public boolean isValidValue(String value) {
0712     try {
0713       XMLGregorianCalendar cal = datatypeFactory.newXMLGregorianCalendar(value);
0714       String schema = cal.getXMLSchemaType().getNamespaceURI() "#"
0715               + cal.getXMLSchemaType().getLocalPart();
0716       return schema.equals(getXmlSchemaURIString());
0717     }
0718     catch(Exception e) {
0719       return false;
0720     }
0721   }
0722 }
0723 
0724 class DateTimeDT extends DataType {
0725   public DateTimeDT(OURI xmlSchemaURI) {
0726     super(xmlSchemaURI);
0727   }
0728   public DateTimeDT(String xmlSchemaURIString) {
0729     super(xmlSchemaURIString);
0730   }
0731 
0732   /**
0733    * Methods check if the value is valid for the datatype
0734    */
0735   public boolean isValidValue(String value) {
0736     try {
0737       XMLGregorianCalendar cal = datatypeFactory.newXMLGregorianCalendar(value);
0738       String schema = cal.getXMLSchemaType().getNamespaceURI() "#"
0739               + cal.getXMLSchemaType().getLocalPart();
0740       return schema.equals(getXmlSchemaURIString());
0741     }
0742     catch(Exception e) {
0743       e.printStackTrace();
0744       return false;
0745     }
0746   }
0747 }
0748 
0749 class TimeDT extends DataType {
0750   public TimeDT(OURI xmlSchemaURI) {
0751     super(xmlSchemaURI);
0752   }
0753   public TimeDT(String xmlSchemaURIString) {
0754     super(xmlSchemaURIString);
0755   }
0756 
0757   /**
0758    * Methods check if the value is valid for the datatype
0759    */
0760   public boolean isValidValue(String value) {
0761     try {
0762       XMLGregorianCalendar cal = datatypeFactory.newXMLGregorianCalendar(value);
0763       String schema = cal.getXMLSchemaType().getNamespaceURI() "#"
0764               + cal.getXMLSchemaType().getLocalPart();
0765       return schema.equals(getXmlSchemaURIString());
0766     }
0767     catch(Exception e) {
0768       return false;
0769     }
0770   }
0771 }
0772 
0773 /**
0774  * Long Datatype
0775  
0776  @author niraj
0777  
0778  */
0779 class LongDT extends DataType {
0780   public LongDT(OURI xmlSchemaURI) {
0781     super(xmlSchemaURI);
0782   }
0783   public LongDT(String xmlSchemaURIString) {
0784     super(xmlSchemaURIString);
0785   }
0786 
0787   /**
0788    * Methods check if the value is valid for the datatype
0789    */
0790   public boolean isValidValue(String value) {
0791     try {
0792       if((Long.parseLong(value"").equalsIgnoreCase(value)) return true;
0793       ;
0794       return false;
0795     }
0796     catch(Exception e) {
0797       return false;
0798     }
0799   }
0800 }
0801 
0802 /**
0803  * Float Datatype
0804  
0805  @author niraj
0806  
0807  */
0808 class FloatDT extends DataType {
0809   public FloatDT(OURI xmlSchemaURI) {
0810     super(xmlSchemaURI);
0811   }
0812   public FloatDT(String xmlSchemaURIString) {
0813     super(xmlSchemaURIString);
0814   }
0815 
0816   /**
0817    * Methods check if the value is valid for the datatype
0818    */
0819   public boolean isValidValue(String value) {
0820     try {
0821       Float.parseFloat(value);
0822       return true;
0823     }
0824     catch(Exception e) {
0825       return false;
0826     }
0827   }
0828 }
0829 
0830 /**
0831  * Integer Datatype
0832  
0833  @author niraj
0834  
0835  */
0836 class IntegerDT extends DataType {
0837   public IntegerDT(OURI xmlSchemaURI) {
0838     super(xmlSchemaURI);
0839   }
0840   public IntegerDT(String xmlSchemaURIString) {
0841     super(xmlSchemaURIString);
0842   }
0843 
0844   /**
0845    * Methods check if the value is valid for the datatype
0846    */
0847   public boolean isValidValue(String value) {
0848     try {
0849       if((Integer.parseInt(value"").equalsIgnoreCase(value)) return true;
0850       ;
0851       return false;
0852     }
0853     catch(Exception e) {
0854       return false;
0855     }
0856   }
0857 }
0858 
0859 /**
0860  * Negative Integer Datatype
0861  
0862  @author niraj
0863  
0864  */
0865 class NegativeIntegerDT extends DataType {
0866   public NegativeIntegerDT(OURI xmlSchemaURI) {
0867     super(xmlSchemaURI);
0868   }
0869   public NegativeIntegerDT(String xmlSchemaURIString) {
0870     super(xmlSchemaURIString);
0871   }
0872 
0873   /**
0874    * Methods check if the value is valid for the datatype
0875    */
0876   public boolean isValidValue(String value) {
0877     try {
0878       int intVal = Integer.parseInt(value);
0879       if(!(intVal + "").equalsIgnoreCase(value)) return false;
0880       return intVal < 0;
0881     }
0882     catch(Exception e) {
0883       return false;
0884     }
0885   }
0886 }
0887 
0888 /**
0889  * NonNegativeInteger Datatype
0890  
0891  @author niraj
0892  
0893  */
0894 class NonNegativeIntegerDT extends DataType {
0895   public NonNegativeIntegerDT(OURI xmlSchemaURI) {
0896     super(xmlSchemaURI);
0897   }
0898   public NonNegativeIntegerDT(String xmlSchemaURIString) {
0899     super(xmlSchemaURIString);
0900   }
0901 
0902   /**
0903    * Methods check if the value is valid for the datatype
0904    */
0905   public boolean isValidValue(String value) {
0906     try {
0907       int intVal = Integer.parseInt(value);
0908       if(!(intVal + "").equalsIgnoreCase(value)) return false;
0909       return intVal > -1;
0910     }
0911     catch(Exception e) {
0912       return false;
0913     }
0914   }
0915 }
0916 
0917 /**
0918  * Short Datatype
0919  
0920  @author niraj
0921  
0922  */
0923 class ShortDT extends DataType {
0924   public ShortDT(OURI xmlSchemaURI) {
0925     super(xmlSchemaURI);
0926   }
0927   public ShortDT(String xmlSchemaURIString) {
0928     super(xmlSchemaURIString);
0929   }
0930 
0931   /**
0932    * Methods check if the value is valid for the datatype
0933    */
0934   public boolean isValidValue(String value) {
0935     try {
0936       short intVal = Short.parseShort(value);
0937       if(!(intVal + "").equalsIgnoreCase(value)) return false;
0938       return true;
0939     }
0940     catch(Exception e) {
0941       return false;
0942     }
0943   }
0944 }
0945 
0946 /**
0947  * UnsignedByte Datatype
0948  
0949  @author niraj
0950  
0951  */
0952 class UnsignedByteDT extends DataType {
0953   public UnsignedByteDT(OURI xmlSchemaURI) {
0954     super(xmlSchemaURI);
0955   }
0956   public UnsignedByteDT(String xmlSchemaURIString) {
0957     super(xmlSchemaURIString);
0958   }
0959 
0960   /**
0961    * Methods check if the value is valid for the datatype
0962    */
0963   public boolean isValidValue(String value) {
0964     try {
0965       byte byteVal = Byte.parseByte(value);
0966       if(!(byteVal + "").equalsIgnoreCase(value)) return false;
0967       return byteVal > -1;
0968     }
0969     catch(Exception e) {
0970       return false;
0971     }
0972   }
0973 }
0974 
0975 /**
0976  * UnsignedLong Datatype
0977  
0978  @author niraj
0979  
0980  */
0981 class UnsignedLongDT extends DataType {
0982   public UnsignedLongDT(OURI xmlSchemaURI) {
0983     super(xmlSchemaURI);
0984   }
0985   public UnsignedLongDT(String xmlSchemaURIString) {
0986     super(xmlSchemaURIString);
0987   }
0988 
0989   /**
0990    * Methods check if the value is valid for the datatype
0991    */
0992   public boolean isValidValue(String value) {
0993     try {
0994       long longVal = Long.parseLong(value);
0995       if(!(longVal + "").equalsIgnoreCase(value)) return false;
0996       return longVal > -1;
0997     }
0998     catch(Exception e) {
0999       return false;
1000     }
1001   }
1002 }
1003 
1004 /**
1005  * UnsignedShort Datatype
1006  
1007  @author niraj
1008  
1009  */
1010 class UnsignedShortDT extends DataType {
1011   public UnsignedShortDT(OURI xmlSchemaURI) {
1012     super(xmlSchemaURI);
1013   }
1014   public UnsignedShortDT(String xmlSchemaURIString) {
1015     super(xmlSchemaURIString);
1016   }
1017 
1018   /**
1019    * Methods check if the value is valid for the datatype
1020    */
1021   public boolean isValidValue(String value) {
1022     try {
1023       short shortVal = Short.parseShort(value);
1024       if(!(shortVal + "").equalsIgnoreCase(value)) return false;
1025       return shortVal > -1;
1026     }
1027     catch(Exception e) {
1028       return false;
1029     }
1030   }
1031 
1032 }