use of org.structr.files.ssh.filesystem.path.graph.StructrPropertyValueChannel in project structr by structr.
the class StructrSchemaMethodPath method newFileChannel.
@Override
public FileChannel newFileChannel(final Set<? extends OpenOption> options, final FileAttribute<?>... attrs) throws IOException {
// Possible open options are: CREATE, READ, WRITE, TRUNCATE_EXISTING
// The filesystem code will first try to fetch the attributes of a file, then call this
// method with the CREATE and WRITE OPTIONS (and an optional TRUNCATE_EXISTING)
SchemaMethod method = getSchemaMethodNode();
final boolean read = options.contains(StandardOpenOption.READ);
final boolean create = options.contains(StandardOpenOption.CREATE);
final boolean createNew = options.contains(StandardOpenOption.CREATE_NEW);
final boolean write = options.contains(StandardOpenOption.WRITE);
final boolean truncate = options.contains(StandardOpenOption.TRUNCATE_EXISTING);
final boolean append = options.contains(StandardOpenOption.APPEND);
// creation of a new file requested (=> create a new schema method)
if (create || createNew) {
// if CREATE_NEW, file must not exist, otherwise an error should be thrown
if (createNew && method != null) {
throw new java.nio.file.FileAlreadyExistsException(toString());
}
final App app = StructrApp.getInstance(fs.getSecurityContext());
try (final Tx tx = app.tx()) {
// create a new schema method with an empty source string
method = app.create(SchemaMethod.class, new NodeAttribute<>(SchemaMethod.schemaNode, schemaNode), new NodeAttribute<>(SchemaMethod.virtualFileName, name), new NodeAttribute<>(AbstractNode.name, normalizeFileNameForJavaIdentifier(name)), new NodeAttribute<>(SchemaMethod.source, ""));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
return new StructrPropertyValueChannel(fs.getSecurityContext(), method, SchemaMethod.source, truncate, append);
}
Aggregations