-/*******************************************************************************\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.binary;
-import java.io.IOException;\r
-import java.lang.ref.SoftReference;\r
-import java.util.ArrayList;\r
-import java.util.List;\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.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.file.FileRecordAccessor;\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.binding.Binding;\r
-import org.simantics.databoard.binding.RecordBinding;\r
-import org.simantics.databoard.binding.error.BindingConstructionException;\r
-import org.simantics.databoard.binding.error.BindingException;\r
-import org.simantics.databoard.binding.mutable.MutableVariant;\r
-import org.simantics.databoard.serialization.RuntimeSerializerConstructionException;\r
-import org.simantics.databoard.serialization.Serializer;\r
-import org.simantics.databoard.serialization.SerializerConstructionException;\r
-import org.simantics.databoard.type.RecordType;\r
-import org.simantics.databoard.util.binary.Blob;\r
-import org.simantics.databoard.util.binary.RandomAccessBinary.ByteSide;\r
+import java.io.IOException;
+import java.lang.ref.SoftReference;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executor;
+
+import org.simantics.databoard.Bindings;
+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.file.FileRecordAccessor;
+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.binding.Binding;
+import org.simantics.databoard.binding.RecordBinding;
+import org.simantics.databoard.binding.error.BindingConstructionException;
+import org.simantics.databoard.binding.error.BindingException;
+import org.simantics.databoard.binding.mutable.MutableVariant;
+import org.simantics.databoard.serialization.RuntimeSerializerConstructionException;
+import org.simantics.databoard.serialization.Serializer;
+import org.simantics.databoard.serialization.SerializerConstructionException;
+import org.simantics.databoard.type.RecordType;
+import org.simantics.databoard.util.binary.Blob;
+import org.simantics.databoard.util.binary.RandomAccessBinary.ByteSide;
/**
* Accessor to a Binary Record.
super(parent, blob, type, params);
if (type.isReferable()) throw new AccessorConstructionException("Refereable record are not supported");
- try {\r
- binding = (RecordBinding) params.bindingScheme.getBinding(type);\r
- } catch (BindingConstructionException e) {\r
- throw new AccessorConstructionException(e);\r
+ try {
+ binding = (RecordBinding) params.bindingScheme.getBinding(type);
+ } catch (BindingConstructionException e) {
+ throw new AccessorConstructionException(e);
}
int count = type.getComponentCount();
children = new java.lang.ref.Reference[count];
* @return
* @throws AccessorException
*/
- long getStartPosition(int fieldIndex) throws AccessorException {\r
- assert b.isOpen();\r
+ long getStartPosition(int fieldIndex) throws AccessorException {
+ assert b.isOpen();
readLock();
try {
// sa, saIndex = getFloorExistingAccessor
return b.position();
} catch (IOException ioe) {
throw new AccessorException( ioe );
- } catch (SerializerConstructionException e) {\r
- throw new AccessorException( e ); \r
- } finally {\r
- readUnlock();\r
+ } catch (SerializerConstructionException e) {
+ throw new AccessorException( e );
+ } finally {
+ readUnlock();
}
}
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()+")");
- assert b.isOpen();\r
+ assert b.isOpen();
readLock();
try {
// Get existing or create new
throw new AccessorConstructionException(e);
} catch (AccessorException e) {
throw new AccessorConstructionException(e);
- } catch (SerializerConstructionException e) {\r
- throw new AccessorConstructionException(e);\r
- } finally {\r
- readUnlock();\r
+ } catch (SerializerConstructionException e) {
+ throw new AccessorConstructionException(e);
+ } finally {
+ readUnlock();
}
}
BinaryObject accessor = (ref!=null)?(BinaryObject)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
- assert b.isOpen();\r
+ throws AccessorException {
+ assert b.isOpen();
readLock();
try {
b.position( getStartPosition(index) );
throw new AccessorException(e);
} catch (RuntimeSerializerConstructionException e) {
throw new AccessorException(e);
- } catch (SerializerConstructionException e) {\r
- throw new AccessorException(e);\r
- } finally {\r
- readUnlock();\r
+ } catch (SerializerConstructionException e) {
+ throw new AccessorException(e);
+ } finally {
+ readUnlock();
+ }
+ }
+
+ @Override
+ public void setFieldValue(String fieldName, Binding fieldBinding,
+ Object value) throws AccessorException {
+ assert b.isOpen();
+ writeLock();
+ try {
+ setFieldValueNoflush(fieldName, fieldBinding, value);
+ flush();
+ } finally {
+ writeUnlock();
+ }
+ }
+
+ @Override
+ public void setFieldValueNoflush(String fieldName, Binding fieldBinding,
+ Object value) throws AccessorException {
+ assert b.isOpen();
+ writeLock();
+ try {
+ int fieldIndex = type().getComponentIndex(fieldName);
+ if (fieldIndex<0) throw new AccessorException("Field "+fieldName+" does not exist");
+ setFieldValue(fieldIndex, fieldBinding, value);
+ } finally {
+ writeUnlock();
}
- }\r
- \r
- @Override\r
- public void setFieldValue(String fieldName, Binding fieldBinding,\r
- Object value) throws AccessorException {\r
- assert b.isOpen();\r
- writeLock();\r
- try {\r
- setFieldValueNoflush(fieldName, fieldBinding, value);\r
- flush();\r
- } finally {\r
- writeUnlock();\r
- }\r
- }\r
- \r
- @Override\r
- public void setFieldValueNoflush(String fieldName, Binding fieldBinding,\r
- Object value) throws AccessorException {\r
- assert b.isOpen();\r
- writeLock();\r
- try {\r
- int fieldIndex = type().getComponentIndex(fieldName);\r
- if (fieldIndex<0) throw new AccessorException("Field "+fieldName+" does not exist");\r
- setFieldValue(fieldIndex, fieldBinding, value);\r
- } finally {\r
- writeUnlock();\r
- }\r
}
@Override
public void setFieldValue(int index, Binding fieldBinding,
- Object value) throws AccessorException {\r
- assert b.isOpen();\r
- writeLock();\r
+ Object value) throws AccessorException {
+ assert b.isOpen();
+ writeLock();
try {
setFieldValueNoflush(index, fieldBinding, value);
- flush();\r
- } finally {\r
- writeUnlock();\r
+ flush();
+ } finally {
+ writeUnlock();
}
}
@Override
public void setFieldValueNoflush(int index, Binding cb, Object cv)
throws AccessorException {
- assert b.isOpen();\r
+ assert b.isOpen();
writeLock();
- try { \r
+ try {
BinaryObject sa = getExistingAccessor(index);
if (sa!=null) {
RecordInterestSet is = le.getInterestSet();
if (is.inNotificationsOf(index)) {
MutableVariant newValue = is.inValuesOf(index) ? new MutableVariant(cb, cv) : null;
- if (is.inValuesOf(index)) newValue = new MutableVariant(cb, cb.isImmutable() ? cv : cb.clone(cv));\r
- \r
+ if (is.inValuesOf(index)) newValue = new MutableVariant(cb, cb.isImmutable() ? cv : cb.clone(cv));
+
Event e = new ValueAssigned(new IndexReference(index), newValue);
emitEvent(le, e);
}
throw new AccessorException(e);
} catch (AdaptException e) {
throw new AccessorException(e);
- } catch (SerializerConstructionException e) {\r
- throw new AccessorException(e);\r
- } finally {\r
- writeUnlock();\r
+ } catch (SerializerConstructionException e) {
+ throw new AccessorException(e);
+ } finally {
+ writeUnlock();
}
}
@Override
public <T extends Accessor> T getComponent(ChildReference reference) throws AccessorConstructionException {
if (reference==null) return (T) this;
- \r
- 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
- BinaryObject 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+"\"");
+ BinaryObject 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();
- BinaryObject sa = getFieldAccessor(index);\r
- if (reference.getChildReference() != null) sa = sa.getComponent(reference.getChildReference());\r
- return (T) sa; \r
- } \r
- \r
+ BinaryObject sa = getFieldAccessor(index);
+ if (reference.getChildReference() != null) sa = sa.getComponent(reference.getChildReference());
+ return (T) sa;
+ }
+
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+"\"");
- BinaryObject sa = getFieldAccessor(index);\r
- if (reference.getChildReference() != null) sa = sa.getComponent(reference.getChildReference());\r
- return (T) sa; \r
- } \r
- \r
+ BinaryObject sa = getFieldAccessor(index);
+ if (reference.getChildReference() != null) sa = sa.getComponent(reference.getChildReference());
+ return (T) sa;
+ }
+
throw new ReferenceException(reference.getClass()+" is not a subreference of RecordType");
}
@Override
- public void setValueNoflush(Binding binding, Object newValue) throws AccessorException {\r
- assert b.isOpen();\r
+ public void setValueNoflush(Binding binding, Object newValue) throws AccessorException {
+ assert b.isOpen();
writeLock();
try {
RecordBinding rb = (RecordBinding) binding;
le = le.next;
}
}
- }\r
- \r
- // Notify record specific listeners\r
- /*\r
- if (listeners!=null) {\r
- ListenerEntry le = listeners;\r
- while (le!=null) { \r
- RecordInterestSet is = le.getInterestSet();\r
- if (is.inNotifications() && !is.inComponentNotifications()) {\r
- Event e = new ValueAssigned( binding, is.inValues() ? newValue : null);\r
- le.emitEvent(e);\r
- }\r
- le = le.next;\r
- } \r
- }*/\r
+ }
+
+ // Notify record specific listeners
+ /*
+ if (listeners!=null) {
+ ListenerEntry le = listeners;
+ while (le!=null) {
+ RecordInterestSet is = le.getInterestSet();
+ if (is.inNotifications() && !is.inComponentNotifications()) {
+ Event e = new ValueAssigned( binding, is.inValues() ? newValue : null);
+ le.emitEvent(e);
+ }
+ le = le.next;
+ }
+ }*/
} catch (BindingException e) {
throw new AccessorException(e);
} catch (IOException e) {
throw new AccessorException(e);
- } catch (SerializerConstructionException e) {\r
- throw new AccessorException(e);\r
- } finally {\r
- writeUnlock();\r
+ } catch (SerializerConstructionException e) {
+ throw new AccessorException(e);
+ } finally {
+ writeUnlock();
}
}
@Override
Event applyLocal(Event e, boolean makeRollback) throws AccessorException {
- if (e instanceof ValueAssigned) { \r
- ValueAssigned va = (ValueAssigned) e; \r
- Event rollback = null; \r
- if (makeRollback) {\r
- Binding binding = Bindings.getMutableBinding(type());\r
- rollback = new ValueAssigned(binding, getValue(binding)); \r
- }\r
- setValueNoflush(va.newValue.getBinding(), va.newValue.getValue());\r
- return rollback;\r
- } else {\r
- throw new AccessorException("Cannot apply "+e.getClass().getName()+" to Record Type");\r
+ if (e instanceof ValueAssigned) {
+ ValueAssigned va = (ValueAssigned) e;
+ Event rollback = null;
+ if (makeRollback) {
+ Binding binding = Bindings.getMutableBinding(type());
+ rollback = new ValueAssigned(binding, getValue(binding));
+ }
+ setValueNoflush(va.newValue.getBinding(), va.newValue.getValue());
+ return rollback;
+ } else {
+ throw new AccessorException("Cannot apply "+e.getClass().getName()+" to Record Type");
}
}