]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/ClassBinding.java
Fixing several binding-related bugs
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / reflection / ClassBinding.java
1 /*******************************************************************************
2  *  Copyright (c) 2010 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.reflection;
13
14 import org.simantics.databoard.binding.RecordBinding;
15 import org.simantics.databoard.binding.error.BindingConstructionException;
16
17 /**
18  * RecordBinding that represents a class
19  */
20 public abstract class ClassBinding extends RecordBinding {
21
22         public final ClassInfo ci;
23
24         /**
25          * Create binding for a class. 
26          * 
27          * @param ci
28          * @throws BindingConstructionException
29          */
30         public ClassBinding(ClassInfo ci)
31         {
32                 this.ci = ci;           
33         }
34
35         /**
36          * Create binding for a class. 
37          * 
38          * @param clazz
39          * @throws BindingConstructionException
40          */
41         public ClassBinding(Class<?> clazz) throws BindingConstructionException
42         {
43                 this( ClassInfo.getInfo(clazz) );
44         }
45         
46         public Class<?> getClazz()
47         {
48                 return ci.clazz;
49         }
50         
51         @Override
52         protected boolean baseEquals(Object obj) {
53                 return super.baseEquals(obj) && ((ClassBinding)obj).ci.equals(ci);
54         }
55
56         @Override
57         public int baseHashCode() {
58                 return super.baseHashCode() + 17 * ci.hashCode();
59         }
60 }