-/*******************************************************************************\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.io.File;\r
-import java.lang.ref.SoftReference;\r
-import java.util.Collection;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-import java.util.Map.Entry;\r
-import java.util.SortedMap;\r
-import java.util.TreeMap;\r
-import java.util.concurrent.Executor;\r
-\r
-import org.simantics.databoard.accessor.Accessor;\r
-import org.simantics.databoard.accessor.ArrayAccessor;\r
-import org.simantics.databoard.accessor.StreamAccessor;\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.ArrayElementAdded;\r
-import org.simantics.databoard.accessor.event.ArrayElementRemoved;\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.ArrayInterestSet;\r
-import org.simantics.databoard.accessor.interestset.InterestSet;\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.adapter.AdaptException;\r
-import org.simantics.databoard.adapter.Adapter;\r
-import org.simantics.databoard.adapter.AdapterConstructionException;\r
-import org.simantics.databoard.binding.ArrayBinding;\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.binding.error.BindingException;\r
-import org.simantics.databoard.binding.mutable.MutableVariant;\r
-import org.simantics.databoard.type.ArrayType;\r
+import java.io.File;
+import java.lang.ref.SoftReference;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.concurrent.Executor;
+
+import org.simantics.databoard.accessor.Accessor;
+import org.simantics.databoard.accessor.ArrayAccessor;
+import org.simantics.databoard.accessor.StreamAccessor;
+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.ArrayElementAdded;
+import org.simantics.databoard.accessor.event.ArrayElementRemoved;
+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.ArrayInterestSet;
+import org.simantics.databoard.accessor.interestset.InterestSet;
+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.adapter.AdaptException;
+import org.simantics.databoard.adapter.Adapter;
+import org.simantics.databoard.adapter.AdapterConstructionException;
+import org.simantics.databoard.binding.ArrayBinding;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.error.BindingException;
+import org.simantics.databoard.binding.mutable.MutableVariant;
+import org.simantics.databoard.type.ArrayType;
public class JavaArray extends JavaObject implements ArrayAccessor, StreamAccessor {
}
@Override
- public void add(int index, Binding binding, Object value) throws AccessorException { \r
+ public void add(int index, Binding binding, Object value) throws AccessorException {
writeLock();
try {
boolean lastEntry = index==size();
throw new AccessorException(e);
// } catch (AccessorConstructionException e) {
// throw new AccessorException(e);
- } finally {\r
- writeUnlock();\r
+ } finally {
+ writeUnlock();
}
}
throw new AccessorException(e);
// } catch (AccessorConstructionException e) {
// throw new AccessorException(e);
- } finally {\r
- writeUnlock();\r
+ } 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
- try {\r
- Integer index = new Integer( lr.label );\r
- Accessor result = getAccessor(index);\r
- if (reference.getChildReference() != null)\r
- result = result.getComponent(reference.getChildReference());\r
- return (T) result;\r
- } catch ( NumberFormatException nfe ) {\r
- throw new ReferenceException(nfe);\r
- } \r
+ if (reference==null) return (T) this;
+ if (reference instanceof LabelReference) {
+ LabelReference lr = (LabelReference) reference;
+ try {
+ Integer index = new Integer( lr.label );
+ Accessor result = getAccessor(index);
+ if (reference.getChildReference() != null)
+ result = result.getComponent(reference.getChildReference());
+ return (T) result;
+ } catch ( NumberFormatException nfe ) {
+ throw new ReferenceException(nfe);
+ }
} else if (reference instanceof IndexReference) {
IndexReference ref = (IndexReference) reference;
int index = ref.getIndex();
@SuppressWarnings("unchecked")
@Override
- public <T extends Accessor> T getAccessor(int index) throws AccessorConstructionException {\r
+ public <T extends Accessor> T getAccessor(int index) throws AccessorConstructionException {
try {
int size = getBinding().size(object);
if (index<0 || index>=size) throw new ReferenceException("Element index ("+index+") out of bounds ("+size+")");
// Get existing or create new
JavaObject sa = getExistingAccessor(index);
- if (sa==null) {\r
- readLock();\r
+ if (sa==null) {
+ readLock();
try {
// Instantiate new accessor
Binding cb = getBinding().getComponentBinding();
Object cv = getBinding().get(object, index);
// Instantiate correct sub accessor.
- sa = createSubAccessor(this, cb, cv, params);\r
+ sa = createSubAccessor(this, cb, cv, params);
sa.keyInParent = index;
children.put(index, new SoftReference<JavaObject>(sa) );
// Next listener
le = le.next;
- }\r
- } finally {\r
- readUnlock();\r
+ }
+ } finally {
+ readUnlock();
}
}
@Override
public void getAll(Binding valueBinding, Collection<Object> values)
- throws AccessorException {\r
+ throws AccessorException {
readLock();
try {
Adapter adapter = params.adapterScheme.getAdapter(getBinding().getComponentBinding(), valueBinding, true, true);
throw new AccessorException(e);
} catch (BindingException e) {
throw new AccessorException(e);
- } finally {\r
- readUnlock();\r
+ } finally {
+ readUnlock();
}
}
@Override
- public void getAll(Binding valueBinding, Object[] array) throws AccessorException {\r
+ public void getAll(Binding valueBinding, Object[] array) throws AccessorException {
readLock();
try {
Adapter adapter = params.adapterScheme.getAdapter(getBinding().getComponentBinding(), valueBinding, true, true);
throw new AccessorException(e);
} catch (AdapterConstructionException e) {
throw new AccessorException(e);
- } finally {\r
- readUnlock();\r
+ } finally {
+ readUnlock();
}
}
@Override
public Object get(int index, Binding valueBinding)
- throws AccessorException {\r
+ throws AccessorException {
readLock();
try {
Adapter adapter = params.adapterScheme.getAdapter(getBinding().getComponentBinding(), valueBinding, true, true);
throw new AccessorException(e);
} catch (AdapterConstructionException e) {
throw new AccessorException(e);
- } finally {\r
- readUnlock();\r
+ } finally {
+ readUnlock();
+ }
+ }
+
+ @Override
+ public void get(int index, Binding valueBinding, Object dst)
+ throws AccessorException {
+ readLock();
+ try {
+ Binding scb = getBinding().getComponentBinding();
+ Object sv = getBinding().get(object, index);
+ valueBinding.readFrom(scb, sv, dst);
+ } catch (BindingException e) {
+ throw new AccessorException(e);
+ } finally {
+ readUnlock();
}
- }\r
- \r
- @Override\r
- public void get(int index, Binding valueBinding, Object dst)\r
- throws AccessorException {\r
- readLock();\r
- try { \r
- Binding scb = getBinding().getComponentBinding();\r
- Object sv = getBinding().get(object, index);\r
- valueBinding.readFrom(scb, sv, dst);\r
- } catch (BindingException e) {\r
- throw new AccessorException(e);\r
- } finally {\r
- readUnlock();\r
- }\r
}
@Override
public void remove(int index, int count) throws AccessorException {
if (index<0 || index+count>size()) throw new AccessorException("Index out of bounds");
- \r
+
writeLock();
try {
boolean lastEntry = index==size()-count;
throw new AccessorException(e);
} catch (BindingException e) {
throw new AccessorException(e);
- } finally {\r
- writeUnlock();\r
+ } finally {
+ writeUnlock();
}
}
@Override
public void set(int index, Binding binding, Object value)
throws AccessorException {
- if (index<0 || index>=size()) throw new AccessorException("Index out of bounds");\r
+ if (index<0 || index>=size()) throw new AccessorException("Index out of bounds");
writeLock();
try {
JavaObject sa = getExistingAccessor(index);
throw new AccessorException(e);
// } catch (AccessorConstructionException e) {
// throw new AccessorException(e);
- } finally {\r
- writeUnlock();\r
+ } finally {
+ writeUnlock();
}
}
@Override
public void setValue(Binding arrayBinding, Object newArray)
- throws AccessorException {\r
+ throws AccessorException {
writeLock();
try {
// Replace all elements
} catch (BindingException e) {
throw new AccessorException(e);
- } finally {\r
- writeUnlock();\r
+ } finally {
+ writeUnlock();
}
- }\r
- \r
- @Override\r
- public void setSize(int newSize) throws AccessorException {\r
- if (newSize<0) throw new AccessorException("Index out of bounds");\r
- \r
- writeLock();\r
- try {\r
- int oldSize = getBinding().size(object);\r
- \r
- // Add dummy instances\r
- if (newSize>oldSize) {\r
- Binding c = getBinding().getComponentBinding();\r
- int count = newSize-oldSize;\r
- Object[] arr = new Object[count];\r
- for (int i=0; i<count; i++) arr[i] = c.createDefault();\r
- addAll(oldSize, c, arr);\r
- }\r
- \r
- // Remove instances \r
- if (newSize<oldSize) {\r
- remove(newSize, oldSize-newSize);\r
- }\r
- \r
- } catch (BindingException e) {\r
- throw new AccessorException( e );\r
- } finally {\r
- writeUnlock();\r
- }\r
- \r
- }\r
+ }
@Override
- public int size() throws AccessorException { \r
+ public void setSize(int newSize) throws AccessorException {
+ if (newSize<0) throw new AccessorException("Index out of bounds");
+
+ writeLock();
+ try {
+ int oldSize = getBinding().size(object);
+
+ // Add dummy instances
+ if (newSize>oldSize) {
+ Binding c = getBinding().getComponentBinding();
+ int count = newSize-oldSize;
+ Object[] arr = new Object[count];
+ for (int i=0; i<count; i++) arr[i] = c.createDefault();
+ addAll(oldSize, c, arr);
+ }
+
+ // Remove instances
+ if (newSize<oldSize) {
+ remove(newSize, oldSize-newSize);
+ }
+
+ } catch (BindingException e) {
+ throw new AccessorException( e );
+ } finally {
+ writeUnlock();
+ }
+
+ }
+
+ @Override
+ public int size() throws AccessorException {
readLock();
try {
return getBinding().size(object);
} catch (BindingException e) {
throw new AccessorException(e);
- } finally {\r
- readUnlock();\r
+ } finally {
+ readUnlock();
}
}
@Override
Event applyLocal(Event e, boolean makeRollback) throws AccessorException {
try {
- Event rollback = null;\r
- if (e instanceof ValueAssigned) {\r
- ValueAssigned va = (ValueAssigned) e;\r
- if (makeRollback) rollback = new ValueAssigned(getBinding(), getValue(getBinding())); \r
- setValue(va.newValue.getBinding(), va.newValue.getValue());\r
+ Event rollback = null;
+ if (e instanceof ValueAssigned) {
+ ValueAssigned va = (ValueAssigned) e;
+ if (makeRollback) rollback = new ValueAssigned(getBinding(), getValue(getBinding()));
+ setValue(va.newValue.getBinding(), va.newValue.getValue());
} else
if (e instanceof ArrayElementAdded) {
ArrayElementAdded aa = (ArrayElementAdded) e;
} catch (AdaptException ae) {
throw new AccessorException( ae );
}
- }\r
-\r
- @Override\r
- public void flush() throws AccessorException {\r
- }\r
-\r
- @Override\r
- public void close() throws AccessorException {\r
- }\r
-\r
- @Override\r
- public void reset() throws AccessorException {\r
- }\r
-\r
- @Override\r
- public void addNoflush(Binding binding, Object value)\r
- throws AccessorException {\r
- add(binding, value);\r
- }\r
-\r
- @Override\r
- public void addAllNoflush(Binding binding, Object[] values)\r
- throws AccessorException {\r
- addAll(binding, values);\r
- }\r
-\r
- @Override\r
- public void addAllNoflush(int index, Binding binding, Object[] values)\r
- throws AccessorException {\r
- addAll(index, binding, values);\r
- }\r
-\r
- @Override\r
- public void addNoflush(int index, Binding binding, Object value)\r
- throws AccessorException {\r
- add(index, binding, value);\r
- }\r
-\r
- @Override\r
- public void setValueNoflush(Binding binding, Object newValue)\r
- throws AccessorException {\r
- setValue(binding, newValue);\r
- }\r
-\r
- @Override\r
- public void setNoflush(int index, Binding binding, Object value) throws AccessorException {\r
- set(index, binding, value);\r
- }\r
-\r
- @Override\r
- public void removeNoflush(int index, int count) throws AccessorException {\r
- remove(index, count);\r
- }\r
-\r
- @Override\r
- public void setSizeNoflush(int newSize) throws AccessorException {\r
- setSize(newSize);\r
- }\r
-\r
- @Override\r
- public File file() {\r
- return null;\r
- }\r
- \r
+ }
+
+ @Override
+ public void flush() throws AccessorException {
+ }
+
+ @Override
+ public void close() throws AccessorException {
+ }
+
+ @Override
+ public void reset() throws AccessorException {
+ }
+
+ @Override
+ public void addNoflush(Binding binding, Object value)
+ throws AccessorException {
+ add(binding, value);
+ }
+
+ @Override
+ public void addAllNoflush(Binding binding, Object[] values)
+ throws AccessorException {
+ addAll(binding, values);
+ }
+
+ @Override
+ public void addAllNoflush(int index, Binding binding, Object[] values)
+ throws AccessorException {
+ addAll(index, binding, values);
+ }
+
+ @Override
+ public void addNoflush(int index, Binding binding, Object value)
+ throws AccessorException {
+ add(index, binding, value);
+ }
+
+ @Override
+ public void setValueNoflush(Binding binding, Object newValue)
+ throws AccessorException {
+ setValue(binding, newValue);
+ }
+
+ @Override
+ public void setNoflush(int index, Binding binding, Object value) throws AccessorException {
+ set(index, binding, value);
+ }
+
+ @Override
+ public void removeNoflush(int index, int count) throws AccessorException {
+ remove(index, count);
+ }
+
+ @Override
+ public void setSizeNoflush(int newSize) throws AccessorException {
+ setSize(newSize);
+ }
+
+ @Override
+ public File file() {
+ return null;
+ }
+
}