1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/xsom/XmlString.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,117 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.xsom; 1.30 + 1.31 +import org.relaxng.datatype.ValidationContext; 1.32 + 1.33 +/** 1.34 + * String with in-scope namespace binding information. 1.35 + * 1.36 + * <p> 1.37 + * In a general case, text (PCDATA/attributes) that appear in XML schema 1.38 + * cannot be correctly interpreted unless you also have in-scope namespace 1.39 + * binding (a case in point is QName.) Therefore, it's convenient to 1.40 + * handle the lexical representation and the in-scope namespace binding 1.41 + * in a pair. 1.42 + * 1.43 + * @author Kohsuke Kawaguchi 1.44 + */ 1.45 +public final class XmlString { 1.46 + /** 1.47 + * Textual value. AKA lexical representation. 1.48 + */ 1.49 + public final String value; 1.50 + 1.51 + /** 1.52 + * Used to resole in-scope namespace bindings. 1.53 + */ 1.54 + public final ValidationContext context; 1.55 + 1.56 + /** 1.57 + * Creates a new {@link XmlString} from a lexical representation and in-scope namespaces. 1.58 + */ 1.59 + public XmlString(String value, ValidationContext context) { 1.60 + this.value = value; 1.61 + this.context = context; 1.62 + if(context==null) 1.63 + throw new IllegalArgumentException(); 1.64 + } 1.65 + 1.66 + /** 1.67 + * Creates a new {@link XmlString} with empty in-scope namespace bindings. 1.68 + */ 1.69 + public XmlString(String value) { 1.70 + this(value,NULL_CONTEXT); 1.71 + } 1.72 + 1.73 + /** 1.74 + * Resolves a namespace prefix to the corresponding namespace URI. 1.75 + * 1.76 + * This method is used for resolving prefixes in the {@link #value} 1.77 + * (such as when {@link #value} represents a QName type.) 1.78 + * 1.79 + * <p> 1.80 + * If the prefix is "" (empty string), the method 1.81 + * returns the default namespace URI. 1.82 + * 1.83 + * <p> 1.84 + * If the prefix is "xml", then the method returns 1.85 + * "http://www.w3.org/XML/1998/namespace", 1.86 + * as defined in the XML Namespaces Recommendation. 1.87 + * 1.88 + * @return 1.89 + * namespace URI of this prefix. 1.90 + * If the specified prefix is not declared, 1.91 + * the implementation returns null. 1.92 + */ 1.93 + public final String resolvePrefix(String prefix) { 1.94 + return context.resolveNamespacePrefix(prefix); 1.95 + } 1.96 + 1.97 + public String toString() { 1.98 + return value; 1.99 + } 1.100 + 1.101 + private static final ValidationContext NULL_CONTEXT = new ValidationContext() { 1.102 + public String resolveNamespacePrefix(String s) { 1.103 + if(s.length()==0) return ""; 1.104 + if(s.equals("xml")) return "http://www.w3.org/XML/1998/namespace"; 1.105 + return null; 1.106 + } 1.107 + 1.108 + public String getBaseUri() { 1.109 + return null; 1.110 + } 1.111 + 1.112 + public boolean isUnparsedEntity(String s) { 1.113 + return false; 1.114 + } 1.115 + 1.116 + public boolean isNotation(String s) { 1.117 + return false; 1.118 + } 1.119 + }; 1.120 +}