001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.xml.saaj;
031:
032: import javax.xml.namespace.QName;
033: import javax.xml.soap.*;
034:
035: import org.w3c.dom.*;
036:
037: public class NameImpl extends QName implements Name {
038: private String _qualifiedName;
039:
040: NameImpl(String localPart) {
041: super (localPart);
042:
043: _qualifiedName = localPart;
044: }
045:
046: NameImpl(String namespaceURI, String localPart) {
047: super (namespaceURI, localPart);
048:
049: _qualifiedName = localPart;
050: }
051:
052: NameImpl(String namespaceURI, String localPart, String prefix) {
053: super (namespaceURI, localPart, prefix);
054:
055: if (prefix != null && !"".equals(prefix))
056: _qualifiedName = prefix + ':' + localPart;
057: else
058: _qualifiedName = localPart;
059: }
060:
061: static NameImpl fromQualifiedName(String uri, String qualifiedName) {
062: int colon = qualifiedName.indexOf(':');
063:
064: if (colon >= 0) {
065: String prefix = qualifiedName.substring(0, colon);
066: String localName = qualifiedName.substring(colon + 1);
067:
068: return new NameImpl(uri, localName, prefix);
069: }
070:
071: return new NameImpl(uri, qualifiedName);
072: }
073:
074: static NameImpl fromName(Name name) {
075: if (name instanceof NameImpl)
076: return (NameImpl) name;
077:
078: else if (name.getPrefix() != null)
079: return new NameImpl(name.getURI(), name.getLocalName(),
080: name.getPrefix());
081: else if (name.getURI() != null)
082: return new NameImpl(name.getURI(), name.getLocalName());
083: else
084: return new NameImpl(name.getLocalName());
085: }
086:
087: static NameImpl fromQName(QName qname) {
088: if (qname instanceof NameImpl)
089: return (NameImpl) qname;
090:
091: else if (qname.getPrefix() != null)
092: return new NameImpl(qname.getNamespaceURI(), qname
093: .getLocalPart(), qname.getPrefix());
094: else if (qname.getNamespaceURI() != null)
095: return new NameImpl(qname.getNamespaceURI(), qname
096: .getLocalPart());
097: else
098: return new NameImpl(qname.getLocalPart());
099: }
100:
101: static NameImpl fromElement(org.w3c.dom.Element element) {
102: return fromNode(element);
103: }
104:
105: static NameImpl fromNode(org.w3c.dom.Node node) {
106: if (node.getPrefix() != null)
107: return new NameImpl(node.getNamespaceURI(), node
108: .getLocalName(), node.getPrefix());
109: else if (node.getNamespaceURI() != null)
110: return new NameImpl(node.getNamespaceURI(), node
111: .getLocalName());
112: else if (node.getLocalName() != null)
113: return new NameImpl(node.getLocalName());
114: else
115: return new NameImpl(node.getNodeName());
116: }
117:
118: public String getLocalName() {
119: return getLocalPart();
120: }
121:
122: public String getQualifiedName() {
123: return _qualifiedName;
124: }
125:
126: public String getURI() {
127: return getNamespaceURI();
128: }
129:
130: public String toString() {
131: return getQualifiedName();
132: }
133:
134: static QName toQName(Name name) {
135: if (name instanceof QName)
136: return (QName) name;
137:
138: else if (name.getPrefix() != null)
139: return new QName(name.getURI(), name.getLocalName(), name
140: .getPrefix());
141: else if (name.getURI() != null)
142: return new QName(name.getURI(), name.getLocalName());
143: else
144: return new QName(name.getLocalName());
145: }
146: }
|