TopoWeb Commons API

org.topoweb.net
Class Ori

java.lang.Object
  |
  +--org.topoweb.net.Ori
All Implemented Interfaces:
java.lang.Comparable

public class Ori
extends java.lang.Object
implements java.lang.Comparable

Encapsulates a string representation of URIs that is lexicographically ordered by ownership. This class is an attempt to create a format for representing global resources in such a way that given a sorted list of their representations we can quickly find all resources in the list owned by some parent entity. Translations from some standard URIs to instances of this class and viceversa are defined in the OriTranslator class. This class is just a thin wrapper that asserts the structure for our ORI. An ORI is always of the form

<ordered domain>+<scheme>+[port]+[user info]/[path][?query]

This class is not final, but its methods are. Comparison methods are delegated to the instance's string representation. With respect to the state exposed by these methods, instances of this class are both immutable and final.

PENDING: Give more precise definition of valid characters, and sequences of, in the various parts of the identifier.

Implementation Note:

We are not yet dealing with IPv6 literal addresses. We will revisit the issue, I'm sure, soon.

Author:
Babak Farhang

Constructor Summary
Ori(java.lang.String id)
          Creates a new instance using the given identifier.
 
Method Summary
 java.lang.StringBuffer appendDomain(java.lang.StringBuffer work)
          Appends the domain into the specified work buffer.
 java.lang.StringBuffer appendPath(java.lang.StringBuffer work)
          Appends the path to the given work buffer.
 java.lang.StringBuffer appendScheme(java.lang.StringBuffer work)
          Appends the scheme into the specified work buffer.
 java.lang.StringBuffer appendUserInfo(java.lang.StringBuffer work)
          Appends the user information, if any, to the given work buffer.
 int compareTo(java.lang.Object other)
          Compares this instance with the other, as per the java.lang.Comparable contract.
 int compareTo(Ori other)
          Compares this instance with the other Ori instance.
 boolean equals(java.lang.Object other)
          Is this instance equal to the other object?
 boolean equals(Ori other)
          Is this instance equal to the Ori instance?
 java.lang.String getDomain()
          Returns the domain of this instance.
 java.lang.String getPath()
          Returns the path portion of this instance.
 int getPort()
          Returns the port.
 java.lang.String getScheme()
          Returns the scheme of this instance.
 java.lang.String getUserInfo()
          Returns the user information portion of this instance.
 int hashCode()
          Returns the hashcode for this instance as per the contract in java.lang.Object.
 boolean hasUserInfo()
          Does this instance have a user information?
 java.lang.String toString()
          Returns the identifier passed in at instantiation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Ori

public Ori(java.lang.String id)
    throws OriSyntaxException
Creates a new instance using the given identifier. If the identifier is malformed, an OriSyntaxException is thrown.

Parameters:
id - the identifier
Throws:
OriSyntaxException - if id is malformed
See Also:
toString()
Method Detail

appendScheme

public final java.lang.StringBuffer appendScheme(java.lang.StringBuffer work)
Appends the scheme into the specified work buffer.

Parameters:
work - the work buffer
Returns:
the work buffer
See Also:
getScheme()

getScheme

public final java.lang.String getScheme()
Returns the scheme of this instance.

Returns:
the scheme
See Also:
appendScheme(StringBuffer)

appendDomain

public final java.lang.StringBuffer appendDomain(java.lang.StringBuffer work)
Appends the domain into the specified work buffer.

Parameters:
work - the work buffer
Returns:
the work buffer
See Also:
getDomain()

getDomain

public final java.lang.String getDomain()
Returns the domain of this instance.

Returns:
the domain
See Also:
appendDomain(StringBuffer)

getPort

public final int getPort()
Returns the port.

Returns:
the port number, or -1 if unspecified

hasUserInfo

public final boolean hasUserInfo()
Does this instance have a user information?

Returns:
true, if there is user info; false, o.w.

appendUserInfo

public final java.lang.StringBuffer appendUserInfo(java.lang.StringBuffer work)
Appends the user information, if any, to the given work buffer.

Parameters:
work - the work buffer
Returns:
the work buffer
See Also:
getUserInfo()

getUserInfo

public final java.lang.String getUserInfo()
Returns the user information portion of this instance.

Returns:
the user info, or null, if unspecified
See Also:
appendUserInfo(StringBuffer)

appendPath

public final java.lang.StringBuffer appendPath(java.lang.StringBuffer work)
Appends the path to the given work buffer.

Parameters:
work - the work buffer
Returns:
the work buffer
See Also:
getPath()

getPath

public final java.lang.String getPath()
Returns the path portion of this instance.

Returns:
the path
See Also:
appendPath(StringBuffer)

toString

public final java.lang.String toString()
Returns the identifier passed in at instantiation. The string value of the identifier is used to evaluate all the comparison and hashcode methods.

Overrides:
toString in class java.lang.Object
Returns:
the string reprentation of the ORI

equals

public final boolean equals(java.lang.Object other)
Is this instance equal to the other object?

Overrides:
equals in class java.lang.Object
Parameters:
other - the other object
Returns:
true, if other is an instance of Ori, and its string representation is the same; false, o.w.
See Also:
toString(), hashCode()

equals

public final boolean equals(Ori other)
Is this instance equal to the Ori instance?

See Also:
equals(Object)

hashCode

public final int hashCode()
Returns the hashcode for this instance as per the contract in java.lang.Object.

Overrides:
hashCode in class java.lang.Object
Returns:
the hashcode of the string representation of this instance

compareTo

public final int compareTo(java.lang.Object other)
Compares this instance with the other, as per the java.lang.Comparable contract. The comparison is performed on the string representation of this instance.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
other - the instance compared to
See Also:
toString()

compareTo

public final int compareTo(Ori other)
Compares this instance with the other Ori instance.

See Also:
compareTo(Object)

TopoWeb Commons API

Copyright (C) 2002 Babak Farhang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.