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.mail;
018
019 import java.net.URI;
020 import java.util.Map;
021
022 import org.apache.camel.CamelContext;
023 import org.apache.camel.Endpoint;
024 import org.apache.camel.impl.DefaultComponent;
025 import org.apache.camel.util.IntrospectionSupport;
026
027 /**
028 * @version $Revision:520964 $
029 */
030 public class MailComponent extends DefaultComponent<MailExchange> {
031 private MailConfiguration configuration;
032
033 public MailComponent() {
034 this.configuration = new MailConfiguration();
035 }
036
037 public MailComponent(MailConfiguration configuration) {
038 this.configuration = configuration;
039 }
040
041 public MailComponent(CamelContext context) {
042 super(context);
043 this.configuration = new MailConfiguration();
044 }
045
046 /**
047 * Static builder method
048 */
049 public static MailComponent mailComponent() {
050 return new MailComponent();
051 }
052
053 /**
054 * Static builder method
055 */
056 public static MailComponent mailComponent(MailConfiguration configuration) {
057 return new MailComponent(configuration);
058 }
059
060 @Override
061 protected Endpoint<MailExchange> createEndpoint(String uri, String remaining, Map parameters) throws Exception {
062
063 MailConfiguration config = getConfiguration().copy();
064 config.configure(new URI(uri));
065
066 // lets make sure we copy the configuration as each endpoint can customize its own version
067 MailEndpoint endpoint = new MailEndpoint(uri, this, config);
068
069 IntrospectionSupport.setProperties(endpoint.getConfiguration(), parameters);
070 return endpoint;
071 }
072
073 public MailConfiguration getConfiguration() {
074 return configuration;
075 }
076
077 /**
078 * Sets the Mail configuration
079 *
080 * @param configuration the configuration to use by default for endpoints
081 */
082 public void setConfiguration(MailConfiguration configuration) {
083 this.configuration = configuration;
084 }
085
086 /**
087 * A strategy method allowing the URI destination to be translated into the actual Mail destination name
088 * (say by looking up in JNDI or something)
089 */
090 protected String convertPathToActualDestination(String path) {
091 return path;
092 }
093 }