Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ public Object fromXML(File file) {
try {
result = super.fromXML(file);
} catch (ConversionException e) {
LOGGER.error("Can't read file '{}' - it's broken (skipped) \n", file, e);
LOGGER.warn("Can't read file '{}' - it's broken (skipped) \n", file, e);
} catch (CannotResolveClassException e) {
LOGGER.debug("Can't read file '{}' - unknown class (skipped) \n", file, e);
} catch (StreamException e) {
LOGGER.error("Can't read file '{}' - it's broken (skipped): {}", file, e.getCause().getMessage());
LOGGER.warn("Can't read file '{}' - it's broken (skipped)", file, e);
} catch (Exception e) {
LOGGER.warn("Can't read file '{}' - unexpected error (skipped): {}", file, e.getMessage(), e);
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,33 @@
import java.nio.file.Path;
import java.nio.file.Paths;

/**
* Конвертер для чтения ролей из формата конфигуратора
*/
@DesignerConverter
public class RoleConverter extends AbstractReadConverter {

private static final String DATA_FIELD = "data";

/**
* Выполняет чтение роли из XML, включая данные прав доступа из файла Rights.xml
*
* @param reader Ридер XML потока
* @param context Контекст десериализации
* @return Прочитанный объект роли с данными прав доступа
*/
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
var readerContext = super.read(reader, context);
RoleData data;
try {
data = (RoleData) ExtendXStream.read(reader, dataPath(readerContext.getCurrentPath(), readerContext.getName()));
var readResult = ExtendXStream.read(reader, dataPath(readerContext.getCurrentPath(), readerContext.getName()));
if (readResult instanceof RoleData roleData) {
data = roleData;
} else {
// файл не прочитан или прочитан некорректно
data = RoleData.EMPTY;
}
} catch (Exception e) {
// ничего не делаем, считаем файл битым
data = RoleData.EMPTY;
Expand All @@ -51,11 +67,24 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co
return readerContext.build();
}

/**
* Проверяет, может ли конвертер обработать указанный тип
*
* @param type Тип класса для проверки
* @return true, если тип является Role или его подклассом
*/
@Override
public boolean canConvert(Class type) {
return Role.class.isAssignableFrom(type);
}

/**
* Формирует путь к файлу Rights.xml для роли
*
* @param path Путь к файлу описания роли
* @param name Имя роли
* @return Путь к файлу Rights.xml
*/
private static Path dataPath(Path path, String name) {
return Paths.get(path.getParent().toString(), name, "Ext", "Rights.xml");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,33 @@

import java.nio.file.Path;

/**
* Конвертер для чтения ролей из формата ЕДТ
*/
@EDTConverter
public class RoleConverter extends AbstractReadConverter {

private static final String DATA_FIELD = "data";

/**
* Выполняет чтение роли из XML, включая данные прав доступа из файла Rights.rights
*
* @param reader Ридер XML потока
* @param context Контекст десериализации
* @return Прочитанный объект роли с данными прав доступа
*/
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
var readerContext = super.read(reader, context);
RoleData data;
try {
data = (RoleData) ExtendXStream.read(reader, dataPath(readerContext.getCurrentPath()));
var readResult = ExtendXStream.read(reader, dataPath(readerContext.getCurrentPath()));
if (readResult instanceof RoleData roleData) {
data = roleData;
} else {
// файл не прочитан или прочитан некорректно
data = RoleData.EMPTY;
}
} catch (Exception e) {
// ничего не делаем, считаем файл битым
data = RoleData.EMPTY;
Expand All @@ -50,11 +66,23 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co
return readerContext.build();
}

/**
* Проверяет, может ли конвертер обработать указанный тип
*
* @param type Тип класса для проверки
* @return true, если тип является Role или его подклассом
*/
@Override
public boolean canConvert(Class type) {
return Role.class.isAssignableFrom(type);
}

/**
* Формирует путь к файлу Rights.rights для роли
*
* @param path Путь к файлу описания роли
* @return Путь к файлу Rights.rights
*/
private static Path dataPath(Path path) {
return Path.of(path.getParent().toString(), "Rights.rights");
}
Expand Down
Loading