-/*******************************************************************************\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 gnu.trove.map.hash.TObjectIntHashMap;\r
-\r
-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.Datatypes;\r
-import org.simantics.databoard.accessor.Accessor;\r
-import org.simantics.databoard.accessor.VariantAccessor;\r
-import org.simantics.databoard.accessor.error.AccessorConstructionException;\r
-import org.simantics.databoard.accessor.error.AccessorException;\r
-import org.simantics.databoard.accessor.event.Event;\r
-import org.simantics.databoard.accessor.event.ValueAssigned;\r
-import org.simantics.databoard.accessor.file.FileVariantAccessor;\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.VariantInterestSet;\r
-import org.simantics.databoard.accessor.reference.ChildReference;\r
-import org.simantics.databoard.accessor.reference.ComponentReference;\r
-import org.simantics.databoard.accessor.reference.LabelReference;\r
-import org.simantics.databoard.adapter.AdaptException;\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.binding.VariantBinding;\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.Datatype;\r
-import org.simantics.databoard.type.VariantType;\r
-import org.simantics.databoard.util.binary.Blob;\r
+import gnu.trove.map.hash.TObjectIntHashMap;
+
+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.Datatypes;
+import org.simantics.databoard.accessor.Accessor;
+import org.simantics.databoard.accessor.VariantAccessor;
+import org.simantics.databoard.accessor.error.AccessorConstructionException;
+import org.simantics.databoard.accessor.error.AccessorException;
+import org.simantics.databoard.accessor.event.Event;
+import org.simantics.databoard.accessor.event.ValueAssigned;
+import org.simantics.databoard.accessor.file.FileVariantAccessor;
+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.VariantInterestSet;
+import org.simantics.databoard.accessor.reference.ChildReference;
+import org.simantics.databoard.accessor.reference.ComponentReference;
+import org.simantics.databoard.accessor.reference.LabelReference;
+import org.simantics.databoard.adapter.AdaptException;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.VariantBinding;
+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.Datatype;
+import org.simantics.databoard.type.VariantType;
+import org.simantics.databoard.util.binary.Blob;
public class BinaryVariant extends BinaryObject implements VariantAccessor, FileVariantAccessor {
@SuppressWarnings("unchecked")
@Override
public <T extends Accessor> T getContentAccessor()
- throws AccessorConstructionException {\r
- assert b.isOpen();\r
+ throws AccessorConstructionException {
+ assert b.isOpen();
readLock();
try {
BinaryObject sa = getExistingAccessor();
throw new AccessorConstructionException(e);
} catch (AccessorException e) {
throw new AccessorConstructionException(e);
- } finally {\r
- readUnlock();\r
+ } finally {
+ readUnlock();
}
}
- protected BinaryObject getExistingAccessor() {\r
+ protected BinaryObject getExistingAccessor() {
SoftReference<BinaryObject> r = child;
if (r==null) return null;
BinaryObject sa = r.get();
@Override
public void setContentValueNoflush(Binding valueBinding, Object value)
- throws AccessorException {\r
- assert b.isOpen();\r
+ throws AccessorException {
+ assert b.isOpen();
writeLock();
try {
// reuse sub-accessor, if type matches, and sub-accessor exists
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 void setContentValue(Binding valueBinding, Object value)
- throws AccessorException { \r
- assert b.isOpen();\r
- writeLock();\r
+ throws AccessorException {
+ assert b.isOpen();
+ writeLock();
try {
setContentValueNoflush(valueBinding, value);
- flush();\r
- } finally {\r
- writeUnlock();\r
+ flush();
+ } finally {
+ writeUnlock();
}
}
@Override
- public Datatype getContentType() throws AccessorException {\r
- assert b.isOpen();\r
+ public Datatype getContentType() throws AccessorException {
+ assert b.isOpen();
readLock();
try {
b.position(0L);
return type;
} catch (IOException e) {
throw new AccessorException( e );
- } finally {\r
- readUnlock();\r
+ } finally {
+ readUnlock();
}
}
@Override
public Object getContentValue(Binding contentBinding)
- throws AccessorException {\r
- assert b.isOpen();\r
+ throws AccessorException {
+ assert b.isOpen();
readLock();
try {
b.position(0L);
// return adapt(lv, lcb, rcb);
} catch (IOException 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 <T extends Accessor> T getComponent(ChildReference reference)
throws AccessorConstructionException {
- if (reference==null) return (T) this;\r
+ if (reference==null) return (T) this;
+
+ if (reference instanceof LabelReference) {
+ LabelReference lr = (LabelReference) reference;
+ if (lr.label.equals("v")) {
+ Accessor sa = getContentAccessor();
+ if (reference.getChildReference()!=null) sa = sa.getComponent(reference.getChildReference());
+ return (T) sa;
+ }
+ }
+
+ if (reference instanceof ComponentReference) {
+ Accessor sa = getContentAccessor();
+ if (reference.getChildReference()!=null) sa = sa.getComponent(reference.getChildReference());
+ return (T) sa;
+ }
- if (reference instanceof LabelReference) {\r
- LabelReference lr = (LabelReference) reference;\r
- if (lr.label.equals("v")) {\r
- Accessor sa = getContentAccessor();\r
- if (reference.getChildReference()!=null) sa = sa.getComponent(reference.getChildReference());\r
- return (T) sa;\r
- } \r
- } \r
- \r
- if (reference instanceof ComponentReference) {\r
- Accessor sa = getContentAccessor();\r
- if (reference.getChildReference()!=null) sa = sa.getComponent(reference.getChildReference());\r
- return (T) sa;\r
- }\r
- \r
- throw new AccessorConstructionException("Variant value reference expected, got "+reference.getClass().getName());\r
+ throw new AccessorConstructionException("Variant value reference expected, got "+reference.getClass().getName());
}
@Override
Event applyLocal(Event e, boolean makeRollback) throws AccessorException {
try {
if (e instanceof ValueAssigned ) {
- Event rollback = null;\r
+ Event rollback = null;
ValueAssigned va = (ValueAssigned) e;
if (va.newValue==null) throw new AccessorException("Cannot apply variant assignment event, the value is missing");
rollback = new ValueAssigned( Bindings.MUTABLE_VARIANT, new MutableVariant( cb, lv ));
}
- setValueNoflush(va.newValue.getBinding(), va.newValue.getValue());\r
+ setValueNoflush(va.newValue.getBinding(), va.newValue.getValue());
// setContentValueNoflush(va.newValue.getBinding(), va.newValue.getValue());
- return rollback;\r
- } else {\r
- throw new AccessorException("Invalid event "+e.getClass().getName()); \r
+ return rollback;
+ } else {
+ throw new AccessorException("Invalid event "+e.getClass().getName());
}
} catch (IOException ioe) {
throw new AccessorException(ioe);
} catch (RuntimeSerializerConstructionException rsce) {
- throw new AccessorException(rsce);\r
- } catch (SerializerConstructionException e2) { \r
- throw new AccessorException(e2);\r
- } catch (BindingConstructionException e2) {\r
- throw new AccessorException(e2);\r
+ throw new AccessorException(rsce);
+ } catch (SerializerConstructionException e2) {
+ throw new AccessorException(e2);
+ } catch (BindingConstructionException e2) {
+ throw new AccessorException(e2);
}
}
@Override
public void setValueNoflush(Binding variantBinding, Object variantValue)
- throws AccessorException {\r
- assert b.isOpen();\r
+ throws AccessorException {
+ assert b.isOpen();
writeLock();
try {
VariantBinding vb = (VariantBinding) variantBinding;
setContentValueNoflush(cb, cv);
} catch (BindingException e) {
throw new AccessorException( e );
- } finally {\r
- writeUnlock();\r
+ } finally {
+ writeUnlock();
}
}