--- /dev/null
+/*******************************************************************************\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
+package org.simantics.databoard.example.old;
+
+import org.simantics.databoard.Bindings;\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.annotations.Unit;\r
+import org.simantics.databoard.binding.error.BindingConstructionException;\r
+
+public class AdaptionExample2 {
+
+ static public class CarSI {
+ public String modelName;
+ public @Unit("km/h") double maxVelocity;
+ public @Unit("kg") double mass;
+ public @Unit("cm") double length;
+ public @Unit("kW") double power;
+
+ @Override
+ public String toString() {
+ 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);
+ }
+ }
+
+ static public class CarIm {
+ public String modelName;
+ public @Unit("mph") float maxVelocity;
+ public @Unit("lbs") float mass;
+ public @Unit("ft") float length;
+ public @Unit("hp(M)") float power;
+
+ @Override
+ public String toString() {
+ 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);
+ }
+ }
+
+ public static void main(String[] args) throws AdapterConstructionException, AdaptException, BindingConstructionException {
+
+ Adapter si2imAdapter = Bindings.getTypeAdapter(
+ Bindings.getBinding(CarSI.class),
+ Bindings.getBinding(CarIm.class));
+
+ CarSI fiatSi = new CarSI();
+ fiatSi.modelName = "Fiat 500";
+ fiatSi.mass = 1035.;
+ fiatSi.length = 355.;
+ fiatSi.maxVelocity = 205.;
+ fiatSi.power = 75.;
+
+ CarIm fiatIm = (CarIm) si2imAdapter.adapt( fiatSi );
+
+ System.out.println(fiatSi);
+ System.out.println(fiatIm);
+ }
+
+}
+