KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > semantic > RequestSemantic


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2006 Continuent, Inc.
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Initial developer(s): Emmanuel Cecchet.
19  * Contributor(s): ______________________.
20  */

21
22 package org.continuent.sequoia.controller.semantic;
23
24 import java.util.regex.Pattern JavaDoc;
25
26 /**
27  * This class defines a RequestSemantic that is the semantic rule for requests
28  * matching a specific pattern.
29  *
30  * @author <a HREF="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
31  * @version 1.0
32  */

33 public class RequestSemantic extends AbstractSemantic
34 {
35   private Pattern JavaDoc sqlPattern;
36
37   /**
38    * Creates a new <code>RequestSemantic</code> object
39    *
40    * @param sqlRegExp a regular expression that the SQL must match
41    */

42   public RequestSemantic(String JavaDoc sqlRegExp)
43   {
44     this.sqlPattern = Pattern.compile(sqlRegExp, Pattern.CASE_INSENSITIVE
45         | Pattern.DOTALL);
46   }
47
48   /**
49    * Returns true if the given SQL matches the pattern of this request semantic.
50    *
51    * @param sql an SQL statement
52    * @return true if the SQL matches the pattern of this RequestSemantic
53    */

54   public boolean matchesPattern(String JavaDoc sql)
55   {
56     return sqlPattern.matcher(sql).matches();
57   }
58
59   /**
60    * Returns the sqlPattern value.
61    *
62    * @return Returns the sqlPattern.
63    */

64   public Pattern JavaDoc getSqlPattern()
65   {
66     return sqlPattern;
67   }
68
69   /**
70    * @see java.lang.Object#equals(java.lang.Object)
71    */

72   public boolean equals(Object JavaDoc obj)
73   {
74     if (obj instanceof RequestSemantic)
75     {
76       RequestSemantic other = (RequestSemantic) obj;
77       return sqlPattern.equals(other.getSqlPattern());
78     }
79     return false;
80   }
81
82   /**
83    * @see java.lang.Object#hashCode()
84    */

85   public int hashCode()
86   {
87     return sqlPattern.hashCode();
88   }
89
90 }
91
Popular Tags