]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/java/JavaRecord.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / accessor / java / JavaRecord.java
index bae7664026a090a6aad50fb83b4b624ac2e6f7c8..1bc6b5c2862cab903c5b1657008ab80eb481cd39 100644 (file)
@@ -1,41 +1,41 @@
-/*******************************************************************************\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.RecordAccessor;\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.RecordInterestSet;\r
-import org.simantics.databoard.accessor.reference.ChildReference;\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.RecordBinding;\r
-import org.simantics.databoard.binding.error.BindingException;\r
-import org.simantics.databoard.binding.mutable.MutableVariant;\r
-import org.simantics.databoard.type.RecordType;\r
+import java.lang.ref.SoftReference;
+import java.util.concurrent.Executor;
+
+import org.simantics.databoard.accessor.Accessor;
+import org.simantics.databoard.accessor.RecordAccessor;
+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.RecordInterestSet;
+import org.simantics.databoard.accessor.reference.ChildReference;
+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.RecordBinding;
+import org.simantics.databoard.binding.error.BindingException;
+import org.simantics.databoard.binding.mutable.MutableVariant;
+import org.simantics.databoard.type.RecordType;
 
 /**
  * Accessor to a Java Object of Record Type.
@@ -86,7 +86,7 @@ public class JavaRecord extends JavaObject implements RecordAccessor {
        public <T extends Accessor> T getFieldAccessor(int index) throws AccessorConstructionException
        {
                if (index<0 || index>=count()) throw new ReferenceException("Field index ("+index+") out of bounds ("+count()+")");
-               \r
+               
                readLock();
                try {
                        // Get existing or create new
@@ -97,7 +97,7 @@ public class JavaRecord extends JavaObject implements RecordAccessor {
                                // Instantiate new accessor
                                Binding cb = getBinding().getComponentBindings()[index];
                                Object cv = getBinding().getComponent(object, index);
-                               sa = createSubAccessor(this, cb, cv, params);\r
+                               sa = createSubAccessor(this, cb, cv, params);
                                sa.keyInParent = index;
                                children[index] = new SoftReference<JavaObject>(sa);
 
@@ -121,8 +121,8 @@ public class JavaRecord extends JavaObject implements RecordAccessor {
                        return (T) sa;
                } catch (BindingException e) {
                        throw new AccessorConstructionException(e);
-               } finally {\r
-                       readUnlock();\r
+               } finally {
+                       readUnlock();
                }
        }
 
@@ -140,18 +140,18 @@ public class JavaRecord extends JavaObject implements RecordAccessor {
                JavaObject accessor = (ref!=null)?(JavaObject)ref.get():null;
                return accessor;
        }       
-       \r
-       @Override\r
-       public Object getFieldValue(String fieldName, Binding fieldBinding)\r
-                       throws AccessorException {\r
-               int fieldIndex = type().getComponentIndex(fieldName);\r
-               if (fieldIndex<0) throw new AccessorException("Field "+fieldName+" does not exist");\r
-               return getFieldValue(fieldIndex, fieldBinding);\r
-       }\r
+       
+       @Override
+       public Object getFieldValue(String fieldName, Binding fieldBinding)
+                       throws AccessorException {
+               int fieldIndex = type().getComponentIndex(fieldName);
+               if (fieldIndex<0) throw new AccessorException("Field "+fieldName+" does not exist");
+               return getFieldValue(fieldIndex, fieldBinding);
+       }
        
        @Override
        public Object getFieldValue(int index, Binding fieldBinding)
-                       throws AccessorException {\r
+                       throws AccessorException {
                readLock();
                try {
                        Object cv = getBinding().getComponent(object, index);
@@ -161,18 +161,18 @@ public class JavaRecord extends JavaObject implements RecordAccessor {
                        throw new AccessorException(e);
                } catch (AdaptException e) {
                        throw new AccessorException(e);
-               } catch (AdapterConstructionException e) {\r
-                       throw new AccessorException(e);\r
-               } finally {\r
-                       readUnlock();\r
+               } catch (AdapterConstructionException e) {
+                       throw new AccessorException(e);
+               } finally {
+                       readUnlock();
                }
        }
-\r
-       public void setFieldValue(String fieldName, Binding fieldBinding, Object value) throws AccessorException {\r
-               int fieldIndex = type().getComponentIndex(fieldName);\r
-               if (fieldIndex<0) throw new AccessorException("Field "+fieldName+" does not exist");\r
-               setFieldValue(fieldIndex, fieldBinding, value);\r
-       };\r
+
+       public void setFieldValue(String fieldName, Binding fieldBinding, Object value) throws AccessorException {
+               int fieldIndex = type().getComponentIndex(fieldName);
+               if (fieldIndex<0) throw new AccessorException("Field "+fieldName+" does not exist");
+               setFieldValue(fieldIndex, fieldBinding, value);
+       };
        
        @Override
        public void setFieldValue(int index, Binding binding, Object value)
@@ -215,10 +215,10 @@ public class JavaRecord extends JavaObject implements RecordAccessor {
                        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();
                }
        }
        
@@ -264,40 +264,40 @@ public class JavaRecord extends JavaObject implements RecordAccessor {
        public <T extends Accessor> T getComponent(ChildReference reference) throws AccessorConstructionException {
                if (reference==null) return (T) this;
                
-               if (reference instanceof LabelReference) {\r
-                       LabelReference lr = (LabelReference) reference;\r
-                       String fieldName = lr.label;\r
-                       Integer index = type().getComponentIndex(fieldName);\r
-                       if (index==null) throw new ReferenceException("RecordType doesn't have field by name \""+fieldName+"\"");\r
-                       JavaObject sa = getFieldAccessor(index);\r
-                       if (reference.getChildReference() != null) sa = sa.getComponent(reference.getChildReference());\r
-                       return (T) sa;                  \r
-               }               \r
+               if (reference instanceof LabelReference) {
+                       LabelReference lr = (LabelReference) reference;
+                       String fieldName = lr.label;
+                       Integer index = type().getComponentIndex(fieldName);
+                       if (index==null) throw new ReferenceException("RecordType doesn't have field by name \""+fieldName+"\"");
+                       JavaObject sa = getFieldAccessor(index);
+                       if (reference.getChildReference() != null) sa = sa.getComponent(reference.getChildReference());
+                       return (T) sa;                  
+               }               
                
                if (reference instanceof IndexReference) {
                        IndexReference ref = (IndexReference) reference;
                        int index = ref.getIndex();
-                       JavaObject sa = getFieldAccessor(index);\r
-                       if (reference.getChildReference() != null) sa = sa.getComponent(reference.getChildReference());\r
+                       JavaObject sa = getFieldAccessor(index);
+                       if (reference.getChildReference() != null) sa = sa.getComponent(reference.getChildReference());
                        return (T) sa;
-               } \r
-               \r
+               } 
+               
                if (reference instanceof NameReference) {
                        NameReference ref = (NameReference) reference;
                        String fieldName = ref.getName();
                        Integer index = type().getComponentIndex(fieldName);
                        if (index==null) throw new ReferenceException("RecordType doesn't have field by name \""+fieldName+"\"");
-                       JavaObject sa = getFieldAccessor(index);\r
-                       if (reference.getChildReference() != null) sa = sa.getComponent(reference.getChildReference());\r
+                       JavaObject sa = getFieldAccessor(index);
+                       if (reference.getChildReference() != null) sa = sa.getComponent(reference.getChildReference());
                        return (T) sa;                  
-               } \r
-               \r
+               } 
+               
                throw new ReferenceException(reference.getClass()+" is not a subreference of RecordType");
                
        }
 
        @Override
-       public void setValue(Binding binding, Object newValue) throws AccessorException {\r
+       public void setValue(Binding binding, Object newValue) throws AccessorException {
                writeLock();
                try {
                        RecordBinding rb = (RecordBinding) binding;
@@ -308,22 +308,22 @@ public class JavaRecord extends JavaObject implements RecordAccessor {
                        }
                } catch (BindingException e) {
                        throw new AccessorException(e);
-               } finally {\r
-                       writeUnlock();\r
+               } finally {
+                       writeUnlock();
                }
        }
-\r
+
        
        @Override
        Event applyLocal(Event e, boolean makeRollback) throws AccessorException {
-               Event rollback = null;\r
-               if (makeRollback) rollback = new ValueAssigned(getBinding(), getValue(getBinding())); \r
-               if (e instanceof ValueAssigned) {\r
-                       ValueAssigned va = (ValueAssigned) e;\r
-                       setValue(va.newValue.getBinding(), va.newValue.getValue());\r
-                       return rollback;\r
-               } else {\r
-                       throw new AccessorException("Cannot apply "+e.getClass().getName()+" to Record Type");                          \r
+               Event rollback = null;
+               if (makeRollback) rollback = new ValueAssigned(getBinding(), getValue(getBinding())); 
+               if (e instanceof ValueAssigned) {
+                       ValueAssigned va = (ValueAssigned) e;
+                       setValue(va.newValue.getBinding(), va.newValue.getValue());
+                       return rollback;
+               } else {
+                       throw new AccessorException("Cannot apply "+e.getClass().getName()+" to Record Type");                          
                }
        }