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.model; 018 019 import java.util.Collections; 020 import java.util.List; 021 022 import javax.xml.bind.annotation.XmlAccessType; 023 import javax.xml.bind.annotation.XmlAccessorType; 024 import javax.xml.bind.annotation.XmlAttribute; 025 import javax.xml.bind.annotation.XmlTransient; 026 027 import org.apache.camel.Endpoint; 028 import org.apache.camel.ExchangePattern; 029 import org.apache.camel.Processor; 030 import org.apache.camel.processor.SendProcessor; 031 import org.apache.camel.spi.RouteContext; 032 import org.apache.camel.util.ObjectHelper; 033 034 /** 035 * Base class for sending to an endpoint with an optional {@link ExchangePattern} 036 * 037 * @version $Revision: 2227 $ 038 */ 039 //@XmlType(name = "sendType") 040 @XmlAccessorType(XmlAccessType.FIELD) 041 public class SendType<Type extends ProcessorType> extends ProcessorType<Type> { 042 @XmlAttribute(required = false) 043 private String uri; 044 @XmlAttribute(required = false) 045 private String ref; 046 @XmlTransient 047 private Endpoint endpoint; 048 049 @Override 050 public Processor createProcessor(RouteContext routeContext) throws Exception { 051 Endpoint endpoint = resolveEndpoint(routeContext); 052 return new SendProcessor(endpoint, getPattern()); 053 } 054 055 public Endpoint resolveEndpoint(RouteContext context) { 056 if (endpoint == null) { 057 endpoint = context.resolveEndpoint(getUri(), getRef()); 058 } 059 return endpoint; 060 } 061 062 // Properties 063 // ----------------------------------------------------------------------- 064 public String getRef() { 065 return ref; 066 } 067 068 public void setRef(String ref) { 069 this.ref = ref; 070 } 071 072 public String getUri() { 073 return uri; 074 } 075 076 public void setUri(String uri) { 077 this.uri = uri; 078 } 079 080 public Endpoint getEndpoint() { 081 return endpoint; 082 } 083 084 public void setEndpoint(Endpoint endpoint) { 085 this.endpoint = endpoint; 086 } 087 088 public ExchangePattern getPattern() { 089 return null; 090 } 091 092 public List<ProcessorType<?>> getOutputs() { 093 return Collections.EMPTY_LIST; 094 } 095 096 /** 097 * Returns the endpoint URI or the name of the reference to it 098 */ 099 public Object getUriOrRef() { 100 String uri = getUri(); 101 if (ObjectHelper.isEmpty(uri)) { 102 return uri; 103 } else if (endpoint != null) { 104 return endpoint.getEndpointUri(); 105 } 106 return getRef(); 107 } 108 109 @Override 110 public String getLabel() { 111 return FromType.description(getUri(), getRef(), getEndpoint()); 112 } 113 }