2 * Copyright 2005 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;
24 * Operation registry implementation. This implementation ignores the
25 * distinction between different types of resources and simply assumes that
26 * every operation is applicable to every type of resource.
28 * @author Erik Brakkee
30 public class DefaultOperationRegistry implements OperationRegistry {
34 private Map<String, Operation> operations;
37 * Creates a new DefaultOperationRegistry object.
39 * @param aOperations DOCUMENT ME!
41 public DefaultOperationRegistry(Operation[] aOperations) {
42 operations = new TreeMap<String, Operation>();
44 for (Operation operation : aOperations) {
45 operations.put(operation.getName(), operation);
50 * @see org.wamblee.security.authorization.OperationRegistry#getOperations(java.lang.Class)
55 * @param aResourceClass DOCUMENT ME!
57 * @return DOCUMENT ME!
59 public Operation[] getOperations(Class aResourceClass) {
60 return operations.values().toArray(new Operation[0]);
64 * @see org.wamblee.security.authorization.OperationRegistry#encode(org.wamblee.security.authorization.Operation[])
69 * @param aOperations DOCUMENT ME!
71 * @return DOCUMENT ME!
73 public String encode(Operation[] aOperations) {
74 StringBuffer buffer = new StringBuffer();
76 for (Operation operation : aOperations) {
77 if (buffer.length() > 0) {
81 buffer.append(operation.getName());
84 return buffer.toString();
88 * @see org.wamblee.security.authorization.OperationRegistry#decode(java.lang.Class, java.lang.String)
93 * @param aResourceClass DOCUMENT ME!
94 * @param aOperationsString DOCUMENT ME!
96 * @return DOCUMENT ME!
98 public Operation[] decode(Class aResourceClass, String aOperationsString) {
99 return decode(aOperationsString);
103 * @see org.wamblee.security.authorization.OperationRegistry#decode(java.lang.String)
108 * @param aOperationsString DOCUMENT ME!
110 * @return DOCUMENT ME!
112 * @throws IllegalArgumentException DOCUMENT ME!
114 public Operation[] decode(String aOperationsString) {
115 if (aOperationsString.length() == 0) {
116 return new Operation[0];
119 String[] names = aOperationsString.split(",");
120 ArrayList<Operation> result = new ArrayList<Operation>();
122 for (String name : names) {
123 Operation operation = operations.get(name);
125 if (operation == null) {
126 throw new IllegalArgumentException("Unknown operation '" + name
130 result.add(operation);
133 return result.toArray(new Operation[0]);