1 /*
2 * Copyright 2000-2004 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26
27 package javax.print.attribute;
28
29 import java.io.Serializable;
30 import java.net.URI;
31 import java.net.URISyntaxException;
32
33 /**
34 * Class URISyntax is an abstract base class providing the common
35 * implementation of all attributes whose value is a Uniform Resource
36 * Identifier (URI). Once constructed, a URI attribute's value is immutable.
37 * <P>
38 *
39 * @author Alan Kaminsky
40 */
41 public abstract class URISyntax implements Serializable, Cloneable {
42
43 private static final long serialVersionUID = -7842661210486401678L;
44
45 /**
46 * URI value of this URI attribute.
47 * @serial
48 */
49 private URI uri;
50
51 /**
52 * Constructs a URI attribute with the specified URI.
53 *
54 * @param uri URI.
55 *
56 * @exception NullPointerException
57 * (unchecked exception) Thrown if <CODE>uri</CODE> is null.
58 */
59 protected URISyntax(URI uri) {
60 this.uri = verify (uri);
61 }
62
63 private static URI verify(URI uri) {
64 if (uri == null) {
65 throw new NullPointerException(" uri is null");
66 }
67 return uri;
68 }
69
70 /**
71 * Returns this URI attribute's URI value.
72 * @return the URI.
73 */
74 public URI getURI() {
75 return uri;
76 }
77
78 /**
79 * Returns a hashcode for this URI attribute.
80 *
81 * @return A hashcode value for this object.
82 */
83 public int hashCode() {
84 return uri.hashCode();
85 }
86
87 /**
88 * Returns whether this URI attribute is equivalent to the passed in
89 * object.
90 * To be equivalent, all of the following conditions must be true:
91 * <OL TYPE=1>
92 * <LI>
93 * <CODE>object</CODE> is not null.
94 * <LI>
95 * <CODE>object</CODE> is an instance of class URISyntax.
96 * <LI>
97 * This URI attribute's underlying URI and <CODE>object</CODE>'s
98 * underlying URI are equal.
99 * </OL>
100 *
101 * @param object Object to compare to.
102 *
103 * @return True if <CODE>object</CODE> is equivalent to this URI
104 * attribute, false otherwise.
105 */
106 public boolean equals(Object object) {
107 return(object != null &&
108 object instanceof URISyntax &&
109 this.uri.equals (((URISyntax) object).uri));
110 }
111
112 /**
113 * Returns a String identifying this URI attribute. The String is the
114 * string representation of the attribute's underlying URI.
115 *
116 * @return A String identifying this object.
117 */
118 public String toString() {
119 return uri.toString();
120 }
121
122 }