1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.project.management;
\r
14 import java.text.SimpleDateFormat;
\r
15 import java.util.Date;
\r
17 import org.eclipse.equinox.p2.metadata.IVersionedId;
\r
18 import org.eclipse.equinox.p2.metadata.Version;
\r
19 import org.eclipse.equinox.p2.metadata.VersionedId;
\r
20 import org.simantics.databoard.binding.error.RuntimeBindingException;
\r
21 import org.simantics.graph.representation.TransferableGraph1;
\r
24 * Graph Bundle extended.
\r
26 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
\r
28 public class GraphBundleEx extends GraphBundle implements IVersionedId {
\r
30 public static final SimpleDateFormat QUALIFIER_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");
\r
32 public static GraphBundleEx extend(GraphBundle bundle) {
\r
33 return new GraphBundleEx(bundle);
\r
37 * Replace "qualifier" string in version with current time in format of yyyyMMddHHmm.
\r
40 * @return v or new version with current time
\r
42 public static Version buildQualifier(Version v) {
\r
43 String qualifier = v.getSegment(3).toString();
\r
44 if (!qualifier.equals("qualifier")) return v;
\r
46 int major = (Integer) v.getSegment(0);
\r
47 int minor = (Integer) v.getSegment(1);
\r
48 int micro = (Integer) v.getSegment(2);
\r
49 qualifier = QUALIFIER_FORMAT.format( new Date() );
\r
51 return Version.createOSGi(major, minor, micro, qualifier);
\r
54 public static VersionedId buildQualifier(IVersionedId vid) {
\r
55 Version v = vid.getVersion();
\r
56 String id = vid.getId();
\r
57 return new VersionedId(id, buildQualifier(v));
\r
62 GraphBundleEx(GraphBundle e) {
\r
63 this.graph = e.graph;
\r
64 this.resource = e.resource;
\r
65 this.hashcode = e.hashcode;
\r
67 this.major = e.major;
\r
68 this.minor = e.minor;
\r
69 this.service = e.service;
\r
70 this.qualifier = e.qualifier;
\r
71 this.resourceArray = e.resourceArray;
\r
73 this.vid = new VersionedId(id, Version.createOSGi(major, minor, service, qualifier));
\r
74 this.immutable = e.immutable;
\r
77 public GraphBundleEx(String name, TransferableGraph1 data, String versionedId)
\r
78 throws RuntimeBindingException
\r
80 super(name, data, versionedId);
\r
81 Version v = Version.createOSGi(major, minor, service, qualifier);
\r
82 vid = new VersionedId(id, v);
\r
85 public GraphBundleEx(String name, TransferableGraph1 data, String id, String version)
\r
86 throws RuntimeBindingException
\r
88 super(name, data, id, version);
\r
89 Version v = Version.createOSGi(major, minor, service, qualifier);
\r
90 vid = new VersionedId(id, v);
\r
93 public GraphBundleEx(String name, TransferableGraph1 data, String id, Version version)
\r
94 throws RuntimeBindingException
\r
96 super(name, data, id, version.getSegment(0)+"."+version.getSegment(1)+"."+version.getSegment(2)+"."+version.getSegment(3));
\r
97 Version v = Version.createOSGi(major, minor, service, qualifier);
\r
98 vid = new VersionedId(id, v);
\r
101 public GraphBundleEx(String name, TransferableGraph1 data, IVersionedId vid, boolean isImmutable)
\r
102 throws RuntimeBindingException
\r
104 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());
\r
105 this.vid = new VersionedId(id, vid.getVersion());
\r
106 this.immutable = isImmutable;
\r
109 public GraphBundleEx(String name, TransferableGraph1 data, IVersionedId vid)
\r
110 throws RuntimeBindingException
\r
112 this(name, data, vid, true);
\r
116 * Converts "qualifier" into current time in format of "yyyyMMddHHmm".
\r
118 public void build() {
\r
119 vid = buildQualifier(vid);
\r
120 this.qualifier = vid.getVersion().getSegment(3).toString();
\r
123 public VersionedId getVid() {
\r
127 public Version getVersion() {
\r
128 return vid.getVersion();
\r