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.model;
018
019import java.util.ArrayList;
020import java.util.Arrays;
021import java.util.List;
022import java.util.concurrent.atomic.AtomicBoolean;
023import java.util.function.Supplier;
024
025import javax.xml.bind.annotation.XmlAccessType;
026import javax.xml.bind.annotation.XmlAccessorType;
027import javax.xml.bind.annotation.XmlAttribute;
028import javax.xml.bind.annotation.XmlElement;
029import javax.xml.bind.annotation.XmlElementRef;
030import javax.xml.bind.annotation.XmlRootElement;
031import javax.xml.bind.annotation.XmlTransient;
032import javax.xml.bind.annotation.XmlType;
033
034import org.apache.camel.Endpoint;
035import org.apache.camel.ErrorHandlerFactory;
036import org.apache.camel.NamedRoute;
037import org.apache.camel.ShutdownRoute;
038import org.apache.camel.ShutdownRunningTask;
039import org.apache.camel.builder.EndpointConsumerBuilder;
040import org.apache.camel.builder.ErrorHandlerBuilderRef;
041import org.apache.camel.model.rest.RestBindingDefinition;
042import org.apache.camel.model.rest.RestDefinition;
043import org.apache.camel.reifier.errorhandler.ErrorHandlerReifier;
044import org.apache.camel.spi.AsEndpointUri;
045import org.apache.camel.spi.Metadata;
046import org.apache.camel.spi.RoutePolicy;
047
048/**
049 * A Camel route
050 */
051@Metadata(label = "configuration")
052@XmlRootElement(name = "route")
053@XmlType(propOrder = {"input", "inputType", "outputType", "outputs", "routeProperties"})
054@XmlAccessorType(XmlAccessType.PROPERTY)
055// must use XmlAccessType.PROPERTY as there is some custom logic needed to be executed in the setter methods
056public class RouteDefinition extends OutputDefinition<RouteDefinition> implements NamedRoute {
057    private final AtomicBoolean prepared = new AtomicBoolean(false);
058    private FromDefinition input;
059    private String group;
060    private String streamCache;
061    private String trace;
062    private String messageHistory;
063    private String logMask;
064    private String delayer;
065    private String autoStartup;
066    private Integer startupOrder;
067    private List<RoutePolicy> routePolicies;
068    private String routePolicyRef;
069    private String shutdownRoute;
070    private String shutdownRunningTask;
071    private String errorHandlerRef;
072    private ErrorHandlerFactory errorHandlerFactory;
073    // keep state whether the error handler is context scoped or not
074    // (will by default be context scoped of no explicit error handler
075    // configured)
076    private boolean contextScopedErrorHandler = true;
077    private Boolean rest;
078    private RestDefinition restDefinition;
079    private RestBindingDefinition restBindingDefinition;
080    private InputTypeDefinition inputType;
081    private OutputTypeDefinition outputType;
082    private List<PropertyDefinition> routeProperties;
083
084    public RouteDefinition() {
085    }
086
087    public RouteDefinition(@AsEndpointUri String uri) {
088        from(uri);
089    }
090
091    public RouteDefinition(Endpoint endpoint) {
092        from(endpoint);
093    }
094
095    /**
096     * This route is created from the REST DSL.
097     */
098    public void fromRest(@AsEndpointUri String uri) {
099        from(uri);
100        rest = true;
101    }
102
103    /**
104     * Check if the route has been prepared
105     *
106     * @return wether the route has been prepared or not
107     * @see RouteDefinitionHelper#prepareRoute(ModelCamelContext,
108     *      RouteDefinition)
109     */
110    public boolean isPrepared() {
111        return prepared.get();
112    }
113
114    /**
115     * Marks the route definition as prepared.
116     * <p/>
117     * This is needed if routes have been created by components such as
118     * <tt>camel-spring</tt> or <tt>camel-blueprint</tt>. Usually they share
119     * logic in the <tt>camel-core-xml</tt> module which prepares the routes.
120     */
121    public void markPrepared() {
122        prepared.set(true);
123    }
124
125    /**
126     * Marks the route definition as un-prepared.
127     * <p/>
128     * This is needed if routes have been created by components such as
129     * <tt>camel-scala</tt>. To unset the prepare so the routes can be prepared
130     * at a later stage when scala has build the routes completely.
131     */
132    public void markUnprepared() {
133        prepared.set(false);
134    }
135
136    @Override
137    public String toString() {
138        if (getId() != null) {
139            return "Route(" + getId() + ")[" + (input != null ? input : "") + " -> " + outputs + "]";
140        } else {
141            return "Route[" + input + " -> " + outputs + "]";
142        }
143    }
144
145    @Override
146    public String getShortName() {
147        return "route";
148    }
149
150    @Override
151    public String getLabel() {
152        return "Route[" + input.getLabel() + "]";
153    }
154
155    @Override
156    public String getRouteId() {
157        return getId();
158    }
159
160    @Override
161    public String getEndpointUrl() {
162        return input != null ? input.getEndpointUri() : null;
163    }
164
165    // Fluent API
166    // -----------------------------------------------------------------------
167
168    /**
169     * Creates an input to the route
170     *
171     * @param uri the from uri
172     * @return the builder
173     */
174    public RouteDefinition from(@AsEndpointUri String uri) {
175        setInput(new FromDefinition(uri));
176        return this;
177    }
178
179    /**
180     * Creates an input to the route
181     *
182     * @param endpoint the from endpoint
183     * @return the builder
184     */
185    public RouteDefinition from(Endpoint endpoint) {
186        setInput(new FromDefinition(endpoint));
187        return this;
188    }
189
190    /**
191     * Creates an input to the route
192     *
193     * @param endpoint the from endpoint
194     * @return the builder
195     */
196    public RouteDefinition from(EndpointConsumerBuilder endpoint) {
197        setInput(new FromDefinition(endpoint));
198        return this;
199    }
200
201    /**
202     * Set the group name for this route
203     *
204     * @param name the group name
205     * @return the builder
206     */
207    public RouteDefinition group(String name) {
208        setGroup(name);
209        return this;
210    }
211
212    /**
213     * Set the route group for this route
214     *
215     * @param group the route group
216     * @return the builder
217     */
218    @Override
219    public RouteDefinition routeGroup(String group) {
220        setGroup(group);
221        return this;
222    }
223
224    /**
225     * Set the route id for this route
226     *
227     * @param id the route id
228     * @return the builder
229     */
230    @Override
231    public RouteDefinition routeId(String id) {
232        if (hasCustomIdAssigned()) {
233            throw new IllegalArgumentException("You can only set routeId one time per route.");
234        }
235        setId(id);
236        return this;
237    }
238
239    /**
240     * Set the route description for this route
241     *
242     * @param description the route description
243     * @return the builder
244     */
245    @Override
246    public RouteDefinition routeDescription(String description) {
247        DescriptionDefinition desc = new DescriptionDefinition();
248        desc.setText(description);
249        setDescription(desc);
250        return this;
251    }
252
253    /**
254     * Disable stream caching for this route.
255     *
256     * @return the builder
257     */
258    public RouteDefinition noStreamCaching() {
259        setStreamCache("false");
260        return this;
261    }
262
263    /**
264     * Enable stream caching for this route.
265     *
266     * @return the builder
267     */
268    public RouteDefinition streamCaching() {
269        setStreamCache("true");
270        return this;
271    }
272
273    /**
274     * Enable stream caching for this route.
275     *
276     * @param streamCache whether to use stream caching (true or false), the
277     *            value can be a property placeholder
278     * @return the builder
279     */
280    public RouteDefinition streamCaching(String streamCache) {
281        setStreamCache(streamCache);
282        return this;
283    }
284
285    /**
286     * Disable tracing for this route.
287     *
288     * @return the builder
289     */
290    public RouteDefinition noTracing() {
291        setTrace("false");
292        return this;
293    }
294
295    /**
296     * Enable tracing for this route.
297     *
298     * @return the builder
299     */
300    public RouteDefinition tracing() {
301        setTrace("true");
302        return this;
303    }
304
305    /**
306     * Enable tracing for this route.
307     *
308     * @param tracing whether to use tracing (true or false), the value can be a
309     *            property placeholder
310     * @return the builder
311     */
312    public RouteDefinition tracing(String tracing) {
313        setTrace(tracing);
314        return this;
315    }
316
317    /**
318     * Enable message history for this route.
319     *
320     * @return the builder
321     */
322    public RouteDefinition messageHistory() {
323        setMessageHistory("true");
324        return this;
325    }
326
327    /**
328     * Enable message history for this route.
329     *
330     * @param messageHistory whether to use message history (true or false), the
331     *            value can be a property placeholder
332     * @return the builder
333     */
334    public RouteDefinition messageHistory(String messageHistory) {
335        setMessageHistory(messageHistory);
336        return this;
337    }
338
339    /**
340     * Enable security mask for Logging on this route.
341     *
342     * @return the builder
343     */
344    public RouteDefinition logMask() {
345        setLogMask("true");
346        return this;
347    }
348
349    /**
350     * Sets whether security mask for logging is enabled on this route.
351     *
352     * @param logMask whether to enable security mask for Logging (true or
353     *            false), the value can be a property placeholder
354     * @return the builder
355     */
356    public RouteDefinition logMask(String logMask) {
357        setLogMask(logMask);
358        return this;
359    }
360
361    /**
362     * Disable message history for this route.
363     *
364     * @return the builder
365     */
366    public RouteDefinition noMessageHistory() {
367        setMessageHistory("false");
368        return this;
369    }
370
371    /**
372     * Disable delayer for this route.
373     *
374     * @return the builder
375     */
376    public RouteDefinition noDelayer() {
377        setDelayer("0");
378        return this;
379    }
380
381    /**
382     * Enable delayer for this route.
383     *
384     * @param delay delay in millis
385     * @return the builder
386     */
387    public RouteDefinition delayer(long delay) {
388        setDelayer("" + delay);
389        return this;
390    }
391
392    /**
393     * Installs the given
394     * <a href="http://camel.apache.org/error-handler.html">error handler</a>
395     * builder.
396     *
397     * @param errorHandlerBuilder the error handler to be used by default for
398     *            all child routes
399     * @return the current builder with the error handler configured
400     */
401    public RouteDefinition errorHandler(ErrorHandlerFactory errorHandlerBuilder) {
402        setErrorHandlerFactory(errorHandlerBuilder);
403        // we are now using a route scoped error handler
404        contextScopedErrorHandler = false;
405        return this;
406    }
407
408    /**
409     * Disables this route from being auto started when Camel starts.
410     *
411     * @return the builder
412     */
413    public RouteDefinition noAutoStartup() {
414        setAutoStartup("false");
415        return this;
416    }
417
418    /**
419     * Sets the auto startup property on this route.
420     *
421     * @param autoStartup whether to auto startup (true or false), the value can
422     *            be a property placeholder
423     * @return the builder
424     */
425    public RouteDefinition autoStartup(String autoStartup) {
426        setAutoStartup(autoStartup);
427        return this;
428    }
429
430    /**
431     * Sets the auto startup property on this route.
432     *
433     * @param autoStartup - boolean indicator
434     * @return the builder
435     */
436    public RouteDefinition autoStartup(boolean autoStartup) {
437        setAutoStartup(Boolean.toString(autoStartup));
438        return this;
439    }
440
441    /**
442     * Configures the startup order for this route
443     * <p/>
444     * Camel will reorder routes and star them ordered by 0..N where 0 is the
445     * lowest number and N the highest number. Camel will stop routes in reverse
446     * order when its stopping.
447     *
448     * @param order the order represented as a number
449     * @return the builder
450     */
451    @Override
452    public RouteDefinition startupOrder(int order) {
453        setStartupOrder(order);
454        return this;
455    }
456
457    /**
458     * Configures route policies for this route
459     *
460     * @param policies the route policies
461     * @return the builder
462     */
463    public RouteDefinition routePolicy(RoutePolicy... policies) {
464        if (routePolicies == null) {
465            routePolicies = new ArrayList<>();
466        }
467        routePolicies.addAll(Arrays.asList(policies));
468        return this;
469    }
470
471    /**
472     * Configures route policy for this route
473     *
474     * @param policy route policy
475     * @return the builder
476     */
477    public RouteDefinition routePolicy(Supplier<RoutePolicy> policy) {
478        return routePolicy(policy.get());
479    }
480
481    /**
482     * Configures a route policy for this route
483     *
484     * @param routePolicyRef reference to a {@link RoutePolicy} to lookup and
485     *            use. You can specify multiple references by separating using
486     *            comma.
487     * @return the builder
488     */
489    public RouteDefinition routePolicyRef(String routePolicyRef) {
490        setRoutePolicyRef(routePolicyRef);
491        return this;
492    }
493
494    /**
495     * Configures a shutdown route option.
496     *
497     * @param shutdownRoute the option to use when shutting down this route
498     * @return the builder
499     */
500    public RouteDefinition shutdownRoute(ShutdownRoute shutdownRoute) {
501        return shutdownRoute(shutdownRoute.name());
502    }
503
504    /**
505     * Configures a shutdown route option.
506     *
507     * @param shutdownRoute the option to use when shutting down this route
508     * @return the builder
509     */
510    public RouteDefinition shutdownRoute(String shutdownRoute) {
511        setShutdownRoute(shutdownRoute);
512        return this;
513    }
514
515    /**
516     * Configures a shutdown running task option.
517     *
518     * @param shutdownRunningTask the option to use when shutting down and how
519     *            to act upon running tasks.
520     * @return the builder
521     */
522    public RouteDefinition shutdownRunningTask(ShutdownRunningTask shutdownRunningTask) {
523        return shutdownRunningTask(shutdownRunningTask.name());
524    }
525
526    /**
527     * Configures a shutdown running task option.
528     *
529     * @param shutdownRunningTask the option to use when shutting down and how
530     *            to act upon running tasks.
531     * @return the builder
532     */
533    public RouteDefinition shutdownRunningTask(String shutdownRunningTask) {
534        setShutdownRunningTask(shutdownRunningTask);
535        return this;
536    }
537
538    /**
539     * Declare the expected data type of the input message. If the actual
540     * message type is different at runtime, camel look for a required
541     * {@link org.apache.camel.spi.Transformer} and apply if exists. The type
542     * name consists of two parts, 'scheme' and 'name' connected with ':'. For
543     * Java type 'name' is a fully qualified class name. For example
544     * {@code java:java.lang.String}, {@code json:ABCOrder}.
545     *
546     * @see org.apache.camel.spi.Transformer
547     * @param urn input type URN
548     * @return the builder
549     */
550    public RouteDefinition inputType(String urn) {
551        inputType = new InputTypeDefinition().urn(urn).validate(false);
552        return this;
553    }
554
555    /**
556     * Declare the expected data type of the input message with content
557     * validation enabled. If the actual message type is different at runtime,
558     * camel look for a required {@link org.apache.camel.spi.Transformer} and
559     * apply if exists, and then applies {@link org.apache.camel.spi.Validator}
560     * as well. The type name consists of two parts, 'scheme' and 'name'
561     * connected with ':'. For Java type 'name' is a fully qualified class name.
562     * For example {@code java:java.lang.String}, {@code json:ABCOrder}.
563     *
564     * @see org.apache.camel.spi.Transformer
565     * @see org.apache.camel.spi.Validator
566     * @param urn input type URN
567     * @return the builder
568     */
569    public RouteDefinition inputTypeWithValidate(String urn) {
570        inputType = new InputTypeDefinition().urn(urn).validate(true);
571        return this;
572    }
573
574    /**
575     * Declare the expected data type of the input message by Java class. If the
576     * actual message type is different at runtime, camel look for a required
577     * {@link org.apache.camel.spi.Transformer} and apply if exists.
578     *
579     * @see org.apache.camel.spi.Transformer
580     * @param clazz Class object of the input type
581     * @return the builder
582     */
583    public RouteDefinition inputType(Class clazz) {
584        inputType = new InputTypeDefinition().javaClass(clazz).validate(false);
585        return this;
586    }
587
588    /**
589     * Declare the expected data type of the input message by Java class with
590     * content validation enabled. If the actual message type is different at
591     * runtime, camel look for a required
592     * {@link org.apache.camel.spi.Transformer} and apply if exists, and then
593     * applies {@link org.apache.camel.spi.Validator} as well.
594     *
595     * @see org.apache.camel.spi.Transformer
596     * @see org.apache.camel.spi.Validator
597     * @param clazz Class object of the input type
598     * @return the builder
599     */
600    public RouteDefinition inputTypeWithValidate(Class clazz) {
601        inputType = new InputTypeDefinition().javaClass(clazz).validate(true);
602        return this;
603    }
604
605    /**
606     * Declare the expected data type of the output message. If the actual
607     * message type is different at runtime, camel look for a required
608     * {@link org.apache.camel.spi.Transformer} and apply if exists. The type
609     * name consists of two parts, 'scheme' and 'name' connected with ':'. For
610     * Java type 'name' is a fully qualified class name. For example
611     * {@code java:java.lang.String}, {@code json:ABCOrder}.
612     *
613     * @see org.apache.camel.spi.Transformer
614     * @param urn output type URN
615     * @return the builder
616     */
617    public RouteDefinition outputType(String urn) {
618        outputType = new OutputTypeDefinition().urn(urn).validate(false);
619        return this;
620    }
621
622    /**
623     * Declare the expected data type of the output message with content
624     * validation enabled. If the actual message type is different at runtime,
625     * Camel look for a required {@link org.apache.camel.spi.Transformer} and
626     * apply if exists, and then applies {@link org.apache.camel.spi.Validator}
627     * as well. The type name consists of two parts, 'scheme' and 'name'
628     * connected with ':'. For Java type 'name' is a fully qualified class name.
629     * For example {@code java:java.lang.String}, {@code json:ABCOrder}.
630     * 
631     * @see org.apache.camel.spi.Transformer
632     * @see org.apache.camel.spi.Validator
633     * @param urn output type URN
634     * @return the builder
635     */
636    public RouteDefinition outputTypeWithValidate(String urn) {
637        outputType = new OutputTypeDefinition().urn(urn).validate(true);
638        return this;
639    }
640
641    /**
642     * Declare the expected data type of the output message by Java class. If
643     * the actual message type is different at runtime, camel look for a
644     * required {@link org.apache.camel.spi.Transformer} and apply if exists.
645     *
646     * @see org.apache.camel.spi.Transformer
647     * @param clazz Class object of the output type
648     * @return the builder
649     */
650    public RouteDefinition outputType(Class clazz) {
651        outputType = new OutputTypeDefinition().javaClass(clazz).validate(false);
652        return this;
653    }
654
655    /**
656     * Declare the expected data type of the ouput message by Java class with
657     * content validation enabled. If the actual message type is different at
658     * runtime, camel look for a required
659     * {@link org.apache.camel.spi.Transformer} and apply if exists, and then
660     * applies {@link org.apache.camel.spi.Validator} as well.
661     * 
662     * @see org.apache.camel.spi.Transformer
663     * @see org.apache.camel.spi.Validator
664     * @param clazz Class object of the output type
665     * @return the builder
666     */
667    public RouteDefinition outputTypeWithValidate(Class clazz) {
668        outputType = new OutputTypeDefinition().javaClass(clazz).validate(true);
669        return this;
670    }
671
672    /**
673     * Adds a custom property on the route.
674     */
675    public RouteDefinition routeProperty(String key, String value) {
676        if (routeProperties == null) {
677            routeProperties = new ArrayList<>();
678        }
679
680        PropertyDefinition prop = new PropertyDefinition();
681        prop.setKey(key);
682        prop.setValue(value);
683
684        routeProperties.add(prop);
685
686        return this;
687    }
688
689    // Properties
690    // -----------------------------------------------------------------------
691
692    public FromDefinition getInput() {
693        return input;
694    }
695
696    /**
697     * Input to the route.
698     */
699    @XmlElementRef(required = false)
700    public void setInput(FromDefinition input) {
701        // required = false: in rest-dsl you can embed an in-lined route which
702        // does not have a <from> as its implied to be the rest endpoint
703        this.input = input;
704    }
705
706    @Override
707    public List<ProcessorDefinition<?>> getOutputs() {
708        return outputs;
709    }
710
711    /**
712     * Outputs are processors that determines how messages are processed by this
713     * route.
714     */
715    @XmlElementRef
716    @Override
717    public void setOutputs(List<ProcessorDefinition<?>> outputs) {
718        super.setOutputs(outputs);
719    }
720
721    /**
722     * The group that this route belongs to; could be the name of the
723     * RouteBuilder class or be explicitly configured in the XML.
724     * <p/>
725     * May be null.
726     */
727    public String getGroup() {
728        return group;
729    }
730
731    /**
732     * The group that this route belongs to; could be the name of the
733     * RouteBuilder class or be explicitly configured in the XML.
734     * <p/>
735     * May be null.
736     */
737    @XmlAttribute
738    public void setGroup(String group) {
739        this.group = group;
740    }
741
742    /**
743     * Whether stream caching is enabled on this route.
744     */
745    public String getStreamCache() {
746        return streamCache;
747    }
748
749    /**
750     * Whether stream caching is enabled on this route.
751     */
752    @XmlAttribute
753    public void setStreamCache(String streamCache) {
754        this.streamCache = streamCache;
755    }
756
757    /**
758     * Whether tracing is enabled on this route.
759     */
760    public String getTrace() {
761        return trace;
762    }
763
764    /**
765     * Whether tracing is enabled on this route.
766     */
767    @XmlAttribute
768    public void setTrace(String trace) {
769        this.trace = trace;
770    }
771
772    /**
773     * Whether message history is enabled on this route.
774     */
775    public String getMessageHistory() {
776        return messageHistory;
777    }
778
779    /**
780     * Whether message history is enabled on this route.
781     */
782    @XmlAttribute
783    @Metadata(defaultValue = "true")
784    public void setMessageHistory(String messageHistory) {
785        this.messageHistory = messageHistory;
786    }
787
788    /**
789     * Whether security mask for Logging is enabled on this route.
790     */
791    public String getLogMask() {
792        return logMask;
793    }
794
795    /**
796     * Whether security mask for Logging is enabled on this route.
797     */
798    @XmlAttribute
799    public void setLogMask(String logMask) {
800        this.logMask = logMask;
801    }
802
803    /**
804     * Whether to slow down processing messages by a given delay in msec.
805     */
806    public String getDelayer() {
807        return delayer;
808    }
809
810    /**
811     * Whether to slow down processing messages by a given delay in msec.
812     */
813    @XmlAttribute
814    public void setDelayer(String delayer) {
815        this.delayer = delayer;
816    }
817
818    /**
819     * Whether to auto start this route
820     */
821    public String getAutoStartup() {
822        return autoStartup;
823    }
824
825    /**
826     * Whether to auto start this route
827     */
828    @XmlAttribute
829    @Metadata(defaultValue = "true")
830    public void setAutoStartup(String autoStartup) {
831        this.autoStartup = autoStartup;
832    }
833
834    /**
835     * To configure the ordering of the routes being started
836     */
837    public Integer getStartupOrder() {
838        return startupOrder;
839    }
840
841    /**
842     * To configure the ordering of the routes being started
843     */
844    @XmlAttribute
845    public void setStartupOrder(Integer startupOrder) {
846        this.startupOrder = startupOrder;
847    }
848
849    /**
850     * Sets the bean ref name of the error handler builder to use on this route
851     */
852    @XmlAttribute
853    public void setErrorHandlerRef(String errorHandlerRef) {
854        this.errorHandlerRef = errorHandlerRef;
855        // we use an specific error handler ref (from Spring DSL) then wrap that
856        // with a error handler build ref so Camel knows its not just the
857        // default one
858        setErrorHandlerFactory(new ErrorHandlerBuilderRef(errorHandlerRef));
859    }
860
861    /**
862     * Sets the bean ref name of the error handler builder to use on this route
863     */
864    public String getErrorHandlerRef() {
865        return errorHandlerRef;
866    }
867
868    /**
869     * Sets the error handler if one is not already set
870     */
871    @XmlTransient
872    public void setErrorHandlerFactoryIfNull(ErrorHandlerFactory errorHandlerFactory) {
873        if (this.errorHandlerFactory == null) {
874            setErrorHandlerFactory(errorHandlerFactory);
875        }
876    }
877
878    /**
879     * Reference to custom {@link org.apache.camel.spi.RoutePolicy} to use by
880     * the route. Multiple policies can be configured by separating values using
881     * comma.
882     */
883    @XmlAttribute
884    public void setRoutePolicyRef(String routePolicyRef) {
885        this.routePolicyRef = routePolicyRef;
886    }
887
888    /**
889     * Reference to custom {@link org.apache.camel.spi.RoutePolicy} to use by
890     * the route. Multiple policies can be configured by separating values using
891     * comma.
892     */
893    public String getRoutePolicyRef() {
894        return routePolicyRef;
895    }
896
897    public List<RoutePolicy> getRoutePolicies() {
898        return routePolicies;
899    }
900
901    @XmlTransient
902    public void setRoutePolicies(List<RoutePolicy> routePolicies) {
903        this.routePolicies = routePolicies;
904    }
905
906    public String getShutdownRoute() {
907        return shutdownRoute;
908    }
909
910    /**
911     * To control how to shutdown the route.
912     */
913    @XmlAttribute
914    @Metadata(javaType = "org.apache.camel.ShutdownRoute", defaultValue = "Default", enums = "Default,Defer")
915    public void setShutdownRoute(String shutdownRoute) {
916        this.shutdownRoute = shutdownRoute;
917    }
918
919    /**
920     * To control how to shutdown the route.
921     */
922    public String getShutdownRunningTask() {
923        return shutdownRunningTask;
924    }
925
926    /**
927     * To control how to shutdown the route.
928     */
929    @XmlAttribute
930    @Metadata(javaType = "org.apache.camel.ShutdownRunningTask", defaultValue = "CompleteCurrentTaskOnly", enums = "CompleteCurrentTaskOnly,CompleteAllTasks")
931    public void setShutdownRunningTask(String shutdownRunningTask) {
932        this.shutdownRunningTask = shutdownRunningTask;
933    }
934
935    private ErrorHandlerFactory createErrorHandlerBuilder() {
936        if (errorHandlerRef != null) {
937            return new ErrorHandlerBuilderRef(errorHandlerRef);
938        }
939
940        // return a reference to the default error handler
941        return new ErrorHandlerBuilderRef(ErrorHandlerReifier.DEFAULT_ERROR_HANDLER_BUILDER);
942    }
943
944    public ErrorHandlerFactory getErrorHandlerFactory() {
945        if (errorHandlerFactory == null) {
946            errorHandlerFactory = createErrorHandlerBuilder();
947        }
948        return errorHandlerFactory;
949    }
950
951    /**
952     * Sets the error handler to use with processors created by this builder
953     */
954    @XmlTransient
955    public void setErrorHandlerFactory(ErrorHandlerFactory errorHandlerFactory) {
956        this.errorHandlerFactory = errorHandlerFactory;
957    }
958
959    @XmlAttribute
960    public Boolean isRest() {
961        return rest;
962    }
963
964    public RestDefinition getRestDefinition() {
965        return restDefinition;
966    }
967
968    @XmlTransient
969    public void setRestDefinition(RestDefinition restDefinition) {
970        this.restDefinition = restDefinition;
971    }
972
973    public RestBindingDefinition getRestBindingDefinition() {
974        return restBindingDefinition;
975    }
976
977    @XmlTransient
978    public void setRestBindingDefinition(RestBindingDefinition restBindingDefinition) {
979        this.restBindingDefinition = restBindingDefinition;
980    }
981
982    public boolean isContextScopedErrorHandler() {
983        return contextScopedErrorHandler;
984    }
985
986    @XmlElementRef(required = false)
987    public void setInputType(InputTypeDefinition inputType) {
988        this.inputType = inputType;
989    }
990
991    public InputTypeDefinition getInputType() {
992        return this.inputType;
993    }
994
995    @XmlElementRef(required = false)
996    public void setOutputType(OutputTypeDefinition outputType) {
997        this.outputType = outputType;
998    }
999
1000    public OutputTypeDefinition getOutputType() {
1001        return this.outputType;
1002    }
1003
1004    public List<PropertyDefinition> getRouteProperties() {
1005        return routeProperties;
1006    }
1007
1008    /**
1009     * To set metadata as properties on the route.
1010     */
1011    @XmlElement(name = "routeProperty")
1012    @Metadata(label = "advanced")
1013    public void setRouteProperties(List<PropertyDefinition> routeProperties) {
1014        this.routeProperties = routeProperties;
1015    }
1016
1017    // ****************************
1018    // Static helpers
1019    // ****************************
1020
1021    public static RouteDefinition fromUri(String uri) {
1022        return new RouteDefinition().from(uri);
1023    }
1024
1025    public static RouteDefinition fromEndpoint(Endpoint endpoint) {
1026        return new RouteDefinition().from(endpoint);
1027    }
1028
1029}