001 /**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements. See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.camel.component.file.remote;
019
020 import org.apache.camel.CamelContext;
021 import org.apache.camel.RuntimeCamelException;
022 import org.apache.camel.impl.DefaultComponent;
023 import org.apache.camel.util.IntrospectionSupport;
024
025 import java.net.URI;
026 import java.util.Map;
027
028 public class RemoteFileComponent extends DefaultComponent<RemoteFileExchange> {
029 private RemoteFileConfiguration configuration;
030
031 public RemoteFileComponent() {
032 this.configuration = new RemoteFileConfiguration();
033 }
034
035 public RemoteFileComponent(RemoteFileConfiguration configuration) {
036 this.configuration = configuration;
037 }
038
039 public RemoteFileComponent(CamelContext context) {
040 super(context);
041 this.configuration = new RemoteFileConfiguration();
042 }
043
044 public static RemoteFileComponent remoteFileComponent() {
045 return new RemoteFileComponent();
046 }
047
048 protected RemoteFileEndpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
049 RemoteFileConfiguration config = getConfiguration().copy();
050 config.configure(new URI(uri));
051
052 // lets make sure we copy the configuration as each endpoint can customize its own version
053 final RemoteFileEndpoint endpoint;
054 if ("ftp".equals(config.getProtocol())) {
055 endpoint = new FtpEndpoint(uri, this, config);
056 }
057 else if ("sftp".equals(config.getProtocol())) {
058 endpoint = new SftpEndpoint(uri, this, config);
059 }
060 else {
061 throw new RuntimeCamelException("Unsupported protocol: " + config.getProtocol());
062 }
063
064 IntrospectionSupport.setProperties(endpoint.getConfiguration(), parameters);
065 return endpoint;
066 }
067
068 public RemoteFileConfiguration getConfiguration() {
069 return configuration;
070 }
071
072 public void setConfiguration(RemoteFileConfiguration configuration) {
073 this.configuration = configuration;
074 }
075 }