All files / src/Ice DefaultsAndOverrides.js

74.54% Statements 41/55
54.54% Branches 6/11
100% Functions 1/1
74.54% Lines 41/55

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 5641x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 67x 67x 67x 67x 67x 67x 67x 67x 67x 67x 67x 67x 67x 67x 67x             67x 67x 67x         67x 67x 67x         67x 67x 67x 67x 67x 67x 67x 67x 41x  
// Copyright (c) ZeroC, Inc.
 
import { FormatType } from "./FormatType.js";
import { EndpointSelectionType } from "./EndpointSelectionType.js";
import { Protocol, stringToEncodingVersion } from "./Protocol.js";
import { ParseException, InitializationException } from "./LocalExceptions.js";
import { TcpTransceiver } from "./TcpTransceiver.js";
 
// Even though this class is called DefaultsAndOverrides, like in other languages, it only holds Default values.
export class DefaultsAndOverrides {
    constructor(properties) {
        this.defaultProtocol = properties.getPropertyWithDefault(
            "Ice.Default.Protocol",
            TcpTransceiver !== null ? "tcp" : "ws",
        );
 
        let value = properties.getIceProperty("Ice.Default.Host");
        this.defaultHost = value.length > 0 ? value : null;
 
        value = properties.getIceProperty("Ice.Default.SourceAddress");
        this.defaultSourceAddress = value.length > 0 ? value : null;
 
        value = properties.getIceProperty("Ice.Default.EndpointSelection");
        if (value === "Random") {
            this.defaultEndpointSelection = EndpointSelectionType.Random;
        } else if (value === "Ordered") {
            this.defaultEndpointSelection = EndpointSelectionType.Ordered;
        } else {
            throw new ParseException(
                `illegal value '${value}' in property Ice.Default.EndpointSelection; expected 'Random' or 'Ordered'`,
            );
        }
 
        this.defaultLocatorCacheTimeout = properties.getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout");
        if (this.defaultLocatorCacheTimeout < -1) {
            throw new InitializationException(
                `invalid value for Ice.Default.LocatorCacheTimeout: ${this.defaultLocatorCacheTimeout}`,
            );
        }
 
        this.defaultInvocationTimeout = properties.getIcePropertyAsInt("Ice.Default.InvocationTimeout");
        if (this.defaultInvocationTimeout < 1 && this.defaultInvocationTimeout !== -1) {
            throw new InitializationException(
                `invalid value for Ice.Default.InvocationTimeout: ${this.defaultInvocationTimeout}`,
            );
        }
 
        value = properties.getIceProperty("Ice.Default.EncodingVersion");
        this.defaultEncoding = stringToEncodingVersion(value);
        Protocol.checkSupportedEncoding(this.defaultEncoding);
 
        const slicedFormat = properties.getIcePropertyAsInt("Ice.Default.SlicedFormat") > 0;
        this.defaultFormat = slicedFormat ? FormatType.SlicedFormat : FormatType.CompactFormat;
    }
}