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