-/*******************************************************************************\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.factory;
-import java.util.Map;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.binding.error.BindingConstructionException;\r
-import org.simantics.databoard.binding.impl.ArrayListBinding;\r
-import org.simantics.databoard.binding.impl.TreeMapBinding;\r
-import org.simantics.databoard.binding.mutable.ContainerOptionalBinding;\r
-import org.simantics.databoard.binding.mutable.MutableBooleanBinding;\r
-import org.simantics.databoard.binding.mutable.MutableByteBinding;\r
-import org.simantics.databoard.binding.mutable.MutableDoubleBinding;\r
-import org.simantics.databoard.binding.mutable.MutableFloatBinding;\r
-import org.simantics.databoard.binding.mutable.MutableIntegerBinding;\r
-import org.simantics.databoard.binding.mutable.MutableLongBinding;\r
-import org.simantics.databoard.binding.mutable.MutableStringBinding;\r
-import org.simantics.databoard.binding.mutable.UnionTaggedObjectBinding;\r
-import org.simantics.databoard.type.ArrayType;\r
-import org.simantics.databoard.type.BooleanType;\r
-import org.simantics.databoard.type.ByteType;\r
-import org.simantics.databoard.type.Datatype;\r
-import org.simantics.databoard.type.DoubleType;\r
-import org.simantics.databoard.type.FloatType;\r
-import org.simantics.databoard.type.IntegerType;\r
-import org.simantics.databoard.type.LongType;\r
-import org.simantics.databoard.type.MapType;\r
-import org.simantics.databoard.type.OptionalType;\r
-import org.simantics.databoard.type.RecordType;\r
-import org.simantics.databoard.type.StringType;\r
-import org.simantics.databoard.type.UnionType;\r
+import java.util.Map;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.error.BindingConstructionException;
+import org.simantics.databoard.binding.impl.ArrayListBinding;
+import org.simantics.databoard.binding.impl.TreeMapBinding;
+import org.simantics.databoard.binding.mutable.ContainerOptionalBinding;
+import org.simantics.databoard.binding.mutable.MutableBooleanBinding;
+import org.simantics.databoard.binding.mutable.MutableByteBinding;
+import org.simantics.databoard.binding.mutable.MutableDoubleBinding;
+import org.simantics.databoard.binding.mutable.MutableFloatBinding;
+import org.simantics.databoard.binding.mutable.MutableIntegerBinding;
+import org.simantics.databoard.binding.mutable.MutableLongBinding;
+import org.simantics.databoard.binding.mutable.MutableStringBinding;
+import org.simantics.databoard.binding.mutable.UnionTaggedObjectBinding;
+import org.simantics.databoard.type.ArrayType;
+import org.simantics.databoard.type.BooleanType;
+import org.simantics.databoard.type.ByteType;
+import org.simantics.databoard.type.Datatype;
+import org.simantics.databoard.type.DoubleType;
+import org.simantics.databoard.type.FloatType;
+import org.simantics.databoard.type.IntegerType;
+import org.simantics.databoard.type.LongType;
+import org.simantics.databoard.type.MapType;
+import org.simantics.databoard.type.OptionalType;
+import org.simantics.databoard.type.RecordType;
+import org.simantics.databoard.type.StringType;
+import org.simantics.databoard.type.UnionType;
/**
- * MutableBindingScheme is a type to binding mapping that binds any DataType to an Object.\r
+ * MutableBindingScheme is a type to binding mapping that binds any DataType to an Object.
* All resulting bindings are completely mutable java classes.
*
* DataType | Class of the bound instance
*
* @author Toni Kalajainen <toni.kalajainen@vtt.fi>
*/
-\r
-public class MutableBindingFactory extends TypeBindingFactory {\r
-\r
- /**\r
- * Construct a binding factory.\r
- */\r
- public MutableBindingFactory() {\r
- super();\r
- }\r
- \r
- /**\r
- * Construct a scheme factory that appends constructed bindings to the user given\r
- * repository \r
- * \r
- * @param repository repository where bindings are placed\r
- */\r
- public MutableBindingFactory(Map<Datatype, Binding> repository) {\r
- super(repository);\r
- }\r
-\r
- @Override\r
- protected Binding doConstruct(Datatype type)\r
- throws BindingConstructionException {\r
-\r
- // Exact, non-annotated types\r
- if (type.equals( Bindings.BOOLEAN.type() )) return Bindings.MUTABLE_BOOLEAN;\r
- if (type.equals( Bindings.BYTE.type() )) return Bindings.MUTABLE_BYTE;\r
- if (type.equals( Bindings.INTEGER.type() )) return Bindings.MUTABLE_INTEGER;\r
- if (type.equals( Bindings.LONG.type() )) return Bindings.MUTABLE_LONG;\r
- if (type.equals( Bindings.FLOAT.type() )) return Bindings.MUTABLE_FLOAT;\r
- if (type.equals( Bindings.DOUBLE.type() )) return Bindings.MUTABLE_DOUBLE;\r
- if (type.equals( Bindings.STRING.type() )) return Bindings.MUTABLE_STRING;\r
- if (type.equals( Bindings.VARIANT.type() )) return Bindings.MUTABLE_VARIANT;\r
- \r
- // Annotated types \r
- if (type instanceof BooleanType) return new MutableBooleanBinding((BooleanType)type);\r
- if (type instanceof DoubleType) return new MutableDoubleBinding((DoubleType)type);\r
- if (type instanceof FloatType) return new MutableFloatBinding((FloatType)type);\r
- if (type instanceof ByteType) return new MutableByteBinding((ByteType)type);\r
- if (type instanceof IntegerType) return new MutableIntegerBinding((IntegerType)type);\r
- if (type instanceof LongType) return new MutableLongBinding((LongType)type);\r
- if (type instanceof StringType) return new MutableStringBinding((StringType)type);\r
- \r
- // Constructed types\r
- if (type instanceof ArrayType) {\r
- ArrayType arrayType = (ArrayType) type;\r
- Datatype componentType = arrayType.componentType();\r
-\r
- ArrayListBinding binding = new ArrayListBinding(arrayType, null);\r
- inprogress.put(type, binding);\r
- binding.componentBinding = construct( componentType ); \r
- inprogress.remove(type);\r
- return binding;\r
- }\r
- \r
- if (type instanceof OptionalType) {\r
- OptionalType optionalType = (OptionalType) type;\r
- Datatype componentType = optionalType.componentType;\r
- ContainerOptionalBinding binding = new ContainerOptionalBinding( optionalType, null );\r
- inprogress.put(type, binding);\r
- binding.componentBinding = construct( componentType );\r
- inprogress.remove(type);\r
- return binding;\r
- }\r
- \r
- if (type instanceof RecordType) { \r
- RecordType recordType = (RecordType) type;\r
- Binding componentBindings[] = new Binding[ recordType.getComponentCount() ];\r
- RecordObjectArrayBinding binding = new RecordObjectArrayBinding(recordType, componentBindings);\r
- inprogress.put(type, binding);\r
- for (int i=0; i<componentBindings.length; i++) {\r
- componentBindings[i] = construct( recordType.getComponentType(i) );\r
- }\r
- inprogress.remove(type);\r
- return binding;\r
- }\r
- \r
- if (type instanceof UnionType) {\r
- UnionType unionType = (UnionType) type;\r
- Binding componentBindings[] = new Binding[ unionType.components.length ];\r
- UnionTaggedObjectBinding binding = new UnionTaggedObjectBinding(unionType, componentBindings);\r
- inprogress.put(type, binding);\r
- for (int i=0; i<componentBindings.length; i++) {\r
- componentBindings[i] = construct( unionType.getComponent(i).type );\r
- }\r
- inprogress.remove(type);\r
- return binding;\r
- } \r
- \r
- if (type instanceof MapType) { \r
- MapType mapType = (MapType) type;\r
- TreeMapBinding binding = new TreeMapBinding(mapType, null, null);\r
- inprogress.put(type, binding);\r
- binding.setKeyBinding( construct(mapType.keyType) );\r
- binding.setValueBinding( construct(mapType.valueType) );\r
- inprogress.remove(type);\r
- return binding;\r
- }\r
- \r
- throw new BindingConstructionException("Unexpected, I don't know how to create binding for "+type);\r
- }\r
-\r
- @Override\r
- public boolean supportsType(Datatype type) {\r
- // unexpected\r
- if (failures.containsKey(type)) return false;\r
- return true;\r
- }\r
- \r
-}\r
-\r
-\r
-\r
+
+public class MutableBindingFactory extends TypeBindingFactory {
+
+ /**
+ * Construct a binding factory.
+ */
+ public MutableBindingFactory() {
+ super();
+ }
+
+ /**
+ * Construct a scheme factory that appends constructed bindings to the user given
+ * repository
+ *
+ * @param repository repository where bindings are placed
+ */
+ public MutableBindingFactory(Map<Datatype, Binding> repository) {
+ super(repository);
+ }
+
+ @Override
+ protected Binding doConstruct(Datatype type)
+ throws BindingConstructionException {
+
+ // Exact, non-annotated types
+ if (type.equals( Bindings.BOOLEAN.type() )) return Bindings.MUTABLE_BOOLEAN;
+ if (type.equals( Bindings.BYTE.type() )) return Bindings.MUTABLE_BYTE;
+ if (type.equals( Bindings.INTEGER.type() )) return Bindings.MUTABLE_INTEGER;
+ if (type.equals( Bindings.LONG.type() )) return Bindings.MUTABLE_LONG;
+ if (type.equals( Bindings.FLOAT.type() )) return Bindings.MUTABLE_FLOAT;
+ if (type.equals( Bindings.DOUBLE.type() )) return Bindings.MUTABLE_DOUBLE;
+ if (type.equals( Bindings.STRING.type() )) return Bindings.MUTABLE_STRING;
+ if (type.equals( Bindings.VARIANT.type() )) return Bindings.MUTABLE_VARIANT;
+
+ // Annotated types
+ if (type instanceof BooleanType) return new MutableBooleanBinding((BooleanType)type);
+ if (type instanceof DoubleType) return new MutableDoubleBinding((DoubleType)type);
+ if (type instanceof FloatType) return new MutableFloatBinding((FloatType)type);
+ if (type instanceof ByteType) return new MutableByteBinding((ByteType)type);
+ if (type instanceof IntegerType) return new MutableIntegerBinding((IntegerType)type);
+ if (type instanceof LongType) return new MutableLongBinding((LongType)type);
+ if (type instanceof StringType) return new MutableStringBinding((StringType)type);
+
+ // Constructed types
+ if (type instanceof ArrayType) {
+ ArrayType arrayType = (ArrayType) type;
+ Datatype componentType = arrayType.componentType();
+
+ ArrayListBinding binding = new ArrayListBinding(arrayType, null);
+ inprogress.put(type, binding);
+ binding.componentBinding = construct( componentType );
+ inprogress.remove(type);
+ return binding;
+ }
+
+ if (type instanceof OptionalType) {
+ OptionalType optionalType = (OptionalType) type;
+ Datatype componentType = optionalType.componentType;
+ ContainerOptionalBinding binding = new ContainerOptionalBinding( optionalType, null );
+ inprogress.put(type, binding);
+ binding.componentBinding = construct( componentType );
+ inprogress.remove(type);
+ return binding;
+ }
+
+ if (type instanceof RecordType) {
+ RecordType recordType = (RecordType) type;
+ Binding componentBindings[] = new Binding[ recordType.getComponentCount() ];
+ RecordObjectArrayBinding binding = new RecordObjectArrayBinding(recordType, componentBindings);
+ inprogress.put(type, binding);
+ for (int i=0; i<componentBindings.length; i++) {
+ componentBindings[i] = construct( recordType.getComponentType(i) );
+ }
+ inprogress.remove(type);
+ return binding;
+ }
+
+ if (type instanceof UnionType) {
+ UnionType unionType = (UnionType) type;
+ Binding componentBindings[] = new Binding[ unionType.components.length ];
+ UnionTaggedObjectBinding binding = new UnionTaggedObjectBinding(unionType, componentBindings);
+ inprogress.put(type, binding);
+ for (int i=0; i<componentBindings.length; i++) {
+ componentBindings[i] = construct( unionType.getComponent(i).type );
+ }
+ inprogress.remove(type);
+ return binding;
+ }
+
+ if (type instanceof MapType) {
+ MapType mapType = (MapType) type;
+ TreeMapBinding binding = new TreeMapBinding(mapType, null, null);
+ inprogress.put(type, binding);
+ binding.setKeyBinding( construct(mapType.keyType) );
+ binding.setValueBinding( construct(mapType.valueType) );
+ inprogress.remove(type);
+ return binding;
+ }
+
+ throw new BindingConstructionException("Unexpected, I don't know how to create binding for "+type);
+ }
+
+ @Override
+ public boolean supportsType(Datatype type) {
+ // unexpected
+ if (failures.containsKey(type)) return false;
+ return true;
+ }
+
+}
+
+
+