use of dev.hawala.xns.level4.filing.FilingCommon.AttributeValueErrorRecord in project dodo by devhawala.
the class FilingImpl method createFile.
private static FileEntry createFile(Volume.Session modificationSession, Session session, long directoryFileID, AttributeSequence pAttributes, iContentSource source, ExceptionHandler exceptionHandler) {
// get the volume
Volume vol = session.getService().getVolume();
// extract the minimal attributes => required: name ; optional: isDirectory(false), version(1/next), type(unknown)
String name = null;
boolean isDirectory = false;
Integer version = null;
Long type = null;
for (int i = 0; i < pAttributes.value.size(); i++) {
Attribute attr = pAttributes.value.get(i);
switch((int) (attr.type.get() & 0xFFFF)) {
case FilingCommon.atName:
name = attr.getAsString();
break;
case FilingCommon.atIsDirectory:
isDirectory = attr.getAsBoolean();
break;
case FilingCommon.atVersion:
version = attr.getAsCardinal();
break;
case FilingCommon.atType:
type = attr.getAsLongCardinal();
break;
}
}
if (name == null) {
new AttributeValueErrorRecord(ArgumentProblem.missing, FilingCommon.atName).raise();
}
// create the new file
List<iValueSetter> attrSetters = getCourier2FileAttributeSetters(pAttributes);
System.out.printf("volStartModificationsession()\n");
try {
System.out.printf("createFile( dirId = %d , isdirectory = %s , name = '%s' )\n", directoryFileID, "" + isDirectory, name);
Volume.Session modSession = (modificationSession == null) ? vol.startModificationSession() : modificationSession;
final FileEntry fe;
try {
fe = modSession.createFile(directoryFileID, isDirectory, name, version, type, session.getUsername(), attrSetters, source);
} finally {
if (modificationSession == null) {
modSession.close();
}
}
System.out.printf("-> done createFile(): fileID = %d\n", (fe != null) ? fe.getFileID() : -2);
return fe;
} catch (InterruptedException e) {
System.out.printf("!!! InterruptedException !!!\n");
new UndefinedErrorRecord(FilingCommon.UNDEFINEDERROR_CANNOT_MODIFY_VOLUME).raise();
} catch (EndOfMessageException e) {
System.out.printf("!!! EndOfMessageException !!!\n");
new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
} catch (CourierException ce) {
// this is a RuntimeException, why is it catch-ed by Exception ???????
System.out.printf("!!! CourierException !!!\n");
throw ce;
} catch (Exception e) {
System.out.printf("!!! Exception: %s -- %s !!!\n", e.getClass().getName(), e.getMessage());
if (exceptionHandler != null) {
exceptionHandler.accept(e);
} else {
new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
}
}
// keep the compiler happy
return null;
}
use of dev.hawala.xns.level4.filing.FilingCommon.AttributeValueErrorRecord in project dodo by devhawala.
the class FilingImpl method open.
/*
* Open: PROCEDURE [ attributes: AttributeSequence, directory: Handle,
* controls: ControlSequence, session: Session ]
* RETURNS [ file: Handle ]
* REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
* AuthenticationError, ControlTypeError, ControlValueError,
* HandleError, SessionError, UndefinedError ]
* = 2;
*/
private static void open(OpenParams params, FileHandleRecord results) {
logParams("open", params);
// check session
Session session = resolveSession(params.session);
Volume vol = session.getService().getVolume();
// check specified parent directory handle
Handle directoryHandle = Handle.get(params.directory);
// attributes specifying the file to open
// - exactly one of: fileID, name, pathname
// - optional: parentID, type, version
int primaryAttrCount = 0;
Long fileId = null;
String name = null;
String pathname = null;
Long parentId = null;
Long type = null;
Integer version = null;
AttributeSequence attrs = params.attributes;
for (int i = 0; i < attrs.value.size(); i++) {
Attribute av = attrs.value.get(i);
switch((int) (av.type.get() & 0xFFFF)) {
case FilingCommon.atFileID:
if (primaryAttrCount == 1) {
new AttributeValueErrorRecord(ArgumentProblem.unreasonable, FilingCommon.atFileID).raise();
}
primaryAttrCount = 1;
fileId = av.getAsFileID();
break;
case FilingCommon.atName:
if (primaryAttrCount == 1) {
new AttributeValueErrorRecord(ArgumentProblem.unreasonable, FilingCommon.atName).raise();
}
primaryAttrCount = 1;
name = av.getAsString();
break;
case FilingCommon.atPathname:
if (primaryAttrCount == 1) {
new AttributeValueErrorRecord(ArgumentProblem.unreasonable, FilingCommon.atPathname).raise();
}
primaryAttrCount = 1;
pathname = av.getAsString();
break;
case FilingCommon.atParentID:
parentId = av.getAsFileID();
break;
case FilingCommon.atType:
type = av.getAsLongCardinal();
break;
case FilingCommon.atVersion:
version = av.getAsCardinal();
break;
default:
}
}
// check the file specs
if (primaryAttrCount == 0) {
if ((directoryHandle == null || directoryHandle.isNullHandle()) && (parentId == null || parentId.longValue() == 0L)) {
Handle rootHandle = new Handle(session, vol.rootDirectory);
rootHandle.setIdTo(results.file);
logResult("Open", results);
return;
}
new AttributeValueErrorRecord(ArgumentProblem.missing, FilingCommon.atFileID).raise();
}
if (directoryHandle != null && parentId != null) {
if (directoryHandle.isVolumeRoot()) {
if (parentId != 0) {
new AttributeValueErrorRecord(ArgumentProblem.unreasonable, FilingCommon.atParentID).raise();
}
} else {
if (directoryHandle.getFe().getFileID() != parentId) {
new AttributeValueErrorRecord(ArgumentProblem.unreasonable, FilingCommon.atParentID).raise();
}
}
} else if (directoryHandle != null && !directoryHandle.isVolumeRoot()) {
parentId = directoryHandle.getFe().getFileID();
}
FileEntry fe = null;
if (fileId != null) {
if (fileId == FsConstants.rootFileID) {
fe = vol.rootDirectory;
} else {
fe = vol.openByFileID(fileId, parentId, type, session.getUsername());
}
} else if (name != null) {
fe = vol.openByName(name, parentId, type, version, session.getUsername());
} else if (pathname != null) {
List<PathElement> path = PathElement.parse(pathname);
fe = vol.openByPath(path, parentId, type, version, session.getUsername());
}
// check the outcome
if (fe != null) {
Handle newHandle = new Handle(session, fe);
newHandle.setIdTo(results.file);
} else {
new AccessErrorRecord(AccessProblem.fileNotFound).raise();
}
logResult("Open", results);
}
use of dev.hawala.xns.level4.filing.FilingCommon.AttributeValueErrorRecord in project dodo by devhawala.
the class ErrorRaiser method attributeValueError.
@Override
public void attributeValueError(int attributeType, String msg) {
this.log(msg);
new AttributeValueErrorRecord(ArgumentProblem.unreasonable, attributeType).raise();
}
Aggregations