]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.image.ontology/src/org/simantics/diagram/stubs/ImageResource.java
Check head.state file existence before validating its integrity
[simantics/platform.git] / bundles / org.simantics.image.ontology / src / org / simantics / diagram / stubs / ImageResource.java
1 package org.simantics.diagram.stubs;
2
3 import org.simantics.db.RequestProcessor;
4 import org.simantics.db.Resource;
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.request.Read;
7 import org.simantics.db.Session;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.service.QueryControl;
10
11 public class ImageResource {
12     
13     public final Resource BitmapImage;
14     public final Resource HasAlphaData;
15     public final Resource HasAlphaData_Inverse;
16     public final Resource HasIcon;
17     public final Resource HasIcon_Inverse;
18     public final Resource HasImage;
19     public final Resource HasImageData;
20     public final Resource HasImageData_Inverse;
21     public final Resource HasImageDocument;
22     public final Resource HasImageDocument_Inverse;
23     public final Resource HasImage_Inverse;
24     public final Resource HasMatrixImageIndex;
25     public final Resource HasMatrixImageIndex_Inverse;
26     public final Resource HasMatrixType;
27     public final Resource HasMatrixType_Inverse;
28     public final Resource HasPhysicalHeight;
29     public final Resource HasPhysicalHeight_Inverse;
30     public final Resource HasPhysicalWidth;
31     public final Resource HasPhysicalWidth_Inverse;
32     public final Resource HasPixelHeight;
33     public final Resource HasPixelHeight_Inverse;
34     public final Resource HasPixelWidth;
35     public final Resource HasPixelWidth_Inverse;
36     public final Resource HasRGBData;
37     public final Resource HasRGBData_Inverse;
38     public final Resource HasSVGDocument;
39     public final Resource IconLibrary;
40     public final Resource Image;
41     public final Resource ImageLibrary;
42     public final Resource MatrixImage;
43     public final Resource SVGImage;
44         
45     public static class URIs {
46         public static final String BitmapImage = "http://www.simantics.org/Image-1.1/BitmapImage";
47         public static final String HasAlphaData = "http://www.simantics.org/Image-1.1/HasAlphaData";
48         public static final String HasAlphaData_Inverse = "http://www.simantics.org/Image-1.1/HasAlphaData/Inverse";
49         public static final String HasIcon = "http://www.simantics.org/Image-1.1/HasIcon";
50         public static final String HasIcon_Inverse = "http://www.simantics.org/Image-1.1/HasIcon/Inverse";
51         public static final String HasImage = "http://www.simantics.org/Image-1.1/HasImage";
52         public static final String HasImageData = "http://www.simantics.org/Image-1.1/HasImageData";
53         public static final String HasImageData_Inverse = "http://www.simantics.org/Image-1.1/HasImageData/Inverse";
54         public static final String HasImageDocument = "http://www.simantics.org/Image-1.1/HasImageDocument";
55         public static final String HasImageDocument_Inverse = "http://www.simantics.org/Image-1.1/HasImageDocument/Inverse";
56         public static final String HasImage_Inverse = "http://www.simantics.org/Image-1.1/HasImage/Inverse";
57         public static final String HasMatrixImageIndex = "http://www.simantics.org/Image-1.1/HasMatrixImageIndex";
58         public static final String HasMatrixImageIndex_Inverse = "http://www.simantics.org/Image-1.1/HasMatrixImageIndex/Inverse";
59         public static final String HasMatrixType = "http://www.simantics.org/Image-1.1/HasMatrixType";
60         public static final String HasMatrixType_Inverse = "http://www.simantics.org/Image-1.1/HasMatrixType/Inverse";
61         public static final String HasPhysicalHeight = "http://www.simantics.org/Image-1.1/HasPhysicalHeight";
62         public static final String HasPhysicalHeight_Inverse = "http://www.simantics.org/Image-1.1/HasPhysicalHeight/Inverse";
63         public static final String HasPhysicalWidth = "http://www.simantics.org/Image-1.1/HasPhysicalWidth";
64         public static final String HasPhysicalWidth_Inverse = "http://www.simantics.org/Image-1.1/HasPhysicalWidth/Inverse";
65         public static final String HasPixelHeight = "http://www.simantics.org/Image-1.1/HasPixelHeight";
66         public static final String HasPixelHeight_Inverse = "http://www.simantics.org/Image-1.1/HasPixelHeight/Inverse";
67         public static final String HasPixelWidth = "http://www.simantics.org/Image-1.1/HasPixelWidth";
68         public static final String HasPixelWidth_Inverse = "http://www.simantics.org/Image-1.1/HasPixelWidth/Inverse";
69         public static final String HasRGBData = "http://www.simantics.org/Image-1.1/HasRGBData";
70         public static final String HasRGBData_Inverse = "http://www.simantics.org/Image-1.1/HasRGBData/Inverse";
71         public static final String HasSVGDocument = "http://www.simantics.org/Image-1.1/HasSVGDocument";
72         public static final String IconLibrary = "http://www.simantics.org/Image-1.1/IconLibrary";
73         public static final String Image = "http://www.simantics.org/Image-1.1/Image";
74         public static final String ImageLibrary = "http://www.simantics.org/Image-1.1/ImageLibrary";
75         public static final String MatrixImage = "http://www.simantics.org/Image-1.1/MatrixImage";
76         public static final String SVGImage = "http://www.simantics.org/Image-1.1/SVGImage";
77     }
78     
79     public static Resource getResourceOrNull(ReadGraph graph, String uri) {
80         try {
81             return graph.getResource(uri);
82         } catch(DatabaseException e) {
83             System.err.println(e.getMessage());
84             return null;
85         }
86     }
87     
88     public ImageResource(ReadGraph graph) {
89         BitmapImage = getResourceOrNull(graph, URIs.BitmapImage);
90         HasAlphaData = getResourceOrNull(graph, URIs.HasAlphaData);
91         HasAlphaData_Inverse = getResourceOrNull(graph, URIs.HasAlphaData_Inverse);
92         HasIcon = getResourceOrNull(graph, URIs.HasIcon);
93         HasIcon_Inverse = getResourceOrNull(graph, URIs.HasIcon_Inverse);
94         HasImage = getResourceOrNull(graph, URIs.HasImage);
95         HasImageData = getResourceOrNull(graph, URIs.HasImageData);
96         HasImageData_Inverse = getResourceOrNull(graph, URIs.HasImageData_Inverse);
97         HasImageDocument = getResourceOrNull(graph, URIs.HasImageDocument);
98         HasImageDocument_Inverse = getResourceOrNull(graph, URIs.HasImageDocument_Inverse);
99         HasImage_Inverse = getResourceOrNull(graph, URIs.HasImage_Inverse);
100         HasMatrixImageIndex = getResourceOrNull(graph, URIs.HasMatrixImageIndex);
101         HasMatrixImageIndex_Inverse = getResourceOrNull(graph, URIs.HasMatrixImageIndex_Inverse);
102         HasMatrixType = getResourceOrNull(graph, URIs.HasMatrixType);
103         HasMatrixType_Inverse = getResourceOrNull(graph, URIs.HasMatrixType_Inverse);
104         HasPhysicalHeight = getResourceOrNull(graph, URIs.HasPhysicalHeight);
105         HasPhysicalHeight_Inverse = getResourceOrNull(graph, URIs.HasPhysicalHeight_Inverse);
106         HasPhysicalWidth = getResourceOrNull(graph, URIs.HasPhysicalWidth);
107         HasPhysicalWidth_Inverse = getResourceOrNull(graph, URIs.HasPhysicalWidth_Inverse);
108         HasPixelHeight = getResourceOrNull(graph, URIs.HasPixelHeight);
109         HasPixelHeight_Inverse = getResourceOrNull(graph, URIs.HasPixelHeight_Inverse);
110         HasPixelWidth = getResourceOrNull(graph, URIs.HasPixelWidth);
111         HasPixelWidth_Inverse = getResourceOrNull(graph, URIs.HasPixelWidth_Inverse);
112         HasRGBData = getResourceOrNull(graph, URIs.HasRGBData);
113         HasRGBData_Inverse = getResourceOrNull(graph, URIs.HasRGBData_Inverse);
114         HasSVGDocument = getResourceOrNull(graph, URIs.HasSVGDocument);
115         IconLibrary = getResourceOrNull(graph, URIs.IconLibrary);
116         Image = getResourceOrNull(graph, URIs.Image);
117         ImageLibrary = getResourceOrNull(graph, URIs.ImageLibrary);
118         MatrixImage = getResourceOrNull(graph, URIs.MatrixImage);
119         SVGImage = getResourceOrNull(graph, URIs.SVGImage);
120     }
121     
122     public static ImageResource getInstance(ReadGraph graph) {
123         Session session = graph.getSession();
124         ImageResource ret = session.peekService(ImageResource.class);
125         if(ret == null) {
126             QueryControl qc = graph.getService(QueryControl.class);
127             ret = new ImageResource(qc.getIndependentGraph(graph));
128             session.registerService(ImageResource.class, ret);
129         }
130         return ret;
131     }
132     
133     public static ImageResource getInstance(RequestProcessor session) throws DatabaseException {
134         ImageResource ret = session.peekService(ImageResource.class);
135         if(ret == null) {
136             ret = session.syncRequest(new Read<ImageResource>() {
137                 public ImageResource perform(ReadGraph graph) throws DatabaseException {
138                     QueryControl qc = graph.getService(QueryControl.class);
139                     return new ImageResource(qc.getIndependentGraph(graph));
140                 }
141             });
142             session.registerService(ImageResource.class, ret);
143         }
144         return ret;
145     }
146     
147 }
148