]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/factory/DefaultBindingFactory.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / factory / DefaultBindingFactory.java
index 73f2d2f16d167d34de11a541e097cadf78890378..8b5663597d28ebc0208d3f8fecccbeaa08bb9bc7 100644 (file)
@@ -1,54 +1,54 @@
-/*******************************************************************************\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.BooleanArrayBinding;\r
-import org.simantics.databoard.binding.impl.BooleanBindingDefault;\r
-import org.simantics.databoard.binding.impl.ByteArrayBinding;\r
-import org.simantics.databoard.binding.impl.ByteBindingDefault;\r
-import org.simantics.databoard.binding.impl.DefaultMapBinding;\r
-import org.simantics.databoard.binding.impl.DoubleArrayBinding;\r
-import org.simantics.databoard.binding.impl.DoubleBindingDefault;\r
-import org.simantics.databoard.binding.impl.FloatArrayBinding;\r
-import org.simantics.databoard.binding.impl.FloatBindingDefault;\r
-import org.simantics.databoard.binding.impl.IntArrayBinding;\r
-import org.simantics.databoard.binding.impl.IntegerBindingDefault;\r
-import org.simantics.databoard.binding.impl.LongArrayBinding;\r
-import org.simantics.databoard.binding.impl.LongBindingDefault;\r
-import org.simantics.databoard.binding.impl.ObjectArrayBinding;\r
-import org.simantics.databoard.binding.impl.StringBindingDefault;\r
-import org.simantics.databoard.binding.mutable.ContainerOptionalBinding;\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.BooleanArrayBinding;
+import org.simantics.databoard.binding.impl.BooleanBindingDefault;
+import org.simantics.databoard.binding.impl.ByteArrayBinding;
+import org.simantics.databoard.binding.impl.ByteBindingDefault;
+import org.simantics.databoard.binding.impl.DefaultMapBinding;
+import org.simantics.databoard.binding.impl.DoubleArrayBinding;
+import org.simantics.databoard.binding.impl.DoubleBindingDefault;
+import org.simantics.databoard.binding.impl.FloatArrayBinding;
+import org.simantics.databoard.binding.impl.FloatBindingDefault;
+import org.simantics.databoard.binding.impl.IntArrayBinding;
+import org.simantics.databoard.binding.impl.IntegerBindingDefault;
+import org.simantics.databoard.binding.impl.LongArrayBinding;
+import org.simantics.databoard.binding.impl.LongBindingDefault;
+import org.simantics.databoard.binding.impl.ObjectArrayBinding;
+import org.simantics.databoard.binding.impl.StringBindingDefault;
+import org.simantics.databoard.binding.mutable.ContainerOptionalBinding;
+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;
 
 /**
- * DefaultBindingScheme is a type to binding mapping that binds any DataType to an Object.\r
+ * DefaultBindingScheme is a type to binding mapping that binds any DataType to an Object.
  * All resulting bindings typicaly immutable java classes.
  * 
  * DataType           | Class of the bound instance
@@ -64,95 +64,95 @@ import org.simantics.databoard.type.UnionType;
  * OptionType         | ValueContainer.class
  * RecordType         | Object[].class
  * MapType            | TreeMap.class
- * VariantType        | Variant.class\r
- * ArrayType(Boolean) | boolean[].class\r
- * ArrayType(Byte)    | byte[].class\r
- * ArrayType(Integer) | int[].class\r
- * ArrayType(Long)    | long[].class\r
- * ArrayType(Float)   | float[].class\r
- * ArrayType(Double)  | double[].class\r
- * ArrayType(Byte)    | byte[].class\r
- * ArrayType( T )     | Object[].class\r
+ * VariantType        | Variant.class
+ * ArrayType(Boolean) | boolean[].class
+ * ArrayType(Byte)    | byte[].class
+ * ArrayType(Integer) | int[].class
+ * ArrayType(Long)    | long[].class
+ * ArrayType(Float)   | float[].class
+ * ArrayType(Double)  | double[].class
+ * ArrayType(Byte)    | byte[].class
+ * ArrayType( T )     | Object[].class
  * 
  *
  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
  */
