2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.security.authorization;
18 import java.util.ArrayList;
20 import java.util.TreeMap;
23 * Operation registry implementation. This implementation ignores the
24 * distinction between different types of resources and simply assumes that
25 * every operation is applicable to every type of resource.
27 * @author Erik Brakkee
29 public class DefaultOperationRegistry implements OperationRegistry {
30 private Map<String, Operation> operations;
33 * Creates a new DefaultOperationRegistry object.
36 public DefaultOperationRegistry(Operation[] aOperations) {
37 operations = new TreeMap<String, Operation>();
39 for (Operation operation : aOperations) {
40 operations.put(operation.getName(), operation);
48 * org.wamblee.security.authorization.OperationRegistry#getOperations(java
51 public Operation[] getOperations(Class aResourceClass) {
52 return operations.values().toArray(new Operation[0]);
59 * org.wamblee.security.authorization.OperationRegistry#encode(org.wamblee
60 * .security.authorization.Operation[])
62 public String encode(Operation[] aOperations) {
63 StringBuffer buffer = new StringBuffer();
65 for (Operation operation : aOperations) {
66 if (buffer.length() > 0) {
70 buffer.append(operation.getName());
73 return buffer.toString();
80 * org.wamblee.security.authorization.OperationRegistry#decode(java.lang
81 * .Class, java.lang.String)
83 public Operation[] decode(Class aResourceClass, String aOperationsString) {
84 return decode(aOperationsString);
91 * org.wamblee.security.authorization.OperationRegistry#decode(java.lang
94 public Operation[] decode(String aOperationsString) {
95 if (aOperationsString.length() == 0) {
96 return new Operation[0];
99 String[] names = aOperationsString.split(",");
100 ArrayList<Operation> result = new ArrayList<Operation>();
102 for (String name : names) {
103 Operation operation = operations.get(name);
105 if (operation == null) {
106 throw new IllegalArgumentException("Unknown operation '" +
110 result.add(operation);
113 return result.toArray(new Operation[0]);