(no commit message)
[utils] / security / impl / src / main / java / org / wamblee / security / authorization / RegexpPathCondition.java
1 /*
2  * Copyright 2005-2010 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 javax.persistence.DiscriminatorValue;
19 import javax.persistence.Entity;
20
21 import org.wamblee.security.AbstractPersistent;
22
23 /**
24  * Condition to check whether a path matches a given regula expression.
25  * 
26  * @author Erik Brakkee
27  */
28 @Entity
29 @DiscriminatorValue("REGEXP")
30 public class RegexpPathCondition extends PathCondition {
31     /**
32      * String the path must start with.
33      */
34     private String pattern;
35
36     /**
37      * Constructs the condition.
38      * 
39      * @param aPattern
40      *            String the path must start with.
41      */
42     public RegexpPathCondition(String aPattern) {
43         pattern = aPattern;
44     }
45
46     /**
47      * For OR mapping.
48      * 
49      */
50     protected RegexpPathCondition() {
51         pattern = null;
52     }
53
54     /*
55      * (non-Javadoc)
56      * 
57      * @see
58      * org.wamblee.security.authorization.PathCondition#matches(java.lang.String
59      * )
60      */
61     public boolean matches(String aPath) {
62         return aPath.matches(pattern);
63     }
64
65     /**
66      * 
67      * @return Returns the _path.
68      */
69     protected String getPattern() {
70         return pattern;
71     }
72
73     /**
74      * 
75      * @param aPattern
76      *            The _path to set.
77      */
78     protected void setPattern(String aPattern) {
79         pattern = aPattern;
80     }
81
82     /*
83      * (non-Javadoc)
84      * 
85      * @see java.lang.Object#toString()
86      */
87     @Override
88     public String toString() {
89         return "RegexpCondition(pattern = '" + pattern + "')";
90     }
91 }