Skip to content

Commit fa58259

Browse files
committed
Introduced NativeGraphExporter
1 parent 07da7f0 commit fa58259

File tree

5 files changed

+76
-10
lines changed

5 files changed

+76
-10
lines changed

src/main/java/nl/utwente/groove/explore/util/StateReporter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public void report() throws IOException {
4848
var exporter = Exporters.getExporter(ExportKind.GRAPH, fileType);
4949
if (exporter == null) {
5050
this.logger
51-
.append("Pattern %s does not specify known export format: states saved in native GXL%n",
52-
this.statePattern);
51+
.append("Pattern %s does not specify known export format: states saved in native %s%n",
52+
this.statePattern, FileType.STATE.getExtension());
5353
} else {
5454
this.logger.append("States saved as %s%n", fileType.getDescription());
5555
}

src/main/java/nl/utwente/groove/io/external/Exporters.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
import nl.utwente.groove.io.external.format.GraphExportListener.DotListener;
4141
import nl.utwente.groove.io.external.format.LTS2ControlExporter;
4242
import nl.utwente.groove.io.external.format.ListenerExporter;
43-
import nl.utwente.groove.io.external.format.NativePorter;
43+
import nl.utwente.groove.io.external.format.NativeGraphExporter;
44+
import nl.utwente.groove.io.external.format.NativeResourcePorter;
4445
import nl.utwente.groove.io.external.format.RasterExporter;
4546
import nl.utwente.groove.io.external.format.TikzExporter;
4647
import nl.utwente.groove.io.external.format.VectorExporter;
@@ -129,7 +130,8 @@ public static List<Exporter> getExporters() {
129130
/** Creates the list of all known exporters. */
130131
private static List<Exporter> createExporters() {
131132
List<Exporter> result = new ArrayList<>();
132-
result.add(NativePorter.getInstance());
133+
result.add(NativeResourcePorter.getInstance());
134+
result.add(NativeGraphExporter.getInstance());
133135
result.add(RasterExporter.getInstance());
134136
result.add(VectorExporter.getInstance());
135137
result.add(AutPorter.instance());

src/main/java/nl/utwente/groove/io/external/Importers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import nl.utwente.groove.io.external.format.AutPorter;
4242
import nl.utwente.groove.io.external.format.ColImporter;
4343
import nl.utwente.groove.io.external.format.EcorePorter;
44-
import nl.utwente.groove.io.external.format.NativePorter;
44+
import nl.utwente.groove.io.external.format.NativeResourcePorter;
4545

4646
/**
4747
* Utilities for importers.
@@ -131,7 +131,7 @@ public static List<Importer> getImporters() {
131131

132132
private static List<Importer> createImporters() {
133133
List<Importer> result = new ArrayList<>();
134-
result.add(NativePorter.getInstance());
134+
result.add(NativeResourcePorter.getInstance());
135135
result.add(AutPorter.instance());
136136
result.add(ColImporter.getInstance());
137137
result.add(EcorePorter.instance());
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* GROOVE: GRaphs for Object Oriented VErification
2+
* Copyright 2003--2023 University of Twente
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing,
10+
* software distributed under the License is distributed on an
11+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
* either express or implied. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* $Id$
16+
*/
17+
package nl.utwente.groove.io.external.format;
18+
19+
import java.io.File;
20+
import java.io.IOException;
21+
22+
import nl.utwente.groove.grammar.aspect.GraphConverter;
23+
import nl.utwente.groove.grammar.model.ResourceKind;
24+
import nl.utwente.groove.io.FileType;
25+
import nl.utwente.groove.io.external.AbstractExporter;
26+
import nl.utwente.groove.io.external.Exportable;
27+
import nl.utwente.groove.io.external.PortException;
28+
import nl.utwente.groove.io.graph.GxlIO;
29+
30+
/**
31+
* Import and export resources native to GROOVE, such as type and host graphs, and control programs
32+
* @author Harold Bruijntjes
33+
* @version $Revision$
34+
*/
35+
public class NativeGraphExporter extends AbstractExporter {
36+
private NativeGraphExporter() {
37+
super(ExportKind.GRAPH);
38+
register(ResourceKind.TYPE);
39+
register(ResourceKind.HOST);
40+
register(ResourceKind.RULE);
41+
}
42+
43+
/** Registers a resource kind with its default file type. */
44+
private void register(ResourceKind kind) {
45+
register(kind.getFileType());
46+
}
47+
48+
@Override
49+
public void doExport(Exportable exportable, File file, FileType fileType) throws PortException {
50+
var graph = GraphConverter.toAspect(exportable.graph());
51+
try {
52+
GxlIO.instance().saveGraph(graph.toPlainGraph(), file);
53+
} catch (IOException e) {
54+
throw new PortException(e);
55+
}
56+
}
57+
58+
/** Returns the singleton instance of this class. */
59+
public static final NativeGraphExporter getInstance() {
60+
return instance;
61+
}
62+
63+
private static final NativeGraphExporter instance = new NativeGraphExporter();
64+
}

src/main/java/nl/utwente/groove/io/external/format/NativePorter.java renamed to src/main/java/nl/utwente/groove/io/external/format/NativeResourcePorter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
* @author Harold Bruijntjes
4242
* @version $Revision$
4343
*/
44-
public class NativePorter extends AbstractResourcePorter {
45-
private NativePorter() {
44+
public class NativeResourcePorter extends AbstractResourcePorter {
45+
private NativeResourcePorter() {
4646
register(ResourceKind.TYPE);
4747
register(ResourceKind.HOST);
4848
register(ResourceKind.RULE);
@@ -137,9 +137,9 @@ public void doExport(Exportable exportable, File file, FileType fileType) throws
137137
}
138138

139139
/** Returns the singleton instance of this class. */
140-
public static final NativePorter getInstance() {
140+
public static final NativeResourcePorter getInstance() {
141141
return instance;
142142
}
143143

144-
private static final NativePorter instance = new NativePorter();
144+
private static final NativeResourcePorter instance = new NativeResourcePorter();
145145
}

0 commit comments

Comments
 (0)