use of net.parostroj.timetable.model.library.LibraryBuilder in project grafikon by jub77.
the class LSLibraryImpl method load.
@Override
public Library load(ZipInputStream is) throws LSException {
try {
ZipEntry entry = null;
ModelVersion version = (ModelVersion) properties.get(VERSION_PROPERTY);
LibraryBuilder libraryBuilder = new LibraryBuilder();
while ((entry = is.getNextEntry()) != null) {
if (entry.getName().equals(METADATA)) {
// check major and minor version (do not allow load newer versions)
Properties props = new Properties();
props.load(is);
version = checkVersion(METADATA_KEY_LIBRARY_VERSION, props);
continue;
}
LSLibraryItem lsItem = lss.load(is, LSLibraryItem.class);
lsItem.createLibraryItem(libraryBuilder);
}
log.debug("Loaded version: {}", version != null ? version : "<missing>");
return libraryBuilder.build();
} catch (IOException e) {
throw new LSException(e);
}
}
use of net.parostroj.timetable.model.library.LibraryBuilder 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;
}
use of net.parostroj.timetable.model.library.LibraryBuilder in project grafikon by jub77.
the class ExportAction method createLibrary.
private Library createLibrary(ExportImportSelection selection) {
LibraryBuilder libBuilder = new LibraryBuilder(new LibraryBuilder.Config().setAddMissing(true));
selection.getObjectMap().values().stream().flatMap(item -> item.stream()).forEach(object -> libBuilder.importObject(object));
return libBuilder.build();
}
Aggregations