1
/* ========================================================================
2
* JCommon : a free general purpose class library for the Java(tm) platform
3
* ========================================================================
5
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
7
* Project Info: http://www.jfree.org/jcommon/index.html
9
* This library is free software; you can redistribute it and/or modify it
10
* under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2.1 of the License, or
12
* (at your option) any later version.
14
* This library is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
* License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25
* in the United States and other countries.]
27
* ---------------------
28
* BasicTypeSupport.java
29
* ---------------------
30
* (C)opyright 2003-2005, by Thomas Morgner and Contributors.
32
* Original Author: Thomas Morgner;
33
* Contributor(s): David Gilbert (for Object Refinery Limited);
35
* $Id: BasicTypeSupport.java,v 1.4 2005/10/18 13:33:53 mungady Exp $
39
* 12-Nov-2003 : Initial version (TM);
40
* 26-Nov-2003 : Updated header and Javadocs (DG);
44
package org.jfree.xml.util;
46
import org.jfree.xml.attributehandlers.BooleanAttributeHandler;
47
import org.jfree.xml.attributehandlers.ByteAttributeHandler;
48
import org.jfree.xml.attributehandlers.DoubleAttributeHandler;
49
import org.jfree.xml.attributehandlers.FloatAttributeHandler;
50
import org.jfree.xml.attributehandlers.IntegerAttributeHandler;
51
import org.jfree.xml.attributehandlers.LongAttributeHandler;
52
import org.jfree.xml.attributehandlers.ShortAttributeHandler;
53
import org.jfree.xml.attributehandlers.StringAttributeHandler;
56
* A class that contains information about some basic types.
58
public class BasicTypeSupport {
60
private BasicTypeSupport ()
65
* Returns the fully qualified class name for the attribute handler for a property of
66
* the specified class.
68
* @param c the property class.
70
* @return the attribute handler class name.
72
public static String getHandlerClass(final Class c) {
73
if (c.equals(Integer.class) || c.equals(Integer.TYPE)) {
74
return IntegerAttributeHandler.class.getName();
76
if (c.equals(Short.class) || c.equals(Short.TYPE)) {
77
return ShortAttributeHandler.class.getName();
79
if (c.equals(Long.class) || c.equals(Long.TYPE)) {
80
return LongAttributeHandler.class.getName();
82
if (c.equals(Boolean.class) || c.equals(Boolean.TYPE)) {
83
return BooleanAttributeHandler.class.getName();
85
if (c.equals(Float.class) || c.equals(Float.TYPE)) {
86
return FloatAttributeHandler.class.getName();
88
if (c.equals(Double.class) || c.equals(Double.TYPE)) {
89
return DoubleAttributeHandler.class.getName();
91
if (c.equals(Byte.class) || c.equals(Byte.TYPE)) {
92
return ByteAttributeHandler.class.getName();
94
// string can also be handled directly ...
95
if (c.equals(String.class)) {
96
return StringAttributeHandler.class.getName();
98
throw new IllegalArgumentException("BasicTypeSupport.getHandlerClass(Class): "
99
+ "this is no attribute type.");
103
* Returns <code>true</code> if the specified class is a "basic" type, and <code>false</code>
104
* otherwise. Basic types are written as attributes (rather than elements) in XML output.
106
* @param c the class.
110
public static boolean isBasicDataType (final Class c) {
111
if (c.equals(Integer.class) || c.equals(Integer.TYPE)) {
114
if (c.equals(Short.class) || c.equals(Short.TYPE)) {
117
if (c.equals(Long.class) || c.equals(Long.TYPE)) {
120
if (c.equals(Boolean.class) || c.equals(Boolean.TYPE)) {
123
if (c.equals(Float.class) || c.equals(Float.TYPE)) {
126
if (c.equals(Double.class) || c.equals(Double.TYPE)) {
129
if (c.equals(Byte.class) || c.equals(Byte.TYPE)) {
132
// string can also be handled directly ...
133
if (c.equals(String.class)) {
140
* Returns the class for a given primitive class type.
142
* @param className the primitive class name.
146
public static Class getClassRepresentation(final String className) {
147
if (className.equals("::double")) {
150
if (className.equals("::boolean")) {
153
if (className.equals("::int")) {
156
if (className.equals("::short")) {
159
if (className.equals("::long")) {
162
if (className.equals("::byte")) {
165
throw new IllegalArgumentException("This is none of my primitives.");