001: /*
002: * Copyright (c) 2002-2007 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.xwork.config.entities;
006:
007: import java.util.ArrayList;
008: import java.util.Collection;
009: import java.util.List;
010: import java.io.Serializable;
011:
012: import com.opensymphony.xwork.util.location.Located;
013:
014: /**
015: * Configuration for InterceptorStack.
016: * <p/>
017: * In the xml configuration file this is defined as the <code>interceptor-stack</code> tag.
018: *
019: * @author Mike
020: * @author Rainer Hermanns
021: * @author tmjee
022: *
023: * @version $Date: 2007-05-20 19:57:53 +0200 (Sun, 20 May 2007) $ $Id: InterceptorStackConfig.java 1515 2007-05-20 17:57:53Z tm_jee $
024: */
025: public class InterceptorStackConfig extends Located implements
026: InterceptorListHolder, Serializable {
027:
028: private static final long serialVersionUID = 2897260918170270343L;
029:
030: private List interceptors; // a list of InterceptorMapping object
031: private String name;
032:
033: /**
034: * Creates an InterceptorStackConfig object.
035: */
036: public InterceptorStackConfig() {
037: this .interceptors = new ArrayList();
038: }
039:
040: /**
041: * Creates an InterceptorStackConfig object with a particular <code>name</code>.
042: * @param name
043: */
044: public InterceptorStackConfig(String name) {
045: this ();
046: this .name = name;
047: }
048:
049: /**
050: * Returns a <code>Collection</code> of InterceptorMapping objects.
051: * @return
052: */
053: public Collection getInterceptors() {
054: return interceptors;
055: }
056:
057: /**
058: * Set the name of this interceptor stack configuration.
059: * @param name
060: */
061: public void setName(String name) {
062: this .name = name;
063: }
064:
065: /**
066: * Get the name of this interceptor stack configuration.
067: * @return String
068: */
069: public String getName() {
070: return name;
071: }
072:
073: /**
074: * Add an <code>InterceptorMapping</code> object.
075: */
076: public void addInterceptor(InterceptorMapping interceptor) {
077: this .interceptors.add(interceptor);
078: }
079:
080: /**
081: * Add a List of <code>InterceptorMapping</code> objects.
082: */
083: public void addInterceptors(List interceptors) {
084: this .interceptors.addAll(interceptors);
085: }
086:
087: /**
088: * An InterceptorStackConfig object is equals with <code>o</code> only if
089: * <ul>
090: * <li>o is an InterceptorStackConfig object</li>
091: * <li>both names are equals</li>
092: * <li>all of their <code>InterceptorMapping</code>s are equals</li>
093: * </ul>
094: */
095: public boolean equals(Object o) {
096: if (this == o) {
097: return true;
098: }
099:
100: if (!(o instanceof InterceptorStackConfig)) {
101: return false;
102: }
103:
104: final InterceptorStackConfig interceptorStackConfig = (InterceptorStackConfig) o;
105:
106: if ((interceptors != null) ? (!interceptors
107: .equals(interceptorStackConfig.interceptors))
108: : (interceptorStackConfig.interceptors != null)) {
109: return false;
110: }
111:
112: if ((name != null) ? (!name.equals(interceptorStackConfig.name))
113: : (interceptorStackConfig.name != null)) {
114: return false;
115: }
116:
117: return true;
118: }
119:
120: /**
121: * Generate hashcode based on <code>InterceptorStackConfig</code>'s name and its
122: * <code>InterceptorMapping</code>s.
123: */
124: public int hashCode() {
125: int result;
126: result = ((name != null) ? name.hashCode() : 0);
127: result = (29 * result)
128: + ((interceptors != null) ? interceptors.hashCode() : 0);
129:
130: return result;
131: }
132: }
|