]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/java/JavaVariant.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / accessor / java / JavaVariant.java
index 74b7efb0d4bf0c1ded4c0c7190a6dddfac382cca..ab1f7523103c13cb66a83810c2e4e3d05abf14a7 100644 (file)
@@ -1,43 +1,43 @@
-/*******************************************************************************\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.accessor.java;
 
-import java.lang.ref.SoftReference;\r
-import java.util.concurrent.Executor;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.accessor.Accessor;\r
-import org.simantics.databoard.accessor.VariantAccessor;\r
-import org.simantics.databoard.accessor.error.AccessorConstructionException;\r
-import org.simantics.databoard.accessor.error.AccessorException;\r
-import org.simantics.databoard.accessor.error.ReferenceException;\r
-import org.simantics.databoard.accessor.event.Event;\r
-import org.simantics.databoard.accessor.event.ValueAssigned;\r
-import org.simantics.databoard.accessor.impl.AccessorParams;\r
-import org.simantics.databoard.accessor.impl.ListenerEntry;\r
-import org.simantics.databoard.accessor.interestset.InterestSet;\r
-import org.simantics.databoard.accessor.interestset.VariantInterestSet;\r
-import org.simantics.databoard.accessor.reference.ChildReference;\r
-import org.simantics.databoard.accessor.reference.ComponentReference;\r
-import org.simantics.databoard.accessor.reference.LabelReference;\r
-import org.simantics.databoard.adapter.AdaptException;\r
-import org.simantics.databoard.binding.ArrayBinding;\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.binding.RecordBinding;\r
-import org.simantics.databoard.binding.VariantBinding;\r
-import org.simantics.databoard.binding.error.BindingException;\r
-import org.simantics.databoard.binding.mutable.MutableVariant;\r
-import org.simantics.databoard.type.Datatype;\r
-import org.simantics.databoard.type.VariantType;\r
+import java.lang.ref.SoftReference;
+import java.util.concurrent.Executor;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.accessor.Accessor;
+import org.simantics.databoard.accessor.VariantAccessor;
+import org.simantics.databoard.accessor.error.AccessorConstructionException;
+import org.simantics.databoard.accessor.error.AccessorException;
+import org.simantics.databoard.accessor.error.ReferenceException;
+import org.simantics.databoard.accessor.event.Event;
+import org.simantics.databoard.accessor.event.ValueAssigned;
+import org.simantics.databoard.accessor.impl.AccessorParams;
+import org.simantics.databoard.accessor.impl.ListenerEntry;
+import org.simantics.databoard.accessor.interestset.InterestSet;
+import org.simantics.databoard.accessor.interestset.VariantInterestSet;
+import org.simantics.databoard.accessor.reference.ChildReference;
+import org.simantics.databoard.accessor.reference.ComponentReference;
+import org.simantics.databoard.accessor.reference.LabelReference;
+import org.simantics.databoard.adapter.AdaptException;
+import org.simantics.databoard.binding.ArrayBinding;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.RecordBinding;
+import org.simantics.databoard.binding.VariantBinding;
+import org.simantics.databoard.binding.error.BindingException;
+import org.simantics.databoard.binding.mutable.MutableVariant;
+import org.simantics.databoard.type.Datatype;
+import org.simantics.databoard.type.VariantType;
 
 public class JavaVariant extends JavaObject implements VariantAccessor {
 
@@ -62,9 +62,9 @@ public class JavaVariant extends JavaObject implements VariantAccessor {
        public <T extends Accessor> T getContentAccessor() throws AccessorConstructionException {
                try {
                        JavaObject sa = getExistingAccessor();
-                       if (sa==null) \r
-                       {\r
-                               readLock();\r
+                       if (sa==null) 
+                       {
+                               readLock();
                                try {
                                        // Create new child
                                        Binding cb = getBinding().getContentBinding(object);
@@ -96,8 +96,8 @@ public class JavaVariant extends JavaObject implements VariantAccessor {
                                                }
                                                le = le.next;
                                        }
-                               } finally {\r
-                                       readUnlock();\r
+                               } finally {
+                                       readUnlock();
                                }                               
                        }
                        return (T) sa;
@@ -112,22 +112,22 @@ public class JavaVariant extends JavaObject implements VariantAccessor {
        @Override
        public <T extends Accessor> T getComponent(ChildReference reference)
                        throws AccessorConstructionException {          
-               if (reference==null) return (T) this;\r
-               \r
-               if (reference instanceof LabelReference) {\r
-                       LabelReference lr = (LabelReference) reference;\r
-                       if (lr.label.equals("v")) {\r
-                               Accessor sa = getContentAccessor();\r
-                               if (reference.getChildReference()!=null) sa = sa.getComponent(reference.getChildReference());\r
-                               return (T) sa;\r
-                       }                       \r
-               }               \r
+               if (reference==null) return (T) this;
+               
+               if (reference instanceof LabelReference) {
+                       LabelReference lr = (LabelReference) reference;
+                       if (lr.label.equals("v")) {
+                               Accessor sa = getContentAccessor();
+                               if (reference.getChildReference()!=null) sa = sa.getComponent(reference.getChildReference());
+                               return (T) sa;
+                       }                       
+               }               
                
-               if (reference instanceof ComponentReference) {\r
-                       Accessor sa = getContentAccessor();\r
-                       if (reference.getChildReference()!=null) sa = sa.getComponent(reference.getChildReference());\r
-                       return (T) sa;\r
-               }\r
+               if (reference instanceof ComponentReference) {
+                       Accessor sa = getContentAccessor();
+                       if (reference.getChildReference()!=null) sa = sa.getComponent(reference.getChildReference());
+                       return (T) sa;
+               }
                
                throw new ReferenceException("Variant value reference expected, got "+reference.getClass().getName());
        }
@@ -141,50 +141,50 @@ public class JavaVariant extends JavaObject implements VariantAccessor {
        
        @Override
        public void setValue(Binding variantBinding, Object newVariant)
-               throws AccessorException {\r
+               throws AccessorException {
                writeLock();
                try {
                        if (binding instanceof VariantBinding == false)
-                               throw new AccessorException("VariantBinding is expected.");\r
-                       \r
+                               throw new AccessorException("VariantBinding is expected.");
+                       
                        Binding newValueBinding = ((VariantBinding)variantBinding).getContentBinding(newVariant);
                        Object newValueObject = ((VariantBinding)variantBinding).getContent(newVariant);
                        setContentValue(newValueBinding, newValueObject);
                } catch (BindingException e) {
                        throw new AccessorException( e ); 
-               } finally {\r
-                       writeUnlock();\r
+               } finally {
+                       writeUnlock();
                }
        }
 
        @Override
        public Object getContentValue(Binding contentBinding)
-       throws AccessorException {\r
+       throws AccessorException {
                readLock();
                try {
                        return getBinding().getContent(object);
                } catch (BindingException e) {
                        throw new AccessorException(e);
-               } finally {\r
-                       readUnlock();\r
+               } finally {
+                       readUnlock();
                }
        }
        
        @Override
-       public Datatype getContentType() throws AccessorException {\r
+       public Datatype getContentType() throws AccessorException {
                readLock();
                try {
                        return getBinding().getContentType(object);
                } catch (BindingException e) {
                        throw new AccessorException(e);
-               } finally {\r
-                       readUnlock();\r
+               } finally {
+                       readUnlock();
                }
        }
        
        @Override
        public void setContentValue(Binding valueBinding, Object newValue)
-       throws AccessorException {\r
+       throws AccessorException {
                writeLock();
                try {
                        // reuse sub-accessor, if type matches, and sub-accessor exists
@@ -201,31 +201,31 @@ public class JavaVariant extends JavaObject implements VariantAccessor {
                                        sa.invalidatedNotification();
                                        child = null;
                                        sa = null;
-                               }\r
-                               \r
-                               \r
-                               if (binding.isImmutable() && parent!=null && parent instanceof JavaArray) {\r
-                                       JavaObject jo = (JavaObject) parent;\r
-                                       ArrayBinding ab = (ArrayBinding) jo.binding;\r
-                                       Object nv = getBinding().create(valueBinding, newValue);\r
-                                       ab.set(jo.object, (Integer)keyInParent, nv);\r
-                                       this.object = nv;\r
-                               } else if (binding.isImmutable() && parent!=null && parent instanceof JavaRecord) {\r
-                                       JavaObject jo = (JavaObject) parent;\r
-                                       RecordBinding rb = (RecordBinding) jo.binding;\r
-                                       Object nv = getBinding().create(valueBinding, newValue);\r
-                                       rb.setComponent(jo.object, (Integer)keyInParent, nv);\r
-                                       this.object = nv;\r
-                               } else if (binding.isImmutable() && parent!=null && parent instanceof JavaVariant) {\r
-                                       JavaObject jo = (JavaObject) parent;\r
-                                       VariantBinding vb = (VariantBinding) jo.binding;\r
-                                       Object nv = getBinding().create(valueBinding, newValue);\r
-                                       vb.setContent(jo.object, getBinding(), nv);\r
-                                       this.object = nv;\r
-                               } else {                        \r
-                                       // Write new value\r
-                                       getBinding().setContent(object, valueBinding, newValue);\r
-                               }       \r
+                               }
+                               
+                               
+                               if (binding.isImmutable() && parent!=null && parent instanceof JavaArray) {
+                                       JavaObject jo = (JavaObject) parent;
+                                       ArrayBinding ab = (ArrayBinding) jo.binding;
+                                       Object nv = getBinding().create(valueBinding, newValue);
+                                       ab.set(jo.object, (Integer)keyInParent, nv);
+                                       this.object = nv;
+                               } else if (binding.isImmutable() && parent!=null && parent instanceof JavaRecord) {
+                                       JavaObject jo = (JavaObject) parent;
+                                       RecordBinding rb = (RecordBinding) jo.binding;
+                                       Object nv = getBinding().create(valueBinding, newValue);
+                                       rb.setComponent(jo.object, (Integer)keyInParent, nv);
+                                       this.object = nv;
+                               } else if (binding.isImmutable() && parent!=null && parent instanceof JavaVariant) {
+                                       JavaObject jo = (JavaObject) parent;
+                                       VariantBinding vb = (VariantBinding) jo.binding;
+                                       Object nv = getBinding().create(valueBinding, newValue);
+                                       vb.setContent(jo.object, getBinding(), nv);
+                                       this.object = nv;
+                               } else {                        
+                                       // Write new value
+                                       getBinding().setContent(object, valueBinding, newValue);
+                               }       
                                
                                
                                // Notify Listeners
@@ -233,13 +233,13 @@ public class JavaVariant extends JavaObject implements VariantAccessor {
                                while (le!=null) {
                                        // Notification
                                        VariantInterestSet is = le.getInterestSet();
-                                       if (is.inNotifications()) {\r
-                                               if (is.inValues()) {\r
-                                                       MutableVariant value = new MutableVariant( valueBinding, valueBinding.isImmutable() ? newValue : valueBinding.clone(newValue) );\r
-                                                       ValueAssigned e = new ValueAssigned(Bindings.MUTABLE_VARIANT, value );\r
-                                                       emitEvent(le, e);\r
-                                               } else {\r
-                                                       emitEvent( le, new ValueAssigned() );                                                   \r
+                                       if (is.inNotifications()) {
+                                               if (is.inValues()) {
+                                                       MutableVariant value = new MutableVariant( valueBinding, valueBinding.isImmutable() ? newValue : valueBinding.clone(newValue) );
+                                                       ValueAssigned e = new ValueAssigned(Bindings.MUTABLE_VARIANT, value );
+                                                       emitEvent(le, e);
+                                               } else {
+                                                       emitEvent( le, new ValueAssigned() );                                                   
                                                }
                                        }
                                        
@@ -259,8 +259,8 @@ public class JavaVariant extends JavaObject implements VariantAccessor {
 //                     throw new AccessorException(e);
                } catch (AdaptException e) {
                        throw new AccessorException(e);
-               } finally {\r
-                       writeUnlock();\r
+               } finally {
+                       writeUnlock();
                }
        }
        
@@ -317,13 +317,13 @@ public class JavaVariant extends JavaObject implements VariantAccessor {
                                        Object cv = getBinding().getContent(object);
                                        rollback = new ValueAssigned( Bindings.MUTABLE_VARIANT, new MutableVariant( cb, cv ) );
                                }
-       \r
+       
                                setValue(va.newValue.getBinding(), va.newValue.getValue());
 //                             setContentValue(va.newValue.getBinding(), va.newValue.getValue());
                                
-                               return rollback;\r
-                       } else {\r
-                               throw new AccessorException("Invalid event "+e.getClass().getName());\r
+                               return rollback;
+                       } else {
+                               throw new AccessorException("Invalid event "+e.getClass().getName());
                        }
                } catch (BindingException be) {
                        throw new AccessorException(be);