-/*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
+/*******************************************************************************
+ * Copyright (c) 2010 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
package org.simantics.databoard.binding.reflection;
-import java.lang.reflect.Field;\r
-import java.lang.reflect.InvocationTargetException;\r
-import java.lang.reflect.Method;\r
-import java.lang.reflect.Modifier;\r
-import java.lang.reflect.Type;\r
-\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.binding.BooleanBinding;\r
-import org.simantics.databoard.binding.ByteBinding;\r
-import org.simantics.databoard.binding.DoubleBinding;\r
-import org.simantics.databoard.binding.FloatBinding;\r
-import org.simantics.databoard.binding.IntegerBinding;\r
-import org.simantics.databoard.binding.LongBinding;\r
-import org.simantics.databoard.binding.error.BindingConstructionException;\r
-import org.simantics.databoard.binding.error.BindingException;\r
-import org.simantics.databoard.type.RecordType;\r
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.BooleanBinding;
+import org.simantics.databoard.binding.ByteBinding;
+import org.simantics.databoard.binding.DoubleBinding;
+import org.simantics.databoard.binding.FloatBinding;
+import org.simantics.databoard.binding.IntegerBinding;
+import org.simantics.databoard.binding.LongBinding;
+import org.simantics.databoard.binding.error.BindingConstructionException;
+import org.simantics.databoard.binding.error.BindingException;
+import org.simantics.databoard.type.RecordType;
/**
* ReflectionRecordBinding binding of a Record Type and Java Class.
* - All fields are set with getter/setter
*/
class RecordClassBinding extends ClassBinding {
-\r
- private static final Object[] NO_ARGS = new Object[0]; \r
- \r
+
+ private static final Object[] NO_ARGS = new Object[0];
+
/**
* Create a Reflection Record Bindings.
*
* @throws BindingConstructionException
*/
public RecordClassBinding(ClassInfo ci, RecordType type)
- {\r
- super(ci);\r
- if ( ci == null ) throw new IllegalArgumentException("null ClassInfo");\r
- this.type = type;\r
- componentBindings = new Binding[ ci.fields.length ]; \r
- }\r
- \r
+ {
+ super(ci);
+ if ( ci == null ) throw new IllegalArgumentException("null ClassInfo");
+ this.type = type;
+ componentBindings = new Binding[ ci.fields.length ];
+ }
+
@Override
public Object createPartial() throws BindingException {
try {
if (ci.noArgsConstructor!=null)
return ci.noArgsConstructor.newInstance();
- else if (ci.argsConstructor!=null) {\r
- \r
- // Create default values \r
- Object values[] = new Object[ci.fields.length];\r
- for (int i=0; i<values.length; i++) {\r
- Binding fb = componentBindings[i];\r
- values[i] = fb.createDefault();\r
- } \r
+ else if (ci.argsConstructor!=null) {
+
+ // Create default values
+ Object values[] = new Object[ci.fields.length];
+ for (int i=0; i<values.length; i++) {
+ Binding fb = componentBindings[i];
+ values[i] = fb.createDefault();
+ }
return ci.argsConstructor.newInstance((Object[])values);
-// return clazz.newInstance();\r
+// return clazz.newInstance();
} else throw new BindingException("Class "+ci.clazz.getName()+" doesn't support construction. No no-args or args(fields) constructor.");
} catch (InstantiationException e) {
throw new BindingException(e);
}
return result;
- } catch (InstantiationException e) {\r
- boolean isPublic = (ci.clazz.getModifiers() & Modifier.PUBLIC)!=0;\r
+ } catch (InstantiationException e) {
+ boolean isPublic = (ci.clazz.getModifiers() & Modifier.PUBLIC)!=0;
if (!isPublic) throw new BindingException("Failed to instantiate "+ci.clazz.getName()+", maybe it should be public class.");
throw new BindingException("Failed to instantiate "+ci.clazz.getName());
} catch (IllegalAccessException e) {
}
@Override
- public boolean isImmutable() {\r
+ public boolean isImmutable() {
return false;
}
} catch (IllegalArgumentException e) {
throw new BindingException(e);
} catch (InvocationTargetException e) {
- throw new BindingException(e.getCause());\r
+ throw new BindingException(e.getCause());
}
- }\r
- \r
- public void setBoolean(Object r, int index, boolean z) throws BindingException\r
- {\r
- try {\r
- Field f = ci.fields[index];\r
- Class<?> cl = f.getType();\r
- if ( cl==boolean.class || cl==Boolean.class ) {\r
- f.setBoolean(r, z); \r
- } else { \r
- BooleanBinding b = (BooleanBinding) getComponentBinding(index);\r
- setComponent(r, index, b.create(z));\r
- }\r
- } catch (IllegalArgumentException e) {\r
- throw new BindingException(e);\r
- } catch (IllegalAccessException e) {\r
- throw new BindingException(e);\r
- }\r
- }\r
- \r
- public boolean getBoolean(Object r, int index) throws BindingException\r
- {\r
- try {\r
- Field f = ci.fields[index];\r
- Class<?> cl = f==null?null:f.getType();\r
- if ( cl==boolean.class || cl==Boolean.class ) return f.getBoolean(r);\r
- Object o = getComponent(r, index);\r
- BooleanBinding b = (BooleanBinding) getComponentBinding(index); \r
- return b.getValue_(o);\r
- } catch (IllegalArgumentException e) {\r
- throw new BindingException(e);\r
- } catch (IllegalAccessException e) {\r
- throw new BindingException(e);\r
- }\r
- }\r
- \r
- public void setByte(Object r, int index, byte x) throws BindingException\r
- {\r
- try {\r
- Field f = ci.fields[index];\r
- Class<?> cl = f.getType();\r
- if ( cl==byte.class || cl==Byte.class ) {\r
- f.setByte(r, x); \r
- } else { \r
- ByteBinding b = (ByteBinding) getComponentBinding(index);\r
- setComponent(r, index, b.create(x));\r
- }\r
- } catch (IllegalArgumentException e) {\r
- throw new BindingException(e);\r
- } catch (IllegalAccessException e) {\r
- throw new BindingException(e);\r
- }\r
- }\r
- \r
- public byte getByte(Object r, int index) throws BindingException\r
- {\r
- try {\r
- Field f = ci.fields[index];\r
- Class<?> cl = f==null?null:f.getType();\r
- if ( cl==byte.class || cl==Byte.class ) return f.getByte(r);\r
- Object o = getComponent(r, index);\r
- ByteBinding b = (ByteBinding) getComponentBinding(index); \r
- return b.getValue_(o);\r
- } catch (IllegalArgumentException e) {\r
- throw new BindingException(e);\r
- } catch (IllegalAccessException e) {\r
- throw new BindingException(e);\r
- }\r
- }\r
-\r
- public void setInt(Object r, int index, int x) throws BindingException\r
- {\r
- try {\r
- Field f = ci.fields[index];\r
- Class<?> cl = f.getType();\r
- if ( cl==int.class || cl==Integer.class ) {\r
- f.setInt(r, x); \r
- } else { \r
- IntegerBinding b = (IntegerBinding) getComponentBinding(index);\r
- setComponent(r, index, b.create(x));\r
- }\r
- } catch (IllegalArgumentException e) {\r
- throw new BindingException(e);\r
- } catch (IllegalAccessException e) {\r
- throw new BindingException(e);\r
- }\r
- }\r
- \r
- public int getInt(Object r, int index) throws BindingException\r
- {\r
- try {\r
- Field f = ci.fields[index];\r
- Class<?> cl = f==null?null:f.getType();\r
- if ( cl==int.class || cl==Integer.class ) return f.getInt(r);\r
- Object o = getComponent(r, index);\r
- IntegerBinding b = (IntegerBinding) getComponentBinding(index); \r
- return b.getValue_(o);\r
- } catch (IllegalArgumentException e) {\r
- throw new BindingException(e);\r
- } catch (IllegalAccessException e) {\r
- throw new BindingException(e);\r
- }\r
- }\r
- \r
- public void setLong(Object r, int index, long x) throws BindingException\r
- {\r
- try {\r
- Field f = ci.fields[index];\r
- Class<?> cl = f.getType();\r
- if ( cl==long.class || cl==Long.class ) {\r
- f.setLong(r, x); \r
- } else { \r
- LongBinding b = (LongBinding) getComponentBinding(index);\r
- setComponent(r, index, b.create(x));\r
- }\r
- } catch (IllegalArgumentException e) {\r
- throw new BindingException(e);\r
- } catch (IllegalAccessException e) {\r
- throw new BindingException(e);\r
- }\r
- }\r
- \r
- public long getLong(Object r, int index) throws BindingException\r
- {\r
- try {\r
- Field f = ci.fields[index];\r
- Class<?> cl = f==null?null:f.getType();\r
- if ( cl==long.class || cl==Long.class ) return f.getLong(r);\r
- Object o = getComponent(r, index);\r
- LongBinding b = (LongBinding) getComponentBinding(index); \r
- return b.getValue_(o);\r
- } catch (IllegalArgumentException e) {\r
- throw new BindingException(e);\r
- } catch (IllegalAccessException e) {\r
- throw new BindingException(e);\r
- }\r
- }\r
- \r
- public void setFloat(Object r, int index, float x) throws BindingException\r
- {\r
- try {\r
- Field f = ci.fields[index];\r
- Class<?> cl = f.getType();\r
- if ( cl==float.class || cl==Float.class ) {\r
- f.setFloat(r, x); \r
- } else { \r
- FloatBinding b = (FloatBinding) getComponentBinding(index);\r
- setComponent(r, index, b.create(x));\r
- }\r
- } catch (IllegalArgumentException e) {\r
- throw new BindingException(e);\r
- } catch (IllegalAccessException e) {\r
- throw new BindingException(e);\r
- }\r
- }\r
- \r
- public float getFloat(Object r, int index) throws BindingException\r
- {\r
- try {\r
- Field f = ci.fields[index];\r
- Class<?> cl = f==null?null:f.getType();\r
- if ( cl==float.class || cl==Float.class ) return f.getFloat(r);\r
- Object o = getComponent(r, index);\r
- FloatBinding b = (FloatBinding) getComponentBinding(index); \r
- return b.getValue_(o);\r
- } catch (IllegalArgumentException e) {\r
- throw new BindingException(e);\r
- } catch (IllegalAccessException e) {\r
- throw new BindingException(e);\r
- }\r
- }\r
- \r
- public void setDouble(Object r, int index, double x) throws BindingException\r
- {\r
- try {\r
- Field f = ci.fields[index];\r
- Class<?> cl = f.getType();\r
- if ( cl==double.class || cl==Double.class ) {\r
- f.setDouble(r, x); \r
- } else { \r
- DoubleBinding b = (DoubleBinding) getComponentBinding(index);\r
- setComponent(r, index, b.create(x));\r
- }\r
- } catch (IllegalArgumentException e) {\r
- throw new BindingException(e);\r
- } catch (IllegalAccessException e) {\r
- throw new BindingException(e);\r
- }\r
- }\r
- \r
- public double getDouble(Object r, int index) throws BindingException\r
- {\r
- try {\r
- Field f = ci.fields[index];\r
- Class<?> cl = f==null?null:f.getType();\r
- if ( cl==double.class || cl==Double.class ) return f.getDouble(r);\r
- Object o = getComponent(r, index);\r
- DoubleBinding b = (DoubleBinding) getComponentBinding(index); \r
- return b.getValue_(o);\r
- } catch (IllegalArgumentException e) {\r
- throw new BindingException(e);\r
- } catch (IllegalAccessException e) {\r
- throw new BindingException(e);\r
- }\r
- }\r
-\r
+ }
+
+ public void setBoolean(Object r, int index, boolean z) throws BindingException
+ {
+ try {
+ Field f = ci.fields[index];
+ Class<?> cl = f.getType();
+ if ( cl==boolean.class || cl==Boolean.class ) {
+ f.setBoolean(r, z);
+ } else {
+ BooleanBinding b = (BooleanBinding) getComponentBinding(index);
+ setComponent(r, index, b.create(z));
+ }
+ } catch (IllegalArgumentException e) {
+ throw new BindingException(e);
+ } catch (IllegalAccessException e) {
+ throw new BindingException(e);
+ }
+ }
+
+ public boolean getBoolean(Object r, int index) throws BindingException
+ {
+ try {
+ Field f = ci.fields[index];
+ Class<?> cl = f==null?null:f.getType();
+ if ( cl==boolean.class || cl==Boolean.class ) return f.getBoolean(r);
+ Object o = getComponent(r, index);
+ BooleanBinding b = (BooleanBinding) getComponentBinding(index);
+ return b.getValue_(o);
+ } catch (IllegalArgumentException e) {
+ throw new BindingException(e);
+ } catch (IllegalAccessException e) {
+ throw new BindingException(e);
+ }
+ }
+
+ public void setByte(Object r, int index, byte x) throws BindingException
+ {
+ try {
+ Field f = ci.fields[index];
+ Class<?> cl = f.getType();
+ if ( cl==byte.class || cl==Byte.class ) {
+ f.setByte(r, x);
+ } else {
+ ByteBinding b = (ByteBinding) getComponentBinding(index);
+ setComponent(r, index, b.create(x));
+ }
+ } catch (IllegalArgumentException e) {
+ throw new BindingException(e);
+ } catch (IllegalAccessException e) {
+ throw new BindingException(e);
+ }
+ }
+
+ public byte getByte(Object r, int index) throws BindingException
+ {
+ try {
+ Field f = ci.fields[index];
+ Class<?> cl = f==null?null:f.getType();
+ if ( cl==byte.class || cl==Byte.class ) return f.getByte(r);
+ Object o = getComponent(r, index);
+ ByteBinding b = (ByteBinding) getComponentBinding(index);
+ return b.getValue_(o);
+ } catch (IllegalArgumentException e) {
+ throw new BindingException(e);
+ } catch (IllegalAccessException e) {
+ throw new BindingException(e);
+ }
+ }
+
+ public void setInt(Object r, int index, int x) throws BindingException
+ {
+ try {
+ Field f = ci.fields[index];
+ Class<?> cl = f.getType();
+ if ( cl==int.class || cl==Integer.class ) {
+ f.setInt(r, x);
+ } else {
+ IntegerBinding b = (IntegerBinding) getComponentBinding(index);
+ setComponent(r, index, b.create(x));
+ }
+ } catch (IllegalArgumentException e) {
+ throw new BindingException(e);
+ } catch (IllegalAccessException e) {
+ throw new BindingException(e);
+ }
+ }
+
+ public int getInt(Object r, int index) throws BindingException
+ {
+ try {
+ Field f = ci.fields[index];
+ Class<?> cl = f==null?null:f.getType();
+ if ( cl==int.class || cl==Integer.class ) return f.getInt(r);
+ Object o = getComponent(r, index);
+ IntegerBinding b = (IntegerBinding) getComponentBinding(index);
+ return b.getValue_(o);
+ } catch (IllegalArgumentException e) {
+ throw new BindingException(e);
+ } catch (IllegalAccessException e) {
+ throw new BindingException(e);
+ }
+ }
+
+ public void setLong(Object r, int index, long x) throws BindingException
+ {
+ try {
+ Field f = ci.fields[index];
+ Class<?> cl = f.getType();
+ if ( cl==long.class || cl==Long.class ) {
+ f.setLong(r, x);
+ } else {
+ LongBinding b = (LongBinding) getComponentBinding(index);
+ setComponent(r, index, b.create(x));
+ }
+ } catch (IllegalArgumentException e) {
+ throw new BindingException(e);
+ } catch (IllegalAccessException e) {
+ throw new BindingException(e);
+ }
+ }
+
+ public long getLong(Object r, int index) throws BindingException
+ {
+ try {
+ Field f = ci.fields[index];
+ Class<?> cl = f==null?null:f.getType();
+ if ( cl==long.class || cl==Long.class ) return f.getLong(r);
+ Object o = getComponent(r, index);
+ LongBinding b = (LongBinding) getComponentBinding(index);
+ return b.getValue_(o);
+ } catch (IllegalArgumentException e) {
+ throw new BindingException(e);
+ } catch (IllegalAccessException e) {
+ throw new BindingException(e);
+ }
+ }
+
+ public void setFloat(Object r, int index, float x) throws BindingException
+ {
+ try {
+ Field f = ci.fields[index];
+ Class<?> cl = f.getType();
+ if ( cl==float.class || cl==Float.class ) {
+ f.setFloat(r, x);
+ } else {
+ FloatBinding b = (FloatBinding) getComponentBinding(index);
+ setComponent(r, index, b.create(x));
+ }
+ } catch (IllegalArgumentException e) {
+ throw new BindingException(e);
+ } catch (IllegalAccessException e) {
+ throw new BindingException(e);
+ }
+ }
+
+ public float getFloat(Object r, int index) throws BindingException
+ {
+ try {
+ Field f = ci.fields[index];
+ Class<?> cl = f==null?null:f.getType();
+ if ( cl==float.class || cl==Float.class ) return f.getFloat(r);
+ Object o = getComponent(r, index);
+ FloatBinding b = (FloatBinding) getComponentBinding(index);
+ return b.getValue_(o);
+ } catch (IllegalArgumentException e) {
+ throw new BindingException(e);
+ } catch (IllegalAccessException e) {
+ throw new BindingException(e);
+ }
+ }
+
+ public void setDouble(Object r, int index, double x) throws BindingException
+ {
+ try {
+ Field f = ci.fields[index];
+ Class<?> cl = f.getType();
+ if ( cl==double.class || cl==Double.class ) {
+ f.setDouble(r, x);
+ } else {
+ DoubleBinding b = (DoubleBinding) getComponentBinding(index);
+ setComponent(r, index, b.create(x));
+ }
+ } catch (IllegalArgumentException e) {
+ throw new BindingException(e);
+ } catch (IllegalAccessException e) {
+ throw new BindingException(e);
+ }
+ }
+
+ public double getDouble(Object r, int index) throws BindingException
+ {
+ try {
+ Field f = ci.fields[index];
+ Class<?> cl = f==null?null:f.getType();
+ if ( cl==double.class || cl==Double.class ) return f.getDouble(r);
+ Object o = getComponent(r, index);
+ DoubleBinding b = (DoubleBinding) getComponentBinding(index);
+ return b.getValue_(o);
+ } catch (IllegalArgumentException e) {
+ throw new BindingException(e);
+ } catch (IllegalAccessException e) {
+ throw new BindingException(e);
+ }
+ }
+
}