001 /* 002 * Copyright (c) 2006 Henri Sivonen 003 * 004 * Permission is hereby granted, free of charge, to any person obtaining a 005 * copy of this software and associated documentation files (the "Software"), 006 * to deal in the Software without restriction, including without limitation 007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 008 * and/or sell copies of the Software, and to permit persons to whom the 009 * Software is furnished to do so, subject to the following conditions: 010 * 011 * The above copyright notice and this permission notice shall be included in 012 * all copies or substantial portions of the Software. 013 * 014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 017 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 019 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 020 * DEALINGS IN THE SOFTWARE. 021 */ 022 023 package org.whattf.datatype; 024 025 import org.relaxng.datatype.Datatype; 026 import org.relaxng.datatype.DatatypeBuilder; 027 import org.relaxng.datatype.DatatypeException; 028 import org.relaxng.datatype.DatatypeLibrary; 029 import org.relaxng.datatype.helpers.ParameterlessDatatypeBuilder; 030 031 /** 032 * Factory for HTML5 datatypes. 033 * @version $Id: Html5DatatypeLibrary.java,v 1.6 2006/11/21 09:49:14 hsivonen Exp $ 034 * @author hsivonen 035 */ 036 public class Html5DatatypeLibrary implements DatatypeLibrary { 037 038 public Html5DatatypeLibrary() { 039 super(); 040 } 041 042 /** 043 * Returns a <code>DatatypeBuilder</code> for a named datatype. This method is 044 * unnecessary for direct access. Just use <code>createDatatype</code>. 045 * @param baseTypeLocalName the local name 046 * @return a <code>ParameterlessDatatypeBuilder</code> for the local name 047 * @see org.relaxng.datatype.DatatypeLibrary#createDatatypeBuilder(java.lang.String) 048 */ 049 public DatatypeBuilder createDatatypeBuilder(String baseTypeLocalName) 050 throws DatatypeException { 051 return new ParameterlessDatatypeBuilder(createDatatype(baseTypeLocalName)); 052 } 053 054 /** 055 * The factory method for the datatypes of this library. 056 * @param typeLocalName the local name 057 * @return a <code>Datatype</code> instance for the local name 058 * @see org.relaxng.datatype.DatatypeLibrary#createDatatype(java.lang.String) 059 */ 060 public Datatype createDatatype(String typeLocalName) 061 throws DatatypeException { 062 if ("ID".equals(typeLocalName)) { 063 return new Id(); 064 } else if ("IDREF".equals(typeLocalName)) { 065 return Idref.THE_INSTANCE; 066 } else if ("IDREFS".equals(typeLocalName)) { 067 return Idrefs.THE_INSTANCE; 068 } else if ("pattern".equals(typeLocalName)) { 069 return Pattern.THE_INSTANCE; 070 } else if ("datetime".equals(typeLocalName)) { 071 return Datetime.THE_INSTANCE; 072 } else if ("datetime-local".equals(typeLocalName)) { 073 return DatetimeLocal.THE_INSTANCE; 074 } else if ("datetime-tz".equals(typeLocalName)) { 075 return DatetimeTz.THE_INSTANCE; 076 } else if ("date-or-time".equals(typeLocalName)) { 077 return DateOrTime.THE_INSTANCE; 078 } else if ("date-or-time-content".equals(typeLocalName)) { 079 return DateOrTimeContent.THE_INSTANCE; 080 } else if ("date".equals(typeLocalName)) { 081 return Date.THE_INSTANCE; 082 } else if ("month".equals(typeLocalName)) { 083 return Month.THE_INSTANCE; 084 } else if ("week".equals(typeLocalName)) { 085 return Week.THE_INSTANCE; 086 } else if ("time".equals(typeLocalName)) { 087 return Time.THE_INSTANCE; 088 } else if ("iri".equals(typeLocalName)) { 089 return Iri.THE_INSTANCE; 090 } else if ("iri-ref".equals(typeLocalName)) { 091 return IriRef.THE_INSTANCE; 092 } else if ("ratio".equals(typeLocalName)) { 093 return Ratio.THE_INSTANCE; 094 } 095 throw new DatatypeException("Unknown local name for datatype: " + typeLocalName); 096 } 097 098 }