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 */
017 package org.apache.camel.model;
018
019 import java.util.Collections;
020 import java.util.List;
021
022 import javax.xml.bind.annotation.XmlAccessType;
023 import javax.xml.bind.annotation.XmlAccessorType;
024 import javax.xml.bind.annotation.XmlAttribute;
025 import javax.xml.bind.annotation.XmlRootElement;
026 import javax.xml.bind.annotation.XmlTransient;
027
028 import org.apache.camel.CamelException;
029 import org.apache.camel.Processor;
030 import org.apache.camel.impl.RouteContext;
031 import org.apache.camel.processor.ThrowFaultProcessor;
032
033 @XmlRootElement(name = "throwFault")
034 @XmlAccessorType(XmlAccessType.FIELD)
035 public class ThrowFaultType extends ProcessorType<ThrowFaultType> {
036 @XmlTransient
037 private Throwable fault;
038 @XmlTransient
039 private Processor processor;
040 @XmlAttribute (required = true)
041 private String faultRef;
042
043 public ThrowFaultType() {
044
045 }
046
047 public void setFault(Throwable fault) {
048 this.fault = fault;
049 }
050
051 public Throwable getFault() {
052 return fault;
053 }
054
055 public void setFaultRef(String ref) {
056 this.faultRef = ref;
057 }
058
059 public String getFaultRef() {
060 return faultRef;
061 }
062
063 @Override
064 public Processor createProcessor(RouteContext routeContext) {
065
066 if (processor == null) {
067 if (fault == null) {
068 fault = routeContext.lookup(faultRef, Throwable.class);
069 if (fault == null) {
070 // can't find the fault instance, create a new one
071 fault = new CamelException(faultRef);
072 }
073 }
074 processor = new ThrowFaultProcessor(fault);
075 }
076 return processor;
077 }
078
079 @Override
080 public List<ProcessorType<?>> getOutputs() {
081 return Collections.EMPTY_LIST;
082 }
083 }