KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > message > NameImpl


1 /**
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.axis.message;
8
9 // $Id: NameImpl.java,v 1.1.2.1 2005/03/02 14:29:30 tdiesler Exp $
10

11 import javax.xml.namespace.QName JavaDoc;
12 import javax.xml.soap.Name JavaDoc;
13
14 /**
15  * A representation of an XML name. This interface provides methods for getting the local and namespace-qualified names
16  * and also for getting the prefix associated with the namespace for the name. It is also possible to get the URI
17  * of the namespace.
18  *
19  * The following is an example of a namespace declaration in an element.
20  *
21  * <wombat:GetLastTradePrice xmlns:wombat="http://www.wombat.org/trader">
22  *
23  * The following shows what the methods in the Name interface will return.
24  *
25  * getQualifiedName will return "prefix:LocalName" = "wombat:GetLastTradePrice"
26  * getURI will return "http://www.wombat.org/trader"
27  * getLocalName will return "GetLastTracePrice"
28  * getPrefix will return "wombat"
29  *
30  * XML namespaces are used to disambiguate SOAP identifiers from application-specific identifiers.
31  *
32  * Name objects are created using the method SOAPEnvelope.createName, which has two versions.
33  * One method creates Name objects with a local name, a namespace prefix, and a namespace URI.
34  * The second creates Name objects with just a local name.
35  *
36  * The following line of code, in which se is a SOAPEnvelope object, creates a new Name object with all three.
37  *
38  * Name name = se.createName("GetLastTradePrice", "wombat", "http://www.wombat.org/trader");
39  *
40  * The following line of code gives an example of how a Name object can be used.
41  * The variable element is a SOAPElement object. This code creates a new SOAPElement object with the given name and
42  * adds it to element.
43  *
44  * element.addChildElement(name);
45  *
46  * @author Thomas.Diesler (thomas.diesler@jboss.org)
47  * @since 01-June-2004
48  */

49 public class NameImpl implements Name JavaDoc
50 {
51
52    private QName JavaDoc qname;
53    private String JavaDoc prefix;
54
55    public NameImpl(String JavaDoc local)
56    {
57       this(local, null, null);
58    }
59
60    public NameImpl(String JavaDoc local, String JavaDoc prefix, String JavaDoc uri)
61    {
62       qname = new QName JavaDoc(uri, local);
63       this.prefix = (prefix == null ? "" : prefix);
64    }
65
66    /**
67     * Gets the local name part of the XML name that this Name object represents.
68     *
69     * @return a string giving the local name
70     */

71    public String JavaDoc getLocalName()
72    {
73       return qname.getLocalPart();
74    }
75
76    /**
77     * Returns the prefix that was specified when this Name object was initialized.
78     * This prefix is associated with the namespace for the XML name that this Name object represents.
79     *
80     * @return the prefix as a string
81     */

82    public String JavaDoc getPrefix()
83    {
84       return prefix;
85    }
86
87    /**
88     * Gets the namespace-qualified name of the XML name that this Name object represents.
89     *
90     * @return the namespace-qualified name as a string
91     */

92    public String JavaDoc getQualifiedName()
93    {
94       return prefix + ":" + qname.getLocalPart();
95    }
96
97    /**
98     * Returns the URI of the namespace for the XML name that this Name object represents.
99     *
100     * @return the URI as a string
101     */

102    public String JavaDoc getURI()
103    {
104       return qname.getNamespaceURI();
105    }
106
107    public int hashCode()
108    {
109       return qname.hashCode();
110    }
111
112    /**
113     * Equality compares localPart and namespaceURI.
114     * The prefix is not relevant for equality.
115     */

116    public boolean equals(Object JavaDoc obj)
117    {
118       if (!(obj instanceof NameImpl)) return false;
119       if (obj == this) return true;
120       NameImpl other = (NameImpl)obj;
121       return qname.equals(other.qname);
122    }
123
124    public String JavaDoc toString()
125    {
126       return qname.toString();
127    }
128 }
129
Popular Tags