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.core.xml;
018    
019    import javax.xml.bind.annotation.XmlAccessType;
020    import javax.xml.bind.annotation.XmlAccessorType;
021    import javax.xml.bind.annotation.XmlAttribute;
022    
023    import org.apache.camel.CamelContext;
024    import org.apache.camel.LoggingLevel;
025    import org.apache.camel.processor.RedeliveryPolicy;
026    import org.apache.camel.util.CamelContextHelper;
027    
028    /**
029     * A factory which instantiates {@link RedeliveryPolicy} objects
030     *
031     * @version 
032     */
033    @XmlAccessorType(XmlAccessType.FIELD)
034    public abstract class AbstractCamelRedeliveryPolicyFactoryBean extends AbstractCamelFactoryBean<RedeliveryPolicy> {
035    
036        @XmlAttribute
037        private String maximumRedeliveries;
038        @XmlAttribute
039        private String redeliveryDelay;
040        @XmlAttribute
041        private String asyncDelayedRedelivery;
042        @XmlAttribute
043        private String backOffMultiplier;
044        @XmlAttribute
045        private String useExponentialBackOff;
046        @XmlAttribute
047        private String collisionAvoidanceFactor;
048        @XmlAttribute
049        private String useCollisionAvoidance;
050        @XmlAttribute
051        private String maximumRedeliveryDelay;
052        @XmlAttribute
053        private LoggingLevel retriesExhaustedLogLevel;
054        @XmlAttribute
055        private LoggingLevel retryAttemptedLogLevel;
056        @XmlAttribute
057        private String logRetryAttempted;
058        @XmlAttribute
059        private String logStackTrace;
060        @XmlAttribute
061        private String logRetryStackTrace;
062        @XmlAttribute
063        private String logHandled;
064        @XmlAttribute
065        private String logContinued;
066        @XmlAttribute
067        private String logExhausted;
068        @XmlAttribute
069        private String disableRedelivery;
070        @XmlAttribute
071        private String delayPattern;
072    
073        public RedeliveryPolicy getObject() throws Exception {
074            RedeliveryPolicy answer = new RedeliveryPolicy();
075            CamelContext context = getCamelContext();
076    
077            // copy across the properties - if they are set
078            if (maximumRedeliveries != null) {
079                answer.setMaximumRedeliveries(CamelContextHelper.parseInteger(context, maximumRedeliveries));
080            }
081            if (redeliveryDelay != null) {
082                answer.setRedeliveryDelay(CamelContextHelper.parseLong(context, redeliveryDelay));
083            }
084            if (asyncDelayedRedelivery != null) {
085                if (CamelContextHelper.parseBoolean(context, asyncDelayedRedelivery)) {
086                    answer.asyncDelayedRedelivery();
087                }
088            }
089            if (retriesExhaustedLogLevel != null) {
090                answer.setRetriesExhaustedLogLevel(retriesExhaustedLogLevel);
091            }
092            if (retryAttemptedLogLevel != null) {
093                answer.setRetryAttemptedLogLevel(retryAttemptedLogLevel);
094            }
095            if (backOffMultiplier != null) {
096                answer.setBackOffMultiplier(CamelContextHelper.parseDouble(context, backOffMultiplier));
097            }
098            if (useExponentialBackOff != null) {
099                answer.setUseExponentialBackOff(CamelContextHelper.parseBoolean(context, useExponentialBackOff));
100            }
101            if (collisionAvoidanceFactor != null) {
102                answer.setCollisionAvoidanceFactor(CamelContextHelper.parseDouble(context, collisionAvoidanceFactor));
103            }
104            if (useCollisionAvoidance != null) {
105                answer.setUseCollisionAvoidance(CamelContextHelper.parseBoolean(context, useCollisionAvoidance));
106            }
107            if (maximumRedeliveryDelay != null) {
108                answer.setMaximumRedeliveryDelay(CamelContextHelper.parseLong(context, maximumRedeliveryDelay));
109            }
110            if (logStackTrace != null) {
111                answer.setLogStackTrace(CamelContextHelper.parseBoolean(context, logStackTrace));
112            }
113            if (logRetryStackTrace != null) {
114                answer.setLogRetryStackTrace(CamelContextHelper.parseBoolean(context, logRetryStackTrace));
115            }
116            if (logHandled != null) {
117                answer.setLogHandled(CamelContextHelper.parseBoolean(context, logHandled));
118            }
119            if (logContinued != null) {
120                answer.setLogContinued(CamelContextHelper.parseBoolean(context, logContinued));
121            }
122            if (logRetryAttempted != null) {
123                answer.setLogRetryAttempted(CamelContextHelper.parseBoolean(context, logRetryAttempted));
124            }
125            if (logExhausted != null) {
126                answer.setLogExhausted(CamelContextHelper.parseBoolean(context, logExhausted));
127            }
128            if (disableRedelivery != null) {
129                if (CamelContextHelper.parseBoolean(context, disableRedelivery)) {
130                    answer.setMaximumRedeliveries(0);
131                }
132            }
133            if (delayPattern != null) {
134                answer.setDelayPattern(delayPattern);
135            }
136    
137            return answer;
138        }
139    
140        protected abstract CamelContext getCamelContextWithId(String camelContextId);
141    
142        public Class<RedeliveryPolicy> getObjectType() {
143            return RedeliveryPolicy.class;
144        }
145    
146        public String getMaximumRedeliveries() {
147            return maximumRedeliveries;
148        }
149    
150        public void setMaximumRedeliveries(String maximumRedeliveries) {
151            this.maximumRedeliveries = maximumRedeliveries;
152        }
153    
154        public String getRedeliveryDelay() {
155            return redeliveryDelay;
156        }
157    
158        public void setRedeliveryDelay(String redeliveryDelay) {
159            this.redeliveryDelay = redeliveryDelay;
160        }
161    
162        public String getAsyncDelayedRedelivery() {
163            return asyncDelayedRedelivery;
164        }
165    
166        public void setAsyncDelayedRedelivery(String asyncDelayedRedelivery) {
167            this.asyncDelayedRedelivery = asyncDelayedRedelivery;
168        }
169    
170        public String getBackOffMultiplier() {
171            return backOffMultiplier;
172        }
173    
174        public void setBackOffMultiplier(String backOffMultiplier) {
175            this.backOffMultiplier = backOffMultiplier;
176        }
177    
178        public String getUseExponentialBackOff() {
179            return useExponentialBackOff;
180        }
181    
182        public void setUseExponentialBackOff(String useExponentialBackOff) {
183            this.useExponentialBackOff = useExponentialBackOff;
184        }
185    
186        public String getCollisionAvoidanceFactor() {
187            return collisionAvoidanceFactor;
188        }
189    
190        public void setCollisionAvoidanceFactor(String collisionAvoidanceFactor) {
191            this.collisionAvoidanceFactor = collisionAvoidanceFactor;
192        }
193    
194        public String getUseCollisionAvoidance() {
195            return useCollisionAvoidance;
196        }
197    
198        public void setUseCollisionAvoidance(String useCollisionAvoidance) {
199            this.useCollisionAvoidance = useCollisionAvoidance;
200        }
201    
202        public String getMaximumRedeliveryDelay() {
203            return maximumRedeliveryDelay;
204        }
205    
206        public void setMaximumRedeliveryDelay(String maximumRedeliveryDelay) {
207            this.maximumRedeliveryDelay = maximumRedeliveryDelay;
208        }
209    
210        public LoggingLevel getRetriesExhaustedLogLevel() {
211            return retriesExhaustedLogLevel;
212        }
213    
214        public void setRetriesExhaustedLogLevel(LoggingLevel retriesExhaustedLogLevel) {
215            this.retriesExhaustedLogLevel = retriesExhaustedLogLevel;
216        }
217    
218        public LoggingLevel getRetryAttemptedLogLevel() {
219            return retryAttemptedLogLevel;
220        }
221    
222        public void setRetryAttemptedLogLevel(LoggingLevel retryAttemptedLogLevel) {
223            this.retryAttemptedLogLevel = retryAttemptedLogLevel;
224        }
225    
226        public String getLogRetryAttempted() {
227            return logRetryAttempted;
228        }
229    
230        public void setLogRetryAttempted(String logRetryAttempted) {
231            this.logRetryAttempted = logRetryAttempted;
232        }
233    
234        public String getLogStackTrace() {
235            return logStackTrace;
236        }
237    
238        public void setLogStackTrace(String logStackTrace) {
239            this.logStackTrace = logStackTrace;
240        }
241    
242        public String getLogRetryStackTrace() {
243            return logRetryStackTrace;
244        }
245    
246        public void setLogRetryStackTrace(String logRetryStackTrace) {
247            this.logRetryStackTrace = logRetryStackTrace;
248        }
249    
250        public String getLogHandled() {
251            return logHandled;
252        }
253    
254        public void setLogHandled(String logHandled) {
255            this.logHandled = logHandled;
256        }
257    
258        public String getLogContinued() {
259            return logContinued;
260        }
261    
262        public void setLogContinued(String logContinued) {
263            this.logContinued = logContinued;
264        }
265    
266        public String getLogExhausted() {
267            return logExhausted;
268        }
269    
270        public void setLogExhausted(String logExhausted) {
271            this.logExhausted = logExhausted;
272        }
273    
274        public String getDisableRedelivery() {
275            return disableRedelivery;
276        }
277    
278        public void setDisableRedelivery(String disableRedelivery) {
279            this.disableRedelivery = disableRedelivery;
280        }
281    
282        public String getDelayPattern() {
283            return delayPattern;
284        }
285    
286        public void setDelayPattern(String delayPattern) {
287            this.delayPattern = delayPattern;
288        }
289    }