001/*
002 *   Licensed to the Apache Software Foundation (ASF) under one
003 *   or more contributor license agreements.  See the NOTICE file
004 *   distributed with this work for additional information
005 *   regarding copyright ownership.  The ASF licenses this file
006 *   to you under the Apache License, Version 2.0 (the
007 *   "License"); you may not use this file except in compliance
008 *   with 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,
013 *   software distributed under the License is distributed on an
014 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *   KIND, either express or implied.  See the License for the
016 *   specific language governing permissions and limitations
017 *   under the License.
018 *
019 */
020package org.apache.mina.integration.xbean;
021
022import java.beans.PropertyEditor;
023import java.net.InetAddress;
024import java.net.InetSocketAddress;
025import java.net.SocketAddress;
026
027import org.apache.mina.integration.beans.InetAddressEditor;
028import org.apache.mina.integration.beans.InetSocketAddressEditor;
029import org.apache.mina.integration.beans.VmPipeAddressEditor;
030import org.apache.mina.transport.vmpipe.VmPipeAddress;
031import org.springframework.beans.PropertyEditorRegistrar;
032import org.springframework.beans.PropertyEditorRegistry;
033
034/**
035 * A custom Spring {@link PropertyEditorRegistrar} implementation which 
036 * registers by default all the {@link PropertyEditor} implementations in the 
037 * MINA Integration Beans module.
038 *
039 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
040 */
041public class MinaPropertyEditorRegistrar implements PropertyEditorRegistrar {
042    /**
043     * Registers custom {@link PropertyEditor}s in the MINA Integration Beans
044     * module.
045     * 
046     * Note: I did not know just how useful the rest of the property editors 
047     * were or if they were redundant and replicated existing functionality of
048     * default editors packaged into Spring.  So presently we're only 
049     * registering editors for the following classes which are not found in
050     * Spring:
051     * 
052     * <ul>
053     *   <li>java.net.InetAddress</li>
054     *   <li>java.net.InetSocketAddress</li>
055     *   <li>org.apache.mina.core.session.TrafficMask</li>
056     *   <li>org.apache.mina.integration.beans.VmPipeAddressEditor</li>
057     * </ul>
058     * 
059     * @see PropertyEditorRegistrar#registerCustomEditors(PropertyEditorRegistry)
060     */
061    public void registerCustomEditors(PropertyEditorRegistry registry) {
062        // it is expected that new PropertyEditor instances are created
063        registry.registerCustomEditor(InetAddress.class, new InetAddressEditor());
064        registry.registerCustomEditor(InetSocketAddress.class, new InetSocketAddressEditor());
065        registry.registerCustomEditor(SocketAddress.class, new InetSocketAddressEditor());
066        registry.registerCustomEditor(VmPipeAddress.class, new VmPipeAddressEditor());
067    }
068}