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.file.remote;
018
019 import java.net.URI;
020 import java.util.Map;
021
022 import org.apache.camel.CamelContext;
023 import org.apache.camel.RuntimeCamelException;
024 import org.apache.camel.impl.DefaultComponent;
025 import org.apache.camel.util.IntrospectionSupport;
026
027 public class RemoteFileComponent extends DefaultComponent<RemoteFileExchange> {
028 private RemoteFileConfiguration configuration;
029
030 public RemoteFileComponent() {
031 this.configuration = new RemoteFileConfiguration();
032 }
033
034 public RemoteFileComponent(RemoteFileConfiguration configuration) {
035 this.configuration = configuration;
036 }
037
038 public RemoteFileComponent(CamelContext context) {
039 super(context);
040 this.configuration = new RemoteFileConfiguration();
041 }
042
043 public String toString() {
044 return "RemoteFileComponent";
045 }
046
047 public static RemoteFileComponent remoteFileComponent() {
048 return new RemoteFileComponent();
049 }
050
051 protected RemoteFileEndpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
052 RemoteFileConfiguration config = getConfiguration().copy();
053 config.configure(new URI(uri));
054
055 // lets make sure we copy the configuration as each endpoint can
056 // customize its own version
057 final RemoteFileEndpoint endpoint;
058 if ("ftp".equals(config.getProtocol())) {
059 endpoint = new FtpEndpoint(uri, this, config);
060 } else if ("sftp".equals(config.getProtocol())) {
061 endpoint = new SftpEndpoint(uri, this, config);
062 } else {
063 throw new RuntimeCamelException("Unsupported protocol: " + config.getProtocol());
064 }
065
066 IntrospectionSupport.setProperties(endpoint.getConfiguration(), parameters);
067 return endpoint;
068 }
069
070 public RemoteFileConfiguration getConfiguration() {
071 return configuration;
072 }
073
074 public void setConfiguration(RemoteFileConfiguration configuration) {
075 this.configuration = configuration;
076 }
077 }