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 org.simantics.databoard.Bindings;
15 import org.simantics.databoard.adapter.AdaptException;
16 import org.simantics.databoard.binding.Binding;
17 import org.simantics.databoard.binding.error.BindingConstructionException;
18 import org.simantics.databoard.binding.error.BindingException;
20 public class DeepClone {
22 public static void main(String[] args) throws BindingConstructionException, BindingException, AdaptException {
24 // Binding can copy objects. All copies are deep.
25 // Mutable objects are duplicated, immutable are referenced.
27 // For instance, in object array, the array is copied, but its
28 // immutable literal instances (e.g. 1) is referenced.
30 Object[] original = new Object[] { new Object(), 1, "X", 123.456 };
31 Binding binding = Bindings.getBinding( original.getClass() );
32 Object[] copy = (Object[]) binding.cloneUnchecked( original );
35 System.out.println( "Original: "+binding.toString( original ) );
36 System.out.println( "Clone : "+binding.toString( copy ) );