1 /*******************************************************************************
\r
2 * Copyright (c) 2010 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.databoard.accessor.binary;
14 import java.io.IOException;
\r
16 import org.simantics.databoard.Bindings;
\r
17 import org.simantics.databoard.accessor.Accessor;
\r
18 import org.simantics.databoard.accessor.LongAccessor;
\r
19 import org.simantics.databoard.accessor.error.AccessorConstructionException;
\r
20 import org.simantics.databoard.accessor.error.AccessorException;
\r
21 import org.simantics.databoard.accessor.error.ReferenceException;
\r
22 import org.simantics.databoard.accessor.event.Event;
\r
23 import org.simantics.databoard.accessor.event.ValueAssigned;
\r
24 import org.simantics.databoard.accessor.file.FileLongAccessor;
\r
25 import org.simantics.databoard.accessor.impl.AccessorParams;
\r
26 import org.simantics.databoard.accessor.impl.ListenerEntry;
\r
27 import org.simantics.databoard.accessor.interestset.LongInterestSet;
\r
28 import org.simantics.databoard.accessor.reference.ChildReference;
\r
29 import org.simantics.databoard.binding.Binding;
\r
30 import org.simantics.databoard.binding.LongBinding;
\r
31 import org.simantics.databoard.binding.error.BindingException;
\r
32 import org.simantics.databoard.type.LongType;
\r
33 import org.simantics.databoard.util.binary.Blob;
\r
35 public class BinaryLong extends BinaryObject implements LongAccessor, FileLongAccessor {
37 public BinaryLong(BinaryObject parent, Blob blob, LongType type, AccessorParams params)
38 throws AccessorConstructionException {
39 super(parent, blob, type, params);
42 } catch (IOException e) {
43 throw new AccessorConstructionException(e);
48 public LongType type() {
49 return (LongType) type;
53 public long getValue() throws AccessorException {
\r
59 } catch (IOException e) {
60 throw new AccessorException(e);
67 Event applyLocal(Event e, boolean makeRollback) throws AccessorException {
68 Event rollback = makeRollback ? new ValueAssigned( Bindings.LONG, getValue() ) : null;
\r
69 if (e instanceof ValueAssigned) {
\r
70 ValueAssigned va = (ValueAssigned) e;
\r
71 if (va.newValue == null) throw new AccessorException("Long value expected, got null");
\r
72 setValueNoflush(va.newValue.getBinding(), va.newValue.getValue());
\r
75 throw new AccessorException("Cannot apply "+e.getClass().getName()+" to Long"); }
78 @SuppressWarnings("unchecked")
80 public <T extends Accessor> T getComponent(ChildReference reference)
81 throws AccessorConstructionException {
82 if (reference==null) return (T) this;
83 throw new ReferenceException(reference.getClass()+" is not a subreference of LongType");
87 public Object getValue(Binding binding) throws AccessorException {
\r
89 LongBinding bb = (LongBinding) binding;
92 } catch(BindingException e) {
93 throw new AccessorException(e);
97 public void setValueNoflush(long newValue) throws AccessorException {
\r
103 b.writeLong( newValue );
106 ListenerEntry le = listeners;
108 LongInterestSet is = le.getInterestSet();
109 if (is.inNotifications()) {
110 Event e = new ValueAssigned( Bindings.LONG, is.inValues() ? newValue : null );
116 } catch (IOException e) {
117 throw new AccessorException(e);
124 public void setValue(long newValue) throws AccessorException {
\r
128 setValueNoflush(newValue);
130 } catch (IOException e) {
131 throw new AccessorException(e);
138 public void setValueNoflush(Binding binding, Object newValue)
139 throws AccessorException {
141 long nv = ((LongBinding)binding).getValue_(newValue);
143 } catch (BindingException e) {
144 throw new AccessorException(e);