com.sun.xml.ws.wsdl.parser.MexEntityResolver Maven / Gradle / Ivy
/*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the license at
* https://glassfish.dev.java.net/public/CDDLv1.0.html.
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at https://glassfish.dev.java.net/public/CDDLv1.0.html.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* you own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* Copyright 2006 Sun Microsystems Inc. All Rights Reserved
*/
package com.sun.xml.ws.wsdl.parser;
import com.sun.xml.stream.buffer.XMLStreamBufferResult;
import com.sun.xml.ws.api.server.SDDocumentSource;
import com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver;
import com.sun.xml.ws.util.JAXWSUtils;
import com.sun.xml.ws.util.xml.XmlUtil;
import org.xml.sax.SAXException;
import javax.xml.stream.XMLStreamException;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.ws.WebServiceException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Entity resolver that works on MEX Metadata
*
* @author Vivek Pandey
*/
public final class MexEntityResolver implements XMLEntityResolver {
private final Map wsdls = new HashMap();
public MexEntityResolver(List wsdls) throws IOException {
Transformer transformer = XmlUtil.newTransformer();
for (Source source : wsdls) {
XMLStreamBufferResult xsbr = new XMLStreamBufferResult();
try {
transformer.transform(source, xsbr);
} catch (TransformerException e) {
throw new WebServiceException(e);
}
String systemId = source.getSystemId();
//TODO: can we do anything if the given mex Source has no systemId?
if(systemId != null){
SDDocumentSource doc = SDDocumentSource.create(JAXWSUtils.getFileOrURL(systemId), xsbr.getXMLStreamBuffer());
this.wsdls.put(systemId, doc);
}
}
}
public Parser resolveEntity(String publicId, String systemId) throws SAXException, IOException, XMLStreamException {
if (systemId != null) {
SDDocumentSource src = wsdls.get(systemId);
if (src != null)
return new Parser(src);
}
return null;
}
}