Class BasicStatusLine

java.lang.Object
org.apache.juneau.http.classic.BasicStatusLine
All Implemented Interfaces:
StatusLine
Direct Known Subclasses:
BasicStatusLine.Unmodifiable

public class BasicStatusLine extends Object implements StatusLine
A basic implementation of the StatusLine interface.

Immutability is expressed with the "funnel + nested Unmodifiable snapshot" paradigm: every mutator routes through the single protected modify(Runnable) choke-point, and unmodifiable() returns a point-in-time snapshot of type BasicStatusLine.Unmodifiable whose modify(...) override throws.

See Also:
  • Constructor Details

  • Method Details

    • create

      public static BasicStatusLine create()
      Instantiates a new instance of this bean.
      Returns:
      A new bean.
    • create

      public static BasicStatusLine create(int statusCode, String reasonPhrase)
      Instantiates a new instance of this bean.
      Parameters:
      statusCode - The initial status code.
      reasonPhrase - The initial reason phrase. Can be null to look up the reason phrase from the reason phrase catalog.
      Returns:
      A new bean.
    • copy

      Returns a copy of this bean.
      Returns:
      A copy of this bean.
    • getLocale

      public Locale getLocale()
      Returns the locale of this status line.
      Returns:
      The locale of this status line.
    • getProtocolVersion

      Specified by:
      getProtocolVersion in interface StatusLine
    • getReasonPhrase

      Specified by:
      getReasonPhrase in interface StatusLine
    • getStatusCode

      public int getStatusCode()
      Specified by:
      getStatusCode in interface StatusLine
    • setLocale

      Sets the locale used to retrieve reason phrases.

      If not specified, uses Locale.getDefault().

      Parameters:
      value - The new value.
      Returns:
      This object.
    • setProtocolVersion

      Sets the protocol version on the status line.

      If not specified, "HTTP/1.1" will be used.

      Parameters:
      value - The new value.
      Returns:
      This object.
    • setReasonPhrase

      Sets the reason phrase on the status line.

      If not specified, the reason phrase will be retrieved from the reason phrase catalog using the locale on this bean.

      Parameters:
      value - The new value. Can be null to unset the property.
      Returns:
      This object.
    • setReasonPhraseCatalog

      Sets the reason phrase catalog used to retrieve reason phrases.

      If not specified, uses EnglishReasonPhraseCatalog.

      Parameters:
      value - The new value. Can be null to unset the property.
      Returns:
      This object.
    • setStatusCode

      public BasicStatusLine setStatusCode(int value)
      Sets the status code on the status line.

      If not specified, 0 will be used.

      Parameters:
      value - The new value.
      Returns:
      This object.
    • unmodifiable

      Returns an unmodifiable snapshot of this bean.

      The returned instance is a point-in-time copy of type BasicStatusLine.Unmodifiable; any attempt to set a property on it throws an UnsupportedOperationException. This method is idempotent: if this bean is already unmodifiable it returns itself rather than taking another snapshot. The receiver is left unchanged (and still modifiable unless it was already an BasicStatusLine.Unmodifiable).

      Returns:
      An unmodifiable snapshot of this bean, or this bean if it is already unmodifiable.
    • isUnmodifiable

      public boolean isUnmodifiable()
      Returns whether this bean is unmodifiable.
      Returns:
      true if this bean is an BasicStatusLine.Unmodifiable snapshot.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • modify

      protected BasicStatusLine modify(Runnable mutation)
      Single mutation funnel — the only choke-point through which all state changes on this bean flow.

      Every mutator routes through this method. The BasicStatusLine.Unmodifiable snapshot overrides only this method to throw, which freezes the entire mutation surface with a single override.

      Parameters:
      mutation - The state change to apply.
      Returns:
      This object.
    • freeze

      protected void freeze()
      Deep-freeze hook invoked from the BasicStatusLine.Unmodifiable constructor after the snapshot copy completes.

      This is a no-op for BasicStatusLine: all of its fields are immutable value types (protocol version, status code, reason phrase, locale, reason-phrase catalog) with no mutable sub-beans to deep-freeze. It exists as the paradigm's override point for families whose beans hold mutable sub-beans, which must be frozen here by direct field assignment (never via a setter, which would route through the throwing modify(Runnable)).