001/* $Id: ServletBean.java 1102402 2011-05-12 18:03:26Z simonetripodi $ 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.commons.digester3.annotations.servletbean; 019 020import java.util.HashMap; 021import java.util.Map; 022 023import org.apache.commons.digester3.annotations.rules.BeanPropertySetter; 024import org.apache.commons.digester3.annotations.rules.CallMethod; 025import org.apache.commons.digester3.annotations.rules.CallParam; 026import org.apache.commons.digester3.annotations.rules.ObjectCreate; 027 028/** 029 * @since 2.1 030 */ 031@ObjectCreate( pattern = "web-app/servlet" ) 032public final class ServletBean 033{ 034 035 private final Map<String, String> initParams = new HashMap<String, String>(); 036 037 @BeanPropertySetter( pattern = "web-app/servlet/servlet-name" ) 038 private String servletName; 039 040 @BeanPropertySetter( pattern = "web-app/servlet/servlet-class" ) 041 private String servletClass; 042 043 @CallMethod( pattern = "web-app/servlet/init-param" ) 044 public void addInitParam( @CallParam( pattern = "web-app/servlet/init-param/param-name" ) String name, 045 @CallParam( pattern = "web-app/servlet/init-param/param-value" ) String value ) 046 { 047 this.initParams.put( name, value ); 048 } 049 050 public String getServletName() 051 { 052 return servletName; 053 } 054 055 public void setServletName( String servletName ) 056 { 057 this.servletName = servletName; 058 } 059 060 public String getServletClass() 061 { 062 return servletClass; 063 } 064 065 public void setServletClass( String servletClass ) 066 { 067 this.servletClass = servletClass; 068 } 069 070 public Map<String, String> getInitParams() 071 { 072 return initParams; 073 } 074 075 @Override 076 public boolean equals( Object obj ) 077 { 078 if ( this == obj ) 079 return true; 080 if ( obj == null ) 081 return false; 082 if ( getClass() != obj.getClass() ) 083 return false; 084 ServletBean other = (ServletBean) obj; 085 if ( initParams == null ) 086 { 087 if ( other.initParams != null ) 088 return false; 089 } 090 else if ( !initParams.equals( other.initParams ) ) 091 return false; 092 if ( servletClass == null ) 093 { 094 if ( other.servletClass != null ) 095 return false; 096 } 097 else if ( !servletClass.equals( other.servletClass ) ) 098 return false; 099 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}