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.XmlTransient; 023 024import org.apache.camel.Endpoint; 025import org.apache.camel.ExchangePattern; 026import org.apache.camel.builder.EndpointProducerBuilder; 027import org.apache.camel.spi.Metadata; 028 029/** 030 * Sends the message to an endpoint 031 */ 032@XmlAccessorType(XmlAccessType.FIELD) 033public abstract class SendDefinition<Type extends ProcessorDefinition<Type>> extends NoOutputDefinition<Type> implements EndpointRequiredDefinition { 034 @XmlAttribute 035 @Metadata(required = true) 036 protected String uri; 037 @XmlTransient 038 protected Endpoint endpoint; 039 @XmlTransient 040 protected EndpointProducerBuilder endpointProducerBuilder; 041 042 public SendDefinition() { 043 } 044 045 public SendDefinition(String uri) { 046 this.uri = uri; 047 } 048 049 @Override 050 public String getEndpointUri() { 051 if (endpointProducerBuilder != null) { 052 return endpointProducerBuilder.getUri(); 053 } else if (endpoint != null) { 054 return endpoint.getEndpointUri(); 055 } else { 056 return uri; 057 } 058 } 059 060 public String getUri() { 061 return uri; 062 } 063 064 /** 065 * Sets the uri of the endpoint to send to. 066 * 067 * @param uri the uri of the endpoint 068 */ 069 public void setUri(String uri) { 070 clear(); 071 this.uri = uri; 072 } 073 074 /** 075 * Gets the endpoint if an {@link Endpoint} instance was set. 076 * <p/> 077 * This implementation may return <tt>null</tt> which means you need to use 078 * {@link #getEndpointUri()} to get information about the endpoint. 079 * 080 * @return the endpoint instance, or <tt>null</tt> 081 */ 082 public Endpoint getEndpoint() { 083 return endpoint; 084 } 085 086 public void setEndpoint(Endpoint endpoint) { 087 clear(); 088 this.endpoint = endpoint; 089 this.uri = endpoint != null ? endpoint.getEndpointUri() : null; 090 } 091 092 public EndpointProducerBuilder getEndpointProducerBuilder() { 093 return endpointProducerBuilder; 094 } 095 096 public void setEndpointProducerBuilder(EndpointProducerBuilder endpointProducerBuilder) { 097 clear(); 098 this.endpointProducerBuilder = endpointProducerBuilder; 099 } 100 101 public ExchangePattern getPattern() { 102 return null; 103 } 104 105 @Override 106 public String getLabel() { 107 String uri = getEndpointUri(); 108 return uri != null ? uri : "no uri supplied"; 109 } 110 111 protected void clear() { 112 this.endpointProducerBuilder = null; 113 this.endpoint = null; 114 this.uri = null; 115 } 116}