Skip to content

Commit

Permalink
#27 definition of input document
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPirnbaum committed Jul 27, 2019
1 parent da9a833 commit b32abe0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import javax.xml.bind.JAXBException;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;

/**
* @author Stephan Pirnbaum
Expand Down Expand Up @@ -93,7 +92,7 @@ private void execute() {
this.execute.setDisable(true);
try {
if (this.architecturePath.getText() != null && !this.architecturePath.getText().isEmpty()) {
URL configUrl = new URL(this.architecturePath.getText());
URI configUrl = new URI(this.architecturePath.getText());
this.classificationRunner.startNewIteration(configUrl);
} else {
ClassificationConfigurationXmlMapper classificationConfiguration =
Expand Down Expand Up @@ -122,7 +121,7 @@ private void selectArchitecture() {
chooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("xml", "xml"));
if ((f = chooser.showOpenDialog(this.chooseArchitecture.getScene().getWindow())) != null) {
try {
ClassificationConfigurationXmlMapper classificationConfigurationXmlMapper = this.configurationParser.readConfiguration(new URL(f.getAbsolutePath()));
ClassificationConfigurationXmlMapper classificationConfigurationXmlMapper = this.configurationParser.readConfiguration(f.toURI());
this.architecturePath.setText(f.toURI().toString());
this.artifact.setText(classificationConfigurationXmlMapper.artifact);
this.artifact.setDisable(true);
Expand All @@ -134,7 +133,7 @@ private void selectArchitecture() {
this.populationSize.setDisable(true);
this.generations.setText(String.valueOf(classificationConfigurationXmlMapper.generations));
this.generations.setDisable(true);
} catch (MalformedURLException | JAXBException | SAXException e) {
} catch (JAXBException | SAXException e) {
e.printStackTrace();
showExceptionDialog("Setup Error", "An error occured during opening the configuration!", "", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import org.xml.sax.SAXException;

import javax.xml.bind.JAXBException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

/**
* Created by steph on 04.05.2017.
Expand Down Expand Up @@ -47,20 +45,17 @@ public static void main(String[] args) throws URISyntaxException {
try {
CommandLine cmd = parser.parse(options, args);
URI storeUri = new URI(cmd.getOptionValue("s"));
URL configUrl = cmd.hasOption("c") ? new URL(cmd.getOptionValue("c")) : null;
URI configUri = cmd.hasOption("c") ? new URI(cmd.getOptionValue("c")) : null;
Integer iteration = cmd.hasOption("l") ? Integer.valueOf(cmd.getOptionValue("l")) : null;
URL benchUrl = cmd.hasOption("b") ? new URL(cmd.getOptionValue("b")) : null;
URI benchUri = cmd.hasOption("b") ? new URI(cmd.getOptionValue("b")) : null;

springContext.getBean(XOManager.class, storeUri);
ClassificationRunner runner = springContext.getBean(ClassificationRunner.class);
runner.startNewIteration(configUrl);
runner.startNewIteration(configUri);
} catch (ParseException e) {
LOGGER.error(e.getMessage());
formatter.printHelp("java -jar sarf.jar", options);
System.exit(1);
} catch (MalformedURLException e) {
LOGGER.error("Configuration file not found");
System.exit(1);
} catch (JAXBException | SAXException e) {
LOGGER.error("Configuration file could not be parsed", e);
System.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.xml.sax.SAXException;

import javax.xml.bind.JAXBException;
import java.net.URL;
import java.net.URI;

/**
* @author Stephan Pirnbaum
Expand Down Expand Up @@ -48,8 +48,8 @@ public void startNewIteration(ClassificationConfigurationXmlMapper configuration
this.executor.execute(descriptor);
}

public void startNewIteration(URL configUrl) throws JAXBException, SAXException {
startNewIteration(this.configurationParser.readConfiguration(configUrl));
public void startNewIteration(URI configUri) throws JAXBException, SAXException {
startNewIteration(this.configurationParser.readConfiguration(configUri));
}

private void setUpData(ClassificationConfigurationDescriptor descriptor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
import javax.xml.bind.Unmarshaller;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import java.io.File;
import java.net.URI;
import java.net.URL;

@Slf4j
@Service
public class ConfigurationParser {

public ClassificationConfigurationXmlMapper readConfiguration(URL configUrl) throws JAXBException, SAXException {
public ClassificationConfigurationXmlMapper readConfiguration(URI configUri) throws JAXBException, SAXException {
LOGGER.info("Reading XML Configuration");

URL schemaUrl = ClassificationRunner.class.getClassLoader().getResource("schema.xsd");
Expand All @@ -28,7 +30,7 @@ public ClassificationConfigurationXmlMapper readConfiguration(URL configUrl) thr
jaxbUnmarshaller.setSchema(schema);
LOGGER.info("Unmarshalling XML Configuration");
ClassificationConfigurationXmlMapper mapper =
(ClassificationConfigurationXmlMapper) jaxbUnmarshaller.unmarshal(configUrl);
(ClassificationConfigurationXmlMapper) jaxbUnmarshaller.unmarshal(new File(configUri));
LOGGER.info("Unmarshalling XML Configuration Successful");
return mapper;
}
Expand Down

0 comments on commit b32abe0

Please sign in to comment.