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;
 
 
 
Abstract base class for endpoints that handle the message payload as dom4j elements. Offers the message payload as a dom4j Element, and allows subclasses to create a response by returning an Element.

An AbstractDom4JPayloadEndpoint only accept one payload element. Multiple payload elements are not in accordance with WS-I.

Deprecated:
as of Spring Web Services 2.0, in favor of annotated endpoints
Author(s):
Arjen Poutsma
Since:
1.0.0
See also:
org.dom4j.Element
 
 public abstract class AbstractDom4jPayloadEndpoint extends TransformerObjectSupport implements PayloadEndpoint {
 
     private boolean alwaysTransform = false;

    
Set if the request javax.xml.transform.Source should always be transformed into a new org.dom4j.io.DocumentResult.

Default is false, which is faster.

 
     public void setAlwaysTransform(boolean alwaysTransform) {
         this. = alwaysTransform;
     }
 
     public final Source invoke(Source requestthrows Exception {
         Element requestElement = null;
         if (request != null) {
             DocumentResult dom4jResult = new DocumentResult();
             transform(requestdom4jResult);
             requestElement = dom4jResult.getDocument().getRootElement();
         }
         Document responseDocument = DocumentHelper.createDocument();
         Element responseElement = invokeInternal(requestElementresponseDocument);
         return responseElement != null ? new DocumentSource(responseElement) : null;
     }

    
Returns the payload element of the given source.

Default implementation checks whether the source is a javax.xml.transform.dom.DOMSource, and uses a org.jdom.input.DOMBuilder to create a JDOM org.jdom.Element. In all other cases, or when alwaysTransform is true, the source is transformed into a org.jdom.transform.JDOMResult, which is more expensive. If the passed source is null, null is returned.

Parameters:
source the source to return the root element of; can be null
Returns:
the document element
Throws:
javax.xml.transform.TransformerException in case of errors
 
     protected Element getDocumentElement(Source sourcethrows TransformerException {
         if (source == null) {
             return null;
         }
         if (! && source instanceof DOMSource) {
             Node node = ((DOMSourcesource).getNode();
             if (node.getNodeType() == .) {
                 DOMReader domReader = new DOMReader();
                 Document document = domReader.read((org.w3c.dom.Documentnode);
                 return document.getRootElement();
             }
         }
         // we have no other option than to transform
         DocumentResult dom4jResult = new DocumentResult();
         transform(sourcedom4jResult);
        return dom4jResult.getDocument().getRootElement();
    }

    
Template method. Subclasses must implement this. Offers the request payload as a dom4j Element, and allows subclasses to return a response Element.

The given dom4j Document is to be used for constructing a response element, by using addElement.

Parameters:
requestElement the contents of the SOAP message as dom4j elements
responseDocument a dom4j document to be used for constructing a response
Returns:
the response element. Can be null to specify no response.
    protected abstract Element invokeInternal(Element requestElementDocument responseDocumentthrows Exception;
New to GrepCode? Check out our FAQ X