Search in sources :

Example 1 with AttributeValueErrorRecord

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;
}
Also used : AttributeValueErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AttributeValueErrorRecord) Attribute(dev.hawala.xns.level4.filing.FilingCommon.Attribute) UninterpretedAttribute(dev.hawala.xns.level4.filing.fs.UninterpretedAttribute) SpaceErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord) dev.hawala.xns.level4.filing.fs.iValueSetter(dev.hawala.xns.level4.filing.fs.iValueSetter) ConnectionErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord) NoMoreWriteSpaceException(dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) IOException(java.io.IOException) CourierException(dev.hawala.xns.level3.courier.exception.CourierException) UndefinedErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord) CourierException(dev.hawala.xns.level3.courier.exception.CourierException) Volume(dev.hawala.xns.level4.filing.fs.Volume) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry)

Example 2 with AttributeValueErrorRecord

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);
}
Also used : AccessErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord) AttributeValueErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AttributeValueErrorRecord) Attribute(dev.hawala.xns.level4.filing.FilingCommon.Attribute) UninterpretedAttribute(dev.hawala.xns.level4.filing.fs.UninterpretedAttribute) PathElement(dev.hawala.xns.level4.filing.fs.PathElement) Volume(dev.hawala.xns.level4.filing.fs.Volume) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry) AttributeSequence(dev.hawala.xns.level4.filing.FilingCommon.AttributeSequence)

Example 3 with AttributeValueErrorRecord

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();
}
Also used : AttributeValueErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AttributeValueErrorRecord)

Aggregations

AttributeValueErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.AttributeValueErrorRecord)3 Attribute (dev.hawala.xns.level4.filing.FilingCommon.Attribute)2 FileEntry (dev.hawala.xns.level4.filing.fs.FileEntry)2 UninterpretedAttribute (dev.hawala.xns.level4.filing.fs.UninterpretedAttribute)2 Volume (dev.hawala.xns.level4.filing.fs.Volume)2 CourierException (dev.hawala.xns.level3.courier.exception.CourierException)1 EndOfMessageException (dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException)1 NoMoreWriteSpaceException (dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException)1 AccessErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord)1 AttributeSequence (dev.hawala.xns.level4.filing.FilingCommon.AttributeSequence)1 ConnectionErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord)1 SpaceErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord)1 UndefinedErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord)1 PathElement (dev.hawala.xns.level4.filing.fs.PathElement)1 dev.hawala.xns.level4.filing.fs.iValueSetter (dev.hawala.xns.level4.filing.fs.iValueSetter)1 IOException (java.io.IOException)1