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.net.SocketAddress;
23
24 import org.apache.mina.common.IoAcceptor;
25 import org.apache.mina.common.IoHandler;
26 import org.apache.mina.common.IoServiceConfig;
27 import org.springframework.beans.factory.InitializingBean;
28 import org.springframework.util.Assert;
29
30 /**
31 * Defines an address to {@link IoHandler} binding.
32 * This is used when specifying the addresses to accept new connections on when
33 * creating {@link org.apache.mina.common.IoAcceptor} objects using
34 * {@link IoAcceptorFactoryBean}.
35 * <p>
36 * Note that the <code>address</code> property is of {@link java.net.SocketAddress}
37 * type. Use {@link InetSocketAddressEditor} or {@link VmPipeAddressEditor} in
38 * your Spring configuration file to simply the creation of
39 * {@link java.net.SocketAddress} instances using Spring.
40 * </p>
41 * <p>
42 * This class also allows for an optional service configuration using
43 * {@link #setServiceConfig(IoServiceConfig)} to be specified. If the binding
44 * specifies an {@link IoServiceConfig} {@link IoAcceptorFactoryBean} will
45 * use {@link IoAcceptor#bind(SocketAddress, IoHandler, IoServiceConfig)} instead
46 * of {@link IoAcceptor#bind(SocketAddress, IoHandler)} when binding. The
47 * {@link IoServiceConfig} object lets you specify transport specific
48 * confiuration options and define port specific filters. This makes it possible
49 * to specify different filters depending on the port the client is connecting
50 * on (e.g. using an {@link org.apache.mina.filter.SSLFilter} when connecting
51 * on port 443 but not on port 80).
52 * </p>
53 *
54 * @author The Apache Directory Project (mina-dev@directory.apache.org)
55 * @version $Rev: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (Fri, 13 Jul 2007) $
56 */
57 public class Binding implements InitializingBean {
58 private SocketAddress address = null;
59
60 private IoHandler handler = null;
61
62 private IoServiceConfig serviceConfig = null;
63
64 /**
65 * Creates a new empty instance.
66 */
67 public Binding() {
68 }
69
70 /**
71 * Creates a new instance using the specified values.
72 *
73 * @param address the address.
74 * @param handler the handler.
75 * @throws IllegalArgumentException if the any of the specified values are
76 * <code>null</code>.
77 */
78 public Binding(SocketAddress address, IoHandler handler) {
79 setAddress(address);
80 setHandler(handler);
81 }
82
83 /**
84 * Creates a new instance using the specified values.
85 *
86 * @param address the address.
87 * @param handler the handler.
88 * @param serviceConfig the service configuration.
89 * @throws IllegalArgumentException if the any of the specified values are
90 * <code>null</code>.
91 */
92 public Binding(SocketAddress address, IoHandler handler,
93 IoServiceConfig serviceConfig) {
94 setAddress(address);
95 setHandler(handler);
96 setServiceConfig(serviceConfig);
97 }
98
99 /**
100 * Returns the address the handler of this object will be bound to.
101 *
102 * @return the address.
103 */
104 public SocketAddress getAddress() {
105 return address;
106 }
107
108 /**
109 * Sets the address the handler of this object will be bound to.
110 *
111 * @param address the address.
112 * @throws IllegalArgumentException if the specified value is
113 * <code>null</code>.
114 */
115 public void setAddress(SocketAddress address) {
116 Assert.notNull(address, "Property 'address' may not be null");
117 this.address = address;
118 }
119
120 /**
121 * Returns the handler of this binding object.
122 *
123 * @return the handler.
124 */
125 public IoHandler getHandler() {
126 return handler;
127 }
128
129 /**
130 * Sets the handler of this binding object.
131 *
132 * @param handler the handler.
133 * @throws IllegalArgumentException if the specified value is
134 * <code>null</code>.
135 */
136 public void setHandler(IoHandler handler) {
137 Assert.notNull(handler, "Property 'handler' may not be null");
138 this.handler = handler;
139 }
140
141 public IoServiceConfig getServiceConfig() {
142 return serviceConfig;
143 }
144
145 public void setServiceConfig(IoServiceConfig serviceConfig) {
146 this.serviceConfig = serviceConfig;
147 }
148
149 public void afterPropertiesSet() throws Exception {
150 Assert.notNull(address, "Property 'address' may not be null");
151 Assert.notNull(handler, "Property 'handler' may not be null");
152 }
153
154 }