    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.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  /***
    29   * DOCUMENT ME!
    30   *
    31   * @author Ben Alex
    32   * @version $Id: MockMethodDefinitionSource.java,v 1.4 2005/11/17 00:55:50 benalex Exp $
    33   */
    34  public class MockMethodDefinitionSource extends 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("INVALID_ATTRIBUTE"));
    55              list.add(def2);
    56          }
    57
    58          ConfigAttributeDefinition def3 = new ConfigAttributeDefinition();
    59          def3.addConfigAttribute(new SecurityConfig("MOCK_UPPER"));
    60          def3.addConfigAttribute(new SecurityConfig("RUN_AS_"));
    61          list.add(def3);
    62
    63          if (includeInvalidAttributes) {
    64              ConfigAttributeDefinition def4 = new ConfigAttributeDefinition();
    65              def4.addConfigAttribute(new SecurityConfig("MOCK_SOMETHING"));
    66              def4.addConfigAttribute(new SecurityConfig("ANOTHER_INVALID"));
    67              list.add(def4);
    68          }
    69      }
    70
    71      private MockMethodDefinitionSource() {
    72          super();
    73      }
    74
    75      //~ Methods ================================================================
    76
    77      public Iterator getConfigAttributeDefinitions() {
    78          if (returnAnIterator) {
    79              return list.iterator();
    80          } else {
    81              return null;
    82          }
    83      }
    84
    85      protected ConfigAttributeDefinition lookupAttributes(Method method) {
    86          throw new UnsupportedOperationException("mock method not implemented");
    87      }
    88  }