org.apache.beehive.netui.core.urls
Class FreezableMutableURI

Object
  extended by MutableURI
      extended by FreezableMutableURI

public class FreezableMutableURI
extends MutableURI

A mutable class for creating URIs that can be set to "frozen" such that it becomes immutable. After this class is frozen, any calls to methods to set the data components of the URI will throw


Field Summary
 
Fields inherited from class MutableURI
DEFAULT_ENCODING, UNDEFINED_PORT
 
Constructor Summary
FreezableMutableURI()
          Constructs a FreezableMutableURI.
FreezableMutableURI(String uriString)
          Constructs a FreezableMutableURI.
FreezableMutableURI(String scheme, String userInfo, String host, int port, String path, String query, String fragment)
          Constructs a FreezableMutableURI.
FreezableMutableURI(URI uri)
          Constructs a FreezableMutableURI.
FreezableMutableURI(URL url)
          Constructs a FreezableMutableURI.
 
Method Summary
 void addParameter(String name, String value, boolean encoded)
          Add a parameter for the query string.
 void addParameters(Map newParams, boolean encoded)
          Add a parameter to the query string.
 boolean equals(Object o)
          Determines if the passed-in Object is equivalent to this MutableURI.
 int hashCode()
          Returns a hash code value for the object.
 boolean isFrozen()
           
 void removeParameter(String name)
          Removes the given parameter.
 void setEncoding(String encoding)
          Set the encoding used when adding unencoded parameters.
 void setFragment(String fragment)
          Sets the fragment.
 void setFrozen(boolean frozen)
          Sets a flag indicating that the URI is immutable (or not).
 void setHost(String host)
          Sets the host.
 void setPath(String path)
          Sets the path.
 void setPort(int port)
          Sets the port.
 void setQuery(String query)
          Sets (and resets) the query string.
 void setScheme(String scheme)
          Sets the protocol/scheme.
 void setURI(String uriString)
          Reset the value of the FreezableMutableURI.
 void setUserInfo(String userInfo)
          Sets the userInfo.
 
Methods inherited from class MutableURI
encode, getDefaultParamDelimiter, getEncoding, getFragment, getHost, getParameter, getParameters, getParameters, getPath, getPort, getQuery, getQueryForXML, getScheme, getURIString, getURIStringForXML, getUserInfo, isAbsolute, setAlwaysForXML
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FreezableMutableURI

public FreezableMutableURI()
Constructs a FreezableMutableURI.


FreezableMutableURI

public FreezableMutableURI(String uriString)
                    throws URISyntaxException
Constructs a FreezableMutableURI.

Parameters:
uriString - the string to be parsed into a URI
Throws:
URISyntaxException
See Also:
URI.URI(String)

FreezableMutableURI

public FreezableMutableURI(String scheme,
                           String userInfo,
                           String host,
                           int port,
                           String path,
                           String query,
                           String fragment)
Constructs a FreezableMutableURI.

Parameters:
scheme - the name of the protocol to use
userInfo - the username and password
host - the name of the host
port - the port number on the host
path - the file on the host
query - the query part of this URI
fragment - the fragment part of this URI (internal reference in the URL)

FreezableMutableURI

public FreezableMutableURI(URI uri)
Constructs a FreezableMutableURI.

Parameters:
uri - the initial value for this mutable URI

FreezableMutableURI

public FreezableMutableURI(URL url)
                    throws URISyntaxException
Constructs a FreezableMutableURI.

This is just a convenience constructor that functions the same as FreezableMutableURI(URI) constructor with URL.toURI() as the argument.

Note, any URL instance that complies with RFC 2396 can be converted to a URI. However, some URLs that are not strictly in compliance can not be converted to a URI. See URL

Parameters:
url - the initial value for this mutable URI
Throws:
URISyntaxException - if this URL is not formatted strictly to RFC2396 and cannot be converted to a URI.
See Also:
URL.toURI()
Method Detail

isFrozen

