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