Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/acmsl/regexpplugin/jakartaoro/Perl5MatcherOROAdapter.java


1   /*
2                   Java Regular Expressions Plugin API
3   
4       Copyright (C) 2002  Jose San Leandro Armendáriz
5                           jsanleandro@yahoo.es
6                           chousz@yahoo.com
7   
8       This library is free software; you can redistribute it and/or
9       modify it under the terms of the GNU Lesser General Public
10      License as published by the Free Software Foundation; either
11      version 2.1 of the License, or (at your option) any later version.
12  
13      This library is distributed in the hope that it will be useful,
14      but WITHOUT ANY WARRANTY; without even the implied warranty of
15      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16      Lesser General Public License for more details.
17  
18      You should have received a copy of the GNU Lesser General Public
19      License along with this library; if not, write to the Free Software
20      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  
22      Thanks to ACM S.L. for distributing this library under the LGPL license.
23      Contact info: jsr000@terra.es
24      Postal Address: c/Playa de Lagoa, 1
25                      Urb. Valdecabañas
26                      Boadilla del monte
27                      28660 Madrid
28                      Spain
29  
30      This library uses some external APIs. So far I haven't released such
31      APIs as projects themselves, but you should be able
32      to download them from the web page where you got this source code.
33  
34   ******************************************************************************
35   *
36   * Filename: $RCSfile: Perl5MatcherOROAdapter.java,v $
37   *
38   * Author: Jose San Leandro Armendáriz
39   *
40   * Description: Jakarta ORO-specific regexp compiler adapter. This class makes
41   *              possible the use of ORO compilers inside this API. A delegation
42   *              is used because Perl5Compiler is a final class.
43   *
44   * Last modified by: $Author: dev $ at $Date: 2002/09/27 08:27:16 $
45   *
46   * File version: $Revision: 1.6 $
47   *
48   * Project version: $Name:  $
49   *                  ("Name" means no concrete version has been checked out)
50   *
51   * $Id: Perl5MatcherOROAdapter.java,v 1.6 2002/09/27 08:27:16 dev Exp $
52   *
53   */
54  package org.acmsl.regexpplugin.jakartaoro;
55  
56  /*
57   * Importing project-specific classes.
58   */
59  import org.acmsl.regexpplugin.jakartaoro.PatternOROAdapter;
60  import org.acmsl.regexpplugin.Matcher;
61  import org.acmsl.regexpplugin.MatchResult;
62  import org.acmsl.regexpplugin.Pattern;
63  
64  /*
65   * Importing some ACM classes.
66   */
67  import org.acmsl.version.Version;
68  import org.acmsl.version.VersionFactory;
69  
70  /*
71   * Importing ORO classes.
72   */
73  import org.apache.oro.text.regex.Perl5Matcher;
74  
75  /**
76   * Jakarta ORO-specific regexp compiler adapter. This class makes possible the
77   * use of ORO compilers inside this API. A delegation is used because
78   * Perl5Compiler is a final class.
79   * @author <a href="mailto:jsanleandro@yahoo.es"
80             >Jose San Leandro Armendáriz</a>
81   * @version $Revision: 1.6 $
82   */
83  public class Perl5MatcherOROAdapter
84      implements  Matcher
85  {
86      /**
87       * Delegated instance.
88       */
89      private Perl5Matcher m__Instance;
90  
91      /**
92       * Constructs a Perl5MatcherOROAdapter for given object.
93       * @param adaptee the instance to be adapted.
94       */
95      public Perl5MatcherOROAdapter()
96      {
97          setAdaptee(new Perl5Matcher());
98      }
99  
100     /**
101      * Checks if given text contains specified pattern.
102      * @param text the text to analyze.
103      * @param pattern the regular expression to apply.
104      * @return true if the pattern is found.
105      */
106     public boolean contains(String text, Pattern pattern)
107     {
108         boolean result = false;
109 
110         if  (   (pattern != null)
111              && (pattern instanceof PatternOROAdapter)
112              && (getDelegatedInstance() != null))
113         {
114             result =
115                 getDelegatedInstance().contains(
116                     text,
117                     ((PatternOROAdapter) pattern).getDelegatedInstance());
118         }
119 
120         return result;
121     }
122 
123     /**
124      * Retrieves the last match found due to a previous call to
125      * <i>contains</i> method.
126      * @return such match result.
127      */
128     public MatchResult getMatch()
129     {
130         MatchResult result = null;
131 
132         if  (getDelegatedInstance() != null)
133         {
134             result =
135                 new MatchResultOROAdapter(getDelegatedInstance().getMatch());
136         }
137 
138         return result;
139     }
140 
141     /**
142      * Retrieves an instance of Perl5Matcher class.
143      * @return a the adapted matcher.
144      */
145     protected Perl5Matcher getDelegatedInstance()
146     {
147         return m__Instance;
148     }
149 
150     /**
151      * Sets the adaptee.
152      * @param adaptee the matcher to adapt.
153      */
154     protected void setAdaptee(Perl5Matcher adaptee)
155     {
156         m__Instance = adaptee;
157     }
158 
159     /**
160      * Concrete version object updated everytime it's checked-in in a CVS
161      * repository.
162      */
163     public static final Version VERSION =
164         VersionFactory.createVersion("$Revision: 1.6 $");
165 
166     /**
167      * Retrieves the current version of this object.
168      * @return the version object with such information.
169      */
170     public Version getVersion()
171     {
172         return VERSION;
173     }
174 
175     /**
176      * Retrieves the current version of this class.
177      * @return the object with class version information.
178      */
179     public static Version getClassVersion()
180     {
181         return VERSION;
182     }
183 }