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: 751648 $
038 */
039 //@XmlType(name = "sendType")
040 @XmlAccessorType(XmlAccessType.FIELD)
041 public class SendDefinition<Type extends ProcessorDefinition> extends ProcessorDefinition<Type> {
042 @XmlAttribute(required = false)
043 protected String uri;
044 @XmlAttribute(required = false)
045 protected String ref;
046 @XmlTransient
047 protected 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 @SuppressWarnings("unchecked")
093 public List<ProcessorDefinition> getOutputs() {
094 return Collections.EMPTY_LIST;
095 }
096
097 /**
098 * Returns the endpoint URI or the name of the reference to it
099 */
100 public Object getUriOrRef() {
101 String uri = getUri();
102 if (ObjectHelper.isEmpty(uri)) {
103 return uri;
104 } else if (endpoint != null) {
105 return endpoint.getEndpointUri();
106 }
107 return getRef();
108 }
109
110 @Override
111 public String getLabel() {
112 return FromDefinition.description(getUri(), getRef(), getEndpoint());
113 }
114 }