| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| InterfaceBasedLabelParameterStrategy |
|
| 1.5;1.5 |
| 1 | /* Copyright 2004, 2005, 2006 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.vote; |
|
| 17 | ||
| 18 | import java.lang.reflect.Method; |
|
| 19 | ||
| 20 | ||
| 21 | /** |
|
| 22 | * This is a very useful implementation of the LabelParameterStrategy. Data objects which are meant to be labeled |
|
| 23 | * should implement the LabeledData interface. This strategy will then castdown to that interface for either testing |
|
| 24 | * or retrieval of the label. |
|
| 25 | * |
|
| 26 | * @author Greg Turnquist |
|
| 27 | * @version $Id: InterfaceBasedLabelParameterStrategy.java 1750 2006-11-14 22:07:36Z benalex $ |
|
| 28 | */ |
|
| 29 | 0 | public class InterfaceBasedLabelParameterStrategy implements LabelParameterStrategy { |
| 30 | //~ Instance fields ================================================================================================ |
|
| 31 | ||
| 32 | 0 | private String noLabel = ""; |
| 33 | ||
| 34 | //~ Methods ======================================================================================================== |
|
| 35 | ||
| 36 | /** |
|
| 37 | * Test if the argument is labeled, and if so, downcast to LabeledData and retrieve the domain object's |
|
| 38 | * labeled value. Otherwise, return an empty string. NOTE: The default for no label is an empty string. If somehow |
|
| 39 | * the user wants to make that a label itself, he or she must inject an alternate value to the noLabel property. |
|
| 40 | * |
|
| 41 | * @param method DOCUMENT ME! |
|
| 42 | * @param arg DOCUMENT ME! |
|
| 43 | * |
|
| 44 | * @return DOCUMENT ME! |
|
| 45 | */ |
|
| 46 | public String getLabel(Method method, Object arg) { |
|
| 47 | 0 | if (isLabeled(method, arg)) { |
| 48 | 0 | return ((LabeledData) arg).getLabel(); |
| 49 | } else { |
|
| 50 | 0 | return noLabel; |
| 51 | } |
|
| 52 | } |
|
| 53 | ||
| 54 | public String getNoLabel() { |
|
| 55 | 0 | return noLabel; |
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * Test if the argument implemented the LabeledData interface. NOTE: The invoking method has no bearing for |
|
| 60 | * this strategy, only the argument itself. |
|
| 61 | * |
|
| 62 | * @param method DOCUMENT ME! |
|
| 63 | * @param arg DOCUMENT ME! |
|
| 64 | * |
|
| 65 | * @return DOCUMENT ME! |
|
| 66 | */ |
|
| 67 | public boolean isLabeled(Method method, Object arg) { |
|
| 68 | 0 | return (arg instanceof LabeledData); |
| 69 | } |
|
| 70 | ||
| 71 | public void setNoLabel(String noLabel) { |
|
| 72 | 0 | this.noLabel = noLabel; |
| 73 | 0 | } |
| 74 | } |