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.smpp;
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 
029     */
030    public class SmppComponent extends DefaultComponent {
031    
032        private SmppConfiguration configuration;
033    
034        public SmppComponent() {
035        }
036    
037        public SmppComponent(SmppConfiguration configuration) {
038            this.configuration = configuration;
039        }
040    
041        public SmppComponent(CamelContext context) {
042            super(context);
043        }
044    
045        @SuppressWarnings({ "unchecked", "rawtypes" })
046        @Override
047        protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
048            if (this.configuration == null) {
049                this.configuration = new SmppConfiguration();
050            }
051    
052            // create a copy of the configuration as other endpoints can adjust their copy as well
053            SmppConfiguration config = this.configuration.copy();
054    
055            config.configureFromURI(new URI(uri));
056            if (getCamelContext() != null) {
057                IntrospectionSupport.setProperties(getCamelContext().getTypeConverter(), config, parameters);
058            } else {
059                IntrospectionSupport.setProperties(config, parameters);
060            }
061    
062            return createEndpoint(uri, config);
063        }
064    
065        /**
066         * Create a new smpp endpoint with the provided smpp configuration
067         */
068        protected Endpoint createEndpoint(SmppConfiguration config) throws Exception {
069            return createEndpoint(null, config);
070        }
071    
072        /**
073         * Create a new smpp endpoint with the provided uri and smpp configuration
074         */
075        protected Endpoint createEndpoint(String uri, SmppConfiguration config) throws Exception {
076            return new SmppEndpoint(uri, this, config);
077        }
078    
079        public SmppConfiguration getConfiguration() {
080            return configuration;
081        }
082    
083        public void setConfiguration(SmppConfiguration configuration) {
084            this.configuration = configuration;
085        }
086    }