-
Notifications
You must be signed in to change notification settings - Fork 1
/
XmlDiscoverer.java
83 lines (69 loc) · 2.89 KB
/
XmlDiscoverer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package org.palladiosimulator.retriever.extraction.discoverers;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.CommonPlugin;
import org.jdom2.Document;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.palladiosimulator.retriever.services.Discoverer;
import org.palladiosimulator.retriever.services.RetrieverConfiguration;
import org.palladiosimulator.retriever.services.blackboard.RetrieverBlackboard;
import de.uka.ipd.sdq.workflow.jobs.AbstractBlackboardInteractingJob;
import de.uka.ipd.sdq.workflow.jobs.CleanupFailedException;
import de.uka.ipd.sdq.workflow.jobs.IBlackboardInteractingJob;
import de.uka.ipd.sdq.workflow.jobs.JobFailedException;
import de.uka.ipd.sdq.workflow.jobs.UserCanceledException;
public class XmlDiscoverer implements Discoverer {
public static final String DISCOVERER_ID = "org.palladiosimulator.retriever.extraction.discoverers.xml";
@Override
public IBlackboardInteractingJob<RetrieverBlackboard> create(final RetrieverConfiguration configuration,
final RetrieverBlackboard blackboard) {
return new AbstractBlackboardInteractingJob<>() {
@Override
public void cleanup(final IProgressMonitor monitor) throws CleanupFailedException {
}
@Override
public void execute(final IProgressMonitor monitor) throws JobFailedException, UserCanceledException {
final Path root = Paths.get(CommonPlugin.asLocalURI(configuration.getInputFolder())
.devicePath());
this.setBlackboard(Objects.requireNonNull(blackboard));
final Map<Path, Document> xmls = new HashMap<>();
Discoverer.find(root, ".xml", this.logger)
.forEach(p -> {
try (Reader reader = new FileReader(p.toFile())) {
xmls.put(p, new SAXBuilder().build(reader));
} catch (IOException | JDOMException e) {
this.logger.error(String.format("%s could not be read correctly.", p), e);
}
});
this.getBlackboard()
.putDiscoveredFiles(DISCOVERER_ID, xmls);
}
@Override
public String getName() {
return "XML Discoverer Job";
}
};
}
@Override
public Set<String> getConfigurationKeys() {
return Collections.emptySet();
}
@Override
public String getID() {
return DISCOVERER_ID;
}
@Override
public String getName() {
return "XML Discoverer";
}
}