001    /** 
002     * 
003     * Copyright 2004 Protique Ltd
004     * 
005     * Licensed under the Apache License, Version 2.0 (the "License"); 
006     * you may not use this file except in compliance with the License. 
007     * 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     **/
018    
019    package org.activemq.transport;
020    import org.activemq.io.WireFormat;
021    import org.activemq.io.WireFormatLoader;
022    import org.activemq.util.BeanUtils;
023    import org.activemq.util.URIHelper;
024    import java.net.URI;
025    import java.util.Map;
026    import javax.jms.JMSException;
027    
028    /**
029     * Useful for implementation inheritence
030     * 
031     * @version $Revision: 1.1.1.1 $
032     */
033    public abstract class TransportChannelFactorySupport implements TransportChannelFactory {
034    
035        /**
036         * If a query string is present in the URI then set any simple bean properties on the channel
037         * 
038         * @param channel
039         * @param uri
040         * @return the channel, with properties set
041         * @throws JMSException
042         */
043        protected TransportChannel populateProperties(TransportChannel channel, URI uri) throws JMSException {
044            Map properties = URIHelper.parseQuery(uri);
045            return populateProperties(channel, properties);
046        }
047    
048        /**
049         * If a query string is present in the URI then set any simple bean properties on the channel
050         *
051         * @param channel
052         * @param uri
053         * @return the channel, with properties set
054         * @throws JMSException
055         */
056        protected TransportChannel populateProperties(TransportChannel channel, String uri) throws JMSException {
057            Map properties = URIHelper.parseQuery(uri);
058            return populateProperties(channel, properties);
059        }
060    
061    
062        protected TransportChannel populateProperties(TransportChannel channel, Map properties) throws JMSException {
063            String wireFormatName = (String) properties.remove("wireFormat");
064            if (wireFormatName != null) {
065                wireFormatName = wireFormatName.trim();
066                if (wireFormatName.length() > 0) {
067                    WireFormat wf = WireFormatLoader.getWireFormat(wireFormatName);
068                    if (wf != null) {
069                        channel.setWireFormat(wf);
070                    }
071                }
072            }
073            if (!properties.isEmpty()) {
074                BeanUtils.populate(channel, properties);
075            }
076            return channel;
077        }
078    }