|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ConfigAttributeDefinition.java | 100% | 100% | 100% | 100% |
|
||||||||||||||
| 1 | /* Copyright 2004 Acegi Technology Pty Limited | |
| 2 | * | |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 | * you may not use this file except in compliance with the License. | |
| 5 | * You may obtain a copy of the License at | |
| 6 | * | |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 | * | |
| 9 | * Unless required by applicable law or agreed to in writing, software | |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 | * See the License for the specific language governing permissions and | |
| 13 | * limitations under the License. | |
| 14 | */ | |
| 15 | ||
| 16 | package org.acegisecurity; | |
| 17 | ||
| 18 | import java.io.Serializable; | |
| 19 | ||
| 20 | import java.util.Iterator; | |
| 21 | import java.util.List; | |
| 22 | import java.util.Vector; | |
| 23 | ||
| 24 | ||
| 25 | /** | |
| 26 | * Holds a group of {@link ConfigAttribute}s that are associated with a given | |
| 27 | * secure object target. | |
| 28 | * | |
| 29 | * <p> | |
| 30 | * All the <code>ConfigAttributeDefinition</code>s associated with a given | |
| 31 | * {@link org.acegisecurity.intercept.AbstractSecurityInterceptor} are | |
| 32 | * stored in an {@link org.acegisecurity.intercept.ObjectDefinitionSource}. | |
| 33 | * </p> | |
| 34 | * | |
| 35 | * @author Ben Alex | |
| 36 | * @version $Id: ConfigAttributeDefinition.java,v 1.7 2005/11/17 00:55:49 benalex Exp $ | |
| 37 | */ | |
| 38 | public class ConfigAttributeDefinition implements Serializable { | |
| 39 | //~ Instance fields ======================================================== | |
| 40 | ||
| 41 | private List configAttributes = new Vector(); | |
| 42 | ||
| 43 | //~ Constructors =========================================================== | |
| 44 | ||
| 45 | 312 | public ConfigAttributeDefinition() { |
| 46 | 312 | super(); |
| 47 | } | |
| 48 | ||
| 49 | //~ Methods ================================================================ | |
| 50 | ||
| 51 | /** | |
| 52 | * Returns an <code>Iterator</code> over all the | |
| 53 | * <code>ConfigAttribute</code>s defined by this | |
| 54 | * <code>ConfigAttributeDefinition</code>. | |
| 55 | * | |
| 56 | * <P> | |
| 57 | * Allows <code>AccessDecisionManager</code>s and other classes to loop | |
| 58 | * through every configuration attribute associated with a target secure | |
| 59 | * object. | |
| 60 | * </p> | |
| 61 | * | |
| 62 | * @return all the configuration attributes stored by the instance, or | |
| 63 | * <code>null</code> if an <code>Iterator</code> is unavailable | |
| 64 | */ | |
| 65 | 232 | public Iterator getConfigAttributes() { |
| 66 | 232 | return this.configAttributes.iterator(); |
| 67 | } | |
| 68 | ||
| 69 | /** | |
| 70 | * Adds a <code>ConfigAttribute</code> that is related to the secure object | |
| 71 | * method. | |
| 72 | * | |
| 73 | * @param newConfigAttribute the new configuration attribute to add | |
| 74 | */ | |
| 75 | 461 | public void addConfigAttribute(ConfigAttribute newConfigAttribute) { |
| 76 | 461 | this.configAttributes.add(newConfigAttribute); |
| 77 | } | |
| 78 | ||
| 79 | /** | |
| 80 | * Indicates whether the specified <code>ConfigAttribute</code> is | |
| 81 | * contained within this <code>ConfigAttributeDefinition</code>. | |
| 82 | * | |
| 83 | * @param configAttribute the attribute to locate | |
| 84 | * | |
| 85 | * @return <code>true</code> if the specified <code>ConfigAttribute</code> | |
| 86 | * is contained, <code>false</code> otherwise | |
| 87 | */ | |
| 88 | 18 | public boolean contains(ConfigAttribute configAttribute) { |
| 89 | 18 | return configAttributes.contains(configAttribute); |
| 90 | } | |
| 91 | ||
| 92 | 23 | public boolean equals(Object obj) { |
| 93 | 23 | if (obj instanceof ConfigAttributeDefinition) { |
| 94 | 22 | ConfigAttributeDefinition test = (ConfigAttributeDefinition) obj; |
| 95 | ||
| 96 | 22 | List testAttrs = new Vector(); |
| 97 | 22 | Iterator iter = test.getConfigAttributes(); |
| 98 | ||
| 99 | 22 | while (iter.hasNext()) { |
| 100 | 35 | ConfigAttribute attr = (ConfigAttribute) iter.next(); |
| 101 | 35 | testAttrs.add(attr); |
| 102 | } | |
| 103 | ||
| 104 | 22 | if (this.configAttributes.size() != testAttrs.size()) { |
| 105 | 2 | return false; |
| 106 | } | |
| 107 | ||
| 108 | 20 | for (int i = 0; i < this.configAttributes.size(); i++) { |
| 109 | 32 | if (!this.configAttributes.get(i).equals(testAttrs.get(i))) { |
| 110 | 1 | return false; |
| 111 | } | |
| 112 | } | |
| 113 | ||
| 114 | 19 | return true; |
| 115 | } | |
| 116 | ||
| 117 | 1 | return false; |
| 118 | } | |
| 119 | ||
| 120 | /** | |
| 121 | * Returns the number of <code>ConfigAttribute</code>s defined by this | |
| 122 | * <code>ConfigAttributeDefinition</code>. | |
| 123 | * | |
| 124 | * @return the number of <code>ConfigAttribute</code>s contained | |
| 125 | */ | |
| 126 | 34 | public int size() { |
| 127 | 34 | return configAttributes.size(); |
| 128 | } | |
| 129 | ||
| 130 | 55 | public String toString() { |
| 131 | 55 | return this.configAttributes.toString(); |
| 132 | } | |
| 133 | } |
|
||||||||||