X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=security%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsecurity%2Fauthorization%2FDefaultOperationRegistry.java;h=e5da54b48b215b8e7b200b45f88a98b4ec5a3475;hb=8de36ff0206c996baf3ee4adc3e2293b12ff5f39;hp=7a26fb706e27c3542c1626b723ec0375c54703ed;hpb=162af365e45e54e5e8d656be276914df2005eaec;p=utils diff --git a/security/src/main/java/org/wamblee/security/authorization/DefaultOperationRegistry.java b/security/src/main/java/org/wamblee/security/authorization/DefaultOperationRegistry.java index 7a26fb70..e5da54b4 100644 --- a/security/src/main/java/org/wamblee/security/authorization/DefaultOperationRegistry.java +++ b/security/src/main/java/org/wamblee/security/authorization/DefaultOperationRegistry.java @@ -1,19 +1,18 @@ /* * Copyright 2005 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - + */ package org.wamblee.security.authorization; import java.util.ArrayList; @@ -21,66 +20,96 @@ import java.util.Map; import java.util.TreeMap; /** - * Operation registry implementation. - * This implementation ignores the distinction between different types of resources - * and simply assumes that every operation is applicable to every type of resource. + * Operation registry implementation. This implementation ignores the + * distinction between different types of resources and simply assumes that + * every operation is applicable to every type of resource. + * + * @author Erik Brakkee */ public class DefaultOperationRegistry implements OperationRegistry { + private Map operations; + + /** + * Creates a new DefaultOperationRegistry object. + * + */ + public DefaultOperationRegistry(Operation[] aOperations) { + operations = new TreeMap(); - private Map _operations; - - public DefaultOperationRegistry(Operation[] aOperations) { - _operations = new TreeMap(); - for (Operation operation: aOperations) { - _operations.put(operation.getName(), operation); + for (Operation operation : aOperations) { + operations.put(operation.getName(), operation); } } - - /* (non-Javadoc) - * @see org.wamblee.security.authorization.OperationRegistry#getOperations(java.lang.Class) + + /* + * (non-Javadoc) + * + * @see + * org.wamblee.security.authorization.OperationRegistry#getOperations(java + * .lang.Class) */ public Operation[] getOperations(Class aResourceClass) { - return _operations.values().toArray(new Operation[0]); + return operations.values().toArray(new Operation[0]); } - /* (non-Javadoc) - * @see org.wamblee.security.authorization.OperationRegistry#encode(org.wamblee.security.authorization.Operation[]) + /* + * (non-Javadoc) + * + * @see + * org.wamblee.security.authorization.OperationRegistry#encode(org.wamblee + * .security.authorization.Operation[]) */ public String encode(Operation[] aOperations) { - StringBuffer buffer = new StringBuffer(); - for (Operation operation: aOperations) { - if ( buffer.length() > 0 ) { + StringBuffer buffer = new StringBuffer(); + + for (Operation operation : aOperations) { + if (buffer.length() > 0) { buffer.append(','); } + buffer.append(operation.getName()); } + return buffer.toString(); } - /* (non-Javadoc) - * @see org.wamblee.security.authorization.OperationRegistry#decode(java.lang.Class, java.lang.String) + /* + * (non-Javadoc) + * + * @see + * org.wamblee.security.authorization.OperationRegistry#decode(java.lang + * .Class, java.lang.String) */ public Operation[] decode(Class aResourceClass, String aOperationsString) { - return decode(aOperationsString); + return decode(aOperationsString); } - - /* (non-Javadoc) - * @see org.wamblee.security.authorization.OperationRegistry#decode(java.lang.String) + + /* + * (non-Javadoc) + * + * @see + * org.wamblee.security.authorization.OperationRegistry#decode(java.lang + * .String) */ public Operation[] decode(String aOperationsString) { - if ( aOperationsString.length() == 0 ) { - return new Operation[0]; + if (aOperationsString.length() == 0) { + return new Operation[0]; } + String[] names = aOperationsString.split(","); - ArrayList result = new ArrayList(); - for (String name: names) { - Operation operation = _operations.get(name); - if ( operation == null ) { - throw new IllegalArgumentException("Unknown operation '" + name + "'"); + ArrayList result = new ArrayList(); + + for (String name : names) { + Operation operation = operations.get(name); + + if (operation == null) { + throw new IllegalArgumentException("Unknown operation '" + + name + "'"); } + result.add(operation); } - return result.toArray(new Operation[0]); - } + return result.toArray(new Operation[0]); + } }