001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package com.sun.xml.ws.wsdl.parser;
037:
038: import com.sun.xml.ws.streaming.Attributes;
039: import com.sun.xml.ws.streaming.XMLReader;
040: import com.sun.xml.ws.streaming.XMLReaderException;
041: import com.sun.xml.ws.util.xml.XmlUtil;
042:
043: import java.io.File;
044: import java.net.MalformedURLException;
045: import java.net.URL;
046: import javax.xml.namespace.QName;
047: import javax.xml.stream.XMLStreamReader;
048:
049: /**
050: *
051: * TODO: made public just for now
052: * @author WS Development Team
053: */
054: public class ParserUtil {
055: public static String getAttribute(XMLStreamReader reader,
056: String name) {
057: return reader.getAttributeValue(null, name);
058: }
059:
060: public static String getAttribute(XMLStreamReader reader,
061: String nsUri, String name) {
062: return reader.getAttributeValue(nsUri, name);
063: }
064:
065: public static String getAttribute(XMLStreamReader reader, QName name) {
066: return reader.getAttributeValue(name.getNamespaceURI(), name
067: .getLocalPart());
068: }
069:
070: public static void verifyTag(XMLReader reader, QName name) {
071: if (!name.equals(reader.getName())) {
072: throw new XMLReaderException(
073: "xmlreader.unexpectedState.tag", new Object[] {
074: name, reader.getName() });
075: }
076: }
077:
078: public static QName getQName(XMLStreamReader reader, String tag) {
079: String localName = XmlUtil.getLocalPart(tag);
080: String pfix = XmlUtil.getPrefix(tag);
081: String uri = reader.getNamespaceURI(pfix);
082: return new QName(uri, localName);
083: }
084:
085: public static String getMandatoryNonEmptyAttribute(
086: XMLStreamReader reader, String name) {
087: // String value = getAttribute(reader, name);
088: String value = reader.getAttributeValue(null, name);
089:
090: if (value == null) {
091: failWithLocalName("client.missing.attribute", reader, name);
092: } else if (value.equals("")) {
093: failWithLocalName("client.invalidAttributeValue", reader,
094: name);
095: }
096:
097: return value;
098: }
099:
100: public static void fail(String key, XMLReader reader) {
101: //throw new WebServicesClientException(key,
102: // Integer.toString(reader.getLineNumber()));
103: }
104:
105: public static void failWithFullName(String key, XMLReader reader) {
106: //throw new WebServicesClientException(key,
107: //new Object[]{
108: // Integer.toString(reader.getLineNumber()),
109: // reader.getName().toString()});
110: }
111:
112: public static void failWithFullName(String key,
113: XMLStreamReader reader) {
114: // throw new WebServicesClientException(key,
115: // new Object[]{
116: // Integer.toString(reader.getLineNumber()),
117: // reader.getName().toString()});
118: }
119:
120: public static void failWithLocalName(String key,
121: XMLStreamReader reader) {
122: //throw new WebServicesClientException(key,
123: // new Object[]{
124: // Integer.toString(reader.getLineNumber()),
125: // reader.getLocalName()});
126: }
127:
128: public static void failWithLocalName(String key, XMLReader reader,
129: String arg) {
130: //throw new WebServicesClientException(key,
131: // new Object[]{
132: // Integer.toString(reader.getLineNumber()),
133: // reader.getLocalName(),
134: // arg});
135: }
136:
137: public static void failWithLocalName(String key,
138: XMLStreamReader reader, String arg) {
139: //throw new WebServicesClientException(key,
140: // new Object[]{
141: // Integer.toString(reader.getLineNumber()),
142: // reader.getLocalName(),
143: // arg});
144: }
145: }
|