]> gerrit.simantics Code Review - simantics/platform.git/blob
cd745a5230bd97b0c7bec4631dee01d4d822a61b
[simantics/platform.git] /
1 /*******************************************************************************
2  * Copyright (c) 2007, 2013 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.objmap.graph.annotations.factories;
13
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.layer0.Layer0;
17
18 public class DataTypeUtils {
19     
20     public static Resource dataTypeOfClass(ReadGraph g, Class<?> clazz) {
21         Layer0 b = Layer0.getInstance(g);
22         if(clazz.equals(Double.class) || clazz.equals(double.class))
23             return b.Double;
24         else if(clazz.equals(String.class))
25             return b.String;
26         else if(clazz.equals(Integer.class) || clazz.equals(int.class))
27             return b.Integer;
28         else if(clazz.equals(Float.class) || clazz.equals(float.class))
29             return b.Float;
30         else if(clazz.equals(Boolean.class) || clazz.equals(boolean.class))
31             return b.Boolean;
32         else if(clazz.equals(Long.class) || clazz.equals(long.class))
33             return b.Long;
34         else if(clazz.equals(Byte.class) || clazz.equals(byte.class))
35             return b.Byte;
36         
37         else if(clazz.equals(double[].class))
38             return b.DoubleArray;
39         else if(clazz.equals(int[].class))
40             return b.IntegerArray;
41         else if(clazz.equals(byte[].class))
42             return b.ByteArray;
43         else if(clazz.equals(float[].class))
44             return b.FloatArray;
45         else if(clazz.equals(boolean[].class))
46             return b.BooleanArray;
47         else if(clazz.equals(String[].class))
48             return b.StringArray;
49         else if(clazz.equals(long[].class))
50             return b.LongArray;
51         else {
52                 System.out.println("Couldn't find a data type for " + clazz);
53             return null;
54         }
55     }
56     
57 }