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.SocketAddress;
24
25 import org.apache.mina.transport.vmpipe.VmPipeAddress;
26 import org.springframework.util.Assert;
27
28 /**
29 * Java Bean {@link java.beans.PropertyEditor} which converts Strings into
30 * {@link VmPipeAddress} objects. Valid values specify an integer port number
31 * optionally prefixed with a ':'. E.g.: <code>:80</code>, <code>22</code>.
32 * <p>
33 * Use Spring's CustomEditorConfigurer to use this property editor in a Spring
34 * configuration file. See chapter 3.14 of the Spring Reference Documentation
35 * for more info.
36 * </p>
37 *
38 * @author The Apache Directory Project (mina-dev@directory.apache.org)
39 * @version $Revision: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (Fri, 13 Jul 2007) $
40 *
41 * @see org.apache.mina.transport.vmpipe.VmPipeAddress
42 */
43 public class VmPipeAddressEditor extends PropertyEditorSupport {
44 public void setAsText(String text) throws IllegalArgumentException {
45 setValue(parseSocketAddress(text));
46 }
47
48 private SocketAddress parseSocketAddress(String s) {
49 Assert.notNull(s, "null SocketAddress string");
50 s = s.trim();
51 if (s.startsWith(":")) {
52 s = s.substring(1);
53 }
54 try {
55 return new VmPipeAddress(Integer.parseInt(s.trim()));
56 } catch (NumberFormatException nfe) {
57 throw new IllegalArgumentException("Illegal vm pipe address: " + s);
58 }
59 }
60 }