]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.project/src/org/simantics/project/management/GraphBundleEx.java
Added equations to exported packages
[simantics/platform.git] / bundles / org.simantics.project / src / org / simantics / project / management / GraphBundleEx.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.project.management;\r
13 \r
14 import java.text.SimpleDateFormat;\r
15 import java.util.Date;\r
16 \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
22 \r
23 /**\r
24  * Graph Bundle extended. \r
25  *\r
26  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>\r
27  */\r
28 public class GraphBundleEx extends GraphBundle implements IVersionedId {\r
29         \r
30         public static final SimpleDateFormat QUALIFIER_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");\r
31         \r
32         public static GraphBundleEx extend(GraphBundle bundle) {\r
33                 return new GraphBundleEx(bundle);\r
34         }\r
35         \r
36         /**\r
37          * Replace "qualifier" string in version with current time in format of yyyyMMddHHmm. \r
38          * \r
39          * @param v version\r
40          * @return v or new version with current time\r
41          */\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
45                 \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
50                 \r
51                 return Version.createOSGi(major, minor, micro, qualifier);\r
52         }\r
53         \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
58         }\r
59         \r
60         VersionedId vid;\r
61         \r
62         GraphBundleEx(GraphBundle e) {\r
63                 this.graph = e.graph;\r
64                 this.resource = e.resource;\r
65                 this.hashcode = e.hashcode;\r
66                 this.id = e.id;\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
72                 this.name = e.name;\r
73                 this.vid = new VersionedId(id, Version.createOSGi(major, minor, service, qualifier));\r
74                 this.immutable = e.immutable;\r
75         }\r
76         \r
77         public GraphBundleEx(String name, TransferableGraph1 data, String versionedId) \r
78         throws RuntimeBindingException \r
79         {\r
80                 super(name, data, versionedId);\r
81                 Version v = Version.createOSGi(major, minor, service, qualifier);\r
82                 vid = new VersionedId(id, v);\r
83         }       \r
84         \r
85         public GraphBundleEx(String name, TransferableGraph1 data, String id, String version) \r
86         throws RuntimeBindingException \r
87         {\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
91         }       \r
92 \r
93         public GraphBundleEx(String name, TransferableGraph1 data, String id, Version version) \r
94         throws RuntimeBindingException \r
95         {\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
99         }       \r
100         \r
101         public GraphBundleEx(String name, TransferableGraph1 data, IVersionedId vid, boolean isImmutable) \r
102         throws RuntimeBindingException \r
103         {\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
107         }\r
108 \r
109         public GraphBundleEx(String name, TransferableGraph1 data, IVersionedId vid) \r
110         throws RuntimeBindingException \r
111         {\r
112                 this(name, data, vid, true);\r
113         }\r
114         \r
115         /**\r
116          * Converts "qualifier" into current time in format of "yyyyMMddHHmm". \r
117          */\r
118         public void build() {\r
119                 vid = buildQualifier(vid);\r
120                 this.qualifier = vid.getVersion().getSegment(3).toString();\r
121         }\r
122         \r
123         public VersionedId getVid() {\r
124                 return vid;\r
125         }\r
126         \r
127         public Version getVersion() {\r
128                 return vid.getVersion();\r
129         }\r
130         \r
131 }\r
132 \r