use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.
the class FaultDetailHeader method readHeader.
public XMLStreamReader readHeader() throws XMLStreamException {
MutableXMLStreamBuffer buf = new MutableXMLStreamBuffer();
XMLStreamWriter w = buf.createFromXMLStreamWriter();
writeTo(w);
return buf.readAsXMLStreamReader();
}
use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.
the class EndpointFactory method findMetadataClosure.
/**
* Goes through the original metadata documents and collects the required ones.
* This done traversing from primary WSDL and its imports until it builds a
* complete set of documents(transitive closure) for the endpoint.
*
* @param primaryDoc primary WSDL doc
* @param docList complete metadata
* @return new metadata that doesn't contain extraneous documents.
*/
private static Collection<SDDocumentImpl> findMetadataClosure(final SDDocumentImpl primaryDoc, final Collection<SDDocumentImpl> docList, final EntityResolver resolver) {
return new AbstractCollection<>() {
@Override
public Iterator<SDDocumentImpl> iterator() {
// create a map for old metadata
Map<String, SDDocumentImpl> oldMap = new HashMap<>();
Iterator<SDDocumentImpl> oldDocs = docList.iterator();
// create a map for new metadata
Map<String, SDDocumentImpl> newMap = new HashMap<>();
newMap.put(primaryDoc.getSystemId().toString(), primaryDoc);
List<String> remaining = new ArrayList<String>(primaryDoc.getImports());
while (!remaining.isEmpty()) {
String url = remaining.remove(0);
SDDocumentImpl doc = oldMap.get(url);
if (doc == null) {
while (oldDocs.hasNext()) {
SDDocumentImpl old = oldDocs.next();
String id = old.getSystemId().toString();
oldMap.put(id, old);
if (id.equals(url)) {
doc = old;
break;
}
}
if (doc == null) {
// old metadata doesn't have this imported doc, may be external
if (resolver != null) {
try {
InputSource source = resolver.resolveEntity(null, url);
if (source != null) {
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
XMLStreamReader reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(source.getByteStream());
xsb.createFromXMLStreamReader(reader);
SDDocumentSource sdocSource = SDDocumentImpl.create(new URL(url), xsb);
doc = SDDocumentImpl.create(sdocSource, null, null);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
// Check if new metadata already contains this doc
if (doc != null && !newMap.containsKey(url)) {
newMap.put(url, doc);
remaining.addAll(doc.getImports());
}
}
return newMap.values().iterator();
}
@Override
public int size() {
int size = 0;
Iterator<SDDocumentImpl> it = iterator();
while (it.hasNext()) {
it.next();
size++;
}
return size;
}
@Override
public void clear() {
throw new UnsupportedOperationException();
}
@Override
public boolean isEmpty() {
return docList.isEmpty();
}
};
}
use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.
the class WSDLGenResolver method getWSDL.
/**
* Generates the concrete WSDL that contains service element.
*
* @return Result the generated concrete WSDL
*/
public Result getWSDL(String filename) {
URL url = createURL(filename);
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
xsb.setSystemId(url.toExternalForm());
concreteWsdlSource = SDDocumentSource.create(url, xsb);
newDocs.add(concreteWsdlSource);
XMLStreamBufferResult r = new XMLStreamBufferResult(xsb);
r.setSystemId(filename);
return r;
}
use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.
the class WSDLGenResolver method getSchemaOutput.
/**
* Updates filename if the suggested filename need to be changed in
* xsd:import. If there is already a schema document for the namespace
* in the metadata, then it is not generated.
*
* return null if schema need not be generated
* Result the generated schema document
*/
public Result getSchemaOutput(String namespace, Holder<String> filename) {
List<SDDocumentImpl> schemas = nsMapping.get(namespace);
if (schemas != null) {
if (schemas.size() > 1) {
throw new ServerRtException("server.rt.err", "More than one schema for the target namespace " + namespace);
}
filename.value = schemas.get(0).getURL().toExternalForm();
// Don't generate schema
return null;
}
URL url = createURL(filename.value);
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
xsb.setSystemId(url.toExternalForm());
SDDocumentSource sd = SDDocumentSource.create(url, xsb);
newDocs.add(sd);
XMLStreamBufferResult r = new XMLStreamBufferResult(xsb);
r.setSystemId(filename.value);
return r;
}
use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer in project metro-jax-ws by eclipse-ee4j.
the class JAXBMessage method readPayload.
@Override
public XMLStreamReader readPayload() throws XMLStreamException {
try {
if (infoset == null) {
if (rawContext != null) {
XMLStreamBufferResult sbr = new XMLStreamBufferResult();
Marshaller m = rawContext.createMarshaller();
m.setProperty("jaxb.fragment", Boolean.TRUE);
m.marshal(jaxbObject, sbr);
infoset = sbr.getXMLStreamBuffer();
} else {
MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
writePayloadTo(buffer.createFromXMLStreamWriter());
infoset = buffer;
}
}
XMLStreamReader reader = infoset.readAsXMLStreamReader();
if (reader.getEventType() == XMLStreamConstants.START_DOCUMENT)
XMLStreamReaderUtil.nextElementContent(reader);
return reader;
} catch (JAXBException e) {
// bug 6449684, spec 4.3.4
throw new WebServiceException(e);
}
}
Aggregations