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.cron; 018 019import java.util.HashMap; 020import java.util.Map; 021 022import org.apache.camel.CamelContext; 023import org.apache.camel.CamelContextAware; 024import org.apache.camel.Endpoint; 025import org.apache.camel.component.cron.api.CamelCronConfiguration; 026import org.apache.camel.component.cron.api.CamelCronService; 027 028/** 029 * Allows camel-spring to be used as implementation for camel-cron endpoints. 030 */ 031public class CamelSpringCronService implements CamelCronService, CamelContextAware { 032 033 private CamelContext context; 034 035 @Override 036 public Endpoint createEndpoint(CamelCronConfiguration configuration) throws Exception { 037 CronComponent cronComponent = context.getComponent("cron", CronComponent.class); 038 String uri = "cron:" + configuration.getName(); 039 SpringCronEndpoint cronEndpoint = new SpringCronEndpoint(uri, cronComponent); 040 Map<String, Object> options = new HashMap<>(); 041 options.put("scheduler", "spring"); 042 options.put("scheduler.cron", configuration.getSchedule()); 043 cronEndpoint.configureProperties(options); 044 return cronEndpoint; 045 } 046 047 @Override 048 public String getId() { 049 return "spring"; 050 } 051 052 @Override 053 public void setCamelContext(CamelContext camelContext) { 054 this.context = camelContext; 055 } 056 057 @Override 058 public CamelContext getCamelContext() { 059 return this.context; 060 } 061 062}