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.dom;
 
 
 
 import nu.xom.Builder;
 import nu.xom.Element;
Implementation of MethodArgumentResolver and MethodReturnValueHandler that supports XOM elements.

Author(s):
Arjen Poutsma
Since:
2.0
 
 
 
     @Override
     protected boolean supportsRequestPayloadParameter(MethodParameter parameter) {
         return supports(parameter);
     }
 
     @Override
     protected Element resolveRequestPayloadArgument(MethodParameter parameterSource requestPayload)
             throws TransformerExceptionIOExceptionParsingException {
         if (requestPayload instanceof DOMSource) {
             org.w3c.dom.Node node = ((DOMSourcerequestPayload).getNode();
             if (node.getNodeType() == ....) {
                 return DOMConverter.convert((org.w3c.dom.Elementnode);
             }
             else if (node.getNodeType() == ....) {
                 Document document = DOMConverter.convert((org.w3c.dom.Documentnode);
                 return document.getRootElement();
             }
         }
         // we have no other option than to transform
         ByteArrayInputStream bis = convertToByteArrayInputStream(requestPayload);
         Builder builder = new Builder();
         Document document = builder.build(bis);
         return document.getRootElement();
     }
 
     @Override
     protected boolean supportsResponsePayloadReturnType(MethodParameter returnType) {
         return supports(returnType);
     }
 
     @Override
     protected Source createResponsePayload(MethodParameter returnTypeObject returnValue)
             throws ParserConfigurationException {
         Element returnedElement = (ElementreturnValue;
         Document document = returnedElement.getDocument();
         if (document == null) {
             document = new Document(returnedElement);
         }
         DocumentBuilder documentBuilder = .newDocumentBuilder();
         DOMImplementation domImplementation = documentBuilder.getDOMImplementation();
         org.w3c.dom.Document w3cDocument = DOMConverter.convert(documentdomImplementation);
         return new DOMSource(w3cDocument);
     }
 
     private boolean supports(MethodParameter parameter) {
         return Element.class.equals(parameter.getParameterType());
     }

    
Create a DocumentBuilderFactory that this resolver will use to create response payloads.

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
        return DocumentBuilderFactory.newInstance();
    }
New to GrepCode? Check out our FAQ X