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.aws.s3;
018    
019    import java.util.Map;
020    
021    import org.apache.camel.CamelContext;
022    import org.apache.camel.Endpoint;
023    import org.apache.camel.impl.DefaultComponent;
024    
025    /**
026     * Defines the <a href="http://aws.amazon.com/s3/">AWS S3 Component</a> 
027     */
028    public class S3Component extends DefaultComponent {
029        
030        public S3Component() {
031            super();
032        }
033    
034        public S3Component(CamelContext context) {
035            super(context);
036        }
037    
038        protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
039            S3Configuration configuration = new S3Configuration();
040            setProperties(configuration, parameters);
041    
042            if (remaining == null || remaining.trim().length() == 0) {
043                throw new IllegalArgumentException("Bucket name must be specified.");
044            }
045            configuration.setBucketName(remaining);
046    
047            if (configuration.getAmazonS3Client() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
048                throw new IllegalArgumentException("AmazonS3Client or accessKey and secretKey must be specified");
049            }
050    
051            S3Endpoint endpoint = new S3Endpoint(uri, getCamelContext(), configuration);
052            return endpoint;
053        }
054    }