package designPatternExtensions;
import models.objectOrientedTransfer.DataTransferContext;
import models.objectOrientedTransfer.DataTransferDesign;
import models.objectOrientedTransfer.IllegalRelationException;
import parser.JsonValue;
import parser.Parser;
import parser.Value;
import parser.exceptions.ExpectedArrayValue;
import parser.exceptions.ExpectedJsonValue;
import parser.exceptions.ExpectedStringValue;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class ModelLoader {
public static DataTransferDesign load(String path) {
File file = new File(path);
try {
Parser parser = new Parser(new BufferedReader(new FileReader(file)));
Value jsonValue = parser.getValue();
DataTransferDesign design;
return new DataTransferDesign((JsonValue) jsonValue);
} catch (java.io.FileNotFoundException | ExpectedArrayValue
| ExpectedStringValue | ExpectedJsonValue e) {
throw new RuntimeException("Failed to load model: " + path, e);
} catch (IllegalRelationException e) {
throw new RuntimeException(e);
}
}
public static DataTransferDesign load2(String path) {
File file = new File(path);
try {
Parser parser = new Parser(new BufferedReader(new FileReader(file)));
Value jsonValue = parser.getValue();
DataTransferContext context = new DataTransferContext(jsonValue);
return new DataTransferDesign(context);
} catch (java.io.FileNotFoundException | ExpectedArrayValue
| ExpectedStringValue | ExpectedJsonValue e) {
throw new RuntimeException("Failed to load model: " + path, e);
} catch (IllegalRelationException e) {
throw new RuntimeException(e);
}
}
}