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.component;
018
019 import org.apache.camel.impl.DefaultComponent;
020 import org.slf4j.Logger;
021 import org.slf4j.LoggerFactory;
022 import org.springframework.core.io.Resource;
023 import org.springframework.core.io.ResourceLoader;
024
025 /**
026 * A useful base class for components which depend on a resource
027 * such as things like Velocity or XQuery based components.
028 *
029 * @deprecated use {@link DefaultComponent}. Will be removed in Camel 3.0.
030 */
031 @Deprecated
032 public abstract class ResourceBasedComponent extends DefaultComponent {
033 protected final transient Logger log = LoggerFactory.getLogger(getClass());
034 private ResourceLoader resourceLoader;
035
036 public ResourceLoader getResourceLoader() {
037 if (resourceLoader == null) {
038 resourceLoader = new CamelResourceLoader(getCamelContext());
039 }
040 return resourceLoader;
041 }
042
043 public void setResourceLoader(ResourceLoader resourceLoader) {
044 this.resourceLoader = resourceLoader;
045 }
046
047 protected Resource resolveMandatoryResource(String uri) {
048 Resource resource = getResourceLoader().getResource(uri);
049 if (resource == null) {
050 throw new IllegalArgumentException("Could not find resource for URI: " + uri + " using: " + getResourceLoader());
051 } else {
052 return resource;
053 }
054 }
055
056 }