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 javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlRootElement; 023import javax.xml.bind.annotation.XmlTransient; 024 025import org.apache.camel.ExchangePattern; 026import org.apache.camel.builder.EndpointProducerBuilder; 027import org.apache.camel.spi.Metadata; 028 029/** 030 * Sends the message to a dynamic endpoint 031 * <p/> 032 * You can specify multiple languages in the uri separated by the plus sign, 033 * such as <tt>mock:+language:xpath:/order/@uri</tt> where <tt>mock:</tt> would 034 * be a prefix to a xpath expression. 035 * <p/> 036 * For more dynamic behavior use 037 * <a href="http://camel.apache.org/recipient-list.html">Recipient List</a> or 038 * <a href="http://camel.apache.org/dynamic-router.html">Dynamic Router</a> EIP 039 * instead. 040 */ 041@Metadata(label = "eip,endpoint,routing") 042@XmlRootElement(name = "toD") 043@XmlAccessorType(XmlAccessType.FIELD) 044public class ToDynamicDefinition extends NoOutputDefinition<ToDynamicDefinition> { 045 046 @XmlTransient 047 protected EndpointProducerBuilder endpointProducerBuilder; 048 @XmlAttribute 049 @Metadata(required = true) 050 private String uri; 051 @XmlAttribute 052 private ExchangePattern pattern; 053 @XmlAttribute 054 private Integer cacheSize; 055 @XmlAttribute 056 private Boolean ignoreInvalidEndpoint; 057 @XmlAttribute 058 @Metadata(defaultValue = "true") 059 private Boolean allowOptimisedComponents; 060 061 public ToDynamicDefinition() { 062 } 063 064 public ToDynamicDefinition(String uri) { 065 this.uri = uri; 066 } 067 068 @Override 069 public String getShortName() { 070 return "toD"; 071 } 072 073 @Override 074 public String toString() { 075 return "DynamicTo[" + getLabel() + "]"; 076 } 077 078 @Override 079 public String getLabel() { 080 return uri; 081 } 082 083 // Fluent API 084 // ------------------------------------------------------------------------- 085 086 /** 087 * Sets the optional {@link ExchangePattern} used to invoke this endpoint 088 */ 089 public ToDynamicDefinition pattern(ExchangePattern pattern) { 090 setPattern(pattern); 091 return this; 092 } 093 094 /** 095 * Sets the maximum size used by the 096 * {@link org.apache.camel.spi.ConsumerCache} which is used to cache and 097 * reuse producers. 098 * 099 * @param cacheSize the cache size, use <tt>0</tt> for default cache size, 100 * or <tt>-1</tt> to turn cache off. 101 * @return the builder 102 */ 103 public ToDynamicDefinition cacheSize(int cacheSize) { 104 setCacheSize(cacheSize); 105 return this; 106 } 107 108 /** 109 * Ignore the invalidate endpoint exception when try to create a producer 110 * with that endpoint 111 * 112 * @return the builder 113 */ 114 public ToDynamicDefinition ignoreInvalidEndpoint() { 115 setIgnoreInvalidEndpoint(true); 116 return this; 117 } 118 119 /** 120 * Whether to allow components to optimise toD if they are 121 * {@link org.apache.camel.spi.SendDynamicAware}. 122 * 123 * @return the builder 124 */ 125 public ToDynamicDefinition allowOptimisedComponents(boolean allowOptimisedComponents) { 126 setAllowOptimisedComponents(allowOptimisedComponents); 127 return this; 128 } 129 130 // Properties 131 // ------------------------------------------------------------------------- 132 133 public String getUri() { 134 return uri; 135 } 136 137 /** 138 * The uri of the endpoint to send to. The uri can be dynamic computed using 139 * the {@link org.apache.camel.language.simple.SimpleLanguage} expression. 140 */ 141 public void setUri(String uri) { 142 this.uri = uri; 143 } 144 145 public EndpointProducerBuilder getEndpointProducerBuilder() { 146 return endpointProducerBuilder; 147 } 148 149 public void setEndpointProducerBuilder(EndpointProducerBuilder endpointProducerBuilder) { 150 this.endpointProducerBuilder = endpointProducerBuilder; 151 } 152 153 public ExchangePattern getPattern() { 154 return pattern; 155 } 156 157 public void setPattern(ExchangePattern pattern) { 158 this.pattern = pattern; 159 } 160 161 public Integer getCacheSize() { 162 return cacheSize; 163 } 164 165 public void setCacheSize(Integer cacheSize) { 166 this.cacheSize = cacheSize; 167 } 168 169 public Boolean getIgnoreInvalidEndpoint() { 170 return ignoreInvalidEndpoint; 171 } 172 173 public void setIgnoreInvalidEndpoint(Boolean ignoreInvalidEndpoint) { 174 this.ignoreInvalidEndpoint = ignoreInvalidEndpoint; 175 } 176 177 public Boolean getAllowOptimisedComponents() { 178 return allowOptimisedComponents; 179 } 180 181 public void setAllowOptimisedComponents(Boolean allowOptimisedComponents) { 182 this.allowOptimisedComponents = allowOptimisedComponents; 183 } 184 185}