001    /**
002     * Java Gui Builder - A library to build GUIs using an XML file.
003     * Copyright 2002, 2003 (C) François Beausoleil
004     *
005     * This library is free software; you can redistribute it and/or
006     * modify it under the terms of the GNU Lesser General Public
007     * License as published by the Free Software Foundation; either
008     * version 2.1 of the License, or (at your option) any later version.
009     *
010     * This library is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013     * Lesser General Public License for more details.
014     *
015     * You should have received a copy of the GNU Lesser General Public
016     * License along with this library; if not, write to the Free Software
017     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018     */
019    
020    package jgb.handlers.swing;
021    
022    import org.xml.sax.SAXException;
023    
024    import java.util.Map;
025    
026    /**
027     * @since 0.1a
028     * @author Francois Beausoleil, <a href="mailto:fbos@users.sourceforge.net">fbos@users.sourceforge.net</a>
029     */
030    public class ValueTagHandler extends AbstractValueTagHandler {
031        /**
032         * The name of the data attribute.
033         */
034        protected static final String ATTR_DATA = "data";
035    
036        /**
037         * The name of the type attribute.
038         */
039        protected static final String ATTR_TYPE = "type";
040    
041        /**
042         * The value of type which instantiates a boolean value.
043         */
044        protected static final String BOOLEAN_VALUE = "boolean";
045    
046        /**
047         * The value of type which instantiates a byte value.
048         */
049        protected static final String BYTE_VALUE = "byte";
050    
051        /**
052         * The value of type which instantiates a short value.
053         */
054        protected static final String SHORT_VALUE = "short";
055    
056        /**
057         * The value of type which instantiates an int value.
058         */
059        protected static final String INT_VALUE = "int";
060    
061        /**
062         * The value of type which instantiates a long value.
063         */
064        protected static final String LONG_VALUE = "long";
065    
066        /**
067         * The value of type which instantiates a float value.
068         */
069        protected static final String FLOAT_VALUE = "float";
070    
071        /**
072         * The value of type which instantiates a double value.
073         */
074        protected static final String DOUBLE_VALUE = "double";
075    
076        /**
077         * The value of type which instantiates a char value.
078         */
079        protected static final String CHAR_VALUE = "char";
080    
081        /**
082         * The value of type which instantiates a {@link java.lang.String String}
083         * object.
084         */
085        protected static final String STRING_VALUE = "string";
086    
087        public void enterElement(Map atts) throws SAXException {
088            String type = (String)atts.get(ATTR_TYPE);
089            String value = (String)atts.get(ATTR_DATA);
090    
091            if (type.equals(BOOLEAN_VALUE)) {
092                updateContextParameters(Boolean.TYPE, new Boolean(value));
093            } else if (type.equals(BYTE_VALUE)) {
094                updateContextParameters(Byte.TYPE, new Byte(value));
095            } else if (type.equals(SHORT_VALUE)) {
096                updateContextParameters(Short.TYPE, new Short(value));
097            } else if (type.equals(INT_VALUE)) {
098                updateContextParameters(Integer.TYPE, new Integer(value));
099            } else if (type.equals(LONG_VALUE)) {
100                updateContextParameters(Long.TYPE, new Long(value));
101            } else if (type.equals(FLOAT_VALUE)) {
102                updateContextParameters(Float.TYPE, new Float(value));
103            } else if (type.equals(DOUBLE_VALUE)) {
104                updateContextParameters(Double.TYPE, new Double(value));
105            } else if (type.equals(CHAR_VALUE)) {
106                updateContextParameters(Character.TYPE, new Character(value.charAt(0)));
107            } else if (type.equals(STRING_VALUE)) {
108                updateContextParameters(String.class, value);
109            } else {
110                throwParsingException("Unrecognized type: " + type);
111            }
112        }
113    
114        protected void exitElement() throws SAXException {
115        }
116    }