001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *        http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 */
019package org.apache.isis.viewer.restfulobjects.rendering;
020
021import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
022
023public class ReprRendererException extends RuntimeException {
024
025    public static ReprRendererException create(final String message, final Object... args) {
026        return create((Exception) null, message, args);
027    }
028
029    public static ReprRendererException create(final Exception cause) {
030        return create(cause, null);
031    }
032
033    public static ReprRendererException create(final Exception cause, final String message, final Object... args) {
034        return new ReprRendererException(formatString(message, args), cause, null);
035    }
036
037    public static ReprRendererException create(final JsonRepresentation repr, final String message, final Object... args) {
038        return new ReprRendererException(formatString(message, args), null, repr);
039    }
040
041    private static String formatString(final String formatStr, final Object... args) {
042        return formatStr != null ? String.format(formatStr, args) : null;
043    }
044
045    private static final long serialVersionUID = 1L;
046    private final JsonRepresentation jsonRepresentation;
047
048    private ReprRendererException(final String message, final Throwable ex, final JsonRepresentation jsonRepresentation) {
049        super(message, ex);
050        this.jsonRepresentation = jsonRepresentation;
051    }
052
053    public JsonRepresentation getJsonRepresentation() {
054        return jsonRepresentation;
055    }
056
057}