X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Faccessor%2Fjava%2FJavaLong.java;h=d63942fbe5722c3afbd0e0a52c57f1b58855e675;hb=caad4b50af37ff3731a3e9a557dc697e9116de56;hp=d5d64821ae0234ce887124b1b2f8232d179dba5e;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/java/JavaLong.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/java/JavaLong.java index d5d64821a..d63942fbe 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/java/JavaLong.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/java/JavaLong.java @@ -1,36 +1,36 @@ -/******************************************************************************* - * 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 - *******************************************************************************/ +/******************************************************************************* + * 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 org.simantics.databoard.Bindings; -import org.simantics.databoard.accessor.Accessor; -import org.simantics.databoard.accessor.LongAccessor; -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.LongInterestSet; -import org.simantics.databoard.accessor.reference.ChildReference; -import org.simantics.databoard.binding.ArrayBinding; -import org.simantics.databoard.binding.Binding; -import org.simantics.databoard.binding.LongBinding; -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.ContainerOptionalBinding; -import org.simantics.databoard.type.LongType; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.accessor.Accessor; +import org.simantics.databoard.accessor.LongAccessor; +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.LongInterestSet; +import org.simantics.databoard.accessor.reference.ChildReference; +import org.simantics.databoard.binding.ArrayBinding; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.LongBinding; +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.ContainerOptionalBinding; +import org.simantics.databoard.type.LongType; public class JavaLong extends JavaObject implements LongAccessor { @@ -48,51 +48,51 @@ public class JavaLong extends JavaObject implements LongAccessor { } @Override - public long getValue() throws AccessorException { + public long getValue() throws AccessorException { readLock(); try { return getBinding().getValue_(object); } catch (BindingException e) { throw new AccessorException(e); - } finally { - readUnlock(); + } finally { + readUnlock(); } - } + } @Override public void setValue(long newValue) throws AccessorException { - if (newValue == getValue()) return; - writeLock(); + if (newValue == getValue()) return; + writeLock(); try { - if (binding.isImmutable() && parent!=null && parent instanceof JavaArray) { - JavaObject jo = (JavaObject) parent; - ArrayBinding ab = (ArrayBinding) jo.binding; - Object nv = getBinding().create(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(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(newValue); - vb.setContent(jo.object, getBinding(), nv); - this.object = nv; - } else if (binding.isImmutable() && parent!=null && parent instanceof JavaOptional) { - // Plain assign - JavaOptional jo = (JavaOptional) parent; - ContainerOptionalBinding vb = (ContainerOptionalBinding) jo.binding; - vb.setValue(jo.object, newValue); - this.object = newValue; - } else { - // Set value - getBinding().setValue(object, newValue); - } - + if (binding.isImmutable() && parent!=null && parent instanceof JavaArray) { + JavaObject jo = (JavaObject) parent; + ArrayBinding ab = (ArrayBinding) jo.binding; + Object nv = getBinding().create(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(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(newValue); + vb.setContent(jo.object, getBinding(), nv); + this.object = nv; + } else if (binding.isImmutable() && parent!=null && parent instanceof JavaOptional) { + // Plain assign + JavaOptional jo = (JavaOptional) parent; + ContainerOptionalBinding vb = (ContainerOptionalBinding) jo.binding; + vb.setValue(jo.object, newValue); + this.object = newValue; + } else { + // Set value + getBinding().setValue(object, newValue); + } + // Notify ListenerEntry le = listeners; @@ -107,8 +107,8 @@ public class JavaLong extends JavaObject implements LongAccessor { } catch (BindingException e) { throw new AccessorException(e); - } finally { - writeUnlock(); + } finally { + writeUnlock(); } } @@ -132,14 +132,14 @@ public class JavaLong extends JavaObject implements LongAccessor { @Override Event applyLocal(Event e, boolean makeRollback) throws AccessorException { - Event rollback = makeRollback ? new ValueAssigned( Bindings.LONG, getValue() ) : null; - if (e instanceof ValueAssigned) { - ValueAssigned va = (ValueAssigned) e; - if (va.newValue == null) throw new AccessorException("Long value expected, got null"); - setValue(va.newValue.getBinding(), va.newValue.getValue()); - return rollback; - } else { - throw new AccessorException("Cannot apply "+e.getClass().getName()+" to Long"); + Event rollback = makeRollback ? new ValueAssigned( Bindings.LONG, getValue() ) : null; + if (e instanceof ValueAssigned) { + ValueAssigned va = (ValueAssigned) e; + if (va.newValue == null) throw new AccessorException("Long value expected, got null"); + setValue(va.newValue.getBinding(), va.newValue.getValue()); + return rollback; + } else { + throw new AccessorException("Cannot apply "+e.getClass().getName()+" to Long"); } }