KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > print > attribute > URISyntax


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
8
9 package javax.print.attribute;
10
11 import java.io.Serializable JavaDoc;
12 import java.net.URI JavaDoc;
13 import java.net.URISyntaxException JavaDoc;
14
15 /**
16  * Class URISyntax is an abstract base class providing the common
17  * implementation of all attributes whose value is a Uniform Resource
18  * Identifier (URI). Once constructed, a URI attribute's value is immutable.
19  * <P>
20  *
21  * @author Alan Kaminsky
22  */

23 public abstract class URISyntax implements Serializable JavaDoc, Cloneable JavaDoc {
24
25     private static final long serialVersionUID = -7842661210486401678L;
26
27     /**
28      * URI value of this URI attribute.
29      * @serial
30      */

31     private URI JavaDoc uri;
32
33     /**
34      * Constructs a URI attribute with the specified URI.
35      *
36      * @param uri URI.
37      *
38      * @exception NullPointerException
39      * (unchecked exception) Thrown if <CODE>uri</CODE> is null.
40      */

41     protected URISyntax(URI JavaDoc uri) {
42     this.uri = verify (uri);
43     }
44
45     private static URI JavaDoc verify(URI JavaDoc uri) {
46     if (uri == null) {
47         throw new NullPointerException JavaDoc(" uri is null");
48     }
49     return uri;
50     }
51
52     /**
53      * Returns this URI attribute's URI value.
54      * @return the URI.
55      */

56     public URI JavaDoc getURI() {
57     return uri;
58     }
59
60     /**
61      * Returns a hashcode for this URI attribute.
62      *
63      * @return A hashcode value for this object.
64      */

65     public int hashCode() {
66     return uri.hashCode();
67     }
68
69     /**
70      * Returns whether this URI attribute is equivalent to the passed in
71      * object.
72      * To be equivalent, all of the following conditions must be true:
73      * <OL TYPE=1>
74      * <LI>
75      * <CODE>object</CODE> is not null.
76      * <LI>
77      * <CODE>object</CODE> is an instance of class URISyntax.
78      * <LI>
79      * This URI attribute's underlying URI and <CODE>object</CODE>'s
80      * underlying URI are equal.
81      * </OL>
82      *
83      * @param object Object to compare to.
84      *
85      * @return True if <CODE>object</CODE> is equivalent to this URI
86      * attribute, false otherwise.
87      */

88     public boolean equals(Object JavaDoc object) {
89     return(object != null &&
90            object instanceof URISyntax JavaDoc &&
91            this.uri.equals (((URISyntax JavaDoc) object).uri));
92     }
93     
94     /**
95      * Returns a String identifying this URI attribute. The String is the
96      * string representation of the attribute's underlying URI.
97      *
98      * @return A String identifying this object.
99      */

100     public String JavaDoc toString() {
101     return uri.toString();
102     }
103     
104 }
105
Popular Tags