View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Chris Henson <chenson42@users.sourceforge.net>,
5    *               Keith Naas <knaas@users.sourceforge.net>
6    *
7    * This library is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU Lesser General Public
9    * License as published by the Free Software Foundation; either
10   * version 3 of the License, or (at your option) any later version.
11   *
12   * This library is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this library; if not, see
19   * <http://www.gnu.org/licenses/>.
20   */
21  package org.jumpmind.symmetric.web;
22  
23  import javax.servlet.Filter;
24  import javax.servlet.FilterConfig;
25  import javax.servlet.ServletException;
26  
27  import org.apache.commons.logging.Log;
28  import org.jumpmind.symmetric.ext.IExtensionPoint;
29  import org.jumpmind.symmetric.transport.ITransportResource;
30  import org.springframework.beans.BeanUtils;
31  
32  /***
33   * All symmetric filters (other than {@link SymmetricFilter}) should extend
34   * this class. It is managed by Spring.
35   * 
36   * @since 1.4.0
37   */
38  public abstract class AbstractFilter extends ServletResourceTemplate implements Filter, IExtensionPoint {
39  
40      protected abstract Log getLogger();
41  
42      public void init(FilterConfig filterConfig) throws ServletException {
43          init(filterConfig.getServletContext());
44          if (isContainerCompatible() && !this.isSpringManaged()) {
45              final IServletResource springBean = getSpringBean();
46              if (this != springBean) { // this != is deliberate!
47                  if (getLogger().isInfoEnabled()) {
48                      getLogger().info(String.format("Initializing filter %s", springBean.getClass().getSimpleName()));
49                  }
50                  BeanUtils.copyProperties(springBean, this, IServletResource.class);
51                  BeanUtils.copyProperties(springBean, this, ITransportResource.class);
52                  BeanUtils.copyProperties(springBean, this, this.getClass());
53                  this.refresh();
54              }
55          }
56      }
57      
58      public boolean isAutoRegister() {
59          return true;
60      }
61  }