]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.project/src/org/simantics/project/management/GraphBundleEx.java
Platform startup performance improvements
[simantics/platform.git] / bundles / org.simantics.project / src / org / simantics / project / management / GraphBundleEx.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in 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.project.management;
13
14 import java.text.SimpleDateFormat;
15 import java.util.Date;
16 import java.util.function.Supplier;
17
18 import org.eclipse.equinox.p2.metadata.IVersionedId;
19 import org.eclipse.equinox.p2.metadata.Version;
20 import org.eclipse.equinox.p2.metadata.VersionedId;
21 import org.simantics.databoard.binding.error.RuntimeBindingException;
22 import org.simantics.graph.representation.TransferableGraph1;
23
24 /**
25  * Graph Bundle extended. 
26  *
27  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
28  */
29 public class GraphBundleEx extends GraphBundle implements IVersionedId {
30         
31         public static final SimpleDateFormat QUALIFIER_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");
32         
33         public static GraphBundleEx extend(GraphBundle bundle) {
34                 return new GraphBundleEx(bundle);
35         }
36         
37         /**
38          * Replace "qualifier" string in version with current time in format of yyyyMMddHHmm. 
39          * 
40          * @param v version
41          * @return v or new version with current time
42          */
43         public static Version buildQualifier(Version v) {
44                 String qualifier = v.getSegment(3).toString();
45                 if (!qualifier.equals("qualifier")) return v;
46                 
47                 int major = (Integer) v.getSegment(0);
48                 int minor = (Integer) v.getSegment(1);
49                 int micro = (Integer) v.getSegment(2);          
50                 qualifier = QUALIFIER_FORMAT.format( new Date() );
51                 
52                 return Version.createOSGi(major, minor, micro, qualifier);
53         }
54         
55         public static VersionedId buildQualifier(IVersionedId vid) {
56                 Version v = vid.getVersion();
57                 String id = vid.getId();
58                 return new VersionedId(id, buildQualifier(v));
59         }
60         
61         VersionedId vid;
62         
63         GraphBundleEx(GraphBundle e) {
64                 this.graphSource = e.graphSource;
65                 this.graph = e.graph;
66                 this.resource = e.resource;
67                 this.hashcode = e.hashcode;
68                 this.id = e.id;
69                 this.major = e.major;
70                 this.minor = e.minor;
71                 this.service = e.service;
72                 this.qualifier = e.qualifier;
73                 this.resourceArray = e.resourceArray;
74                 this.name = e.name;
75                 this.vid = new VersionedId(id, Version.createOSGi(major, minor, service, qualifier));
76                 this.immutable = e.immutable;
77         }
78         
79         public GraphBundleEx(String name, TransferableGraph1 data, String versionedId) 
80         throws RuntimeBindingException 
81         {
82                 super(name, data, versionedId);
83                 Version v = Version.createOSGi(major, minor, service, qualifier);
84                 vid = new VersionedId(id, v);
85         }       
86         
87         public GraphBundleEx(String name, TransferableGraph1 data, String id, String version) 
88         throws RuntimeBindingException 
89         {
90                 super(name, data, id, version);
91                 Version v = Version.createOSGi(major, minor, service, qualifier);
92                 vid = new VersionedId(id, v);
93         }       
94
95         public GraphBundleEx(String name, TransferableGraph1 data, String id, Version version) 
96         throws RuntimeBindingException 
97         {
98                 super(name, data, id, version.getSegment(0)+"."+version.getSegment(1)+"."+version.getSegment(2)+"."+version.getSegment(3));
99                 Version v = Version.createOSGi(major, minor, service, qualifier);
100                 vid = new VersionedId(id, v);
101         }       
102         
103         public GraphBundleEx(String name, TransferableGraph1 data, IVersionedId vid, boolean isImmutable) 
104         throws RuntimeBindingException 
105         {
106                 super(name, data, vid.getId(), vid.getVersion().getSegment(0).toString()+"."+vid.getVersion().getSegment(1).toString()+"."+vid.getVersion().getSegment(2).toString()+"."+vid.getVersion().getSegment(3).toString());
107                 this.vid = new VersionedId(id, vid.getVersion());
108                 this.immutable = isImmutable;
109         }
110
111         public GraphBundleEx(String name, Supplier<TransferableGraph1> source, int hashValue, IVersionedId vid, boolean isImmutable) 
112         throws RuntimeBindingException 
113         {
114                 super(name, source, hashValue, vid.getId(), vid.getVersion().getSegment(0).toString()+"."+vid.getVersion().getSegment(1).toString()+"."+vid.getVersion().getSegment(2).toString()+"."+vid.getVersion().getSegment(3).toString());
115                 this.vid = new VersionedId(id, vid.getVersion());
116                 this.immutable = isImmutable;
117         }
118
119         public GraphBundleEx(String name, TransferableGraph1 data, IVersionedId vid) 
120         throws RuntimeBindingException 
121         {
122                 this(name, data, vid, true);
123         }
124         
125         /**
126          * Converts "qualifier" into current time in format of "yyyyMMddHHmm". 
127          */
128         public void build() {
129                 vid = buildQualifier(vid);
130                 this.qualifier = vid.getVersion().getSegment(3).toString();
131         }
132         
133         public VersionedId getVid() {
134                 return vid;
135         }
136         
137         public Version getVersion() {
138                 return vid.getVersion();
139         }
140         
141 }
142