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