]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/factory/JavaUtilBindingsProvider.java
Don't recompile all expressions if only one is modified
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / factory / JavaUtilBindingsProvider.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * 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.databoard.binding.factory;
13
14 import java.util.HashMap;
15 import java.util.HashSet;
16 import java.util.LinkedList;
17 import java.util.List;
18 import java.util.Map;
19 import java.util.PriorityQueue;
20 import java.util.Set;
21 import java.util.TreeMap;
22 import java.util.TreeSet;
23 import java.util.UUID;
24
25 import org.simantics.databoard.Datatypes;
26 import org.simantics.databoard.binding.Binding;
27 import org.simantics.databoard.binding.error.BindingConstructionException;
28 import org.simantics.databoard.binding.impl.ArrayListBinding;
29 import org.simantics.databoard.binding.impl.BooleanArrayBinding;
30 import org.simantics.databoard.binding.impl.ByteArrayBinding;
31 import org.simantics.databoard.binding.impl.DefaultMapBinding;
32 import org.simantics.databoard.binding.impl.DefaultSetBinding;
33 import org.simantics.databoard.binding.impl.DoubleArrayBinding;
34 import org.simantics.databoard.binding.impl.FloatArrayBinding;
35 import org.simantics.databoard.binding.impl.HashMapBinding;
36 import org.simantics.databoard.binding.impl.HashSetBinding;
37 import org.simantics.databoard.binding.impl.IntArrayBinding;
38 import org.simantics.databoard.binding.impl.LinkedListBinding;
39 import org.simantics.databoard.binding.impl.LongArrayBinding;
40 import org.simantics.databoard.binding.impl.ObjectArrayBinding;
41 import org.simantics.databoard.binding.impl.PriorityQueueBinding;
42 import org.simantics.databoard.binding.impl.ThrowableBinding;
43 import org.simantics.databoard.binding.impl.TreeMapBinding;
44 import org.simantics.databoard.binding.impl.TreeSetBinding;
45 import org.simantics.databoard.binding.impl.UUIDBinding;
46 import org.simantics.databoard.binding.reflection.BindingProvider;
47 import org.simantics.databoard.binding.reflection.BindingRequest;
48 import org.simantics.databoard.binding.reflection.ClassBindingFactory;
49 import org.simantics.databoard.binding.reflection.GenericArrayBinding;
50 import org.simantics.databoard.type.ArrayType;
51 import org.simantics.databoard.type.MapType;
52
53 /**
54  * This provider constructs Bindings for java.util classes.
55  * 
56  * @author toni.kalajainen
57  */
58 public class JavaUtilBindingsProvider implements BindingProvider {
59
60         @Override
61         public Binding provideBinding(ClassBindingFactory factory, BindingRequest request) throws BindingConstructionException {
62
63                 if ( UUID.class.isAssignableFrom( request.getClazz() ) ) {
64                         return new UUIDBinding();
65                 }
66                 
67                 if ( Throwable.class.isAssignableFrom( request.getClazz() ) ) {
68                         @SuppressWarnings("unchecked")
69                         Binding b = new ThrowableBinding( (Class<Throwable>) request.getClazz() ); 
70                         return b;
71                 }
72                 
73         if (request.getClazz().isArray()) {
74                 Class<?> c = request.getClazz();
75                 if (c.equals(boolean[].class)) return new BooleanArrayBinding(new ArrayType(), null);
76                 else if (c.equals(byte[].class)) return new ByteArrayBinding(new ArrayType(), null);
77                 else if (c.equals(double[].class)) return new DoubleArrayBinding(new ArrayType(), null);
78                 else if (c.equals(float[].class)) return new FloatArrayBinding(new ArrayType(), null);
79                 else if (c.equals(int[].class)) return new IntArrayBinding(new ArrayType(), null);
80                 else if (c.equals(long[].class)) return new LongArrayBinding(new ArrayType(), null);
81                 else if (c.equals(Object[].class)) return new ObjectArrayBinding(new ArrayType(), null);
82                 else return new GenericArrayBinding(request.getClazz(), new ArrayType(), null);
83         } else if (LinkedList.class.isAssignableFrom(request.getClazz())) {
84                         return new LinkedListBinding(new ArrayType(), null);
85         } else if (List.class.isAssignableFrom(request.getClazz())) {
86                         return new ArrayListBinding(new ArrayType(), null);
87         } else if (PriorityQueue.class.isAssignableFrom(request.getClazz())) {
88                 return new PriorityQueueBinding(new ArrayType(), null);
89         }
90
91         if (TreeSet.class.isAssignableFrom(request.getClazz())) {
92             MapType type = new MapType();
93             type.valueType = Datatypes.VOID;
94                 return new TreeSetBinding(type, null);
95         }
96
97         if (HashSet.class.isAssignableFrom(request.getClazz())) {
98             MapType type = new MapType();
99             type.valueType = Datatypes.VOID;
100                 return new HashSetBinding(type, null);
101         }
102         
103         if (Set.class.isAssignableFrom(request.getClazz())) {
104             MapType type = new MapType();
105             type.valueType = Datatypes.VOID;
106                 return new DefaultSetBinding(type, null);
107         }
108                 
109         if (TreeMap.class.isAssignableFrom(request.getClazz())) {
110                 return new TreeMapBinding(new MapType(), null, null);
111         } 
112
113         if (HashMap.class.isAssignableFrom(request.getClazz())) {
114                 return new HashMapBinding(new MapType(), null, null);
115         }
116
117         if (Map.class.isAssignableFrom(request.getClazz())) {
118                 return new DefaultMapBinding(new MapType(), null, null);
119         }
120                         
121                 return null;
122         }
123
124 }