001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.http.response; 018 019import static org.apache.juneau.commons.utils.Shorts.*; 020 021import org.apache.juneau.http.*; 022 023/** 024 * Represents an <c>HTTP 300 Multiple Choices</c> response. 025 * 026 * <p> 027 * Indicates multiple options for the resource from which the client may choose. 028 * 029 * <h5 class='section'>See Also:</h5><ul> 030 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/NextGenRestClient">Next-Generation REST Client</a> 031 * </ul> 032 * 033 * @since 9.2.1 034 */ 035public class MultipleChoices extends BasicHttpResponse<MultipleChoices> { 036 037 /** HTTP status code */ 038 public static final int STATUS_CODE = 300; 039 040 /** Reason phrase */ 041 public static final String REASON_PHRASE = "Multiple Choices"; 042 043 /** Default status line */ 044 private static final HttpStatusLine STATUS_LINE = HttpStatusLineBean.of(STATUS_CODE, REASON_PHRASE); 045 046 /** Default unmodifiable instance */ 047 public static final MultipleChoices INSTANCE = new MultipleChoices().unmodifiable(); 048 049 /** 050 * Constructor. 051 */ 052 public MultipleChoices() { 053 super(STATUS_LINE); 054 } 055 056 /** 057 * Constructor with a response body. 058 * 059 * @param body The response body. May be <jk>null</jk>. 060 */ 061 public MultipleChoices(HttpBody body) { 062 super(STATUS_LINE, body); 063 } 064 065 /** 066 * Constructor with a plain-text string body. 067 * 068 * @param body The response body as a plain-text string. May be <jk>null</jk>. 069 */ 070 public MultipleChoices(String body) { 071 super(STATUS_LINE, body); 072 } 073 074 /** 075 * Copy constructor. 076 * 077 * @param copyFrom The bean to copy from. Must not be <jk>null</jk>. 078 */ 079 public MultipleChoices(MultipleChoices copyFrom) { 080 super(copyFrom); 081 } 082 083 @Override /* Overridden from BasicHttpResponse */ 084 public MultipleChoices unmodifiable() { 085 return this instanceof UnmodifiableBean ? this : new Unmodifiable(this); 086 } 087 088 /** 089 * Unmodifiable point-in-time snapshot of the enclosing {@link MultipleChoices} response. 090 * 091 * <p> 092 * Its only behavioral override is {@link #modify(Runnable)}, which throws — because all mutation is funneled through 093 * {@code modify(...)}, this single override freezes the entire mutation surface. 094 */ 095 public static class Unmodifiable extends MultipleChoices implements UnmodifiableBean { 096 097 /** 098 * Constructor. 099 * 100 * @param copyFrom The response to snapshot. Must not be <jk>null</jk>. 101 */ 102 @SuppressWarnings({ 103 "java:S1699" // Paradigm intentionally calls the overridable freeze() from the ctor to deep-freeze sub-beans. 104 }) 105 protected Unmodifiable(MultipleChoices copyFrom) { 106 super(copyFrom); 107 freeze(); 108 } 109 110 @Override /* Overridden from BasicHttpResponse */ 111 protected MultipleChoices modify(Runnable mutation) { 112 throw uoex("Bean is unmodifiable."); 113 } 114 } 115}