-/*******************************************************************************\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.Map;\r
-import java.util.Map.Entry;\r
-import java.util.Set;\r
-import java.util.TreeMap;\r
-import java.util.TreeSet;\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.MapAccessor;\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.MapEntryAdded;\r
-import org.simantics.databoard.accessor.event.MapEntryRemoved;\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.MapInterestSet;\r
-import org.simantics.databoard.accessor.reference.ChildReference;\r
-import org.simantics.databoard.accessor.reference.KeyReference;\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.MapBinding;\r
-import org.simantics.databoard.binding.error.BindingException;\r
-import org.simantics.databoard.binding.mutable.MutableVariant;\r
-import org.simantics.databoard.type.MapType;\r
+import java.lang.ref.SoftReference;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.concurrent.Executor;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.accessor.Accessor;
+import org.simantics.databoard.accessor.MapAccessor;
+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.MapEntryAdded;
+import org.simantics.databoard.accessor.event.MapEntryRemoved;
+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.MapInterestSet;
+import org.simantics.databoard.accessor.reference.ChildReference;
+import org.simantics.databoard.accessor.reference.KeyReference;
+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.MapBinding;
+import org.simantics.databoard.binding.error.BindingException;
+import org.simantics.databoard.binding.mutable.MutableVariant;
+import org.simantics.databoard.type.MapType;
public class JavaMap extends JavaObject implements MapAccessor {
}
@Override
- public void clear() throws AccessorException {\r
+ public void clear() throws AccessorException {
writeLock();
try {
if (getBinding().size(object)==0) return;
} catch (BindingException e) {
throw new AccessorException( e );
- } finally {\r
- writeUnlock();\r
+ } finally {
+ writeUnlock();
}
}
* @param localKey
* @throws AccessorException
*/
- void removeLocal(Object lk) throws AccessorException {\r
+ void removeLocal(Object lk) throws AccessorException {
writeLock();
try {
boolean hadValue = getBinding().containsKey(object, lk);
} catch (BindingException e) {
throw new AccessorException( e );
- } finally {\r
- writeUnlock();\r
+ } finally {
+ writeUnlock();
}
}
- void putLocal(Object lk, Object lv) throws AccessorException {\r
+ void putLocal(Object lk, Object lv) throws AccessorException {
writeLock();
try {
JavaObject sa = getExistingAccessor(lk);
throw new AccessorException( e );
} catch (AdaptException e) {
throw new AccessorException( e );
- } finally {\r
- writeUnlock();\r
+ } finally {
+ writeUnlock();
}
}
@Override
public void put(Binding keyBinding, Object key, Binding valueBinding,
- Object value) throws AccessorException {\r
+ Object value) throws AccessorException {
writeLock();
try {
Object rk = key;
throw new AccessorException(e);
} catch (AdaptException e) {
throw new AccessorException(e);
- } finally {\r
- writeUnlock();\r
+ } finally {
+ writeUnlock();
}
}
@Override
public void putAll(Binding keyBinding, Binding valueBinding, Map<Object, Object> from)
- throws AccessorException {\r
+ throws AccessorException {
writeLock();
try {
// Convert keys and values
throw new AccessorException( e );
} catch (AdapterConstructionException e) {
throw new AccessorException( e );
- } finally {\r
- writeUnlock();\r
+ } finally {
+ writeUnlock();
}
}
@Override
- public void putAll(Binding keyBinding, Binding valueBinding, Object[] keys, Object[] values) throws AccessorException {\r
+ public void putAll(Binding keyBinding, Binding valueBinding, Object[] keys, Object[] values) throws AccessorException {
writeLock();
try {
// Convert keys and values
throw new AccessorException( e );
} catch (AdapterConstructionException e) {
throw new AccessorException( e );
- } finally {\r
- writeUnlock();\r
+ } finally {
+ writeUnlock();
}
}
removeLocal(lk);
} catch (AdaptException e) {
throw new AccessorException( e );
- } catch (AdapterConstructionException e) {\r
- throw new AccessorException( e );\r
+ } catch (AdapterConstructionException e) {
+ throw new AccessorException( e );
}
}
* @param values
* @throws AccessorException
*/
- void setValueLocal(Object keys[], Object values[]) throws AccessorException {\r
+ void setValueLocal(Object keys[], Object values[]) throws AccessorException {
writeLock();
try {
Set<Object> oldKeys = new TreeSet<Object>(getKeyBinding());
} catch (BindingException e) {
throw new AccessorException( e );
- } finally {\r
- writeUnlock();\r
+ } finally {
+ writeUnlock();
}
- }\r
+ }
@SuppressWarnings("unchecked")
@Override
}
JavaObject sa = getExistingAccessor(lk);
- if (sa!=null) return (T) sa;\r
- \r
- readLock();\r
+ if (sa!=null) return (T) sa;
+
+ readLock();
try {
Binding vb = getBinding().getValueBinding();
Binding kb = getBinding().getKeyBinding();
MutableVariant kv = new MutableVariant(kb, lk);
// Instantiate correct sub accessor.
- sa = createSubAccessor(this, vb, lv, params);\r
+ sa = createSubAccessor(this, vb, lv, params);
sa.keyInParent = lk;
children.put(lk, new SoftReference<JavaObject>(sa));
// Next listener
le = le.next;
}
- } finally {\r
- readUnlock();\r
- }\r
+ } finally {
+ readUnlock();
+ }
return (T) sa;
} catch (BindingException e) {
@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
- Binding kb = getKeyBinding();\r
- MutableVariant variant = (MutableVariant) adapt(lr.label, Bindings.STRING, Bindings.MUTABLE_VARIANT);\r
- Object value = variant.getValue(kb);\r
- \r
- Accessor result = (T) getValueAccessor(kb, value);\r
- if (reference.getChildReference() != null)\r
- result = result.getComponent(reference.getChildReference());\r
- return (T) result; \r
- } catch (AdaptException e2) {\r
- throw new ReferenceException(e2); \r
- } catch (AdapterConstructionException e) {\r
- throw new ReferenceException(e); \r
- } \r
+ if (reference==null) return (T) this;
+ if (reference instanceof LabelReference) {
+ LabelReference lr = (LabelReference) reference;
+ try {
+ Binding kb = getKeyBinding();
+ MutableVariant variant = (MutableVariant) adapt(lr.label, Bindings.STRING, Bindings.MUTABLE_VARIANT);
+ Object value = variant.getValue(kb);
+
+ Accessor result = (T) getValueAccessor(kb, value);
+ if (reference.getChildReference() != null)
+ result = result.getComponent(reference.getChildReference());
+ return (T) result;
+ } catch (AdaptException e2) {
+ throw new ReferenceException(e2);
+ } catch (AdapterConstructionException e) {
+ throw new ReferenceException(e);
+ }
} else if (reference instanceof KeyReference) {
KeyReference ref = (KeyReference) reference;
Accessor result = getValueAccessor(ref.key.getBinding(), ref.key.getValue());
if (reference.getChildReference() != null)
result = result.getComponent(reference.getChildReference());
return (T) result;
- } \r
+ }
throw new ReferenceException(reference.getClass().getName()+" is not a reference of a map");
}
@Override
- public int size() throws AccessorException {\r
+ 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
public boolean containsKey(Binding keyBinding, Object key)
- throws AccessorException {\r
+ throws AccessorException {
readLock();
try {
MapBinding mb = getBinding();
throw new AccessorException(e);
} catch (BindingException 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();
}
}
@Override
public boolean containsValue(Binding valueBinding, Object value)
- throws AccessorException {\r
+ throws AccessorException {
readLock();
try {
MapBinding mb = getBinding();
throw new AccessorException(e);
} catch (BindingException 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();
}
}
@Override
public Object get(Binding keyBinding, Object key, Binding valueBinding)
- throws AccessorException {\r
+ throws AccessorException {
readLock();
try {
MapBinding mb = getBinding();
Binding rvb = valueBinding;
Object rk = key;
Object lk = adapt(rk, rkb, lkb);
- Object lv = mb.get(object, lk);\r
+ Object lv = mb.get(object, lk);
if (lv == null) return null;
Object rv = adapt(lv, lvb, rvb);
return rv;
throw new AccessorException(e);
} catch (BindingException 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
- \r
- @Override\r
- public int count(Binding keyBinding, Object from,\r
- boolean fromInclusive, Object end, boolean endInclusive)\r
- throws AccessorException {\r
- readLock();\r
- try {\r
- MapBinding mb = getBinding();\r
- Object lf = params.adapterScheme.adapt(from, keyBinding, getKeyBinding());\r
- Object le = params.adapterScheme.adapt(end, keyBinding, getKeyBinding());\r
- return mb.count(object, lf, fromInclusive, le, endInclusive); \r
- } catch (BindingException e) {\r
- throw new AccessorException(e);\r
- } catch (AdaptException e) {\r
- throw new AccessorException(e);\r
- } finally {\r
- readUnlock();\r
- } \r
- }\r
-\r
- \r
- @Override\r
- public int getEntries(Binding keyBinding, Object from, boolean fromInclusive, Object end, boolean endInclusive, ArrayBinding keyArrayBinding, Object keysArray, ArrayBinding valueArrayBinding, Object valueArray, int limit) throws AccessorException {\r
- readLock();\r
- try {\r
- MapBinding mb = getBinding();\r
- Object lfrom = params.adapterScheme.adapt(from, keyBinding, getKeyBinding());\r
- Object lend = params.adapterScheme.adapt(end, keyBinding, getKeyBinding());\r
-\r
- return mb.getEntries(object, lfrom, fromInclusive, lend, endInclusive, keyArrayBinding, keysArray, valueArrayBinding, valueArray, limit);\r
- } catch (BindingException e) {\r
- throw new AccessorException(e);\r
- } catch (AdaptException e) {\r
- throw new AccessorException(e);\r
- } finally {\r
- readUnlock();\r
- } \r
- }\r
+ }
+
+ @Override
+ public int count(Binding keyBinding, Object from,
+ boolean fromInclusive, Object end, boolean endInclusive)
+ throws AccessorException {
+ readLock();
+ try {
+ MapBinding mb = getBinding();
+ Object lf = params.adapterScheme.adapt(from, keyBinding, getKeyBinding());
+ Object le = params.adapterScheme.adapt(end, keyBinding, getKeyBinding());
+ return mb.count(object, lf, fromInclusive, le, endInclusive);
+ } catch (BindingException e) {
+ throw new AccessorException(e);
+ } catch (AdaptException e) {
+ throw new AccessorException(e);
+ } finally {
+ readUnlock();
+ }
+ }
+
+
+ @Override
+ public int getEntries(Binding keyBinding, Object from, boolean fromInclusive, Object end, boolean endInclusive, ArrayBinding keyArrayBinding, Object keysArray, ArrayBinding valueArrayBinding, Object valueArray, int limit) throws AccessorException {
+ readLock();
+ try {
+ MapBinding mb = getBinding();
+ Object lfrom = params.adapterScheme.adapt(from, keyBinding, getKeyBinding());
+ Object lend = params.adapterScheme.adapt(end, keyBinding, getKeyBinding());
+
+ return mb.getEntries(object, lfrom, fromInclusive, lend, endInclusive, keyArrayBinding, keysArray, valueArrayBinding, valueArray, limit);
+ } catch (BindingException e) {
+ throw new AccessorException(e);
+ } catch (AdaptException e) {
+ throw new AccessorException(e);
+ } finally {
+ readUnlock();
+ }
+ }
@Override
public void getAll(Binding keyBinding, Binding valueBinding, Map<Object, Object> to)
- throws AccessorException {\r
+ throws AccessorException {
readLock();
try {
MapBinding mb = getBinding();
throw new AccessorException(e);
} catch (BindingException e) {
throw new AccessorException(e);
- } finally {\r
- readUnlock();\r
+ } finally {
+ readUnlock();
}
}
@Override
- public void getAll(Binding keyBinding, Binding valueBinding, Object[] keys, Object[] values) throws AccessorException {\r
+ public void getAll(Binding keyBinding, Binding valueBinding, Object[] keys, Object[] values) throws AccessorException {
readLock();
try {
int length = getBinding().size(object);
throw new AccessorException(e);
} catch (BindingException e) {
throw new AccessorException(e);
- } finally {\r
- readUnlock();\r
+ } finally {
+ readUnlock();
}
}
@Override
- public Object[] getKeys(Binding keyBinding) throws AccessorException {\r
+ public Object[] getKeys(Binding keyBinding) throws AccessorException {
readLock();
try {
Object[] result = getBinding().getKeys(object);
throw new AccessorException(e);
} catch (BindingException e) {
throw new AccessorException(e);
- } finally {\r
- readUnlock();\r
+ } finally {
+ readUnlock();
}
}
@Override
- public Object[] getValues(Binding valueBinding) throws AccessorException {\r
+ public Object[] getValues(Binding valueBinding) throws AccessorException {
readLock();
try {
Object[] result = getBinding().getValues(object);
throw new AccessorException(e);
} catch (BindingException e) {
throw new AccessorException(e);
- } finally {\r
- readUnlock();\r
+ } finally {
+ readUnlock();
}
}
@Override
- public Object getCeilingKey(Binding keyBinding, Object key) throws AccessorException {\r
+ public Object getCeilingKey(Binding keyBinding, Object key) throws AccessorException {
readLock();
try {
// Local & Requested Key Bindings
return rck;
} 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();
}
}
@Override
- public Object getFirstKey(Binding keyBinding) throws AccessorException {\r
+ public Object getFirstKey(Binding keyBinding) throws AccessorException {
readLock();
try {
Binding lkb = getKeyBinding();
return rfk;
} 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();
}
}
@Override
- public Object getLastKey(Binding keyBinding) throws AccessorException {\r
+ public Object getLastKey(Binding keyBinding) throws AccessorException {
readLock();
try {
Binding lkb = getKeyBinding();
return rfk;
} 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();
}
}
@Override
- public Object getFloorKey(Binding keyBinding, Object key) throws AccessorException {\r
+ public Object getFloorKey(Binding keyBinding, Object key) throws AccessorException {
readLock();
try {
// Local & Requested Key Bindings
return rfk;
} 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();
}
}
@Override
- public Object getHigherKey(Binding keyBinding, Object key) throws AccessorException {\r
+ public Object getHigherKey(Binding keyBinding, Object key) throws AccessorException {
readLock();
try {
// Local & Requested Key Bindings
return rhk;
} 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();
}
}
@Override
- public Object getLowerKey(Binding keyBinding, Object key) throws AccessorException {\r
+ public Object getLowerKey(Binding keyBinding, Object key) throws AccessorException {
readLock();
try {
// Local & Requested Key Bindings
return rlk;
} 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();
}
}
Event applyLocal(Event e, boolean makeRollback) throws AccessorException {
Event rollback = null;
- 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
- return rollback;\r
+ if (e instanceof ValueAssigned) {
+ ValueAssigned va = (ValueAssigned) e;
+ if (makeRollback) rollback = new ValueAssigned(getBinding(), getValue(getBinding()));
+ setValue(va.newValue.getBinding(), va.newValue.getValue());
+ return rollback;
} else if (e instanceof MapEntryAdded) {
MapEntryAdded ea = (MapEntryAdded) e;
if (ea.key==null) throw new AccessorException("Cannot apply entry added event because key is missing");