]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/classfactory/ImmutableClassesFactory.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / classfactory / ImmutableClassesFactory.java
index 203cf6d0cab545eaa13081cbb447a617f8c52c82..0c03dd250e50133594fe1e4c5be3c6b4c922b5b7 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 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
-package org.simantics.databoard.binding.classfactory;\r
-\r
-import java.lang.annotation.Annotation;\r
-import java.lang.reflect.Array;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.TreeMap;\r
-\r
-import org.simantics.databoard.annotations.ArgumentImpl;\r
-import org.simantics.databoard.annotations.LengthImpl;\r
-import org.simantics.databoard.annotations.MIMETypeImpl;\r
-import org.simantics.databoard.annotations.PatternImpl;\r
-import org.simantics.databoard.annotations.RangeImpl;\r
-import org.simantics.databoard.annotations.UnitImpl;\r
-import org.simantics.databoard.binding.error.BindingConstructionException;\r
-import org.simantics.databoard.binding.mutable.Variant;\r
-import org.simantics.databoard.binding.reflection.BindingRequest;\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.NumberType;\r
-import org.simantics.databoard.type.StringType;\r
-import org.simantics.databoard.type.VariantType;\r
-\r
-public class ImmutableClassesFactory implements TypeClassSubFactory {\r
-       \r
-       public ImmutableClassesFactory() {\r
-       }\r
-       \r
-       @Override\r
-       public BindingRequest construct(TypeClassFactory mainFactory, Datatype type) \r
-       throws BindingConstructionException \r
-       {\r
-               \r
-               if ( type instanceof ArrayType ) {\r
-                       List<Annotation> annotations = new ArrayList<Annotation>();\r
-                       ArrayType at = (ArrayType) type;\r
-                       BindingRequest cbr = construct(mainFactory, at.componentType);\r
-                       if ( cbr == null ) {\r
-                               cbr = mainFactory.getClass(at.componentType);                           \r
-                       }\r
-\r
-                       String length = at.metadata.get(ArrayType.KEY_LENGTH);\r
-                       if (length != null) annotations.add( new LengthImpl( length ) );\r
-                       \r
-                       if ( cbr.getClazz() != null ) {\r
-                               for (Annotation a : cbr.annotations)\r
-                               {\r
-                                       annotations.add( a );\r
-                               }\r
-                               \r
-                               Class<?> arrayClass = Array.newInstance(cbr.getClazz(), 0).getClass();\r
-                               return new BindingRequest( arrayClass, annotations );\r
-                       }\r
-               }\r
-               \r
-               if ( type instanceof MapType ) {\r
-                       MapType mt = (MapType) type;\r
-                       List<Annotation> annotations = new ArrayList<Annotation>();\r
-                       BindingRequest kbr = construct(mainFactory, mt.keyType);\r
-                       BindingRequest vbr = construct(mainFactory, mt.valueType);\r
-                       if ( kbr == null ) kbr = mainFactory.getClass(mt.keyType);                                                      \r
-                       if ( vbr == null ) vbr = mainFactory.getClass(mt.valueType);\r
-                       if ( kbr.getClazz()!=null && vbr.getClazz()!=null ) {\r
-                               annotations.add( new ArgumentImpl(kbr.getClazz(), vbr.getClazz()) );                    \r
-                               return new BindingRequest( TreeMap.class, annotations );\r
-                       }\r
-               }\r
-               \r
-               if ( type instanceof StringType ) {\r
-                       List<Annotation> annotations = new ArrayList<Annotation>();\r
-                       StringType st = (StringType) type;\r
-                       \r
-                       String pattern = st.metadata.get(StringType.KEY_PATTERN);\r
-                       if (pattern != null) annotations.add( new PatternImpl( pattern ) );\r
-                       \r
-                       String mimetype = st.metadata.get(StringType.KEY_MIMETYPE);\r
-                       if (mimetype != null) annotations.add( new MIMETypeImpl( mimetype ) );\r
-                       \r
-                       String length = st.metadata.get(StringType.KEY_LENGTH);\r
-                       if (length != null) annotations.add( new LengthImpl( length ) );\r
-                       \r
-                       return new BindingRequest( String.class, annotations );                 \r
-               }\r
-               \r
-               if ( type instanceof NumberType ) {\r
-                       List<Annotation> annotations = new ArrayList<Annotation>();\r
-                       NumberType nt = (NumberType) type;\r
-                       \r
-                       String unit = nt.metadata.get(NumberType.KEY_UNIT);\r
-                       if (unit != null) annotations.add( new UnitImpl(unit) );\r
-                       \r
-                       String range = nt.metadata.get(NumberType.KEY_RANGE);\r
-                       if (range != null) annotations.add( new RangeImpl(range) );\r
-                       \r
-                       Class<?> clazz = null;\r
-                       if ( type instanceof IntegerType ) clazz = int.class;\r
-                       if ( type instanceof ByteType ) clazz = byte.class;\r
-                       if ( type instanceof LongType ) clazz = long.class;\r
-                       if ( type instanceof DoubleType ) clazz = double.class;\r
-                       if ( type instanceof FloatType ) clazz = float.class;\r
-                       \r
-                       return new BindingRequest( clazz, annotations );\r
-               }\r
-               \r
-               if ( type instanceof BooleanType ) {\r
-                       return new BindingRequest( boolean.class );\r
-               }\r
-               \r
-               if ( type instanceof VariantType ) {\r
-                       return new BindingRequest( Variant.class );\r
-               }\r
-               \r
-               return null;\r
-       }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 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.classfactory;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.TreeMap;
+
+import org.simantics.databoard.annotations.ArgumentImpl;
+import org.simantics.databoard.annotations.LengthImpl;
+import org.simantics.databoard.annotations.MIMETypeImpl;
+import org.simantics.databoard.annotations.PatternImpl;
+import org.simantics.databoard.annotations.RangeImpl;
+import org.simantics.databoard.annotations.UnitImpl;
+import org.simantics.databoard.binding.error.BindingConstructionException;
+import org.simantics.databoard.binding.mutable.Variant;
+import org.simantics.databoard.binding.reflection.BindingRequest;
+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.NumberType;
+import org.simantics.databoard.type.StringType;
+import org.simantics.databoard.type.VariantType;
+
+public class ImmutableClassesFactory implements TypeClassSubFactory {
+       
+       public ImmutableClassesFactory() {
+       }
+       
+       @Override
+       public BindingRequest construct(TypeClassFactory mainFactory, Datatype type) 
+       throws BindingConstructionException 
+       {
+               
+               if ( type instanceof ArrayType ) {
+                       List<Annotation> annotations = new ArrayList<Annotation>();
+                       ArrayType at = (ArrayType) type;
+                       BindingRequest cbr = construct(mainFactory, at.componentType);
+                       if ( cbr == null ) {
+                               cbr = mainFactory.getClass(at.componentType);                           
+                       }
+
+                       String length = at.metadata.get(ArrayType.KEY_LENGTH);
+                       if (length != null) annotations.add( new LengthImpl( length ) );
+                       
+                       if ( cbr.getClazz() != null ) {
+                               for (Annotation a : cbr.annotations)
+                               {
+                                       annotations.add( a );
+                               }
+                               
+                               Class<?> arrayClass = Array.newInstance(cbr.getClazz(), 0).getClass();
+                               return new BindingRequest( arrayClass, annotations );
+                       }
+               }
+               
+               if ( type instanceof MapType ) {
+                       MapType mt = (MapType) type;
+                       List<Annotation> annotations = new ArrayList<Annotation>();
+                       BindingRequest kbr = construct(mainFactory, mt.keyType);
+                       BindingRequest vbr = construct(mainFactory, mt.valueType);
+                       if ( kbr == null ) kbr = mainFactory.getClass(mt.keyType);                                                      
+                       if ( vbr == null ) vbr = mainFactory.getClass(mt.valueType);
+                       if ( kbr.getClazz()!=null && vbr.getClazz()!=null ) {
+                               annotations.add( new ArgumentImpl(kbr.getClazz(), vbr.getClazz()) );                    
+                               return new BindingRequest( TreeMap.class, annotations );
+                       }
+               }
+               
+               if ( type instanceof StringType ) {
+                       List<Annotation> annotations = new ArrayList<Annotation>();
+                       StringType st = (StringType) type;
+                       
+                       String pattern = st.metadata.get(StringType.KEY_PATTERN);
+                       if (pattern != null) annotations.add( new PatternImpl( pattern ) );
+                       
+                       String mimetype = st.metadata.get(StringType.KEY_MIMETYPE);
+                       if (mimetype != null) annotations.add( new MIMETypeImpl( mimetype ) );
+                       
+                       String length = st.metadata.get(StringType.KEY_LENGTH);
+                       if (length != null) annotations.add( new LengthImpl( length ) );
+                       
+                       return new BindingRequest( String.class, annotations );                 
+               }
+               
+               if ( type instanceof NumberType ) {
+                       List<Annotation> annotations = new ArrayList<Annotation>();
+                       NumberType nt = (NumberType) type;
+                       
+                       String unit = nt.metadata.get(NumberType.KEY_UNIT);
+                       if (unit != null) annotations.add( new UnitImpl(unit) );
+                       
+                       String range = nt.metadata.get(NumberType.KEY_RANGE);
+                       if (range != null) annotations.add( new RangeImpl(range) );
+                       
+                       Class<?> clazz = null;
+                       if ( type instanceof IntegerType ) clazz = int.class;
+                       if ( type instanceof ByteType ) clazz = byte.class;
+                       if ( type instanceof LongType ) clazz = long.class;
+                       if ( type instanceof DoubleType ) clazz = double.class;
+                       if ( type instanceof FloatType ) clazz = float.class;
+                       
+                       return new BindingRequest( clazz, annotations );
+               }
+               
+               if ( type instanceof BooleanType ) {
+                       return new BindingRequest( boolean.class );
+               }
+               
+               if ( type instanceof VariantType ) {
+                       return new BindingRequest( Variant.class );
+               }
+               
+               return null;
+       }
+
+}