1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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.project.management;
14 import java.text.SimpleDateFormat;
15 import java.util.Date;
16 import java.util.function.Supplier;
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;
25 * Graph Bundle extended.
27 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
29 public class GraphBundleEx extends GraphBundle implements IVersionedId {
31 public static final SimpleDateFormat QUALIFIER_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");
33 public static GraphBundleEx extend(GraphBundle bundle) {
34 return new GraphBundleEx(bundle);
38 * Replace "qualifier" string in version with current time in format of yyyyMMddHHmm.
41 * @return v or new version with current time
43 public static Version buildQualifier(Version v) {
44 String qualifier = v.getSegment(3).toString();
45 if (!qualifier.equals("qualifier")) return v;
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() );
52 return Version.createOSGi(major, minor, micro, qualifier);
55 public static VersionedId buildQualifier(IVersionedId vid) {
56 Version v = vid.getVersion();
57 String id = vid.getId();
58 return new VersionedId(id, buildQualifier(v));
63 GraphBundleEx(GraphBundle e) {
64 this.graphSource = e.graphSource;
66 this.resource = e.resource;
67 this.hashcode = e.hashcode;
71 this.service = e.service;
72 this.qualifier = e.qualifier;
73 this.resourceArray = e.resourceArray;
75 this.vid = new VersionedId(id, Version.createOSGi(major, minor, service, qualifier));
76 this.immutable = e.immutable;
79 public GraphBundleEx(String name, TransferableGraph1 data, String versionedId)
80 throws RuntimeBindingException
82 super(name, data, versionedId);
83 Version v = Version.createOSGi(major, minor, service, qualifier);
84 vid = new VersionedId(id, v);
87 public GraphBundleEx(String name, TransferableGraph1 data, String id, String version)
88 throws RuntimeBindingException
90 super(name, data, id, version);
91 Version v = Version.createOSGi(major, minor, service, qualifier);
92 vid = new VersionedId(id, v);
95 public GraphBundleEx(String name, TransferableGraph1 data, String id, Version version)
96 throws RuntimeBindingException
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);
103 public GraphBundleEx(String name, TransferableGraph1 data, IVersionedId vid, boolean isImmutable)
104 throws RuntimeBindingException
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;
111 public GraphBundleEx(String name, Supplier<TransferableGraph1> source, int hashValue, IVersionedId vid, boolean isImmutable)
112 throws RuntimeBindingException
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;
119 public GraphBundleEx(String name, TransferableGraph1 data, IVersionedId vid)
120 throws RuntimeBindingException
122 this(name, data, vid, true);
126 * Converts "qualifier" into current time in format of "yyyyMMddHHmm".
128 public void build() {
129 vid = buildQualifier(vid);
130 this.qualifier = vid.getVersion().getSegment(3).toString();
133 public VersionedId getVid() {
137 public Version getVersion() {
138 return vid.getVersion();