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.transformer; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlType; 023 024import org.apache.camel.CamelContext; 025import org.apache.camel.Endpoint; 026import org.apache.camel.ExchangePattern; 027import org.apache.camel.impl.transformer.ProcessorTransformer; 028import org.apache.camel.processor.SendProcessor; 029import org.apache.camel.spi.Metadata; 030import org.apache.camel.spi.Transformer; 031 032/** 033 * Represents an endpoint {@link Transformer} which leverages camel {@link Endpoint} to 034 * perform transformation. A {@link ProcessorTransformer} will be created internally 035 * with a {@link SendProcessor} which forwards the message to the specified Endpoint. 036 * One of the Endpoint 'ref' or 'uri' needs to be specified. 037 * 038 * {@see TransformerDefinition} 039 * {@see ProcessorTransformer} 040 */ 041@Metadata(label = "transformation") 042@XmlType(name = "endpointTransformer") 043@XmlAccessorType(XmlAccessType.FIELD) 044public class EndpointTransformerDefinition extends TransformerDefinition { 045 046 @XmlAttribute 047 private String ref; 048 @XmlAttribute 049 private String uri; 050 051 @Override 052 protected Transformer doCreateTransformer(CamelContext context) throws Exception { 053 Endpoint endpoint = uri != null ? context.getEndpoint(uri) 054 : context.getRegistry().lookupByNameAndType(ref, Endpoint.class); 055 SendProcessor processor = new SendProcessor(endpoint, ExchangePattern.InOut); 056 return new ProcessorTransformer(context) 057 .setProcessor(processor) 058 .setModel(getScheme()) 059 .setFrom(getFromType()) 060 .setTo(getToType()); 061 } 062 063 public String getRef() { 064 return ref; 065 } 066 067 /** 068 * Set the reference of the Endpoint. 069 * 070 * @param ref reference of the Endpoint 071 */ 072 public void setRef(String ref) { 073 this.ref = ref; 074 } 075 076 public String getUri() { 077 return uri; 078 } 079 080 /** 081 * Set the URI of the Endpoint. 082 * 083 * @param uri URI of the Endpoint 084 */ 085 public void setUri(String uri) { 086 this.uri = uri; 087 } 088 089} 090