public final boolean isFrozen()

setFrozen

public void setFrozen(boolean frozen)
Sets a flag indicating that the URI is immutable (or not).

Parameters:
frozen - flag to indicate if the URI is now immutable or not.

setURI

public void setURI(String uriString)
            throws URISyntaxException
Reset the value of the FreezableMutableURI.

This method can also be used to clear the FreezableMutableURI.

Overrides:
setURI in class MutableURI
Parameters:
uriString - the string to be parsed into a URI
Throws:
URISyntaxException
See Also:
URI.URI(String)

setEncoding

public void setEncoding(String encoding)
Set the encoding used when adding unencoded parameters.

Overrides:
setEncoding in class MutableURI
Parameters:
encoding -

setScheme

public void setScheme(String scheme)
Sets the protocol/scheme.

Overrides:
setScheme in class MutableURI
Parameters:
scheme - protocol/scheme

setUserInfo

public void setUserInfo(String userInfo)
Sets the userInfo.

Overrides:
setUserInfo in class MutableURI
Parameters:
userInfo - userInfo

setHost

public void setHost(String host)
Sets the host.

Overrides:
setHost in class MutableURI
Parameters:
host - host

setPort

public void setPort(int port)
Sets the port.

Overrides:
setPort in class MutableURI
Parameters:
port - port

setPath

public void setPath(String path)
Sets the path.

Overrides:
setPath in class MutableURI
Parameters:
path - path

setQuery

public void setQuery(String query)
Sets (and resets) the query string. This method assumes that the query is already encoded and the parameter delimiter is the '&' character.

Overrides:
setQuery in class MutableURI
Parameters:
query - Query string

addParameter

public void addParameter(String name,
                         String value,
                         boolean encoded)
Add a parameter for the query string.

If the encoded flag is true then this method assumes that the name and value do not need encoding or are already encoded correctly. Otherwise, it translates the name and value with the character encoding of this URI and adds them to the set of parameters for the query. If the encoding for this URI has not been set, then the default encoding used is "UTF-8".

Multiple values for the same parameter can be set by calling this method multiple times with the same name.

Overrides:
addParameter in class MutableURI
Parameters:
name - name
value - value
encoded - Flag indicating whether the names and values are already encoded.

addParameters

public void addParameters(Map newParams,
                          boolean encoded)
Add a parameter to the query string.

If the encoded flag is true then this method assumes that the name and value do not need encoding or are already encoded correctly. Otherwise, it translates the name and value with the character encoding of this URI and adds them to the set of parameters for the query. If the encoding for this URI has not been set, then the default encoding used is "UTF-8".

Overrides:
addParameters in class MutableURI
Parameters:
newParams - the map of new parameters to add to the URI
encoded - Flag indicating whether the names and values are already encoded.

removeParameter

public void removeParameter(String name)
Removes the given parameter.

Overrides:
removeParameter in class MutableURI
Parameters:
name - name

setFragment

public void setFragment(String fragment)
Sets the fragment.

Overrides:
setFragment in class MutableURI
Parameters:
fragment - fragment

equals

public boolean equals(Object o)
Description copied from class: MutableURI
Determines if the passed-in Object is equivalent to this MutableURI.

Overrides:
equals in class MutableURI
Parameters:
o - the Object to test for equality.
Returns:
true if object is a MutableURI with all values equal to this MutableURI, false otherwise

hashCode

public int hashCode()
Description copied from class: MutableURI
Returns a hash code value for the object.

Implemented in conjunction with equals() override.

This is a mutable class implying that we're basing the hash code on the member data that can change. Therefor it's important not to use this class as a key in a hashtable as it would still appear with an enumeration but not when calling contains. I.E. The object could get lost in the hashtable. A call for the hashcode would return a different value than when it was first placed in the hashtable.

With this in mind, we simply return the same value to support the rules of equality.

Overrides:
hashCode in class MutableURI
Returns:
a hash code value for this object.