001    /**
002     *
003     * Licensed to the Apache Software Foundation (ASF) under one or more
004     * contributor license agreements.  See the NOTICE file distributed with
005     * this work for additional information regarding copyright ownership.
006     * The ASF licenses this file to You under the Apache License, Version 2.0
007     * (the "License"); you may not use this file except in compliance with
008     * the License.  You may obtain a copy of the License at
009     *
010     * http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    package org.apache.camel.builder;
019    
020    import org.apache.camel.Exchange;
021    import org.apache.camel.Expression;
022    
023    /**
024     * A helper class for including portions of the
025     * <a href="http://activemq.apache.org/camel/expression.html">expression</a> and
026     * <a href="http://activemq.apache.org/camel/predicate.html">predicate</a>
027     * <a href="http://activemq.apache.org/camel/dsl.html">Java DSL</a>
028     *
029     * @version $Revision: 1.1 $
030     */
031    public class Builder {
032    
033        /**
034         * Returns a constant expression
035         */
036        public static <E extends Exchange> ValueBuilder<E> constant(Object value) {
037            Expression<E> expression = ExpressionBuilder.constantExpression(value);
038            return new ValueBuilder<E>(expression);
039        }
040    
041        /**
042         * Returns a predicate and value builder for headers on an exchange
043         */
044        public static <E extends Exchange> ValueBuilder<E> header(@FluentArg("name") String name) {
045            Expression<E> expression = ExpressionBuilder.headerExpression(name);
046            return new ValueBuilder<E>(expression);
047        }
048    
049        /**
050         * Returns a predicate and value builder for the inbound body on an exchange
051         */
052        public static <E extends Exchange> ValueBuilder<E> body() {
053            Expression<E> expression = ExpressionBuilder.bodyExpression();
054            return new ValueBuilder<E>(expression);
055        }
056    
057        /**
058         * Returns a predicate and value builder for the inbound message body as a specific type
059         */
060        public static <E extends Exchange, T> ValueBuilder<E> bodyAs( Class<T> type) {
061            Expression<E> expression = ExpressionBuilder.<E, T>bodyExpression(type);
062            return new ValueBuilder<E>(expression);
063        }
064    
065        /**
066         * Returns a predicate and value builder for the outbound body on an exchange
067         */
068        public static <E extends Exchange> ValueBuilder<E> outBody() {
069            Expression<E> expression = ExpressionBuilder.bodyExpression();
070            return new ValueBuilder<E>(expression);
071        }
072    
073        /**
074         * Returns a predicate and value builder for the outbound message body as a specific type
075         */
076        public static <E extends Exchange, T> ValueBuilder<E> outBody(Class<T> type) {
077            Expression<E> expression = ExpressionBuilder.<E, T>bodyExpression(type);
078            return new ValueBuilder<E>(expression);
079        }
080    
081    
082        /**
083         * Returns an expression for the given system property
084         */
085        public static <E extends Exchange> ValueBuilder<E> systemProperty(final String name) {
086            return systemProperty(name, null);
087        }
088    
089        /**
090         * Returns an expression for the given system property
091         */
092        public static <E extends Exchange> ValueBuilder<E> systemProperty(final String name, final String defaultValue) {
093            return new ValueBuilder<E>(ExpressionBuilder.<E>systemProperty(name, defaultValue));
094        }
095    }