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