Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2005-2011 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.test.support;
Subclass of java.lang.AssertionError that also contains a javax.xml.transform.Source for more context.

Author(s):
Lukas Krecan
Arjen Poutsma
Since:
2.0.1
public class SourceAssertionError extends AssertionError {
    private final String sourceLabel;
    private final Source source;
    private final TransformerHelper transformerHelper = new TransformerHelper();

    
Creates a new instance of the SourceAssertionError class with the given parameters.
    public SourceAssertionError(String detailMessageString sourceLabelSource source) {
        super(detailMessage);
        this. = sourceLabel;
        this. = source;
    }

    
Returns the source context of this error.

Returns:
the source
    public Source getSource() {
        return ;
    }
    @Override
    public String getMessage() {
        StringBuilder builder = new StringBuilder();
        builder.append(super.getMessage());
        String sourceString = getSourceString();
        if (sourceString != null) {
            String newLine = System.getProperty("line.separator");
            builder.append(newLine);
            String label =  != null ?  : "Source";
            builder.append(label);
            builder.append(": ");
            builder.append(sourceString);
        }
        return builder.toString();
    }
    private String getSourceString() {
        if ( != null) {
            try {
                StringResult result = new StringResult();
                Transformer transformer = createNonIndentingTransformer();
                transformer.transform(result);
                return result.toString();
            }
            catch (TransformerException ex) {
                // Ignore
            }
        }
        return null;
    }
        Transformer transformer = .createTransformer();
        transformer.setOutputProperty(."yes");
        transformer.setOutputProperty(."no");
        return transformer;
    }
New to GrepCode? Check out our FAQ X