01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.data.shapefile;
17:
18: /**
19: *
20: * @author Ian Schneider
21: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/ShapefileUtilities.java $
22: */
23: public class ShapefileUtilities {
24:
25: private ShapefileUtilities() {
26: }
27:
28: /**
29: * Marshal a given Object into the given Class.
30: */
31: public static Object forAttribute(final Object o, Class colType) {
32: Object object;
33: if (colType == Integer.class) {
34: object = o;
35: } else if ((colType == Short.class) || (colType == Byte.class)) {
36: object = new Integer(((Number) o).intValue());
37: } else if (colType == Double.class) {
38: object = o;
39: } else if (colType == Float.class) {
40: object = new Double(((Number) o).doubleValue());
41: } else if (Number.class.isAssignableFrom(colType)) {
42: object = o;
43: } else if (colType == String.class) {
44: if (o == null) {
45: object = o;
46: } else {
47: object = o.toString();
48: }
49: } else if (colType == Boolean.class) {
50: object = o;
51: } else if (java.util.Date.class.isAssignableFrom(colType)) {
52: object = o;
53: } else {
54: if (colType != null) {
55: throw new RuntimeException("Cannot convert "
56: + colType.getName());
57: } else {
58: throw new RuntimeException("Null Class for conversion");
59: }
60: }
61:
62: return object;
63: }
64:
65: }
|