// Path: com/sun/stylesheet/StylesheetException.java
// public class StylesheetException extends RuntimeException {
//     /** Creates a new <code>StylesheetException</code>. */
//     public StylesheetException() {
//     }
//     
//     
//     /** 
//      * Creates a new <code>StylesheetException</code> with the specified detail 
//      * message. 
//      *
//      *@param msg the exception's detail message
//      */
//     public StylesheetException(String msg) {
//         super(msg);
//     }
// 
//  
//     /**
//      * Creates a new <code>StylesheetException</code> with the specified cause.
//      *
//      *@param initCause the exception's initCause
//      */
//     public StylesheetException(Throwable initCause) {
//         super(initCause);
//     }
// 
// 
//     /**
//      * Creates a new <code>StylesheetException</code> with the specified detail 
//      * message and cause.
//      *
//      *@param msg the exception's detail message
//      *@param initCause the exception's initCause
//      */
//     public StylesheetException(String msg, Throwable initCause) {
//         super(msg, initCause);
//     }
// }


import java.lang.reflect.Field;
import com.sun.stylesheet.StylesheetException;

/*
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */

/* Modified by Volker Härtel, 8 Dec 2011 */ package com.sun.stylesheet.types;



/**
 * Converts string representations of the various "simple" Java types, such as 
 * <code>int</code>, <code>float</code>, and <code>boolean</code>, into their 
 * correct types.
 * <p>
 * <code>short</code>, <code>long</code>, <code>float</code>, and
 * <code>double</code> are simply parsed using their respective parse methods, 
 * such as <code>Float.parseFloat()</code>.
 * <p>
 * <code>int</code> supports all strings recognized by
 * <code>Integer.parseInt()</code>, and
 * additionally supports references to constant fields such as 
 * <code>Font.BOLD</code>.  Classes in <code>java.awt</code>, 
 * <code>javax.swing</code>, and <code>javax.swing.border</code> can be
 * referenced by their simple, unqualified names, while classes in other 
 * packages must be fully named.
 * <p>
 * <code>char</code> requires the input string to be exactly one character long, 
 * and will throw an exception otherwise.
 * <p>
 * <code>boolean</code> requires the input string to be either "true" or "false" 
 * (case insensitive).
 *
 *@author Ethan Nicholas
 */
public class PrimitiveConverter implements TypeConverter<Object> {
    private Class type;
    
    
    public PrimitiveConverter(Class type) {
        this.type = type;
    }
    
    
    public Object convertFromString(String string) {
        try {
            if (type == int.class || type == Integer.class) {
                try {
                    return Integer.valueOf(string);
                }
                catch (NumberFormatException e) {
                    return parseConstant(string);
                }
            }
            else if (type == boolean.class || type == Boolean.class) {
                if (string.toLowerCase().equals("true"))
                    return Boolean.TRUE;
                else if (string.toLowerCase().equals("false"))
                    return Boolean.FALSE;
                else

// Path: com/sun/stylesheet/StylesheetException.java
// public class StylesheetException extends RuntimeException {
//     /** Creates a new <code>StylesheetException</code>. */
//     public StylesheetException() {
//     }
//     
//     
//     /** 
//      * Creates a new <code>StylesheetException</code> with the specified detail 
//      * message. 
//      *
//      *@param msg the exception's detail message
//      */
//     public StylesheetException(String msg) {
//         super(msg);
//     }
// 
//  
//     /**
//      * Creates a new <code>StylesheetException</code> with the specified cause.
//      *
//      *@param initCause the exception's initCause
//      */
//     public StylesheetException(Throwable initCause) {
//         super(initCause);
//     }
// 
// 
//     /**
//      * Creates a new <code>StylesheetException</code> with the specified detail 
//      * message and cause.
//      *
//      *@param msg the exception's detail message
//      *@param initCause the exception's initCause
//      */
//     public StylesheetException(String msg, Throwable initCause) {
//         super(msg, initCause);
//     }
// }


// Path: com/sun/stylesheet/types/PrimitiveConverter.java
import java.lang.reflect.Field;
import com.sun.stylesheet.StylesheetException;

/*
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */

/* Modified by Volker Härtel, 8 Dec 2011 */ package com.sun.stylesheet.types;



/**
 * Converts string representations of the various "simple" Java types, such as 
 * <code>int</code>, <code>float</code>, and <code>boolean</code>, into their 
 * correct types.
 * <p>
 * <code>short</code>, <code>long</code>, <code>float</code>, and
 * <code>double</code> are simply parsed using their respective parse methods, 
 * such as <code>Float.parseFloat()</code>.
 * <p>
 * <code>int</code> supports all strings recognized by
 * <code>Integer.parseInt()</code>, and
 * additionally supports references to constant fields such as 
 * <code>Font.BOLD</code>.  Classes in <code>java.awt</code>, 
 * <code>javax.swing</code>, and <code>javax.swing.border</code> can be
 * referenced by their simple, unqualified names, while classes in other 
 * packages must be fully named.
 * <p>
 * <code>char</code> requires the input string to be exactly one character long, 
 * and will throw an exception otherwise.
 * <p>
 * <code>boolean</code> requires the input string to be either "true" or "false" 
 * (case insensitive).
 *
 *@author Ethan Nicholas
 */
public class PrimitiveConverter implements TypeConverter<Object> {
    private Class type;
    
    
    public PrimitiveConverter(Class type) {
        this.type = type;
    }
    
    
    public Object convertFromString(String string) {
        try {
            if (type == int.class || type == Integer.class) {
                try {
                    return Integer.valueOf(string);
                }
                catch (NumberFormatException e) {
                    return parseConstant(string);
                }
            }
            else if (type == boolean.class || type == Boolean.class) {
                if (string.toLowerCase().equals("true"))
                    return Boolean.TRUE;
                else if (string.toLowerCase().equals("false"))
                    return Boolean.FALSE;
                else

                    throw new StylesheetException("expected 'true' or 'false'" +
