1. /*
  2. * @(#)URISyntax.java 1.6 04/01/07
  3. *
  4. * Copyright 2004 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. private static final long serialVersionUID = -7842661210486401678L;
  21. /**
  22. * URI value of this URI attribute.
  23. * @serial
  24. */
  25. private URI uri;
  26. /**
  27. * Constructs a URI attribute with the specified URI.
  28. *
  29. * @param uri URI.
  30. *
  31. * @exception NullPointerException
  32. * (unchecked exception) Thrown if <CODE>uri</CODE> is null.
  33. */
  34. protected URISyntax(URI uri) {
  35. this.uri = verify (uri);
  36. }
  37. private static URI verify(URI uri) {
  38. if (uri == null) {
  39. throw new NullPointerException(" uri is null");
  40. }
  41. return uri;
  42. }
  43. /**
  44. * Returns this URI attribute's URI value.
  45. * @return the URI.
  46. */
  47. public URI getURI() {
  48. return uri;
  49. }
  50. /**
  51. * Returns a hashcode for this URI attribute.
  52. *
  53. * @return A hashcode value for this object.
  54. */
  55. public int hashCode() {
  56. return uri.hashCode();
  57. }
  58. /**
  59. * Returns whether this URI attribute is equivalent to the passed in
  60. * object.
  61. * To be equivalent, all of the following conditions must be true:
  62. * <OL TYPE=1>
  63. * <LI>
  64. * <CODE>object</CODE> is not null.
  65. * <LI>
  66. * <CODE>object</CODE> is an instance of class URISyntax.
  67. * <LI>
  68. * This URI attribute's underlying URI and <CODE>object</CODE>'s
  69. * underlying URI are equal.
  70. * </OL>
  71. *
  72. * @param object Object to compare to.
  73. *
  74. * @return True if <CODE>object</CODE> is equivalent to this URI
  75. * attribute, false otherwise.
  76. */
  77. public boolean equals(Object object) {
  78. return(object != null &&
  79. object instanceof URISyntax &&
  80. this.uri.equals (((URISyntax) object).uri));
  81. }
  82. /**
  83. * Returns a String identifying this URI attribute. The String is the
  84. * string representation of the attribute's underlying URI.
  85. *
  86. * @return A String identifying this object.
  87. */
  88. public String toString() {
  89. return uri.toString();
  90. }
  91. }