001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel;
018
019/**
020 * Exception when failing to create a {@link org.apache.camel.Route}.
021 *
022 * @version 
023 */
024public class FailedToCreateRouteException extends CamelException {
025    private static final long serialVersionUID = 1L;
026    private final String routeId;
027
028    public FailedToCreateRouteException(String routeId, String route, Throwable cause) {
029        super("Failed to create route " + routeId + ": " + getRouteMessage(route) + " because of " + getExceptionMessage(cause), cause);
030        this.routeId = routeId;
031    }
032
033    public FailedToCreateRouteException(String routeId, String route, String at, Throwable cause) {
034        super("Failed to create route " + routeId + " at: >>> " + at + " <<< in route: " + getRouteMessage(route) + " because of " + cause.getMessage(), cause);
035        this.routeId = routeId;
036    }
037
038    public String getRouteId() {
039        return routeId;
040    }
041    
042    protected static String getExceptionMessage(Throwable cause) {
043        if (cause.getMessage() != null) {
044            return cause.getMessage();
045        } else {
046            return cause.getClass().getSimpleName();
047        }
048    }
049
050    protected static String getRouteMessage(String route) {
051        // cut the route after 60 chars so it won't be too big in the message
052        // users just need to be able to identify the route so they know where to look
053        if (route.length() > 60) {
054            return route.substring(0, 60) + "...";
055        } else {
056            return route;
057        }
058    }
059}