@Override protected void populateUserDefinedHeader(String headerName, Object headerValue, SoapMessage target) { SoapHeader soapHeader = target.getSoapHeader(); if (headerValue instanceof String) { QName qname = QNameUtils.parseQNameString(headerName); soapHeader.addAttribute(qname, (String) headerValue); } else if (headerValue instanceof Source) { Result result = soapHeader.getResult(); try { this.transformerHelper.transform((Source) headerValue, result); } catch (TransformerException e) { throw new SoapHeaderException( "Could not transform source [" + headerValue + "] to result [" + result + "]", e); } } }
/** * Transforms the given {@link Source} to the given {@link Result}. Creates a new {@link Transformer} for every * call, as transformers are not thread-safe. * * @param source the source to transform from * @param result the result to transform to * @throws TransformerException if thrown by JAXP methods */ protected final void transform(Source source, Result result) throws TransformerException { Transformer transformer = createTransformer(); transformer.transform(source, result); }
/** * Does transofrmation. * @param source * @param result */ public static void transform(Source source, Result result) { try { new TransformerHelper().transform(source, result); } catch (TransformerException e) { throw new IllegalArgumentException("Can not transform",e); } }
/** * Creates a new {@code Transformer}. Must be called per request, as transformers are not thread-safe. * * @return the created transformer * @throws TransformerConfigurationException * if thrown by JAXP methods */ protected final Transformer createTransformer() throws TransformerConfigurationException { return transformerHelper.createTransformer(); }
/** * Returns the root qualified name of the given source, transforming it if necessary. * * @param source the source to get the root element from * @param transformerFactory a transformer factory, necessary if the given source is not a {@code DOMSource} * @return the root element, or {@code null} if {@code source} is {@code null} */ public static QName getPayloadRootQName(Source source, TransformerFactory transformerFactory) throws TransformerException { return getPayloadRootQName(source, new TransformerHelper(transformerFactory)); }
/** * Returns the {@code TransformerFactory}. */ protected TransformerFactory getTransformerFactory() { return transformerHelper.getTransformerFactory(); }
/** Returns the <code>TransformerFactory</code>. */ protected TransformerFactory getTransformerFactory() { if (transformerFactory == null) { transformerFactory = newTransformerFactory(transformerFactoryClass); } return transformerFactory; }
/** * Initializes a new instance of the {@code TransformerHelper} with the specified {@link TransformerFactory} class. */ public TransformerHelper(Class<? extends TransformerFactory> transformerFactoryClass) { setTransformerFactoryClass(transformerFactoryClass); }
/** * Creates a new {@code Transformer}. Must be called per request, as transformers are not thread-safe. * * @return the created transformer * @throws TransformerConfigurationException * if thrown by JAXP methods */ protected final Transformer createTransformer() throws TransformerConfigurationException { return transformerHelper.createTransformer(); }
/** * Returns the root qualified name of the given source, transforming it if necessary. * * @param source the source to get the root element from * @param transformerFactory a transformer factory, necessary if the given source is not a <code>DOMSource</code> * @return the root element, or <code>null</code> if <code>source</code> is <code>null</code> */ public static QName getPayloadRootQName(Source source, TransformerFactory transformerFactory) throws TransformerException { return getPayloadRootQName(source, new TransformerHelper(transformerFactory)); }
/** * Creates a new <code>Transformer</code>. Must be called per request, as transformers are not thread-safe. * * @return the created transformer * @throws TransformerConfigurationException * if thrown by JAXP methods */ protected final Transformer createTransformer() throws TransformerConfigurationException { return getTransformerFactory().newTransformer(); }
/** * Instantiate a new TransformerFactory. <p>The default implementation simply calls {@link * TransformerFactory#newInstance()}. If a {@link #setTransformerFactoryClass "transformerFactoryClass"} has been * specified explicitly, the default constructor of the specified class will be called instead. <p>Can be overridden * in subclasses. * * @param transformerFactoryClass the specified factory class (if any) * @return the new TransactionFactory instance * @see #setTransformerFactoryClass * @see #getTransformerFactory() */ protected TransformerFactory newTransformerFactory(Class<? extends TransformerFactory> transformerFactoryClass) { return transformerHelper.newTransformerFactory(transformerFactoryClass); }
/** * Specify the {@code TransformerFactory} class to use. */ public void setTransformerFactoryClass(Class<? extends TransformerFactory> transformerFactoryClass) { transformerHelper.setTransformerFactoryClass(transformerFactoryClass); }
/** * Transforms the given {@link Source} to the given {@link Result}. Creates a new {@link Transformer} for every * call, as transformers are not thread-safe. * * @param source the source to transform from * @param result the result to transform to * @throws TransformerException if thrown by JAXP methods */ protected final void transform(Source source, Result result) throws TransformerException { transformerHelper.transform(source, result); }
/** * Transforms the given {@link Source} to the given {@link Result}. Creates a new {@link Transformer} for every * call, as transformers are not thread-safe. * * @param source the source to transform from * @param result the result to transform to * @throws TransformerException if thrown by JAXP methods */ public void transform(Source source, Result result) throws TransformerException { Transformer transformer = createTransformer(); transformer.transform(source, result); }
/** * Returns the root qualified name of the given source, transforming it if necessary. * * @param source the source to get the root element from * @param transformerFactory a transformer factory, necessary if the given source is not a {@code DOMSource} * @return the root element, or {@code null} if {@code source} is {@code null} */ public static QName getPayloadRootQName(Source source, TransformerFactory transformerFactory) throws TransformerException { return getPayloadRootQName(source, new TransformerHelper(transformerFactory)); }
/** * Returns the {@code TransformerFactory}. */ protected TransformerFactory getTransformerFactory() { return transformerHelper.getTransformerFactory(); }
/** * Instantiate a new TransformerFactory. <p>The default implementation simply calls {@link * TransformerFactory#newInstance()}. If a {@link #setTransformerFactoryClass "transformerFactoryClass"} has been * specified explicitly, the default constructor of the specified class will be called instead. <p>Can be overridden * in subclasses. * * @param transformerFactoryClass the specified factory class (if any) * @return the new TransactionFactory instance * @see #setTransformerFactoryClass * @see #getTransformerFactory() */ protected TransformerFactory newTransformerFactory(Class<? extends TransformerFactory> transformerFactoryClass) { return transformerHelper.newTransformerFactory(transformerFactoryClass); }
/** * Initializes a new instance of the {@code TransformerHelper} with the specified {@link TransformerFactory} class. */ public TransformerHelper(Class<? extends TransformerFactory> transformerFactoryClass) { setTransformerFactoryClass(transformerFactoryClass); }
/** * Transforms the given {@link Source} to the given {@link Result}. Creates a new {@link Transformer} for every * call, as transformers are not thread-safe. * * @param source the source to transform from * @param result the result to transform to * @throws TransformerException if thrown by JAXP methods */ protected final void transform(Source source, Result result) throws TransformerException { transformerHelper.transform(source, result); }