001: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
002: *
003: * Licensed under the Apache License, Version 2.0 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software
010: * distributed under the License is distributed on an "AS IS" BASIS,
011: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: * See the License for the specific language governing permissions and
013: * limitations under the License.
014: */
015:
016: package org.acegisecurity;
017:
018: import java.io.Serializable;
019:
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Vector;
023:
024: /**
025: * Holds a group of {@link ConfigAttribute}s that are associated with a given secure object target.<p>All the
026: * <code>ConfigAttributeDefinition</code>s associated with a given {@link
027: * org.acegisecurity.intercept.AbstractSecurityInterceptor} are stored in an {@link
028: * org.acegisecurity.intercept.ObjectDefinitionSource}.</p>
029: *
030: * @author Ben Alex
031: * @version $Id: ConfigAttributeDefinition.java 1496 2006-05-23 13:38:33Z benalex $
032: */
033: public class ConfigAttributeDefinition implements Serializable {
034: //~ Instance fields ================================================================================================
035:
036: private List configAttributes = new Vector();
037:
038: //~ Constructors ===================================================================================================
039:
040: public ConfigAttributeDefinition() {
041: super ();
042: }
043:
044: //~ Methods ========================================================================================================
045:
046: /**
047: * Adds a <code>ConfigAttribute</code> that is related to the secure object method.
048: *
049: * @param newConfigAttribute the new configuration attribute to add
050: */
051: public void addConfigAttribute(ConfigAttribute newConfigAttribute) {
052: this .configAttributes.add(newConfigAttribute);
053: }
054:
055: /**
056: * Indicates whether the specified <code>ConfigAttribute</code> is contained within this
057: * <code>ConfigAttributeDefinition</code>.
058: *
059: * @param configAttribute the attribute to locate
060: *
061: * @return <code>true</code> if the specified <code>ConfigAttribute</code> is contained, <code>false</code>
062: * otherwise
063: */
064: public boolean contains(ConfigAttribute configAttribute) {
065: return configAttributes.contains(configAttribute);
066: }
067:
068: public boolean equals(Object obj) {
069: if (obj instanceof ConfigAttributeDefinition) {
070: ConfigAttributeDefinition test = (ConfigAttributeDefinition) obj;
071:
072: List testAttrs = new Vector();
073: Iterator iter = test.getConfigAttributes();
074:
075: while (iter.hasNext()) {
076: ConfigAttribute attr = (ConfigAttribute) iter.next();
077: testAttrs.add(attr);
078: }
079:
080: if (this .configAttributes.size() != testAttrs.size()) {
081: return false;
082: }
083:
084: for (int i = 0; i < this .configAttributes.size(); i++) {
085: if (!this .configAttributes.get(i).equals(
086: testAttrs.get(i))) {
087: return false;
088: }
089: }
090:
091: return true;
092: }
093:
094: return false;
095: }
096:
097: /**
098: * Returns an <code>Iterator</code> over all the <code>ConfigAttribute</code>s defined by this
099: * <code>ConfigAttributeDefinition</code>.<P>Allows <code>AccessDecisionManager</code>s and other classes
100: * to loop through every configuration attribute associated with a target secure object.</p>
101: *
102: * @return all the configuration attributes stored by the instance, or <code>null</code> if an
103: * <code>Iterator</code> is unavailable
104: */
105: public Iterator getConfigAttributes() {
106: return this .configAttributes.iterator();
107: }
108:
109: /**
110: * Returns the number of <code>ConfigAttribute</code>s defined by this
111: * <code>ConfigAttributeDefinition</code>.
112: *
113: * @return the number of <code>ConfigAttribute</code>s contained
114: */
115: public int size() {
116: return configAttributes.size();
117: }
118:
119: public String toString() {
120: return this.configAttributes.toString();
121: }
122: }
|