1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 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;
14 import java.io.IOException;
15 import java.util.Arrays;
16 import java.util.List;
18 import org.simantics.databoard.annotations.Identifier;
19 import org.simantics.databoard.parser.repository.DataTypeSyntaxError;
20 import org.simantics.databoard.util.Bean;
22 public class BeanExample {
24 public static class MyBean extends Bean {
26 public List<Integer> values;
29 public static class MyBean2 extends Bean.Id {
30 public @Identifier String name;
31 public List<Integer> values;
34 public static void main(String[] args) throws IOException, DataTypeSyntaxError {
37 MyBean bean = new MyBean();
47 System.out.println( "toString()");
48 System.out.println( " Bean = " + bean );
49 System.out.println( "" );
52 System.out.println( "Serialization" );
53 byte[] data = bean.serialize();
54 MyBean bean2 = new MyBean();
55 bean2.deserialize( data );
56 System.out.println( " Serialize(Bean) = " + Arrays.toString(data) );
57 System.out.println( " Deserialize(data) = " + bean2 );
58 System.out.println( "" );
61 System.out.println("JSON");
62 String json = bean.print();
63 System.out.println( " JSON(Bean3) = " + json);
64 MyBean bean3 = new MyBean();
66 System.out.println( " Parse(json) = " + bean3 );
67 System.out.println( "" );
70 System.out.println( "Hash-Equals" );
71 System.out.println( " hashCode(Bean) = " + bean.hashCode() );
72 System.out.println( " hashCode(Bean2) = " + bean2.hashCode() );
73 System.out.println( " equals(Bean, Bean2) = " + bean.equals(bean2) );
74 System.out.println( "" );
77 System.out.println( "Compare");
78 System.out.println( " compare(Bean, Bean2) = " + bean.compareTo(bean2) );
79 System.out.println( "" );
82 MyBean bean4 = (MyBean) bean.clone();
83 System.out.println( "Clone" );
84 System.out.println( " Bean4 = Bean.Clone()" );
85 System.out.println( " Bean4 = "+bean4 );
86 System.out.println( "" );
89 System.out.println( "ReadFrom");
90 System.out.println( " Bean.Name = \""+bean.name+"\"");
91 bean4.name = "New Name";
92 System.out.println( " Bean4.Name <-- \""+bean4.name+"\"");
93 System.out.println( " Bean.readFrom(Bean4)");
94 bean.readFrom( bean4 );
95 System.out.println( " Bean.Name = \""+bean.name+"\"");