net.disy.ogc.ows.v_1_1_0.OwsException Maven / Gradle / Ivy
/**
* Legato is a configurable, lightweight web mapping client that can be
* easily embedded into web pages and portals, CMS and individual web
* applications. Legato is implemented in JavaScript and based on the
* popular open source library OpenLayers.
*
* Copyright (C) 2010 disy Informationssysteme GmbH, http://www.disy.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package net.disy.ogc.ows.v_1_1_0;
import java.io.PrintWriter;
import java.io.StringWriter;
import net.opengis.ows.v_1_1_0.ExceptionReport;
import net.opengis.ows.v_1_1_0.ExceptionType;
import org.apache.commons.lang.Validate;
/*
* OWS exception constructed with the OWS {@link ExceptionReport}.
*/
public class OwsException extends Exception {
private static final long serialVersionUID = 1L;
private final ExceptionReport exceptionReport;
public ExceptionReport getExceptionReport() {
return exceptionReport;
}
/**
* Constructs a new OWS exception.
*
* @param exceptionReport
* exception report returned by the web service.
*/
public OwsException(ExceptionReport exceptionReport) {
Validate.notNull(exceptionReport);
this.exceptionReport = exceptionReport;
}
public OwsException(String code, String text, Throwable ex) {
super(ex);
Validate.notNull(code);
final ExceptionReport newExceptionReport = new ExceptionReport();
newExceptionReport.setVersion("1.1.0"); //$NON-NLS-1$
final ExceptionType exception = new ExceptionType();
exception.setExceptionCode(code);
if (text != null) {
exception.getExceptionText().add(text);
}
if (ex != null) {
exception.getExceptionText().add(toString(ex));
}
newExceptionReport.getException().add(exception);
exceptionReport = newExceptionReport;
}
public OwsException(String code, String text) {
this(code, text, null);
}
public OwsException(String code, Throwable ex) {
this(code, null, ex);
}
private static String toString(Throwable ex) {
final StringWriter sw = new StringWriter();
ex.printStackTrace(new PrintWriter(sw));
return sw.toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy