]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/examples/org/simantics/databoard/example/RecursiveDeepClone.java
Fixed ComponentTypeCommands.setUnit to support unit == null
[simantics/platform.git] / bundles / org.simantics.databoard / examples / org / simantics / databoard / example / RecursiveDeepClone.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.databoard.example;
13
14 import org.simantics.databoard.Bindings;
15 import org.simantics.databoard.annotations.Referable;
16 import org.simantics.databoard.binding.Binding;
17 import org.simantics.databoard.binding.error.BindingConstructionException;
18 import org.simantics.databoard.binding.error.BindingException;
19
20 public class RecursiveDeepClone {
21
22         // Recursive classes and classes that are referenced should be annotated with
23         // @Referable
24         static @Referable class X {
25                 public X reference;
26         }
27         
28         public static void main(String[] args) throws BindingConstructionException, BindingException {
29                 
30                 // Create recursive instance
31                 X original = new X();
32                 original.reference = original;
33                 
34                 Binding binding = Bindings.getBinding( original.getClass() );
35                 X copy = (X) binding.cloneUnchecked( original );
36
37                 // Print the objects
38                 System.out.println( "Original: "+binding.toString( original ) );
39                 System.out.println( "Clone   : "+binding.toString( copy     ) );
40         }
41         
42 }