-/*******************************************************************************\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.
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
// 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);
return (T) sa;
} catch (BindingException e) {
throw new AccessorConstructionException(e);
- } finally {\r
- readUnlock();\r
+ } finally {
+ readUnlock();
}
}
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);
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)
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();
}
}
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;
}
} 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");
}
}