01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * 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.intercept.method;
17:
18: import org.acegisecurity.ConfigAttributeDefinition;
19: import org.acegisecurity.SecurityConfig;
20:
21: import java.lang.reflect.Method;
22:
23: import java.util.Iterator;
24: import java.util.List;
25: import java.util.Vector;
26:
27: /**
28: * DOCUMENT ME!
29: *
30: * @author Ben Alex
31: * @version $Id: MockMethodDefinitionSource.java 1496 2006-05-23 13:38:33Z benalex $
32: */
33: public class MockMethodDefinitionSource extends
34: AbstractMethodDefinitionSource {
35: //~ Instance fields ================================================================================================
36:
37: private List list;
38: private boolean returnAnIterator;
39:
40: //~ Constructors ===================================================================================================
41:
42: public MockMethodDefinitionSource(boolean includeInvalidAttributes,
43: boolean returnAnIteratorWhenRequested) {
44: returnAnIterator = returnAnIteratorWhenRequested;
45: list = new Vector();
46:
47: ConfigAttributeDefinition def1 = new ConfigAttributeDefinition();
48: def1.addConfigAttribute(new SecurityConfig("MOCK_LOWER"));
49: list.add(def1);
50:
51: if (includeInvalidAttributes) {
52: ConfigAttributeDefinition def2 = new ConfigAttributeDefinition();
53: def2.addConfigAttribute(new SecurityConfig("MOCK_LOWER"));
54: def2.addConfigAttribute(new SecurityConfig(
55: "INVALID_ATTRIBUTE"));
56: list.add(def2);
57: }
58:
59: ConfigAttributeDefinition def3 = new ConfigAttributeDefinition();
60: def3.addConfigAttribute(new SecurityConfig("MOCK_UPPER"));
61: def3.addConfigAttribute(new SecurityConfig("RUN_AS_"));
62: list.add(def3);
63:
64: if (includeInvalidAttributes) {
65: ConfigAttributeDefinition def4 = new ConfigAttributeDefinition();
66: def4
67: .addConfigAttribute(new SecurityConfig(
68: "MOCK_SOMETHING"));
69: def4.addConfigAttribute(new SecurityConfig(
70: "ANOTHER_INVALID"));
71: list.add(def4);
72: }
73: }
74:
75: private MockMethodDefinitionSource() {
76: super ();
77: }
78:
79: //~ Methods ========================================================================================================
80:
81: public Iterator getConfigAttributeDefinitions() {
82: if (returnAnIterator) {
83: return list.iterator();
84: } else {
85: return null;
86: }
87: }
88:
89: protected ConfigAttributeDefinition lookupAttributes(Method method) {
90: throw new UnsupportedOperationException(
91: "mock method not implemented");
92: }
93: }
|