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;
17 import org.eclipse.equinox.p2.metadata.IVersionedId;
18 import org.eclipse.equinox.p2.metadata.Version;
19 import org.eclipse.equinox.p2.metadata.VersionedId;
20 import org.simantics.databoard.binding.error.RuntimeBindingException;
21 import org.simantics.graph.representation.TransferableGraph1;
24 * Graph Bundle extended.
26 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
28 public class GraphBundleEx extends GraphBundle implements IVersionedId {
30 public static final SimpleDateFormat QUALIFIER_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");
32 public static GraphBundleEx extend(GraphBundle bundle) {
33 return new GraphBundleEx(bundle);
37 * Replace "qualifier" string in version with current time in format of yyyyMMddHHmm.
40 * @return v or new version with current time
42 public static Version buildQualifier(Version v) {
43 String qualifier = v.getSegment(3).toString();
44 if (!qualifier.equals("qualifier")) return v;
46 int major = (Integer) v.getSegment(0);
47 int minor = (Integer) v.getSegment(1);
48 int micro = (Integer) v.getSegment(2);
49 qualifier = QUALIFIER_FORMAT.format( new Date() );
51 return Version.createOSGi(major, minor, micro, qualifier);
54 public static VersionedId buildQualifier(IVersionedId vid) {
55 Version v = vid.getVersion();
56 String id = vid.getId();
57 return new VersionedId(id, buildQualifier(v));
62 GraphBundleEx(GraphBundle e) {
64 this.resource = e.resource;
65 this.hashcode = e.hashcode;
69 this.service = e.service;
70 this.qualifier = e.qualifier;
71 this.resourceArray = e.resourceArray;
73 this.vid = new VersionedId(id, Version.createOSGi(major, minor, service, qualifier));
74 this.immutable = e.immutable;
77 public GraphBundleEx(String name, TransferableGraph1 data, String versionedId)
78 throws RuntimeBindingException
80 super(name, data, versionedId);
81 Version v = Version.createOSGi(major, minor, service, qualifier);
82 vid = new VersionedId(id, v);
85 public GraphBundleEx(String name, TransferableGraph1 data, String id, String version)
86 throws RuntimeBindingException
88 super(name, data, id, version);
89 Version v = Version.createOSGi(major, minor, service, qualifier);
90 vid = new VersionedId(id, v);
93 public GraphBundleEx(String name, TransferableGraph1 data, String id, Version version)
94 throws RuntimeBindingException
96 super(name, data, id, version.getSegment(0)+"."+version.getSegment(1)+"."+version.getSegment(2)+"."+version.getSegment(3));
97 Version v = Version.createOSGi(major, minor, service, qualifier);
98 vid = new VersionedId(id, v);
101 public GraphBundleEx(String name, TransferableGraph1 data, IVersionedId vid, boolean isImmutable)
102 throws RuntimeBindingException
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());
105 this.vid = new VersionedId(id, vid.getVersion());
106 this.immutable = isImmutable;
109 public GraphBundleEx(String name, TransferableGraph1 data, IVersionedId vid)
110 throws RuntimeBindingException
112 this(name, data, vid, true);
116 * Converts "qualifier" into current time in format of "yyyyMMddHHmm".
118 public void build() {
119 vid = buildQualifier(vid);
120 this.qualifier = vid.getVersion().getSegment(3).toString();
123 public VersionedId getVid() {
127 public Version getVersion() {
128 return vid.getVersion();