View Javadoc

    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 org.apache.mina.common.IoFilter;
    23  import org.springframework.beans.factory.InitializingBean;
    24  import org.springframework.util.Assert;
    25
    26  /**
    27   * Associates a name with an {@link IoFilter}. This makes it possible to configure
    28   * named filters using Spring.
    29   * <p>
    30   * Use this class when you want to configure the
    31   * filters added to the filter chain of all sessions created from a particular
    32   * {@link org.apache.mina.common.IoService} created using one of the
    33   * {@link org.apache.mina.integration.spring.IoAcceptorFactoryBean}
    34   * sub-classes but you don't want the names to be generated automatically.
    35   * </p>
    36   * <p>
    37   * This class can also be used when creating {@link Binding} objects. This lets
    38   * one configure per-port filters. These filters will only be added to the
    39   * filter chain of sessions for incoming connections on the port specified by
    40   * the {@link Binding}. Note that {@link Binding} can also be configured to
    41   * generate filter names automatically. In that case you add the {@link IoFilter}
    42   * instances directly to the {@link Binding}.
    43   * </p>
    44   *
    45   * @author The Apache Directory Project (mina-dev@directory.apache.org)
    46   * @version $Rev: 555855 $, $Date: 2007-07-13 05:19:00 +0200 (Fri, 13 Jul 2007) $
    47   *
    48   * @see org.apache.mina.integration.spring.IoAcceptorFactoryBean
    49   * @see org.apache.mina.integration.spring.Binding
    50   */
    51  public class IoFilterMapping implements InitializingBean {
    52      private String name = null;
    53
    54      private IoFilter filter = null;
    55
    56      /**
    57       * Creates a new empty instance.
    58       */
    59      public IoFilterMapping() {
    60      }
    61
    62      /**
    63       * Creates a new instance using the specified name and filter.
    64       *
    65       * @param name the name.
    66       * @param filter the filter.
    67       * @throws IllegalArgumentException if any of the arguments are
    68       *         <code>null</code>.
    69       */
    70      public IoFilterMapping(String name, IoFilter filter) {
    71          Assert.notNull(name, "Argument 'name' may not be null");
    72          Assert.notNull(filter, "Argument 'filter' may not be null");
    73
    74          this.name = name;
    75          this.filter = filter;
    76      }
    77
    78      /**
    79       * Returns the filter of this mapping.
    80       *
    81       * @return the filter.
    82       */
    83      public IoFilter getFilter() {
    84          return filter;
    85      }
    86
    87      /**
    88       * Returns the name associated with the filter.
    89       *
    90       * @return the name.
    91       */
    92      public String getName() {
    93          return name;
    94      }
    95
    96      /**
    97       * Sets the filter of this mapping.
    98       *
    99       * @param filter the filter.
    100      * @throws IllegalArgumentException if the specified value is
    101      *         <code>null</code>.
    102      */
    103     public void setFilter(IoFilter filter) {
    104         Assert.notNull(filter, "Argument 'filter' may not be null");
    105         this.filter = filter;
    106     }
    107
    108     /**
    109      * Sets the name associated with the filter.
    110      *
    111      * @param name the name.
    112      * @throws IllegalArgumentException if the specified value is
    113      *         <code>null</code>.
    114      */
    115     public void setName(String name) {
    116         Assert.notNull(name, "Argument 'name' may not be null");
    117         this.name = name;
    118     }
    119
    120     public void afterPropertiesSet() throws Exception {
    121         Assert.notNull(name, "Argument 'name' may not be null");
    122         Assert.notNull(filter, "Argument 'filter' may not be null");
    123     }
    124 }