1. /*
  2. * @(#)URISyntax.java 1.4 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.print.attribute;
  8. import java.io.Serializable;
  9. import java.net.URI;
  10. import java.net.URISyntaxException;
  11. /**
  12. * Class URISyntax is an abstract base class providing the common
  13. * implementation of all attributes whose value is a Uniform Resource
  14. * Identifier (URI). Once constructed, a URI attribute's value is immutable.
  15. * <P>
  16. *
  17. * @author Alan Kaminsky
  18. */
  19. public abstract class URISyntax implements Serializable, Cloneable {
  20. /**
  21. * URI value of this URI attribute.
  22. * @serial
  23. */
  24. private URI uri;
  25. /**
  26. * Constructs a URI attribute with the specified URI.
  27. *
  28. * @param uri URI.
  29. *
  30. * @exception NullPointerException
  31. * (unchecked exception) Thrown if <CODE>uri</CODE> is null.
  32. */
  33. protected URISyntax(URI uri) {
  34. this.uri = verify (uri);
  35. }
  36. private static URI verify(URI uri) {
  37. if (uri == null) {
  38. throw new NullPointerException(" uri is null");
  39. }
  40. return uri;
  41. }
  42. /**
  43. * Returns this URI attribute's URI value.
  44. * @return the URI.
  45. */
  46. public URI getURI() {
  47. return uri;
  48. }
  49. /**
  50. * Returns a hashcode for this URI attribute.
  51. *
  52. * @return A hashcode value for this object.
  53. */
  54. public int hashCode() {
  55. return uri.hashCode();
  56. }
  57. /**
  58. * Returns whether this URI attribute is equivalent to the passed in
  59. * object.
  60. * To be equivalent, all of the following conditions must be true:
  61. * <OL TYPE=1>
  62. * <LI>
  63. * <CODE>object</CODE> is not null.
  64. * <LI>
  65. * <CODE>object</CODE> is an instance of class URISyntax.
  66. * <LI>
  67. * This URI attribute's underlying URI and <CODE>object</CODE>'s
  68. * underlying URI are equal.
  69. * </OL>
  70. *
  71. * @param object Object to compare to.
  72. *
  73. * @return True if <CODE>object</CODE> is equivalent to this URI
  74. * attribute, false otherwise.
  75. */
  76. public boolean equals(Object object) {
  77. return(object != null &&
  78. object instanceof URISyntax &&
  79. this.uri.equals (((URISyntax) object).uri));
  80. }
  81. /**
  82. * Returns a String identifying this URI attribute. The String is the
  83. * string representation of the attribute's underlying URI.
  84. *
  85. * @return A String identifying this object.
  86. */
  87. public String toString() {
  88. return uri.toString();
  89. }
  90. }