]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/TypicalSynchronizationMetadata.java
Fixed ComponentTypeCommands.setUnit to support unit == null
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / typicals / TypicalSynchronizationMetadata.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2012 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.modeling.typicals;
13
14 import java.io.IOException;
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.simantics.databoard.Bindings;
19 import org.simantics.databoard.binding.Binding;
20 import org.simantics.databoard.serialization.SerializationException;
21 import org.simantics.databoard.serialization.Serializer;
22 import org.simantics.db.Metadata;
23 import org.simantics.db.Resource;
24 import org.simantics.db.Session;
25
26 /**
27  * @author Tuukka Lehtonen
28  */
29 public class TypicalSynchronizationMetadata implements Metadata {
30
31     private static final Binding BINDING = 
32             Bindings.getBindingUnchecked(TypicalSynchronizationMetadata.class);
33     private static final Serializer SERIALIZER = 
34             Bindings.getSerializerUnchecked(BINDING);
35
36     public List<Resource> synchronizedTypicals;
37
38     public TypicalSynchronizationMetadata() {
39     }
40
41     @Override
42     public byte[] serialise(Session session) {
43         try {
44             return SERIALIZER.serialize(this);
45         } catch (IOException e) {
46             e.printStackTrace();
47             throw new RuntimeException(e);
48         }
49     }
50
51     public static TypicalSynchronizationMetadata deserialise(Session session, byte[] input) {
52         if (input == null) {
53             TypicalSynchronizationMetadata metadata = new TypicalSynchronizationMetadata();
54             metadata.synchronizedTypicals = new ArrayList<Resource>();
55             return metadata;
56         }
57         try {
58             return (TypicalSynchronizationMetadata) SERIALIZER.deserialize(input);
59         } catch (SerializationException e) {
60             e.printStackTrace();
61         } catch (IOException e) {
62             e.printStackTrace();
63         }
64         return null;
65     }
66
67     /**
68      * @param typicalInstance
69      * @return
70      */
71     public TypicalSynchronizationMetadata addTypical(Resource typicalInstance) {
72         synchronizedTypicals.add(typicalInstance);
73         return this;
74     }
75
76     public List<Resource> getTypicals() {
77         return synchronizedTypicals;
78     }
79
80 }