@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
if(isCalledAs("permissions-to-string")) {
final int mode = ((IntegerValue)args[0].itemAt(0)).getInt();
final Permission perm = PermissionFactory.getPermission(mode);
return new StringValue(perm.toString());
} else {
final String permissionsString = args[0].itemAt(0).getStringValue();
try {
final Permission perm = UnixStylePermissionAider.fromString(permissionsString);
return new IntegerValue(perm.getMode());
} catch(final SyntaxException se) {
throw new XPathException(this, se);
}
}
}