/*
 * Copyright (c) 2013-2015 Josef Hardi <josef.hardi@gmail.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.obidea.semantika.datatype;

import com.obidea.semantika.datatype.exception.InvalidLexicalFormException;
import com.obidea.semantika.datatype.primitive.XsdDecimal;

public abstract class AbstractDerivedDecimalType extends AbstractXmlType<Number>
{
   protected AbstractDerivedDecimalType(String name)
   {
      super(name);
   }

   @Override
   public IDatatype<?> getPrimitiveDatatype()
   {
      return XsdDecimal.getInstance();
   }

   @Override
   public Number getValue(String lexicalForm)
   {
      return parseLexicalForm(lexicalForm);
   }

   @Override
   public boolean isPrimitive()
   {
      return false;
   }

   /**
    * Parse and validate a lexical form of the literal.
    * 
    * @param lexicalForm
    *           the typing form of the literal.
    * @return A <code>Number</code> representation of the literal
    * @throws InvalidLexicalFormException
    *            if the literal form is invalid or the value is out of range
    */
   protected abstract Number parseLexicalForm(String lexicalForm) throws InvalidLexicalFormException;
}
