下面列出了javax.xml.bind.Unmarshaller#setAttachmentUnmarshaller ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
if(hasAttachments())
unmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerImpl(getAttachments()));
try {
return (T)unmarshaller.unmarshal(payload);
} finally{
unmarshaller.setAttachmentUnmarshaller(null);
}
}
private Unmarshaller getUnMarshaller() throws JAXBException {
AttachmentUnmarshallerImpl attachmentUnmarshaller = new AttachmentUnmarshallerImpl(true);
attachmentUnmarshaller.getAttachmentPartMap().putAll(this.attachmentParts);
Unmarshaller unmarshaller = JaxbContextFactory.getJaxbContextForClass(this.unmarshallClass).createUnmarshaller();
unmarshaller.setAttachmentUnmarshaller(attachmentUnmarshaller);
return unmarshaller;
}
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
access();
if (payload != null) {
if(hasAttachments())
unmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerImpl(getAttachments()));
return (T) unmarshaller.unmarshal(payload);
}
return null;
}
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
access();
if (payload != null) {
if(hasAttachments())
unmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerImpl(getAttachments()));
return (T) unmarshaller.unmarshal(payload);
}
return null;
}
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
if(hasAttachments())
unmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerImpl(getAttachments()));
try {
return (T)unmarshaller.unmarshal(payload);
} finally{
unmarshaller.setAttachmentUnmarshaller(null);
}
}
/**
* @since 2.0.3
*/
public final @NotNull T unmarshal(@NotNull Node n, @Nullable AttachmentUnmarshaller au) throws JAXBException {
Unmarshaller u = context.unmarshallerPool.take();
u.setAttachmentUnmarshaller(au);
return exit(unmarshal(u,n),u);
}
/**
* @since 2.0.3
*/
public final @NotNull T unmarshal(@NotNull Source in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
Unmarshaller u = context.unmarshallerPool.take();
u.setAttachmentUnmarshaller(au);
return exit(unmarshal(u,in),u);
}
private T exit(T r, Unmarshaller u) {
u.setAttachmentUnmarshaller(null);
context.unmarshallerPool.recycle(u);
return r;
}
/**
* @since 2.0.3
*/
public final @NotNull T unmarshal(@NotNull XMLStreamReader in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
Unmarshaller u = context.unmarshallerPool.take();
u.setAttachmentUnmarshaller(au);
return exit(unmarshal(u,in),u);
}
/**
* @since 2.0.3
*/
public final @NotNull T unmarshal(@NotNull Node n, @Nullable AttachmentUnmarshaller au) throws JAXBException {
Unmarshaller u = context.unmarshallerPool.take();
u.setAttachmentUnmarshaller(au);
return exit(unmarshal(u,n),u);
}
/**
* @since 2.0.3
*/
public final @NotNull T unmarshal(@NotNull Node n, @Nullable AttachmentUnmarshaller au) throws JAXBException {
Unmarshaller u = context.unmarshallerPool.take();
u.setAttachmentUnmarshaller(au);
return exit(unmarshal(u,n),u);
}
/**
* @since 2.0.3
*/
public final @NotNull T unmarshal(@NotNull Source in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
Unmarshaller u = context.unmarshallerPool.take();
u.setAttachmentUnmarshaller(au);
return exit(unmarshal(u,in),u);
}
/**
* @since 2.0.3
*/
public final @NotNull T unmarshal(@NotNull Node n, @Nullable AttachmentUnmarshaller au) throws JAXBException {
Unmarshaller u = context.unmarshallerPool.take();
u.setAttachmentUnmarshaller(au);
return exit(unmarshal(u,n),u);
}
/**
* @since 2.0.3
*/
public final @NotNull T unmarshal(@NotNull XMLStreamReader in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
Unmarshaller u = context.unmarshallerPool.take();
u.setAttachmentUnmarshaller(au);
return exit(unmarshal(u,in),u);
}
/**
* @since 2.0.3
*/
public final @NotNull T unmarshal(@NotNull Node n, @Nullable AttachmentUnmarshaller au) throws JAXBException {
Unmarshaller u = context.unmarshallerPool.take();
u.setAttachmentUnmarshaller(au);
return exit(unmarshal(u,n),u);
}
private T exit(T r, Unmarshaller u) {
u.setAttachmentUnmarshaller(null);
context.unmarshallerPool.recycle(u);
return r;
}
/**
* @since 2.0.3
*/
public final @NotNull T unmarshal(@NotNull XMLStreamReader in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
Unmarshaller u = context.unmarshallerPool.take();
u.setAttachmentUnmarshaller(au);
return exit(unmarshal(u,in),u);
}
/**
* @since 2.0.3
*/
public final @NotNull T unmarshal(@NotNull XMLStreamReader in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
Unmarshaller u = context.unmarshallerPool.take();
u.setAttachmentUnmarshaller(au);
return exit(unmarshal(u,in),u);
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void invokeInternal(final XTeeMessage<Document> request, final XTeeMessage<Element> response)
throws Exception {
if (getParingKehaClass() == null) {
throw new IllegalStateException("Query body class ('requestClass') is unset/unspecified!");
}
JAXBContext requestJc = getJAXBContextInstance();
Unmarshaller requestUnmarshaller = requestJc.createUnmarshaller();
requestUnmarshaller.setAttachmentUnmarshaller(new XTeeAttachmentUnmarshaller(request));
updateUnmarshaller(requestUnmarshaller);
Document requestOnly = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
if (XRoadProtocolVersion.V2_0 == version) {
requestOnly.appendChild(requestOnly.importNode((Node) XPathFactory.newInstance().newXPath().evaluate("//*[local-name()='keha']",
request.getContent(),
XPathConstants.NODE),
true));
} else {
requestOnly.appendChild(requestOnly.importNode(SOAPUtil.getFirstNonTextChild(request.getContent()), true));
}
XTeeMessage<T> jaxbRequestMessage = new BeanXTeeMessage<T>(request.getHeader(),
requestUnmarshaller.unmarshal(requestOnly.getDocumentElement(),
getParingKehaClass()).getValue(),
request.getAttachments());
XTeeMessage<Object> jaxbResponseMessage =
new BeanXTeeMessage<Object>(response.getHeader(), null, new ArrayList<XTeeAttachment>());
invoke(jaxbRequestMessage, jaxbResponseMessage);
Object bean = jaxbResponseMessage.getContent();
if (bean != null) { // If you do not need to send an object as response, <keha /> is sufficient.
Node parent = response.getContent().getParentNode();
Node child = parent.removeChild(response.getContent());
JAXBContext responseJc = getJAXBContextInstance();
Marshaller responseMarshaller = responseJc.createMarshaller();
responseMarshaller.setAttachmentMarshaller(new XTeeAttachmentMarshaller(response));
updateMarshaller(responseMarshaller);
// TODO Lauri: some namespace hacking might be needed if existing service schema is changed according to new
// standard while upgrading. J-road clients do not mind tho :)
if (XRoadProtocolVersion.V2_0 == version) {
responseMarshaller.marshal(new JAXBElement(new QName("keha"), bean.getClass(), bean), parent);
} else {
responseMarshaller.marshal(new JAXBElement(new QName(response.getContent().getNamespaceURI(),
child.getLocalName(),
response.getContent().getPrefix()),
bean.getClass(),
bean),
parent);
}
}
}
/**
* @since 2.0.3
*/
public final @NotNull T unmarshal(@NotNull Source in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
Unmarshaller u = context.unmarshallerPool.take();
u.setAttachmentUnmarshaller(au);
return exit(unmarshal(u,in),u);
}