Search in sources :

Example 6 with LSException

use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.

the class LSLibraryItem method createLibraryItem.

public LibraryItem createLibraryItem(LibraryBuilder libraryBuilder) throws LSException {
    LibraryItemType type = LibraryItemType.valueOf(getType());
    ObjectWithId object = null;
    switch(type) {
        case ENGINE_CLASS:
            object = ((LSEngineClass) getObject()).createEngineClass(id -> {
                ObjectWithId foundObject = libraryBuilder.getObjectById(id);
                return foundObject instanceof LineClass ? (LineClass) foundObject : null;
            });
            break;
        case LINE_CLASS:
            object = ((LSLineClass) getObject()).createLineClass();
            break;
        case NODE:
            object = ((LSNode) getObject()).createNode(libraryBuilder.getPartFactory(), libraryBuilder::getObjectById);
            break;
        case OUTPUT_TEMPLATE:
            object = ((LSOutputTemplate) getObject()).createOutputTemplate(libraryBuilder.getPartFactory(), libraryBuilder::getObjectById);
            break;
        case TRAIN_TYPE:
            object = ((LSTrainType) getObject()).createTrainType(libraryBuilder.getPartFactory(), libraryBuilder::getObjectById, id -> {
                ObjectWithId foundObject = libraryBuilder.getObjectById(id);
                return foundObject instanceof TrainTypeCategory ? (TrainTypeCategory) foundObject : null;
            });
            break;
        case TRAIN_TYPE_CATEGORY:
            object = ((LSTrainTypeCategory) getObject()).createTrainTypeCategory();
            break;
    }
    LibraryItem item = libraryBuilder.addObject(object);
    item.getAttributes().add(this.getAttributes().createAttributes(libraryBuilder::getObjectById));
    return item;
}
Also used : XmlAttribute(javax.xml.bind.annotation.XmlAttribute) LibraryItem(net.parostroj.timetable.model.library.LibraryItem) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Node(net.parostroj.timetable.model.Node) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) OutputTemplate(net.parostroj.timetable.model.OutputTemplate) XmlType(javax.xml.bind.annotation.XmlType) TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory) XmlElements(javax.xml.bind.annotation.XmlElements) LibraryBuilder(net.parostroj.timetable.model.library.LibraryBuilder) LSException(net.parostroj.timetable.model.ls.LSException) EngineClass(net.parostroj.timetable.model.EngineClass) TrainType(net.parostroj.timetable.model.TrainType) LibraryItemType(net.parostroj.timetable.model.library.LibraryItemType) LineClass(net.parostroj.timetable.model.LineClass) XmlElement(javax.xml.bind.annotation.XmlElement) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) LineClass(net.parostroj.timetable.model.LineClass) LibraryItem(net.parostroj.timetable.model.library.LibraryItem) LibraryItemType(net.parostroj.timetable.model.library.LibraryItemType) TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory)

Example 7 with LSException

use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.

the class LSTrainType method createTrainType.

public TrainType createTrainType(TrainDiagram diagram) throws LSException {
    TrainType type = diagram.getPartFactory().createTrainType(id);
    type.setAbbr(LocalizedString.fromString(abbr));
    type.setColor(Conversions.convertTextToColor(color));
    type.setDesc(LocalizedString.fromString(desc));
    type.setPlatform(platform);
    type.setCategory(this.convertToCategory(diagram));
    try {
        type.setTrainCompleteNameTemplate(trainCompleteNameTemplate != null ? TextTemplate.createTextTemplate(trainCompleteNameTemplate, TextTemplate.Language.MVEL) : null);
        type.setTrainNameTemplate(trainNameTemplate != null ? TextTemplate.createTextTemplate(trainNameTemplate, TextTemplate.Language.MVEL) : null);
    } catch (GrafikonException e) {
        throw new LSException(e);
    }
    return type;
}
Also used : TrainType(net.parostroj.timetable.model.TrainType) LSException(net.parostroj.timetable.model.ls.LSException)

Example 8 with LSException

use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.

the class LSAttributesItem method convertScript.

private Object convertScript(String value, String valueType) throws LSException {
    String languageStr = valueType.substring(SCRIPT_KEY_PREFIX.length());
    Script.Language language = Script.Language.valueOf(languageStr);
    try {
        return Script.createScript(value, language);
    } catch (GrafikonException e) {
        throw new LSException("Cannot convert script: " + e.getMessage(), e);
    }
}
Also used : LSException(net.parostroj.timetable.model.ls.LSException)

Example 9 with LSException

use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.

the class LSAttributesItem method convertTextTemplate.

private Object convertTextTemplate(String value, String valueType) throws LSException {
    String languageStr = valueType.substring(TEXT_TEMPLATE_KEY_PREFIX.length());
    TextTemplate.Language language = TextTemplate.Language.valueOf(languageStr);
    try {
        return TextTemplate.createTextTemplate(value, language);
    } catch (GrafikonException e) {
        throw new LSException("Cannot convert template: " + e.getMessage(), e);
    }
}
Also used : LSException(net.parostroj.timetable.model.ls.LSException)

Example 10 with LSException

use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.

the class FileLoadSaveImpl method checkVersion.

private ModelVersion checkVersion(Properties props) throws LSException {
    ModelVersion current = ModelVersion.parseModelVersion(METADATA_MODEL_VERSION);
    ModelVersion loaded = ModelVersion.parseModelVersion(props.getProperty(METADATA_KEY_MODEL_VERSION));
    if (current.compareTo(loaded) < 0) {
        throw new LSException(String.format("Current version [%s] is older than the version of loaded file [%s].", current.toString(), loaded.toString()));
    }
    return loaded;
}
Also used : ModelVersion(net.parostroj.timetable.model.ls.ModelVersion) LSException(net.parostroj.timetable.model.ls.LSException)

Aggregations

LSException (net.parostroj.timetable.model.ls.LSException)38 IOException (java.io.IOException)8 JAXBException (javax.xml.bind.JAXBException)7 LSFile (net.parostroj.timetable.model.ls.LSFile)7 FileNotFoundException (java.io.FileNotFoundException)6 ZipEntry (java.util.zip.ZipEntry)6 ModelVersion (net.parostroj.timetable.model.ls.ModelVersion)6 ZipInputStream (java.util.zip.ZipInputStream)5 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)5 Properties (java.util.Properties)4 TrainType (net.parostroj.timetable.model.TrainType)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 OutputTemplate (net.parostroj.timetable.model.OutputTemplate)3 Route (net.parostroj.timetable.model.Route)3 File (java.io.File)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2 URL (java.net.URL)2 EngineClass (net.parostroj.timetable.model.EngineClass)2 DiagramChangeSet (net.parostroj.timetable.model.changes.DiagramChangeSet)2