KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > routing > filters > RegExFilter


1 /*
2  * $Id: RegExFilter.java 4219 2006-12-09 10:15:14Z lajos $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.routing.filters;
12
13 import java.util.regex.Pattern JavaDoc;
14
15 import org.mule.umo.UMOFilter;
16 import org.mule.umo.UMOMessage;
17
18 /**
19  * <code>RegExFilter</code> is used to match a String argument against a regular
20  * expression.
21  */

22
23 public class RegExFilter implements UMOFilter, ObjectFilter
24 {
25     private Pattern JavaDoc pattern;
26
27     public RegExFilter()
28     {
29         super();
30     }
31
32     public RegExFilter(String JavaDoc pattern)
33     {
34         this.pattern = Pattern.compile(pattern);
35     }
36
37     public boolean accept(UMOMessage message)
38     {
39         return accept(message.getPayload());
40     }
41
42     public boolean accept(Object JavaDoc object)
43     {
44         if (object == null)
45         {
46             return false;
47         }
48
49         return (pattern != null ? pattern.matcher(object.toString()).find() : false);
50     }
51
52     public String JavaDoc getPattern()
53     {
54         return (pattern == null ? null : pattern.pattern());
55     }
56
57     public void setPattern(String JavaDoc pattern)
58     {
59         this.pattern = (pattern != null ? Pattern.compile(pattern) : null);
60     }
61
62 }
63
Popular Tags