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.adapter.AdaptException;
16 import org.simantics.databoard.adapter.Adapter;
17 import org.simantics.databoard.adapter.AdapterConstructionException;
18 import org.simantics.databoard.annotations.Unit;
19 import org.simantics.databoard.binding.error.BindingConstructionException;
21 public class AdaptionExample2 {
23 static public class CarSI {
24 public String modelName;
25 public @Unit("km/h") double maxVelocity;
26 public @Unit("kg") double mass;
27 public @Unit("cm") double length;
28 public @Unit("kW") double power;
31 public String toString() {
32 return String.format("Name:%s, Mass: %2.0f kg, Power: %2.0f kW, Speed: %2.0f km/h, Length: %2.0f cm", modelName, mass, power, maxVelocity, length);
36 static public class CarIm {
37 public String modelName;
38 public @Unit("mph") float maxVelocity;
39 public @Unit("lbs") float mass;
40 public @Unit("ft") float length;
41 public @Unit("hp(M)") float power;
44 public String toString() {
45 return String.format("Name:%s, Mass: %2.0f lbs, Power: %2.0f hp, Speed: %2.0f mph, Length: %2.0f ft", modelName, mass, power, maxVelocity, length);
49 public static void main(String[] args) throws AdapterConstructionException, AdaptException, BindingConstructionException {
51 Adapter si2imAdapter = Bindings.getTypeAdapter(
52 Bindings.getBinding(CarSI.class),
53 Bindings.getBinding(CarIm.class));
55 CarSI fiatSi = new CarSI();
56 fiatSi.modelName = "Fiat 500";
59 fiatSi.maxVelocity = 205.;
62 CarIm fiatIm = (CarIm) si2imAdapter.adapt( fiatSi );
64 System.out.println(fiatSi);
65 System.out.println(fiatIm);