001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package com.sun.xml.internal.ws.wsdl.parser;
026:
027: import com.sun.xml.internal.ws.streaming.Attributes;
028: import com.sun.xml.internal.ws.streaming.XMLReader;
029: import com.sun.xml.internal.ws.streaming.XMLReaderException;
030: import com.sun.xml.internal.ws.util.xml.XmlUtil;
031:
032: import java.io.File;
033: import java.net.MalformedURLException;
034: import java.net.URL;
035: import javax.xml.namespace.QName;
036: import javax.xml.stream.XMLStreamReader;
037:
038: /**
039: * @author WS Development Team
040: */
041: public class ParserUtil {
042: public static String getAttribute(XMLStreamReader reader,
043: String name) {
044: return reader.getAttributeValue(null, name);
045: }
046:
047: public static void verifyTag(XMLReader reader, QName name) {
048: if (!name.equals(reader.getName())) {
049: throw new XMLReaderException(
050: "xmlreader.unexpectedState.tag", new Object[] {
051: name, reader.getName() });
052: }
053: }
054:
055: public static QName getQName(XMLStreamReader reader, String tag) {
056: String localName = XmlUtil.getLocalPart(tag);
057: String pfix = XmlUtil.getPrefix(tag);
058: String uri = reader.getNamespaceURI(pfix);
059: return new QName(uri, localName);
060: }
061:
062: public static String getMandatoryNonEmptyAttribute(
063: XMLStreamReader reader, String name) {
064: // String value = getAttribute(reader, name);
065: String value = reader.getAttributeValue(null, name);
066:
067: if (value == null) {
068: failWithLocalName("client.missing.attribute", reader, name);
069: } else if (value.equals("")) {
070: failWithLocalName("client.invalidAttributeValue", reader,
071: name);
072: }
073:
074: return value;
075: }
076:
077: public static void fail(String key, XMLReader reader) {
078: //throw new WebServicesClientException(key,
079: // Integer.toString(reader.getLineNumber()));
080: }
081:
082: public static void failWithFullName(String key, XMLReader reader) {
083: //throw new WebServicesClientException(key,
084: //new Object[]{
085: // Integer.toString(reader.getLineNumber()),
086: // reader.getName().toString()});
087: }
088:
089: public static void failWithFullName(String key,
090: XMLStreamReader reader) {
091: // throw new WebServicesClientException(key,
092: // new Object[]{
093: // Integer.toString(reader.getLineNumber()),
094: // reader.getName().toString()});
095: }
096:
097: public static void failWithLocalName(String key,
098: XMLStreamReader reader) {
099: //throw new WebServicesClientException(key,
100: // new Object[]{
101: // Integer.toString(reader.getLineNumber()),
102: // reader.getLocalName()});
103: }
104:
105: public static void failWithLocalName(String key, XMLReader reader,
106: String arg) {
107: //throw new WebServicesClientException(key,
108: // new Object[]{
109: // Integer.toString(reader.getLineNumber()),
110: // reader.getLocalName(),
111: // arg});
112: }
113:
114: public static void failWithLocalName(String key,
115: XMLStreamReader reader, String arg) {
116: //throw new WebServicesClientException(key,
117: // new Object[]{
118: // Integer.toString(reader.getLineNumber()),
119: // reader.getLocalName(),
120: // arg});
121: }
122: }
|