Removed DOCUMENT ME comments that were generated and applied source code
[utils] / security / src / main / java / org / wamblee / security / authorization / IsaOperationCondition.java
1 /*
2  * Copyright 2005 the original author or authors.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.wamblee.security.authorization;
17
18 import org.wamblee.persistence.AbstractPersistent;
19
20 /**
21  * Determiens if an operation is a subclass of a specified operation.
22  */
23 public class IsaOperationCondition extends AbstractPersistent implements
24     OperationCondition {
25     /**
26      * Operation that the other operation must be a subclass of.
27      */
28     private Class<? extends Operation> operation;
29
30     /**
31      * Constructs the condition.
32      * 
33      * @param aOperation
34      *            Operation that an operation must be an instance of.
35      */
36     public IsaOperationCondition(Class<? extends Operation> aOperation) {
37         operation = aOperation;
38     }
39
40     /**
41      * For OR mapping.
42      * 
43      */
44     public IsaOperationCondition() {
45         operation = null;
46     }
47
48     /*
49      * (non-Javadoc)
50      * 
51      * @see
52      * org.wamblee.security.authorization.OperationCondition#matches(org.wamblee
53      * .security.authorization.Operation)
54      */
55     public boolean matches(Operation aOperation) {
56         return operation.isInstance(aOperation);
57     }
58
59     /**
60      * Gets the operation as a string. For OR mapping only.
61      * 
62      * @return Operation string.
63      */
64     protected String getOperationString() {
65         if (operation == null) {
66             return null;
67         }
68
69         return operation.getName();
70     }
71
72     /**
73      * Sets the operation as a string. For OR mapping only.
74      * 
75      * @param aOperation
76      *            Operation string.
77      * 
78      */
79     protected void setOperationString(String aOperation) {
80         if (aOperation == null) {
81             return;
82         }
83
84         try {
85             operation = (Class<? extends Operation>) Class.forName(aOperation);
86         } catch (Exception e) {
87             throw new IllegalArgumentException("Unknown class '" + aOperation +
88                 "'");
89         }
90     }
91
92     /*
93      * (non-Javadoc)
94      * 
95      * @see java.lang.Object#toString()
96      */
97     @Override
98     public String toString() {
99         return "IsaOperationCondition(operation=" + operation.getName() + ")";
100     }
101 }