Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2005-2010 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.springframework.ws.server.endpoint.adapter.method;
 
 
 
Implementation of MethodArgumentResolver and MethodReturnValueHandler that supports javax.xml.transform.Source objects.

Author(s):
Arjen Poutsma
Since:
2.0
 
 
 
     // MethodArgumentResolver
 
     @Override
     protected boolean supportsRequestPayloadParameter(MethodParameter parameter) {
         return supports(parameter);
     }
 
     @Override
     protected Source resolveRequestPayloadArgument(MethodParameter parameterSource requestPayloadthrows Exception {
         Class<?> parameterType = parameter.getParameterType();
         if (parameterType.isAssignableFrom(requestPayload.getClass())) {
             return requestPayload;
         }
         if (DOMSource.class.isAssignableFrom(parameterType)) {
             DOMResult domResult = new DOMResult();
             transform(requestPayloaddomResult);
             Node node = domResult.getNode();
             if (node.getNodeType() == .) {
                 return new DOMSource(((Documentnode).getDocumentElement());
             }
             else {
                 return new DOMSource(domResult.getNode());
             }
         }
         else if (SAXSource.class.isAssignableFrom(parameterType)) {
             ByteArrayInputStream bis = convertToByteArrayInputStream(requestPayload);
             InputSource inputSource = new InputSource(bis);
             return new SAXSource(inputSource);
         }
         else if (StreamSource.class.isAssignableFrom(parameterType)) {
             ByteArrayInputStream bis = convertToByteArrayInputStream(requestPayload);
             return new StreamSource(bis);
         }
         else if (JaxpVersion.isAtLeastJaxp14() && Jaxp14StaxHandler.isStaxSource(parameterType)) {
             XMLStreamReader streamReader;
             try {
                 streamReader = .createXMLStreamReader(requestPayload);
             } catch (UnsupportedOperationException ignored) {
                 streamReader = null;
             }
             catch (XMLStreamException ignored) {
                 streamReader = null;
             }
             if (streamReader == null) {
                 ByteArrayInputStream bis = convertToByteArrayInputStream(requestPayload);
                 streamReader = .createXMLStreamReader(bis);
             }
             return Jaxp14StaxHandler.createStaxSource(streamReaderrequestPayload.getSystemId());
         }
         throw new IllegalArgumentException("Unknown Source type: " + parameterType);
    }
    // MethodReturnValueHandler
    @Override
    protected boolean supportsResponsePayloadReturnType(MethodParameter returnType) {
        return supports(returnType);
    }
    @Override
    protected Source createResponsePayload(MethodParameter returnTypeObject returnValue) {
        return (SourcereturnValue;
    }
    private boolean supports(MethodParameter parameter) {
        return Source.class.isAssignableFrom(parameter.getParameterType());
    }

    
Create a XMLInputFactory that this resolver will use to create javax.xml.stream.XMLStreamReader and javax.xml.stream.XMLEventReader objects.

Can be overridden in subclasses, adding further initialization of the factory. The resulting factory is cached, so this method will only be called once.

Returns:
the created factory
    protected XMLInputFactory createXmlInputFactory() {
        return XMLInputFactory.newInstance();
    }

    
Inner class to avoid a static JAXP 1.4 dependency.
    private static class Jaxp14StaxHandler {
        private static boolean isStaxSource(Class<?> clazz) {
            return StAXSource.class.isAssignableFrom(clazz);
        }
        private static Source createStaxSource(XMLStreamReader streamReaderString systemId) {
            return new StAXSource(new SystemIdStreamReaderDelegate(streamReadersystemId));
        }
    }
    private static class SystemIdStreamReaderDelegate extends StreamReaderDelegate {
        private final String systemId;
        private SystemIdStreamReaderDelegate(XMLStreamReader readerString systemId) {
            super(reader);
            this. = systemId;
        }
        @Override
        public Location getLocation() {
            final Location parentLocation = getParent().getLocation();
            return new Location() {
                public int getLineNumber() {
                    return parentLocation != null ? parentLocation.getLineNumber() : -1;
                }
                public int getColumnNumber() {
                    return parentLocation != null ? parentLocation.getColumnNumber() : -1;
                }
                public int getCharacterOffset() {
                    return parentLocation != null ? parentLocation.getLineNumber() : -1;
                }
                public String getPublicId() {
                    return parentLocation != null ? parentLocation.getPublicId() : null;
                }
                public String getSystemId() {
                    return ;
                }
            };
        }
    }
New to GrepCode? Check out our FAQ X