X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.project%2Fsrc%2Forg%2Fsimantics%2Fproject%2Fmanagement%2FGraphBundleEx.java;fp=bundles%2Forg.simantics.project%2Fsrc%2Forg%2Fsimantics%2Fproject%2Fmanagement%2FGraphBundleEx.java;h=a7c0ad742a773601294e530b5bb77ecefe11bc41;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.project/src/org/simantics/project/management/GraphBundleEx.java b/bundles/org.simantics.project/src/org/simantics/project/management/GraphBundleEx.java new file mode 100644 index 000000000..a7c0ad742 --- /dev/null +++ b/bundles/org.simantics.project/src/org/simantics/project/management/GraphBundleEx.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.project.management; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.eclipse.equinox.p2.metadata.IVersionedId; +import org.eclipse.equinox.p2.metadata.Version; +import org.eclipse.equinox.p2.metadata.VersionedId; +import org.simantics.databoard.binding.error.RuntimeBindingException; +import org.simantics.graph.representation.TransferableGraph1; + +/** + * Graph Bundle extended. + * + * @author Toni Kalajainen + */ +public class GraphBundleEx extends GraphBundle implements IVersionedId { + + public static final SimpleDateFormat QUALIFIER_FORMAT = new SimpleDateFormat("yyyyMMddHHmm"); + + public static GraphBundleEx extend(GraphBundle bundle) { + return new GraphBundleEx(bundle); + } + + /** + * Replace "qualifier" string in version with current time in format of yyyyMMddHHmm. + * + * @param v version + * @return v or new version with current time + */ + public static Version buildQualifier(Version v) { + String qualifier = v.getSegment(3).toString(); + if (!qualifier.equals("qualifier")) return v; + + int major = (Integer) v.getSegment(0); + int minor = (Integer) v.getSegment(1); + int micro = (Integer) v.getSegment(2); + qualifier = QUALIFIER_FORMAT.format( new Date() ); + + return Version.createOSGi(major, minor, micro, qualifier); + } + + public static VersionedId buildQualifier(IVersionedId vid) { + Version v = vid.getVersion(); + String id = vid.getId(); + return new VersionedId(id, buildQualifier(v)); + } + + VersionedId vid; + + GraphBundleEx(GraphBundle e) { + this.graph = e.graph; + this.resource = e.resource; + this.hashcode = e.hashcode; + this.id = e.id; + this.major = e.major; + this.minor = e.minor; + this.service = e.service; + this.qualifier = e.qualifier; + this.resourceArray = e.resourceArray; + this.name = e.name; + this.vid = new VersionedId(id, Version.createOSGi(major, minor, service, qualifier)); + this.immutable = e.immutable; + } + + public GraphBundleEx(String name, TransferableGraph1 data, String versionedId) + throws RuntimeBindingException + { + super(name, data, versionedId); + Version v = Version.createOSGi(major, minor, service, qualifier); + vid = new VersionedId(id, v); + } + + public GraphBundleEx(String name, TransferableGraph1 data, String id, String version) + throws RuntimeBindingException + { + super(name, data, id, version); + Version v = Version.createOSGi(major, minor, service, qualifier); + vid = new VersionedId(id, v); + } + + public GraphBundleEx(String name, TransferableGraph1 data, String id, Version version) + throws RuntimeBindingException + { + super(name, data, id, version.getSegment(0)+"."+version.getSegment(1)+"."+version.getSegment(2)+"."+version.getSegment(3)); + Version v = Version.createOSGi(major, minor, service, qualifier); + vid = new VersionedId(id, v); + } + + public GraphBundleEx(String name, TransferableGraph1 data, IVersionedId vid, boolean isImmutable) + throws RuntimeBindingException + { + 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()); + this.vid = new VersionedId(id, vid.getVersion()); + this.immutable = isImmutable; + } + + public GraphBundleEx(String name, TransferableGraph1 data, IVersionedId vid) + throws RuntimeBindingException + { + this(name, data, vid, true); + } + + /** + * Converts "qualifier" into current time in format of "yyyyMMddHHmm". + */ + public void build() { + vid = buildQualifier(vid); + this.qualifier = vid.getVersion().getSegment(3).toString(); + } + + public VersionedId getVid() { + return vid; + } + + public Version getVersion() { + return vid.getVersion(); + } + +} +