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.builder;
018    
019    import org.apache.camel.Exchange;
020    import org.apache.camel.Expression;
021    
022    /**
023     * A helper class for including portions of the <a
024     * href="http://activemq.apache.org/camel/expression.html">expression</a> and
025     * <a href="http://activemq.apache.org/camel/predicate.html">predicate</a> <a
026     * href="http://activemq.apache.org/camel/dsl.html">Java DSL</a>
027     * 
028     * @version $Revision: 1.1 $
029     */
030    public class Builder {
031        
032        /**
033         * Utility classes should not have a public constructor.
034         */
035        private Builder() {        
036        }
037    
038        /**
039         * Returns a constant expression
040         */
041        public static <E extends Exchange> ValueBuilder<E> constant(Object value) {
042            Expression<E> expression = ExpressionBuilder.constantExpression(value);
043            return new ValueBuilder<E>(expression);
044        }
045    
046        /**
047         * Returns a predicate and value builder for headers on an exchange
048         */
049        public static <E extends Exchange> ValueBuilder<E> header(String name) {
050            Expression<E> expression = ExpressionBuilder.headerExpression(name);
051            return new ValueBuilder<E>(expression);
052        }
053    
054        /**
055         * Returns a predicate and value builder for the inbound body on an exchange
056         */
057        public static <E extends Exchange> ValueBuilder<E> body() {
058            Expression<E> expression = ExpressionBuilder.bodyExpression();
059            return new ValueBuilder<E>(expression);
060        }
061    
062        /**
063         * Returns a predicate and value builder for the inbound message body as a
064         * specific type
065         */
066        public static <E extends Exchange, T> ValueBuilder<E> bodyAs(Class<T> type) {
067            Expression<E> expression = ExpressionBuilder.<E, T> bodyExpression(type);
068            return new ValueBuilder<E>(expression);
069        }
070    
071        /**
072         * Returns a predicate and value builder for the outbound body on an
073         * exchange
074         */
075        public static <E extends Exchange> ValueBuilder<E> outBody() {
076            Expression<E> expression = ExpressionBuilder.bodyExpression();
077            return new ValueBuilder<E>(expression);
078        }
079    
080        /**
081         * Returns a predicate and value builder for the outbound message body as a
082         * specific type
083         */
084        public static <E extends Exchange, T> ValueBuilder<E> outBody(Class<T> type) {
085            Expression<E> expression = ExpressionBuilder.<E, T> bodyExpression(type);
086            return new ValueBuilder<E>(expression);
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) {
093            return systemProperty(name, null);
094        }
095    
096        /**
097         * Returns an expression for the given system property
098         */
099        public static <E extends Exchange> ValueBuilder<E> systemProperty(final String name,
100                                                                          final String defaultValue) {
101            return new ValueBuilder<E>(ExpressionBuilder.<E> systemProperty(name, defaultValue));
102        }
103    }