use std::any::Any;
use std::sync::Arc;
use crate::context::CamelContext;
use crate::error::{kinds, CamelError, Result};
use crate::spi::{Component, Endpoint};
use crate::util::Parameters;
#[derive(Default)]
pub struct RefComponent;
impl Component for RefComponent {
fn create_endpoint(&self, ctx: &CamelContext, _uri: &str, remaining: &str, _params: &mut Parameters) -> Result<Arc<dyn Endpoint>> {
let name = remaining.trim_start_matches('#');
if let Some(e) = ctx.registry().lookup::<Arc<dyn Endpoint>>(name) {
return Ok((*e).clone());
}
if let Some(uri) = ctx.registry().lookup::<String>(name) {
return ctx.get_endpoint(&uri);
}
Err(CamelError::new(kinds::NO_SUCH_ENDPOINT, format!("No bean could be found in the registry for: {} of type: Endpoint", name)))
}
fn as_any(&self) -> &dyn Any {
self
}
}