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.spring.spi;
018    
019    import java.io.File;
020    import java.io.IOException;
021    import java.io.InputStream;
022    import java.net.URL;
023    
024    import org.aopalliance.intercept.MethodInvocation;
025    
026    import org.apache.camel.Converter;
027    import org.apache.camel.component.bean.BeanInvocation;
028    
029    import org.springframework.core.io.ByteArrayResource;
030    import org.springframework.core.io.FileSystemResource;
031    import org.springframework.core.io.Resource;
032    import org.springframework.core.io.UrlResource;
033    
034    
035    /**
036     * Some Spring based
037     * <a href="http://activemq.apache.org/camel/type-converter.html">Type Converters</a>
038     *
039     * @version $Revision: 630591 $
040     */
041    @Converter
042    public final class SpringConverters {
043        
044        private SpringConverters() {        
045        }
046        
047        @Converter
048        public static InputStream toInputStream(Resource resource) throws IOException {
049            return resource.getInputStream();
050        }
051    
052        @Converter
053        public static File toFile(Resource resource) throws IOException {
054            return resource.getFile();
055        }
056    
057        @Converter
058        public static URL toUrl(Resource resource) throws IOException {
059            return resource.getURL();
060        }
061    
062        @Converter
063        public static UrlResource toResource(String uri) throws IOException {
064            return new UrlResource(uri);
065        }
066    
067        @Converter
068        public static UrlResource toResource(URL uri) throws IOException {
069            return new UrlResource(uri);
070        }
071    
072        @Converter
073        public static FileSystemResource toResource(File file) throws IOException {
074            return new FileSystemResource(file);
075        }
076    
077        @Converter
078        public static ByteArrayResource toResource(byte[] data) throws IOException {
079            return new ByteArrayResource(data);
080        }
081    
082        @Converter
083        public static BeanInvocation toBeanInvocation(MethodInvocation invocation) {
084            return new BeanInvocation(invocation.getMethod(), invocation.getArguments());
085        }
086    }