-public class DefaultBindingFactory extends TypeBindingFactory {\r
-       \r
-       /**\r
-        * Construct a binding factory.\r
-        */\r
-       public DefaultBindingFactory() {\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 DefaultBindingFactory(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.BOOLEAN;\r
-               if (type.equals( Bindings.BYTE.type() )) return Bindings.BYTE;\r
-               if (type.equals( Bindings.INTEGER.type() )) return Bindings.INTEGER;\r
-               if (type.equals( Bindings.LONG.type() )) return Bindings.LONG;\r
-               if (type.equals( Bindings.FLOAT.type() )) return Bindings.FLOAT;\r
-               if (type.equals( Bindings.DOUBLE.type() )) return Bindings.DOUBLE;\r
-               if (type.equals( Bindings.STRING.type() )) return Bindings.STRING;\r
-               if (type.equals( Bindings.VARIANT.type() )) return Bindings.VARIANT;\r
-               if (type.equals( Bindings.BOOLEAN_ARRAY.type() )) return Bindings.BOOLEAN_ARRAY;\r
-               if (type.equals( Bindings.BYTE_ARRAY.type() )) return Bindings.BYTE_ARRAY;\r
-               if (type.equals( Bindings.INT_ARRAY.type() )) return Bindings.INT_ARRAY;\r
-               if (type.equals( Bindings.LONG_ARRAY.type() )) return Bindings.LONG_ARRAY;\r
-               if (type.equals( Bindings.FLOAT_ARRAY.type() )) return Bindings.FLOAT_ARRAY;\r
-               if (type.equals( Bindings.DOUBLE_ARRAY.type() )) return Bindings.DOUBLE_ARRAY;\r
-               if (type.equals( Bindings.BOOLEAN_ARRAY.type() )) return Bindings.BOOLEAN_ARRAY;\r
-               if (type.equals( Bindings.STRING_ARRAY.type() )) return Bindings.STRING_ARRAY;\r
-               \r
-               // Annotated types \r
-               if (type instanceof BooleanType) return new BooleanBindingDefault((BooleanType)type);\r
-               if (type instanceof DoubleType) return new DoubleBindingDefault((DoubleType)type);\r
-               if (type instanceof FloatType) return new FloatBindingDefault((FloatType)type);\r
-               if (type instanceof ByteType) return new ByteBindingDefault((ByteType)type);\r
-               if (type instanceof IntegerType) return new IntegerBindingDefault((IntegerType)type);\r
-               if (type instanceof LongType) return new LongBindingDefault((LongType)type);\r
-               if (type instanceof StringType) return new StringBindingDefault((StringType)type);\r
-               \r
-               // Constructed types\r
+public class DefaultBindingFactory extends TypeBindingFactory {
+       
+       /**
+        * Construct a binding factory.
+        */
+       public DefaultBindingFactory() {
+               super();
+       }
+       
+       /**
+        * Construct a scheme factory that appends constructed bindings to the user given
+        * repository  
+        * 
+        * @param repository repository where bindings are placed
+        */
+       public DefaultBindingFactory(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.BOOLEAN;
+               if (type.equals( Bindings.BYTE.type() )) return Bindings.BYTE;
+               if (type.equals( Bindings.INTEGER.type() )) return Bindings.INTEGER;
+               if (type.equals( Bindings.LONG.type() )) return Bindings.LONG;
+               if (type.equals( Bindings.FLOAT.type() )) return Bindings.FLOAT;
+               if (type.equals( Bindings.DOUBLE.type() )) return Bindings.DOUBLE;
+               if (type.equals( Bindings.STRING.type() )) return Bindings.STRING;
+               if (type.equals( Bindings.VARIANT.type() )) return Bindings.VARIANT;
+               if (type.equals( Bindings.BOOLEAN_ARRAY.type() )) return Bindings.BOOLEAN_ARRAY;
+               if (type.equals( Bindings.BYTE_ARRAY.type() )) return Bindings.BYTE_ARRAY;
+               if (type.equals( Bindings.INT_ARRAY.type() )) return Bindings.INT_ARRAY;
+               if (type.equals( Bindings.LONG_ARRAY.type() )) return Bindings.LONG_ARRAY;
+               if (type.equals( Bindings.FLOAT_ARRAY.type() )) return Bindings.FLOAT_ARRAY;
+               if (type.equals( Bindings.DOUBLE_ARRAY.type() )) return Bindings.DOUBLE_ARRAY;
+               if (type.equals( Bindings.BOOLEAN_ARRAY.type() )) return Bindings.BOOLEAN_ARRAY;
+               if (type.equals( Bindings.STRING_ARRAY.type() )) return Bindings.STRING_ARRAY;
+               
+               // Annotated types 
+               if (type instanceof BooleanType) return new BooleanBindingDefault((BooleanType)type);
+               if (type instanceof DoubleType) return new DoubleBindingDefault((DoubleType)type);
+               if (type instanceof FloatType) return new FloatBindingDefault((FloatType)type);
+               if (type instanceof ByteType) return new ByteBindingDefault((ByteType)type);
+               if (type instanceof IntegerType) return new IntegerBindingDefault((IntegerType)type);
+               if (type instanceof LongType) return new LongBindingDefault((LongType)type);
+               if (type instanceof StringType) return new StringBindingDefault((StringType)type);
+               
+               // Constructed types
                if (type instanceof ArrayType) {
                        ArrayType arrayType = (ArrayType) type;
-                       Datatype componentType = arrayType.componentType();\r
+                       Datatype componentType = arrayType.componentType();
                        
-                       if (componentType instanceof BooleanType) return BooleanArrayBinding.createFrom(arrayType);\r
-                       if (componentType instanceof ByteType) return ByteArrayBinding.createFrom(arrayType);\r
-                       if (componentType instanceof IntegerType) return IntArrayBinding.createFrom(arrayType);\r
-                       if (componentType instanceof LongType) return LongArrayBinding.createFrom(arrayType);\r
-                       if (componentType instanceof FloatType) return FloatArrayBinding.createFrom(arrayType);\r
-                       if (componentType instanceof DoubleType) return DoubleArrayBinding.createFrom(arrayType);\r
-\r
-                       ObjectArrayBinding binding = new ObjectArrayBinding(arrayType, null);\r
-                       inprogress.put(type, binding);\r
-                       binding.componentBinding = construct( componentType );                                          \r
-                       inprogress.remove(type);\r
-                       return binding;\r
+                       if (componentType instanceof BooleanType) return BooleanArrayBinding.createFrom(arrayType);
+                       if (componentType instanceof ByteType) return ByteArrayBinding.createFrom(arrayType);
+                       if (componentType instanceof IntegerType) return IntArrayBinding.createFrom(arrayType);
+                       if (componentType instanceof LongType) return LongArrayBinding.createFrom(arrayType);
+                       if (componentType instanceof FloatType) return FloatArrayBinding.createFrom(arrayType);
+                       if (componentType instanceof DoubleType) return DoubleArrayBinding.createFrom(arrayType);
+
+                       ObjectArrayBinding binding = new ObjectArrayBinding(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);\r
-                       binding.componentBinding = construct( componentType );\r
-                       inprogress.remove(type);\r
+                       inprogress.put(type, binding);
+                       binding.componentBinding = construct( componentType );
+                       inprogress.remove(type);
                        return binding;
                }
                
@@ -160,11 +160,11 @@ public class DefaultBindingFactory extends TypeBindingFactory {
                        RecordType recordType = (RecordType) type;
                        Binding componentBindings[] = new Binding[ recordType.getComponentCount() ];
                        RecordObjectArrayBinding binding = new RecordObjectArrayBinding(recordType, componentBindings);
-                       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
+                       inprogress.put(type, binding);
+                       for (int i=0; i<componentBindings.length; i++) {
+                               componentBindings[i] = construct( recordType.getComponentType(i) );
+                       }
+                       inprogress.remove(type);
                        return binding;
                }
                
@@ -172,33 +172,33 @@ public class DefaultBindingFactory extends TypeBindingFactory {
                        UnionType unionType = (UnionType) type;
                        Binding componentBindings[] = new Binding[ unionType.components.length ];
                        UnionTaggedObjectBinding binding = new UnionTaggedObjectBinding(unionType, componentBindings);
-                       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
+                       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;
                        DefaultMapBinding binding = new DefaultMapBinding(mapType, null, null);
-                       inprogress.put(type, binding);\r
-                       binding.setKeyBinding( construct(mapType.keyType) );\r
-                       binding.setValueBinding( construct(mapType.valueType) );\r
-                       inprogress.remove(type);\r
-                       return binding;\r
+                       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);
-       }\r
-\r
-       @Override\r
-       public boolean supportsType(Datatype type) {\r
-               // unexpected\r
-               if (failures.containsKey(type)) return false;\r
-               return true;\r
-       }\r
+       }
+
+       @Override
+       public boolean supportsType(Datatype type) {
+               // unexpected
+               if (failures.containsKey(type)) return false;
+               return true;
+       }
        
 }