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 import javax.xml.bind.annotation.XmlAccessType;
022 import javax.xml.bind.annotation.XmlAccessorType;
023 import javax.xml.bind.annotation.XmlAttribute;
024 import javax.xml.bind.annotation.XmlRootElement;
025
026 import org.apache.camel.Processor;
027 import org.apache.camel.processor.RollbackProcessor;
028 import org.apache.camel.spi.RouteContext;
029
030 /**
031 * Represents an XML <rollback/> element
032 */
033 @XmlRootElement(name = "rollback")
034 @XmlAccessorType(XmlAccessType.FIELD)
035 public class RollbackDefinition extends ProcessorDefinition<RollbackDefinition> {
036
037 @XmlAttribute
038 private Boolean markRollbackOnly;
039 @XmlAttribute
040 private Boolean markRollbackOnlyLast;
041 @XmlAttribute
042 private String message;
043
044 public RollbackDefinition() {
045 }
046
047 public RollbackDefinition(String message) {
048 this.message = message;
049 }
050
051 public String getMessage() {
052 return message;
053 }
054
055 @Override
056 public String getShortName() {
057 return "rollback";
058 }
059
060 @Override
061 public String toString() {
062 if (message != null) {
063 return "Rollback[" + message + "]";
064 } else {
065 return "Rollback";
066 }
067 }
068
069 @Override
070 public Processor createProcessor(RouteContext routeContext) {
071 // validate that only either mark rollbacks is chosen and not both
072 if (markRollbackOnly != null && markRollbackOnly.booleanValue()
073 && markRollbackOnlyLast != null && markRollbackOnlyLast.booleanValue()) {
074 throw new IllegalArgumentException("Only either one of markRollbackOnly and markRollbackOnlyLast is possible to select as true");
075 }
076
077 RollbackProcessor answer = new RollbackProcessor(message);
078 answer.setMarkRollbackOnly(markRollbackOnly != null ? markRollbackOnly : false);
079 answer.setMarkRollbackOnlyLast(markRollbackOnlyLast != null ? markRollbackOnlyLast : false);
080 return answer;
081 }
082
083 @Override
084 @SuppressWarnings("unchecked")
085 public List<ProcessorDefinition> getOutputs() {
086 return Collections.EMPTY_LIST;
087 }
088
089 public Boolean isMarkRollbackOnly() {
090 return markRollbackOnly;
091 }
092
093 public void setMarkRollbackOnly(Boolean markRollbackOnly) {
094 this.markRollbackOnly = markRollbackOnly;
095 }
096
097 public Boolean isMarkRollbackOnlyLast() {
098 return markRollbackOnlyLast;
099 }
100
101 public void setMarkRollbackOnlyLast(Boolean markRollbackOnlyLast) {
102 this.markRollbackOnlyLast = markRollbackOnlyLast;
103 }
104 }