]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.project/src/org/simantics/project/management/GraphBundleEx.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.project / src / org / simantics / project / management / GraphBundleEx.java
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 (file)
index 0000000..a7c0ad7
--- /dev/null
@@ -0,0 +1,132 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.project.management;\r
+\r
+import java.text.SimpleDateFormat;\r
+import java.util.Date;\r
+\r
+import org.eclipse.equinox.p2.metadata.IVersionedId;\r
+import org.eclipse.equinox.p2.metadata.Version;\r
+import org.eclipse.equinox.p2.metadata.VersionedId;\r
+import org.simantics.databoard.binding.error.RuntimeBindingException;\r
+import org.simantics.graph.representation.TransferableGraph1;\r
+\r
+/**\r
+ * Graph Bundle extended. \r
+ *\r
+ * @author Toni Kalajainen <toni.kalajainen@vtt.fi>\r
+ */\r
+public class GraphBundleEx extends GraphBundle implements IVersionedId {\r
+       \r
+       public static final SimpleDateFormat QUALIFIER_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");\r
+       \r
+       public static GraphBundleEx extend(GraphBundle bundle) {\r
+               return new GraphBundleEx(bundle);\r
+       }\r
+       \r
+       /**\r
+        * Replace "qualifier" string in version with current time in format of yyyyMMddHHmm. \r
+        * \r
+        * @param v version\r
+        * @return v or new version with current time\r
+        */\r
+       public static Version buildQualifier(Version v) {\r
+               String qualifier = v.getSegment(3).toString();\r
+               if (!qualifier.equals("qualifier")) return v;\r
+               \r
+               int major = (Integer) v.getSegment(0);\r
+               int minor = (Integer) v.getSegment(1);\r
+               int micro = (Integer) v.getSegment(2);          \r
+               qualifier = QUALIFIER_FORMAT.format( new Date() );\r
+               \r
+               return Version.createOSGi(major, minor, micro, qualifier);\r
+       }\r
+       \r
+       public static VersionedId buildQualifier(IVersionedId vid) {\r
+               Version v = vid.getVersion();\r
+               String id = vid.getId();\r
+               return new VersionedId(id, buildQualifier(v));\r
+       }\r
+       \r
+       VersionedId vid;\r
+       \r
+       GraphBundleEx(GraphBundle e) {\r
+               this.graph = e.graph;\r
+               this.resource = e.resource;\r
+               this.hashcode = e.hashcode;\r
+               this.id = e.id;\r
+               this.major = e.major;\r
+               this.minor = e.minor;\r
+               this.service = e.service;\r
+               this.qualifier = e.qualifier;\r
+               this.resourceArray = e.resourceArray;\r
+               this.name = e.name;\r
+               this.vid = new VersionedId(id, Version.createOSGi(major, minor, service, qualifier));\r
+               this.immutable = e.immutable;\r
+       }\r
+       \r
+       public GraphBundleEx(String name, TransferableGraph1 data, String versionedId) \r
+       throws RuntimeBindingException \r
+       {\r
+               super(name, data, versionedId);\r
+               Version v = Version.createOSGi(major, minor, service, qualifier);\r
+               vid = new VersionedId(id, v);\r
+       }       \r
+       \r
+       public GraphBundleEx(String name, TransferableGraph1 data, String id, String version) \r
+       throws RuntimeBindingException \r
+       {\r
+               super(name, data, id, version);\r
+               Version v = Version.createOSGi(major, minor, service, qualifier);\r
+               vid = new VersionedId(id, v);\r
+       }       \r
+\r
+       public GraphBundleEx(String name, TransferableGraph1 data, String id, Version version) \r
+       throws RuntimeBindingException \r
+       {\r
+               super(name, data, id, version.getSegment(0)+"."+version.getSegment(1)+"."+version.getSegment(2)+"."+version.getSegment(3));\r
+               Version v = Version.createOSGi(major, minor, service, qualifier);\r
+               vid = new VersionedId(id, v);\r
+       }       \r
+       \r
+       public GraphBundleEx(String name, TransferableGraph1 data, IVersionedId vid, boolean isImmutable) \r
+       throws RuntimeBindingException \r
+       {\r
+               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
+               this.vid = new VersionedId(id, vid.getVersion());\r
+               this.immutable = isImmutable;\r
+       }\r
+\r
+       public GraphBundleEx(String name, TransferableGraph1 data, IVersionedId vid) \r
+       throws RuntimeBindingException \r
+       {\r
+               this(name, data, vid, true);\r
+       }\r
+       \r
+       /**\r
+        * Converts "qualifier" into current time in format of "yyyyMMddHHmm". \r
+        */\r
+       public void build() {\r
+               vid = buildQualifier(vid);\r
+               this.qualifier = vid.getVersion().getSegment(3).toString();\r
+       }\r
+       \r
+       public VersionedId getVid() {\r
+               return vid;\r
+       }\r
+       \r
+       public Version getVersion() {\r
+               return vid.getVersion();\r
+       }\r
+       \r
+}\r
+\r