View Javadoc

1   /* $Id: ServletBean.java 1102402 2011-05-12 18:03:26Z simonetripodi $
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    * contributor license agreements.  See the NOTICE file distributed with
5    * this work for additional information regarding copyright ownership.
6    * The ASF licenses this file to You under the Apache License, Version 2.0
7    * (the "License"); you may not use this file except in compliance with
8    * 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, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.commons.digester3.annotations.servletbean;
19  
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  import org.apache.commons.digester3.annotations.rules.BeanPropertySetter;
24  import org.apache.commons.digester3.annotations.rules.CallMethod;
25  import org.apache.commons.digester3.annotations.rules.CallParam;
26  import org.apache.commons.digester3.annotations.rules.ObjectCreate;
27  
28  /**
29   * @since 2.1
30   */
31  @ObjectCreate( pattern = "web-app/servlet" )
32  public final class ServletBean
33  {
34  
35      private final Map<String, String> initParams = new HashMap<String, String>();
36  
37      @BeanPropertySetter( pattern = "web-app/servlet/servlet-name" )
38      private String servletName;
39  
40      @BeanPropertySetter( pattern = "web-app/servlet/servlet-class" )
41      private String servletClass;
42  
43      @CallMethod( pattern = "web-app/servlet/init-param" )
44      public void addInitParam( @CallParam( pattern = "web-app/servlet/init-param/param-name" ) String name,
45                                @CallParam( pattern = "web-app/servlet/init-param/param-value" ) String value )
46      {
47          this.initParams.put( name, value );
48      }
49  
50      public String getServletName()
51      {
52          return servletName;
53      }
54  
55      public void setServletName( String servletName )
56      {
57          this.servletName = servletName;
58      }
59  
60      public String getServletClass()
61      {
62          return servletClass;
63      }
64  
65      public void setServletClass( String servletClass )
66      {
67          this.servletClass = servletClass;
68      }
69  
70      public Map<String, String> getInitParams()
71      {
72          return initParams;
73      }
74  
75      @Override
76      public boolean equals( Object obj )
77      {
78          if ( this == obj )
79              return true;
80          if ( obj == null )
81              return false;
82          if ( getClass() != obj.getClass() )
83              return false;
84          ServletBean other = (ServletBean) obj;
85          if ( initParams == null )
86          {
87              if ( other.initParams != null )
88                  return false;
89          }
90          else if ( !initParams.equals( other.initParams ) )
91              return false;
92          if ( servletClass == null )
93          {
94              if ( other.servletClass != null )
95                  return false;
96          }
97          else if ( !servletClass.equals( other.servletClass ) )
98              return false;
99          if ( servletName == null )
100         {
101             if ( other.servletName != null )
102                 return false;
103         }
104         else if ( !servletName.equals( other.servletName ) )
105             return false;
106         return true;
107     }
108 
109     @Override
110     public String toString()
111     {
112         return "ServletBean [initParams=" + initParams + ", servletClass=" + servletClass + ", servletName="
113             + servletName + "]";
114     }
115 
116 }