1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.mina.integration.spring; 21 22 import java.beans.PropertyEditorSupport; 23 import java.net.InetAddress; 24 import java.net.UnknownHostException; 25 26 /** 27 * Java Bean {@link java.beans.PropertyEditor} which converts Strings into 28 * {@link InetAddress} objects. This may be used together with Spring to be able 29 * to set {@link InetAddress} bean properties, e.g. 30 * {@link org.apache.mina.filter.BlacklistFilter#setBlacklist(InetAddress[])}. 31 * Simply calls {@link InetAddress#getByName(java.lang.String)} when 32 * converting from a String. 33 * <p> 34 * Use Spring's CustomEditorConfigurer to use this property editor in a Spring 35 * configuration file. See chapter 3.14 of the Spring Reference Documentation 36 * for more info. 37 * </p> 38 * 39 * @author The Apache Directory Project (mina-dev@directory.apache.org) 40 * @version $Revision: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (금, 13 7월 2007) $ 41 * 42 * @see java.net.InetAddress 43 */ 44 public class InetAddressEditor extends PropertyEditorSupport { 45 public void setAsText(String text) throws IllegalArgumentException { 46 try { 47 setValue(InetAddress.getByName(text)); 48 } catch (UnknownHostException uhe) { 49 IllegalArgumentException iae = new IllegalArgumentException(); 50 iae.initCause(uhe); 51 } 52 } 53 } 54