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:
037: package com.sun.tools.ws.wsdl.parser;
038:
039: import com.sun.tools.ws.wsdl.document.schema.SchemaConstants;
040: import com.sun.tools.ws.wsdl.document.schema.SchemaKinds;
041: import com.sun.tools.ws.wsdl.document.soap.SOAPConstants;
042: import com.sun.tools.ws.wsdl.framework.EntityReferenceValidator;
043: import com.sun.tools.ws.wsdl.framework.Kind;
044:
045: import javax.xml.namespace.QName;
046: import java.util.HashSet;
047: import java.util.Set;
048:
049: /**
050: * An interface implemented by a class that is capable of validating
051: * a QName/Kind pair referring to an external entity.
052: *
053: * @author WS Development Team
054: */
055: public class SOAPEntityReferenceValidator implements
056: EntityReferenceValidator {
057: public SOAPEntityReferenceValidator() {
058: }
059:
060: public boolean isValid(Kind kind, QName name) {
061:
062: // just let all "xml:" QNames through
063: if (name.getNamespaceURI().equals(Constants.NS_XML))
064: return true;
065:
066: if (kind == SchemaKinds.XSD_TYPE) {
067: return _validTypes.contains(name);
068: } else if (kind == SchemaKinds.XSD_ELEMENT) {
069: return _validElements.contains(name);
070: } else if (kind == SchemaKinds.XSD_ATTRIBUTE) {
071: return _validAttributes.contains(name);
072: } else {
073: // no luck
074: return false;
075: }
076: }
077:
078: private static final Set _validTypes;
079: private static final Set _validElements;
080: private static final Set _validAttributes;
081:
082: static {
083: // add all XML Schema and SOAP types
084: _validTypes = new HashSet();
085: _validTypes.add(SOAPConstants.QNAME_TYPE_ARRAY);
086: _validTypes.add(SchemaConstants.QNAME_TYPE_STRING);
087: _validTypes.add(SchemaConstants.QNAME_TYPE_NORMALIZED_STRING);
088: _validTypes.add(SchemaConstants.QNAME_TYPE_TOKEN);
089: _validTypes.add(SchemaConstants.QNAME_TYPE_BYTE);
090: _validTypes.add(SchemaConstants.QNAME_TYPE_UNSIGNED_BYTE);
091: _validTypes.add(SchemaConstants.QNAME_TYPE_BASE64_BINARY);
092: _validTypes.add(SchemaConstants.QNAME_TYPE_HEX_BINARY);
093: _validTypes.add(SchemaConstants.QNAME_TYPE_INTEGER);
094: _validTypes.add(SchemaConstants.QNAME_TYPE_POSITIVE_INTEGER);
095: _validTypes.add(SchemaConstants.QNAME_TYPE_NEGATIVE_INTEGER);
096: _validTypes
097: .add(SchemaConstants.QNAME_TYPE_NON_NEGATIVE_INTEGER);
098: _validTypes
099: .add(SchemaConstants.QNAME_TYPE_NON_POSITIVE_INTEGER);
100: _validTypes.add(SchemaConstants.QNAME_TYPE_INT);
101: _validTypes.add(SchemaConstants.QNAME_TYPE_UNSIGNED_INT);
102: _validTypes.add(SchemaConstants.QNAME_TYPE_LONG);
103: _validTypes.add(SchemaConstants.QNAME_TYPE_UNSIGNED_LONG);
104: _validTypes.add(SchemaConstants.QNAME_TYPE_SHORT);
105: _validTypes.add(SchemaConstants.QNAME_TYPE_UNSIGNED_SHORT);
106: _validTypes.add(SchemaConstants.QNAME_TYPE_DECIMAL);
107: _validTypes.add(SchemaConstants.QNAME_TYPE_FLOAT);
108: _validTypes.add(SchemaConstants.QNAME_TYPE_DOUBLE);
109: _validTypes.add(SchemaConstants.QNAME_TYPE_BOOLEAN);
110: _validTypes.add(SchemaConstants.QNAME_TYPE_TIME);
111: _validTypes.add(SchemaConstants.QNAME_TYPE_DATE_TIME);
112: _validTypes.add(SchemaConstants.QNAME_TYPE_DURATION);
113: _validTypes.add(SchemaConstants.QNAME_TYPE_DATE);
114: _validTypes.add(SchemaConstants.QNAME_TYPE_G_MONTH);
115: _validTypes.add(SchemaConstants.QNAME_TYPE_G_YEAR);
116: _validTypes.add(SchemaConstants.QNAME_TYPE_G_YEAR_MONTH);
117: _validTypes.add(SchemaConstants.QNAME_TYPE_G_DAY);
118: _validTypes.add(SchemaConstants.QNAME_TYPE_G_MONTH_DAY);
119: _validTypes.add(SchemaConstants.QNAME_TYPE_NAME);
120: _validTypes.add(SchemaConstants.QNAME_TYPE_QNAME);
121: _validTypes.add(SchemaConstants.QNAME_TYPE_NCNAME);
122: _validTypes.add(SchemaConstants.QNAME_TYPE_ANY_URI);
123: _validTypes.add(SchemaConstants.QNAME_TYPE_ID);
124: _validTypes.add(SchemaConstants.QNAME_TYPE_IDREF);
125: _validTypes.add(SchemaConstants.QNAME_TYPE_IDREFS);
126: _validTypes.add(SchemaConstants.QNAME_TYPE_ENTITY);
127: _validTypes.add(SchemaConstants.QNAME_TYPE_ENTITIES);
128: _validTypes.add(SchemaConstants.QNAME_TYPE_NOTATION);
129: _validTypes.add(SchemaConstants.QNAME_TYPE_NMTOKEN);
130: _validTypes.add(SchemaConstants.QNAME_TYPE_NMTOKENS);
131: _validTypes.add(SchemaConstants.QNAME_TYPE_URTYPE);
132: _validTypes.add(SchemaConstants.QNAME_TYPE_SIMPLE_URTYPE);
133: _validTypes.add(SOAPConstants.QNAME_TYPE_STRING);
134: _validTypes.add(SOAPConstants.QNAME_TYPE_NORMALIZED_STRING);
135: _validTypes.add(SOAPConstants.QNAME_TYPE_TOKEN);
136: _validTypes.add(SOAPConstants.QNAME_TYPE_BYTE);
137: _validTypes.add(SOAPConstants.QNAME_TYPE_UNSIGNED_BYTE);
138: _validTypes.add(SOAPConstants.QNAME_TYPE_BASE64_BINARY);
139: _validTypes.add(SOAPConstants.QNAME_TYPE_HEX_BINARY);
140: _validTypes.add(SOAPConstants.QNAME_TYPE_INTEGER);
141: _validTypes.add(SOAPConstants.QNAME_TYPE_POSITIVE_INTEGER);
142: _validTypes.add(SOAPConstants.QNAME_TYPE_NEGATIVE_INTEGER);
143: _validTypes.add(SOAPConstants.QNAME_TYPE_NON_NEGATIVE_INTEGER);
144: _validTypes.add(SOAPConstants.QNAME_TYPE_NON_POSITIVE_INTEGER);
145: _validTypes.add(SOAPConstants.QNAME_TYPE_INT);
146: _validTypes.add(SOAPConstants.QNAME_TYPE_UNSIGNED_INT);
147: _validTypes.add(SOAPConstants.QNAME_TYPE_LONG);
148: _validTypes.add(SOAPConstants.QNAME_TYPE_UNSIGNED_LONG);
149: _validTypes.add(SOAPConstants.QNAME_TYPE_SHORT);
150: _validTypes.add(SOAPConstants.QNAME_TYPE_UNSIGNED_SHORT);
151: _validTypes.add(SOAPConstants.QNAME_TYPE_DECIMAL);
152: _validTypes.add(SOAPConstants.QNAME_TYPE_FLOAT);
153: _validTypes.add(SOAPConstants.QNAME_TYPE_DOUBLE);
154: _validTypes.add(SOAPConstants.QNAME_TYPE_BOOLEAN);
155: _validTypes.add(SOAPConstants.QNAME_TYPE_TIME);
156: _validTypes.add(SOAPConstants.QNAME_TYPE_DATE_TIME);
157: _validTypes.add(SOAPConstants.QNAME_TYPE_DURATION);
158: _validTypes.add(SOAPConstants.QNAME_TYPE_DATE);
159: _validTypes.add(SOAPConstants.QNAME_TYPE_G_MONTH);
160: _validTypes.add(SOAPConstants.QNAME_TYPE_G_YEAR);
161: _validTypes.add(SOAPConstants.QNAME_TYPE_G_YEAR_MONTH);
162: _validTypes.add(SOAPConstants.QNAME_TYPE_G_DAY);
163: _validTypes.add(SOAPConstants.QNAME_TYPE_G_MONTH_DAY);
164: _validTypes.add(SOAPConstants.QNAME_TYPE_NAME);
165: _validTypes.add(SOAPConstants.QNAME_TYPE_QNAME);
166: _validTypes.add(SOAPConstants.QNAME_TYPE_NCNAME);
167: _validTypes.add(SOAPConstants.QNAME_TYPE_ANY_URI);
168: _validTypes.add(SOAPConstants.QNAME_TYPE_ID);
169: _validTypes.add(SOAPConstants.QNAME_TYPE_IDREF);
170: _validTypes.add(SOAPConstants.QNAME_TYPE_IDREFS);
171: _validTypes.add(SOAPConstants.QNAME_TYPE_ENTITY);
172: _validTypes.add(SOAPConstants.QNAME_TYPE_ENTITIES);
173: _validTypes.add(SOAPConstants.QNAME_TYPE_NOTATION);
174: _validTypes.add(SOAPConstants.QNAME_TYPE_NMTOKEN);
175: _validTypes.add(SOAPConstants.QNAME_TYPE_NMTOKENS);
176: _validTypes.add(SOAPConstants.QNAME_TYPE_BASE64);
177: // New types 12/3/02
178: _validTypes.add(SchemaConstants.QNAME_TYPE_LANGUAGE);
179:
180: // add all SOAP encoding elements
181: _validElements = new HashSet();
182: _validElements.add(SOAPConstants.QNAME_ELEMENT_STRING);
183: _validElements
184: .add(SOAPConstants.QNAME_ELEMENT_NORMALIZED_STRING);
185: _validElements.add(SOAPConstants.QNAME_ELEMENT_TOKEN);
186: _validElements.add(SOAPConstants.QNAME_ELEMENT_BYTE);
187: _validElements.add(SOAPConstants.QNAME_ELEMENT_UNSIGNED_BYTE);
188: _validElements.add(SOAPConstants.QNAME_ELEMENT_BASE64_BINARY);
189: _validElements.add(SOAPConstants.QNAME_ELEMENT_HEX_BINARY);
190: _validElements.add(SOAPConstants.QNAME_ELEMENT_INTEGER);
191: _validElements
192: .add(SOAPConstants.QNAME_ELEMENT_POSITIVE_INTEGER);
193: _validElements
194: .add(SOAPConstants.QNAME_ELEMENT_NEGATIVE_INTEGER);
195: _validElements
196: .add(SOAPConstants.QNAME_ELEMENT_NON_NEGATIVE_INTEGER);
197: _validElements
198: .add(SOAPConstants.QNAME_ELEMENT_NON_POSITIVE_INTEGER);
199: _validElements.add(SOAPConstants.QNAME_ELEMENT_INT);
200: _validElements.add(SOAPConstants.QNAME_ELEMENT_UNSIGNED_INT);
201: _validElements.add(SOAPConstants.QNAME_ELEMENT_LONG);
202: _validElements.add(SOAPConstants.QNAME_ELEMENT_UNSIGNED_LONG);
203: _validElements.add(SOAPConstants.QNAME_ELEMENT_SHORT);
204: _validElements.add(SOAPConstants.QNAME_ELEMENT_UNSIGNED_SHORT);
205: _validElements.add(SOAPConstants.QNAME_ELEMENT_DECIMAL);
206: _validElements.add(SOAPConstants.QNAME_ELEMENT_FLOAT);
207: _validElements.add(SOAPConstants.QNAME_ELEMENT_DOUBLE);
208: _validElements.add(SOAPConstants.QNAME_ELEMENT_BOOLEAN);
209: _validElements.add(SOAPConstants.QNAME_ELEMENT_TIME);
210: _validElements.add(SOAPConstants.QNAME_ELEMENT_DATE_TIME);
211: _validElements.add(SOAPConstants.QNAME_ELEMENT_DURATION);
212: _validElements.add(SOAPConstants.QNAME_ELEMENT_DATE);
213: _validElements.add(SOAPConstants.QNAME_ELEMENT_G_MONTH);
214: _validElements.add(SOAPConstants.QNAME_ELEMENT_G_YEAR);
215: _validElements.add(SOAPConstants.QNAME_ELEMENT_G_YEAR_MONTH);
216: _validElements.add(SOAPConstants.QNAME_ELEMENT_G_DAY);
217: _validElements.add(SOAPConstants.QNAME_ELEMENT_G_MONTH_DAY);
218: _validElements.add(SOAPConstants.QNAME_ELEMENT_NAME);
219: _validElements.add(SOAPConstants.QNAME_ELEMENT_QNAME);
220: _validElements.add(SOAPConstants.QNAME_ELEMENT_NCNAME);
221: _validElements.add(SOAPConstants.QNAME_ELEMENT_ANY_URI);
222: _validElements.add(SOAPConstants.QNAME_ELEMENT_ID);
223: _validElements.add(SOAPConstants.QNAME_ELEMENT_IDREF);
224: _validElements.add(SOAPConstants.QNAME_ELEMENT_IDREFS);
225: _validElements.add(SOAPConstants.QNAME_ELEMENT_ENTITY);
226: _validElements.add(SOAPConstants.QNAME_ELEMENT_ENTITIES);
227: _validElements.add(SOAPConstants.QNAME_ELEMENT_NOTATION);
228: _validElements.add(SOAPConstants.QNAME_ELEMENT_NMTOKEN);
229: _validElements.add(SOAPConstants.QNAME_ELEMENT_NMTOKENS);
230:
231: _validAttributes = new HashSet();
232: _validAttributes.add(SOAPConstants.QNAME_ATTR_ARRAY_TYPE);
233: _validAttributes.add(SOAPConstants.QNAME_ATTR_OFFSET);
234: _validAttributes.add(SOAPConstants.QNAME_ATTR_POSITION);
235: }
236: }
|