Search in sources :

Example 1 with LibraryItemType

use of net.parostroj.timetable.model.library.LibraryItemType in project grafikon by jub77.

the class LSLibraryImpl method save.

@Override
public void save(Library library, ZipOutputStream zipOutput) throws LSException {
    try {
        // save metadata
        zipOutput.putNextEntry(new ZipEntry(METADATA));
        this.createMetadata(METADATA_KEY_LIBRARY_VERSION).store(zipOutput, null);
        for (LibraryItemType itemType : LibraryItemType.values()) {
            for (LibraryItem item : library.getItems().get(itemType)) {
                this.save(zipOutput, String.format("%s/%s.%s", LSLibraryTypeMapping.typeToDirectory(item.getType()), item.getObject().getId(), "xml"), new LSLibraryItem(item));
            }
        }
    } catch (IOException e) {
        throw new LSException(e);
    }
}
Also used : LibraryItem(net.parostroj.timetable.model.library.LibraryItem) LibraryItemType(net.parostroj.timetable.model.library.LibraryItemType) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) LSException(net.parostroj.timetable.model.ls.LSException)

Example 2 with LibraryItemType

use of net.parostroj.timetable.model.library.LibraryItemType 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)

Aggregations

LibraryItem (net.parostroj.timetable.model.library.LibraryItem)2 LibraryItemType (net.parostroj.timetable.model.library.LibraryItemType)2 LSException (net.parostroj.timetable.model.ls.LSException)2 IOException (java.io.IOException)1 ZipEntry (java.util.zip.ZipEntry)1 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 XmlElements (javax.xml.bind.annotation.XmlElements)1 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)1 XmlType (javax.xml.bind.annotation.XmlType)1 EngineClass (net.parostroj.timetable.model.EngineClass)1 LineClass (net.parostroj.timetable.model.LineClass)1 Node (net.parostroj.timetable.model.Node)1 ObjectWithId (net.parostroj.timetable.model.ObjectWithId)1 OutputTemplate (net.parostroj.timetable.model.OutputTemplate)1 TrainType (net.parostroj.timetable.model.TrainType)1 TrainTypeCategory (net.parostroj.timetable.model.TrainTypeCategory)1 LibraryBuilder (net.parostroj.timetable.model.library.LibraryBuilder)1