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.component.ref; 018 019import org.apache.camel.Component; 020import org.apache.camel.Consumer; 021import org.apache.camel.DelegateEndpoint; 022import org.apache.camel.Endpoint; 023import org.apache.camel.Processor; 024import org.apache.camel.Producer; 025import org.apache.camel.impl.DefaultEndpoint; 026import org.apache.camel.spi.Metadata; 027import org.apache.camel.spi.UriEndpoint; 028import org.apache.camel.spi.UriPath; 029import org.apache.camel.util.CamelContextHelper; 030 031@UriEndpoint(scheme = "ref", title = "Ref", syntax = "ref:name", label = "core,endpoint") 032public class RefEndpoint extends DefaultEndpoint implements DelegateEndpoint { 033 034 private volatile Endpoint endpoint; 035 036 @UriPath @Metadata(required = "true") 037 private String name; 038 039 public RefEndpoint(String endpointUri, Component component) { 040 super(endpointUri, component); 041 } 042 043 public String getName() { 044 return name; 045 } 046 047 /** 048 * Name of endpoint to lookup in the registry. 049 */ 050 public void setName(String name) { 051 this.name = name; 052 } 053 054 @Override 055 public Producer createProducer() throws Exception { 056 return endpoint.createProducer(); 057 } 058 059 @Override 060 public Consumer createConsumer(Processor processor) throws Exception { 061 return endpoint.createConsumer(processor); 062 } 063 064 @Override 065 public boolean isSingleton() { 066 return true; 067 } 068 069 @Override 070 public Endpoint getEndpoint() { 071 return endpoint; 072 } 073 074 @Override 075 protected void doStart() throws Exception { 076 endpoint = CamelContextHelper.mandatoryLookup(getCamelContext(), name, Endpoint.class); 077 // add the endpoint as a service so Camel can manage the endpoint and enlist the endpoint in JMX etc. 078 getCamelContext().addService(endpoint); 079 super.doStart(); 080 } 081 082 @Override 083 protected void doStop() throws Exception { 084 super.doStop(); 085 // noop 086 } 087}