src/share/jaxws_classes/com/sun/xml/internal/ws/wsdl/parser/MexEntityResolver.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
equal deleted inserted replaced
-1:000000000000 0:373ffda63c9a
1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.xml.internal.ws.wsdl.parser;
27
28 import com.sun.xml.internal.stream.buffer.XMLStreamBufferResult;
29 import com.sun.xml.internal.ws.api.server.SDDocumentSource;
30 import com.sun.xml.internal.ws.api.wsdl.parser.XMLEntityResolver;
31 import com.sun.xml.internal.ws.util.JAXWSUtils;
32 import com.sun.xml.internal.ws.util.xml.XmlUtil;
33 import org.xml.sax.SAXException;
34
35 import javax.xml.stream.XMLStreamException;
36 import javax.xml.transform.Source;
37 import javax.xml.transform.Transformer;
38 import javax.xml.transform.TransformerException;
39 import javax.xml.ws.WebServiceException;
40 import java.io.IOException;
41 import java.util.HashMap;
42 import java.util.List;
43 import java.util.Map;
44
45 /**
46 * Entity resolver that works on MEX Metadata
47 *
48 * @author Vivek Pandey
49 */
50 public final class MexEntityResolver implements XMLEntityResolver {
51 private final Map<String, SDDocumentSource> wsdls = new HashMap<String, SDDocumentSource>();
52
53 public MexEntityResolver(List<? extends Source> wsdls) throws IOException {
54 Transformer transformer = XmlUtil.newTransformer();
55 for (Source source : wsdls) {
56 XMLStreamBufferResult xsbr = new XMLStreamBufferResult();
57 try {
58 transformer.transform(source, xsbr);
59 } catch (TransformerException e) {
60 throw new WebServiceException(e);
61 }
62 String systemId = source.getSystemId();
63
64 //TODO: can we do anything if the given mex Source has no systemId?
65 if(systemId != null){
66 SDDocumentSource doc = SDDocumentSource.create(JAXWSUtils.getFileOrURL(systemId), xsbr.getXMLStreamBuffer());
67 this.wsdls.put(systemId, doc);
68 }
69 }
70 }
71
72 public Parser resolveEntity(String publicId, String systemId) throws SAXException, IOException, XMLStreamException {
73 if (systemId != null) {
74 SDDocumentSource src = wsdls.get(systemId);
75 if (src != null)
76 return new Parser(src);
77 }
78 return null;
79 }
80 }

mercurial