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