All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.resourcemanager.dnsresolver.fluent.models.ForwardingRuleProperties Maven / Gradle / Ivy

Go to download

This package contains Microsoft Azure SDK for DnsResolver Management SDK. For documentation on how to use this package, please see https://aka.ms/azsdk/java/mgmt. The DNS Resolver Management Client. Package tag package-2022-07.

There is a newer version: 1.0.0-beta.3
Show newest version
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.dnsresolver.fluent.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import com.azure.resourcemanager.dnsresolver.models.ForwardingRuleState;
import com.azure.resourcemanager.dnsresolver.models.ProvisioningState;
import com.azure.resourcemanager.dnsresolver.models.TargetDnsServer;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Represents the properties of a forwarding rule within a DNS forwarding ruleset.
 */
@Fluent
public final class ForwardingRuleProperties implements JsonSerializable {
    /*
     * The domain name for the forwarding rule.
     */
    private String domainName;

    /*
     * DNS servers to forward the DNS query to.
     */
    private List targetDnsServers;

    /*
     * Metadata attached to the forwarding rule.
     */
    private Map metadata;

    /*
     * The state of forwarding rule.
     */
    private ForwardingRuleState forwardingRuleState;

    /*
     * The current provisioning state of the forwarding rule. This is a read-only property and any attempt to set this
     * value will be ignored.
     */
    private ProvisioningState provisioningState;

    /**
     * Creates an instance of ForwardingRuleProperties class.
     */
    public ForwardingRuleProperties() {
    }

    /**
     * Get the domainName property: The domain name for the forwarding rule.
     * 
     * @return the domainName value.
     */
    public String domainName() {
        return this.domainName;
    }

    /**
     * Set the domainName property: The domain name for the forwarding rule.
     * 
     * @param domainName the domainName value to set.
     * @return the ForwardingRuleProperties object itself.
     */
    public ForwardingRuleProperties withDomainName(String domainName) {
        this.domainName = domainName;
        return this;
    }

    /**
     * Get the targetDnsServers property: DNS servers to forward the DNS query to.
     * 
     * @return the targetDnsServers value.
     */
    public List targetDnsServers() {
        return this.targetDnsServers;
    }

    /**
     * Set the targetDnsServers property: DNS servers to forward the DNS query to.
     * 
     * @param targetDnsServers the targetDnsServers value to set.
     * @return the ForwardingRuleProperties object itself.
     */
    public ForwardingRuleProperties withTargetDnsServers(List targetDnsServers) {
        this.targetDnsServers = targetDnsServers;
        return this;
    }

    /**
     * Get the metadata property: Metadata attached to the forwarding rule.
     * 
     * @return the metadata value.
     */
    public Map metadata() {
        return this.metadata;
    }

    /**
     * Set the metadata property: Metadata attached to the forwarding rule.
     * 
     * @param metadata the metadata value to set.
     * @return the ForwardingRuleProperties object itself.
     */
    public ForwardingRuleProperties withMetadata(Map metadata) {
        this.metadata = metadata;
        return this;
    }

    /**
     * Get the forwardingRuleState property: The state of forwarding rule.
     * 
     * @return the forwardingRuleState value.
     */
    public ForwardingRuleState forwardingRuleState() {
        return this.forwardingRuleState;
    }

    /**
     * Set the forwardingRuleState property: The state of forwarding rule.
     * 
     * @param forwardingRuleState the forwardingRuleState value to set.
     * @return the ForwardingRuleProperties object itself.
     */
    public ForwardingRuleProperties withForwardingRuleState(ForwardingRuleState forwardingRuleState) {
        this.forwardingRuleState = forwardingRuleState;
        return this;
    }

    /**
     * Get the provisioningState property: The current provisioning state of the forwarding rule. This is a read-only
     * property and any attempt to set this value will be ignored.
     * 
     * @return the provisioningState value.
     */
    public ProvisioningState provisioningState() {
        return this.provisioningState;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (domainName() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException(
                    "Missing required property domainName in model ForwardingRuleProperties"));
        }
        if (targetDnsServers() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException(
                    "Missing required property targetDnsServers in model ForwardingRuleProperties"));
        } else {
            targetDnsServers().forEach(e -> e.validate());
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(ForwardingRuleProperties.class);

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("domainName", this.domainName);
        jsonWriter.writeArrayField("targetDnsServers", this.targetDnsServers,
            (writer, element) -> writer.writeJson(element));
        jsonWriter.writeMapField("metadata", this.metadata, (writer, element) -> writer.writeString(element));
        jsonWriter.writeStringField("forwardingRuleState",
            this.forwardingRuleState == null ? null : this.forwardingRuleState.toString());
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of ForwardingRuleProperties from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of ForwardingRuleProperties if the JsonReader was pointing to an instance of it, or null if
     * it was pointing to JSON null.
     * @throws IllegalStateException If the deserialized JSON object was missing any required properties.
     * @throws IOException If an error occurs while reading the ForwardingRuleProperties.
     */
    public static ForwardingRuleProperties fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            ForwardingRuleProperties deserializedForwardingRuleProperties = new ForwardingRuleProperties();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("domainName".equals(fieldName)) {
                    deserializedForwardingRuleProperties.domainName = reader.getString();
                } else if ("targetDnsServers".equals(fieldName)) {
                    List targetDnsServers
                        = reader.readArray(reader1 -> TargetDnsServer.fromJson(reader1));
                    deserializedForwardingRuleProperties.targetDnsServers = targetDnsServers;
                } else if ("metadata".equals(fieldName)) {
                    Map metadata = reader.readMap(reader1 -> reader1.getString());
                    deserializedForwardingRuleProperties.metadata = metadata;
                } else if ("forwardingRuleState".equals(fieldName)) {
                    deserializedForwardingRuleProperties.forwardingRuleState
                        = ForwardingRuleState.fromString(reader.getString());
                } else if ("provisioningState".equals(fieldName)) {
                    deserializedForwardingRuleProperties.provisioningState
                        = ProvisioningState.fromString(reader.getString());
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedForwardingRuleProperties;
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy