]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/java/JavaUnion.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / accessor / java / JavaUnion.java
index dfcb874bc7dce213aaa54965329cbe6de30f249c..60e3c997a324dadc4aa6fd8111ab67a8837b719f 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.accessor.Accessor;\r
-import org.simantics.databoard.accessor.UnionAccessor;\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.UnionValueAssigned;\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.UnionInterestSet;\r
-import org.simantics.databoard.accessor.reference.ChildReference;\r
-import org.simantics.databoard.accessor.reference.ComponentReference;\r
-import org.simantics.databoard.accessor.reference.IndexReference;\r
-import org.simantics.databoard.accessor.reference.LabelReference;\r
-import org.simantics.databoard.accessor.reference.NameReference;\r
-import org.simantics.databoard.adapter.AdaptException;\r
-import org.simantics.databoard.adapter.AdapterConstructionException;\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.binding.UnionBinding;\r
-import org.simantics.databoard.binding.error.BindingException;\r
-import org.simantics.databoard.binding.mutable.MutableVariant;\r
-import org.simantics.databoard.type.UnionType;\r
+import java.lang.ref.SoftReference;
+import java.util.concurrent.Executor;
+
+import org.simantics.databoard.accessor.Accessor;
+import org.simantics.databoard.accessor.UnionAccessor;
+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.UnionValueAssigned;
+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.UnionInterestSet;
+import org.simantics.databoard.accessor.reference.ChildReference;
+import org.simantics.databoard.accessor.reference.ComponentReference;
+import org.simantics.databoard.accessor.reference.IndexReference;
+import org.simantics.databoard.accessor.reference.LabelReference;
+import org.simantics.databoard.accessor.reference.NameReference;
+import org.simantics.databoard.adapter.AdaptException;
+import org.simantics.databoard.adapter.AdapterConstructionException;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.UnionBinding;
+import org.simantics.databoard.binding.error.BindingException;
+import org.simantics.databoard.binding.mutable.MutableVariant;
+import org.simantics.databoard.type.UnionType;
 
 /**
  * Accessor to Java Object of Union Type
@@ -68,35 +68,35 @@ public class JavaUnion extends JavaObject implements UnionAccessor {
        public <T extends Accessor> T getComponent(ChildReference reference)
                        throws AccessorConstructionException {
                try {
-                       if (reference==null) return (T) this;\r
-                       \r
-                       if (reference instanceof LabelReference) {\r
-                               LabelReference lr = (LabelReference) reference;\r
-                               Integer tag = type().getComponentIndex( lr.label );\r
-                               \r
-                               if (tag==null && lr.label.equals("uv")) {\r
-                                       Accessor result = getComponentAccessor();\r
-                                       if (reference.getChildReference() != null)\r
-                                               result = result.getComponent(reference.getChildReference());\r
-                                       return (T) result;\r
-                               } else if (tag==null) {\r
-                                       throw new ReferenceException("Tag \""+lr.label+"\" not found");\r
-                               }\r
-                               \r
-                               if (tag != getTag()) throw new ReferenceException("The union isn't currently assigned with the expected type ("+type().getComponent(tag).name+")");\r
-                               Accessor result = getComponentAccessor();\r
-                               if (reference.getChildReference() != null)\r
-                                       result = result.getComponent(reference.getChildReference());\r
-                               return (T) result;                              \r
-                       }\r
+                       if (reference==null) return (T) this;
+                       
+                       if (reference instanceof LabelReference) {
+                               LabelReference lr = (LabelReference) reference;
+                               Integer tag = type().getComponentIndex( lr.label );
+                               
+                               if (tag==null && lr.label.equals("uv")) {
+                                       Accessor result = getComponentAccessor();
+                                       if (reference.getChildReference() != null)
+                                               result = result.getComponent(reference.getChildReference());
+                                       return (T) result;
+                               } else if (tag==null) {
+                                       throw new ReferenceException("Tag \""+lr.label+"\" not found");
+                               }
+                               
+                               if (tag != getTag()) throw new ReferenceException("The union isn't currently assigned with the expected type ("+type().getComponent(tag).name+")");
+                               Accessor result = getComponentAccessor();
+                               if (reference.getChildReference() != null)
+                                       result = result.getComponent(reference.getChildReference());
+                               return (T) result;                              
+                       }
                        
                        if (reference instanceof ComponentReference) {
                                Accessor result = getComponentAccessor();
                                if (reference.getChildReference() != null)
                                        result = result.getComponent(reference.getChildReference());
                                return (T) result;
-                       }\r
-                       \r
+                       }
+                       
                        if (reference instanceof IndexReference) {
                                IndexReference ir = (IndexReference) reference;
                                if (ir.index<0 || ir.index>=type().getComponentCount()) throw new ReferenceException("Tag index out of bounds");
@@ -105,8 +105,8 @@ public class JavaUnion extends JavaObject implements UnionAccessor {
                                if (reference.getChildReference() != null)
                                        result = result.getComponent(reference.getChildReference());
                                return (T) result;
-                       }\r
-                       \r
+                       }
+                       
                        if (reference instanceof NameReference) {
                                NameReference nr = (NameReference) reference;
                                Integer tag = type().getComponentIndex( nr.name );
@@ -116,7 +116,7 @@ public class JavaUnion extends JavaObject implements UnionAccessor {
                                if (reference.getChildReference() != null)
                                        result = result.getComponent(reference.getChildReference());
                                return (T) result;
-                       }\r
+                       }
                        
                        throw new ReferenceException(reference.getClass()+" is not a reference of UnionType");
                } catch (AccessorException ae) {
@@ -141,7 +141,7 @@ public class JavaUnion extends JavaObject implements UnionAccessor {
 
        @Override
        public void setValue(Binding unionBinding, Object newUnionValue)
-                       throws AccessorException {\r
+                       throws AccessorException {
                writeLock();
                try {
                        UnionBinding newUb = (UnionBinding) unionBinding;
@@ -151,8 +151,8 @@ public class JavaUnion extends JavaObject implements UnionAccessor {
                        setComponentValue(tag, cb, cv);
                } catch (BindingException e) {
                        throw new AccessorException(e);
-               } finally {\r
-                       writeUnlock();\r
+               } finally {
+                       writeUnlock();
                }
        }
 
@@ -163,8 +163,8 @@ public class JavaUnion extends JavaObject implements UnionAccessor {
                        // Get existing or create new
                        JavaObject sa = getExistingAccessor();
 
-                       if (sa==null) {\r
-                               readLock();\r
+                       if (sa==null) {
+                               readLock();
                                try {
                                        // Instantiate new accessor
                                        int tag = getBinding().getTag(object);
@@ -189,9 +189,9 @@ public class JavaUnion extends JavaObject implements UnionAccessor {
                                                        }
                                                }
                                                le = le.next;
-                                       }\r
-                               } finally {\r
-                                       readUnlock();\r
+                                       }
+                               } finally {
+                                       readUnlock();
                                }
 
                        }
@@ -203,7 +203,7 @@ public class JavaUnion extends JavaObject implements UnionAccessor {
        }
 
        @Override
-       public Object getComponentValue(Binding componentBinding) throws AccessorException {\r
+       public Object getComponentValue(Binding componentBinding) throws AccessorException {
                readLock();
                try {
                        int tag = getBinding().getTag(object);
@@ -214,22 +214,22 @@ public class JavaUnion extends JavaObject implements UnionAccessor {
                        throw new AccessorException( ae );
                } catch (BindingException be) {
                        throw new AccessorException( be );
-               } catch (AdapterConstructionException e) {\r
-                       throw new AccessorException( e );\r
-               } finally {\r
-                       readUnlock();\r
+               } catch (AdapterConstructionException e) {
+                       throw new AccessorException( e );
+               } finally {
+                       readUnlock();
                }
        }
 
        @Override
-       public int getTag() throws AccessorException {\r
+       public int getTag() throws AccessorException {
                readLock();
                try {
                        return getBinding().getTag(object);
                } catch (BindingException e) {
                        throw new AccessorException();
-               } finally {\r
-                       readUnlock();\r
+               } finally {
+                       readUnlock();
                }
        }
 
@@ -286,10 +286,10 @@ public class JavaUnion extends JavaObject implements UnionAccessor {
                        throw new AccessorException(e);
                } catch (AdaptException e) {
                        throw new AccessorException(e);
-               } catch (AdapterConstructionException e) {\r
-                       throw new AccessorException(e);\r
-               } finally {\r
-                       writeUnlock();\r
+               } catch (AdapterConstructionException e) {
+                       throw new AccessorException(e);
+               } finally {
+                       writeUnlock();
                }
                
        }
@@ -330,13 +330,13 @@ public class JavaUnion extends JavaObject implements UnionAccessor {
        @Override
        Event applyLocal(Event e, boolean makeRollback) throws AccessorException {
                try {
-                       Event rollback = null;\r
-                       if (e instanceof ValueAssigned) {\r
-                               ValueAssigned va = (ValueAssigned) e;\r
-                               if (makeRollback) rollback = new ValueAssigned(getBinding(), getValue(getBinding())); \r
-                               setValue(va.newValue.getBinding(), va.newValue.getValue());\r
-                               return rollback;\r
-                       } else          \r
+                       Event rollback = null;
+                       if (e instanceof ValueAssigned) {
+                               ValueAssigned va = (ValueAssigned) e;
+                               if (makeRollback) rollback = new ValueAssigned(getBinding(), getValue(getBinding())); 
+                               setValue(va.newValue.getBinding(), va.newValue.getValue());
+                               return rollback;
+                       } else          
                        if (e instanceof UnionValueAssigned) {          
                                UnionValueAssigned ua = (UnionValueAssigned) e;
                                if (ua.tag<0 || ua.tag>=type().getComponentCount()) throw new AccessorException("Tag index ("+ua.tag+") out of bounds.");
@@ -352,9 +352,9 @@ public class JavaUnion extends JavaObject implements UnionAccessor {
                                        rollback = new UnionValueAssigned(tag, v);                      
                                }
                                setComponentValue(ua.tag, ua.newValue.getBinding(), ua.newValue.getValue());            
-                               return rollback;\r
-                       } else {\r
-                               throw new AccessorException("Cannot apply "+e.getClass().getName()+" to Union Type");                           \r
+                               return rollback;
+                       } else {
+                               throw new AccessorException("Cannot apply "+e.getClass().getName()+" to Union Type");                           
                        }
                } catch (BindingException be) {
                        throw new AccessorException(be);