-/*******************************************************************************\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.binding;
-import java.util.IdentityHashMap;\r
-import java.util.Set;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.accessor.reference.ChildReference;\r
-import org.simantics.databoard.accessor.reference.IndexReference;\r
-import org.simantics.databoard.accessor.reference.KeyReference;\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.error.BindingException;\r
-import org.simantics.databoard.binding.error.RuntimeBindingException;\r
-import org.simantics.databoard.binding.impl.BindingPrintContext;\r
-import org.simantics.databoard.type.OptionalType;\r
-import org.simantics.databoard.util.IdentityPair;\r
+import java.util.IdentityHashMap;
+import java.util.Set;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.accessor.reference.ChildReference;
+import org.simantics.databoard.accessor.reference.IndexReference;
+import org.simantics.databoard.accessor.reference.KeyReference;
+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.error.BindingException;
+import org.simantics.databoard.binding.error.RuntimeBindingException;
+import org.simantics.databoard.binding.impl.BindingPrintContext;
+import org.simantics.databoard.type.OptionalType;
+import org.simantics.databoard.util.IdentityPair;
/**
public Binding getComponentBinding() {
return componentBinding;
}
- \r
- @Override\r
- public void readFrom(Binding srcBinding, Object src, Object dst)\r
- throws BindingException {\r
- OptionalBinding sb = (OptionalBinding) srcBinding;\r
- if (sb.hasValue(src)) {\r
- Binding dcb = getComponentBinding();\r
- Binding scb = sb.getComponentBinding();\r
- Object scv = sb.getValue(src);\r
- if (dcb.isImmutable() || !hasValue(dst)) {\r
- try {\r
- Object v = Bindings.clone(scv, scb, dcb);\r
- v = dcb.readFromTry(scb, scv, v);\r
- setValue(dst, v);\r
- } catch (AdaptException e) {\r
- throw new BindingException(e);\r
- }\r
- } else {\r
- Object v = getValue(src);\r
- v = dcb.readFromTry(scb, scv, v);\r
- setValue(dst, v);\r
- }\r
- } else {\r
- setNoValue(dst);\r
- }\r
- }\r
+
+ @Override
+ public void readFrom(Binding srcBinding, Object src, Object dst)
+ throws BindingException {
+ OptionalBinding sb = (OptionalBinding) srcBinding;
+ if (sb.hasValue(src)) {
+ Binding dcb = getComponentBinding();
+ Binding scb = sb.getComponentBinding();
+ Object scv = sb.getValue(src);
+ if (dcb.isImmutable() || !hasValue(dst)) {
+ try {
+ Object v = Bindings.clone(scv, scb, dcb);
+ v = dcb.readFromTry(scb, scv, v);
+ setValue(dst, v);
+ } catch (AdaptException e) {
+ throw new BindingException(e);
+ }
+ } else {
+ Object v = getValue(src);
+ v = dcb.readFromTry(scb, scv, v);
+ setValue(dst, v);
+ }
+ } else {
+ setNoValue(dst);
+ }
+ }
@Override
public void accept(Visitor1 v, Object obj) {
}
@Override
- public int deepCompare(Object o1, Object o2, Set<IdentityPair<Object, Object>> compareHistory) throws BindingException \r
+ public int deepCompare(Object o1, Object o2, Set<IdentityPair<Object, Object>> compareHistory) throws BindingException
{
Boolean h1 = hasValue(o1);
Boolean h2 = hasValue(o2);
throw new RuntimeBindingException(e);
}
}
-\r
- @Override\r
- protected void toString(Object value, BindingPrintContext ctx) throws BindingException {\r
- if(hasValue(value)) {\r
- getComponentBinding().toString(getValue(value), ctx);\r
- } else {\r
- ctx.b.append("null");\r
- }\r
- }\r
- \r
- @Override\r
- public Binding getComponentBinding(ChildReference path) {\r
- if (path==null) return this;\r
- if (path instanceof KeyReference) throw new IllegalArgumentException("KeyReference is not supported in OptionalType"); \r
- if (path instanceof NameReference) throw new IllegalArgumentException("NameReference is not supported in OptionalType"); \r
- if (path instanceof IndexReference && ((IndexReference) path).index!=0) throw new IllegalArgumentException("Index out of bounds");\r
- if (path instanceof LabelReference && !((LabelReference) path).label.equals("v")) throw new IllegalArgumentException("Unknown label");\r
- return componentBinding.getComponentBinding(path.childReference);\r
- } \r
- \r
- @Override\r
- public int getComponentCount() {\r
- return 1;\r
- }\r
- \r
- @Override\r
- public Binding getComponentBinding(int index) {\r
- if (index==0) return componentBinding;\r
- throw new IllegalArgumentException();\r
- }\r
-\r
- @Override\r
- protected boolean deepEquals(Object obj,\r
- Set<IdentityPair<Binding, Binding>> compareHistory) {\r
- return super.deepEquals( obj, compareHistory ) && componentBinding.equals(((OptionalBinding) obj).componentBinding, compareHistory);\r
- }\r
- \r
- @Override\r
- public int deepHashCode(IdentityHashMap<Object, Object> hashedObjects) {\r
- return super.deepHashCode( hashedObjects ) + componentBinding.hashCode(hashedObjects);\r
+
+ @Override
+ protected void toString(Object value, BindingPrintContext ctx) throws BindingException {
+ if(hasValue(value)) {
+ getComponentBinding().toString(getValue(value), ctx);
+ } else {
+ ctx.b.append("null");
+ }
+ }
+
+ @Override
+ public Binding getComponentBinding(ChildReference path) {
+ if (path==null) return this;
+ if (path instanceof KeyReference) throw new IllegalArgumentException("KeyReference is not supported in OptionalType");
+ if (path instanceof NameReference) throw new IllegalArgumentException("NameReference is not supported in OptionalType");
+ if (path instanceof IndexReference && ((IndexReference) path).index!=0) throw new IllegalArgumentException("Index out of bounds");
+ if (path instanceof LabelReference && !((LabelReference) path).label.equals("v")) throw new IllegalArgumentException("Unknown label");
+ return componentBinding.getComponentBinding(path.childReference);
+ }
+
+ @Override
+ public int getComponentCount() {
+ return 1;
+ }
+
+ @Override
+ public Binding getComponentBinding(int index) {
+ if (index==0) return componentBinding;
+ throw new IllegalArgumentException();
+ }
+
+ @Override
+ protected boolean deepEquals(Object obj,
+ Set<IdentityPair<Binding, Binding>> compareHistory) {
+ return super.deepEquals( obj, compareHistory ) && componentBinding.equals(((OptionalBinding) obj).componentBinding, compareHistory);
+ }
+
+ @Override
+ public int deepHashCode(IdentityHashMap<Object, Object> hashedObjects) {
+ return super.deepHashCode( hashedObjects ) + componentBinding.hashCode(hashedObjects);
}
}