1 /*******************************************************************************
2 * Copyright (c) 2010 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.databoard.example.old;
14 import org.simantics.databoard.Bindings;
15 import org.simantics.databoard.binding.Binding;
16 import org.simantics.databoard.parser.repository.DataValueRepository;
20 * In this DuckTyping example, one input is deserialized to three classes
21 * that look about the same.
23 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
25 public class AdaptionExample1 {
27 static final String INPUT = "(3, 6, 9)";
29 static class DoubleVector {
30 public DoubleVector() {}
31 public double x, y, z;
33 static final Binding DoubleVectorBinding = Bindings.getBindingUnchecked( DoubleVector.class );
35 static class FloatVector {
36 public FloatVector() {}
39 static final Binding FloatVectorBinding = Bindings.getBindingUnchecked( FloatVector.class );
41 static class IntVector {
45 static final Binding IntVectorBinding = Bindings.getBindingUnchecked( IntVector.class );
47 public static void main(String[] args) throws Exception {
49 // Read to DoubleVector
50 DataValueRepository repo = new DataValueRepository();
51 DoubleVector doubleVector = (DoubleVector) DoubleVectorBinding.parseValue( INPUT, repo );
52 System.out.printf("DoubleVector: %f, %f, %f\n", doubleVector.x, doubleVector.y, doubleVector.z);
54 // Read to FloatVector
55 FloatVector floatVector = (FloatVector) FloatVectorBinding.parseValue( INPUT, repo );
56 System.out.printf("FloatVector: %f, %f, %f\n", floatVector.x, floatVector.y, floatVector.z);
59 IntVector intVector = (IntVector) IntVectorBinding.parseValue( INPUT, repo );
60 System.out.printf("IntVector: %d, %d, %d\n", intVector.x, intVector.y, intVector.z);