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://camel.apache.org/expression.html">expression</a> and 025 * <a href="http://camel.apache.org/predicate.html">predicate</a> <a 026 * href="http://camel.apache.org/dsl.html">Java DSL</a> 027 * 028 * @version $Revision: 746225 $ 029 */ 030 public final class Builder { 031 032 /** 033 * Utility classes should not have a public constructor. 034 */ 035 private Builder() { 036 } 037 038 /** 039 * Returns a <a href="http://camel.apache.org/bean-language.html">bean expression</a> 040 * value builder 041 * 042 * @param beanRef reference to bean to lookup in the Registry 043 * @return the builder 044 */ 045 public static ValueBuilder bean(String beanRef) { 046 Expression expression = ExpressionBuilder.beanExpression(beanRef); 047 return new ValueBuilder(expression); 048 } 049 050 /** 051 * Returns a <a href="http://camel.apache.org/bean-language.html">bean expression</a> 052 * value builder 053 * 054 * @param beanRef reference to bean to lookup in the Registry 055 * @param method name of method to invoke 056 * @return the builder 057 */ 058 public static ValueBuilder bean(String beanRef, String method) { 059 Expression expression = ExpressionBuilder.beanExpression(beanRef, method); 060 return new ValueBuilder(expression); 061 } 062 063 /** 064 * Returns a constant expression 065 */ 066 public static ValueBuilder constant(Object value) { 067 Expression expression = ExpressionBuilder.constantExpression(value); 068 return new ValueBuilder(expression); 069 } 070 071 /** 072 * Returns a predicate and value builder for headers on an exchange 073 */ 074 public static ValueBuilder header(String name) { 075 Expression expression = ExpressionBuilder.headerExpression(name); 076 return new ValueBuilder(expression); 077 } 078 079 /** 080 * Returns a predicate and value builder for properties on an exchange 081 */ 082 public static ValueBuilder property(String name) { 083 Expression expression = ExpressionBuilder.propertyExpression(name); 084 return new ValueBuilder(expression); 085 } 086 087 /** 088 * Returns a predicate and value builder for the inbound body on an exchange 089 */ 090 public static ValueBuilder body() { 091 Expression expression = ExpressionBuilder.bodyExpression(); 092 return new ValueBuilder(expression); 093 } 094 095 /** 096 * Returns a predicate and value builder for the inbound message body as a 097 * specific type 098 */ 099 public static <E extends Exchange, T> ValueBuilder bodyAs(Class<T> type) { 100 Expression expression = ExpressionBuilder.bodyExpression(type); 101 return new ValueBuilder(expression); 102 } 103 104 /** 105 * Returns a predicate and value builder for the outbound body on an 106 * exchange 107 */ 108 public static ValueBuilder outBody() { 109 Expression expression = ExpressionBuilder.outBodyExpression(); 110 return new ValueBuilder(expression); 111 } 112 113 /** 114 * Returns a predicate and value builder for the outbound message body as a 115 * specific type 116 */ 117 public static <E extends Exchange, T> ValueBuilder outBodyAs(Class<T> type) { 118 Expression expression = ExpressionBuilder.outBodyExpression(type); 119 return new ValueBuilder(expression); 120 } 121 122 /** 123 * Returns a predicate and value builder for the fault body on an 124 * exchange 125 */ 126 public static ValueBuilder faultBody() { 127 Expression expression = ExpressionBuilder.faultBodyExpression(); 128 return new ValueBuilder(expression); 129 } 130 131 /** 132 * Returns a predicate and value builder for the fault message body as a 133 * specific type 134 */ 135 public static <E extends Exchange, T> ValueBuilder faultBodyAs(Class<T> type) { 136 Expression expression = ExpressionBuilder.faultBodyExpression(type); 137 return new ValueBuilder(expression); 138 } 139 140 /** 141 * Returns an expression for the given system property 142 */ 143 public static ValueBuilder systemProperty(final String name) { 144 return systemProperty(name, null); 145 } 146 147 /** 148 * Returns an expression for the given system property 149 */ 150 public static ValueBuilder systemProperty(final String name, final String defaultValue) { 151 return new ValueBuilder(ExpressionBuilder.systemPropertyExpression(name, defaultValue)); 152 } 153 154 /** 155 * Returns a predicate and value builder for the exception message on an exchange 156 */ 157 public static ValueBuilder exceptionMessage() { 158 Expression expression = ExpressionBuilder.exchangeExceptionMessageExpression(); 159 return new ValueBuilder(expression); 160 } 161 162 /** 163 * Returns an expression that replaces all occurrences of the regular 164 * expression with the given replacement 165 */ 166 public static ValueBuilder regexReplaceAll(Expression content, String regex, String replacement) { 167 Expression newExp = ExpressionBuilder.regexReplaceAll(content, regex, replacement); 168 return new ValueBuilder(newExp); 169 } 170 171 /** 172 * Returns an expression that replaces all occurrences of the regular 173 * expression with the given replacement 174 */ 175 public static ValueBuilder regexReplaceAll(Expression content, String regex, Expression replacement) { 176 Expression newExp = ExpressionBuilder.regexReplaceAll(content, regex, replacement); 177 return new ValueBuilder(newExp); 178 } 179 }