use of net.parostroj.timetable.model.library.LibraryItem 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);
}
}
use of net.parostroj.timetable.model.library.LibraryItem 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;
}
Aggregations