X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fexamples%2Forg%2Fsimantics%2Fdataboard%2Fexample%2Fold%2FSerializerExample2.java;fp=bundles%2Forg.simantics.databoard%2Fexamples%2Forg%2Fsimantics%2Fdataboard%2Fexample%2Fold%2FSerializerExample2.java;h=f7c6021f23524fba102ad5d2356c3b6a1a7955c6;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/examples/org/simantics/databoard/example/old/SerializerExample2.java b/bundles/org.simantics.databoard/examples/org/simantics/databoard/example/old/SerializerExample2.java new file mode 100644 index 000000000..f7c6021f2 --- /dev/null +++ b/bundles/org.simantics.databoard/examples/org/simantics/databoard/example/old/SerializerExample2.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * 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.example.old; + +import java.awt.geom.Rectangle2D; +import java.io.IOException; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Datatypes; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.error.BindingException; +import org.simantics.databoard.parser.repository.DataTypeSyntaxError; +import org.simantics.databoard.serialization.SerializationException; +import org.simantics.databoard.type.Datatype; + +/** + * This example demostrates how to use String serialization. + * + * @author Toni Kalajainen + */ +public class SerializerExample2 { + + public static void main(String[] args) throws SerializationException, IOException, BindingException, DataTypeSyntaxError { + + // Create Rectangle + Rectangle2D rect = new Rectangle2D.Double(5, 5, 100, 200); + Binding rectangleBinding = Bindings.getBindingUnchecked( Rectangle2D.Double.class ); + Datatype rectangleDataType = rectangleBinding.type(); + + // Print Rectangle Instance + System.out.println( rectangleBinding.printValueDefinition(rect, true) ); + + // Print Rectangle DataType + Binding dataTypeBinding = Bindings.getBindingUnchecked( Datatype.class ); + System.out.println( dataTypeBinding.printValueDefinition(rectangleDataType, true) ); + + Datatype vectorType = Datatypes.getDatatypeUnchecked(RepresentationExample2.Vector.class); + System.out.println( dataTypeBinding.printValueDefinition(vectorType, true ) ); + + // Decode Recrangle + rect = (Rectangle2D) rectangleBinding.parseValueDefinition( "(10, 10, 200, 200)" ); + + // Print decoded rectangle + System.out.println(rect); + + } + +} +