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

Quick Search    Search Deep

Source code: org/acmsl/regexpplugin/jakartaoro/AwkCompilerOROAdapter.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: AwkCompilerOROAdapter.java,v $
37   *
38   * Author: Jose San Leandro Armendáriz
39   *
40   * Description: Jakarta ORO-specific Awk compiler adapter. A delegation is used
41   *              because AwkCompiler is a final class.
42   *
43   * Last modified by: $Author: dev $ at $Date: 2002/09/27 08:27:14 $
44   *
45   * File version: $Revision: 1.9 $
46   *
47   * Project version: $Name:  $
48   *                  ("Name" means no concrete version has been checked out)
49   *
50   * $Id: AwkCompilerOROAdapter.java,v 1.9 2002/09/27 08:27:14 dev Exp $
51   *
52   */
53  package org.acmsl.regexpplugin.jakartaoro;
54  
55  /*
56   * Importing project-specific classes.
57   */
58  import org.acmsl.regexpplugin.Compiler;
59  import org.acmsl.regexpplugin.jakartaoro.PatternOROAdapter;
60  import org.acmsl.regexpplugin.Pattern;
61  
62  /*
63   * Importing some ACM classes.
64   */
65  import org.acmsl.version.Version;
66  import org.acmsl.version.VersionFactory;
67  
68  /*
69   * Importing ORO classes.
70   */
71  import org.apache.oro.text.awk.AwkCompiler;
72  
73  /**
74   * Jakarta ORO-specific Awk compiler adapter. A delegation is used because
75   * AwkCompiler is a final class.
76   * @author <a href="mailto:jsanleandro@yahoo.es"
77             >Jose San Leandro Armendáriz</a>
78   * @version $Revision: 1.9 $
79   */
80  public class AwkCompilerOROAdapter
81      implements  Compiler
82  {
83      /**
84       * Delegated instance.
85       */
86      private AwkCompiler m__Instance;
87  
88      /**
89       * Case sensitiveness.
90       */
91      private boolean m__bCaseSensitive;
92  
93      /**
94       * Multiline parsing.
95       */
96      private boolean m__bMultiline;
97  
98      /**
99       * Compiles given regular expression and creates a Pattern object to
100      * apply such rule on concrete text contents.
101      * @param regexp the regular expression to compile.
102      * @return the Pattern associated to such regular expression.
103      */
104     public Pattern compile(String regexp)
105         throws  org.acmsl.regexpplugin.MalformedPatternException
106     {
107         Pattern result = null;
108 
109         try
110         {
111             AwkCompiler t_Compiler = getDelegatedInstance();
112 
113             result = new PatternOROAdapter(t_Compiler.compile(regexp));
114         }
115         catch  (org.apache.oro.text.regex.MalformedPatternException exception)
116         {
117             throw new MalformedPatternExceptionOROAdapter(exception);
118         }
119         catch  (IllegalArgumentException illegalArgumentException)
120         {
121             if  (resetOptions())
122             {
123                 result = compile(regexp);
124             }
125         }
126 
127         return result;
128     }
129 
130     /**
131      * Resets the compiler options.
132      * @return true if the options actually changed.
133      */
134     private boolean resetOptions()
135     {
136         boolean result = false;
137 
138         result =
139             (   (isCaseSensitive())
140              || (isMultiline()));
141 
142         setCaseSensitive(false);
143 
144         setMultiline(false);
145 
146         return result;
147     }
148 
149     /**
150      * Retrieves an instance of AwkCompiler class.
151      * @return a new (or already existing) compiler.
152      */
153     AwkCompiler getDelegatedInstance()
154     {
155         AwkCompiler result = m__Instance;
156 
157         if  (m__Instance == null)
158         {
159             m__Instance = new AwkCompiler();
160 
161             result = m__Instance;
162         }
163 
164         return result;
165     }
166 
167     /**
168      * Sets whether the compiler should care about case sensitiveness
169      * or not.
170      * @param caseSensitive true for differentiate upper from lower case.
171      */
172     public void setCaseSensitive(boolean caseSensitive)
173     {
174         m__bCaseSensitive = caseSensitive;
175     }
176 
177     /**
178      * Retrieves whether the compiler should care about case sensitiveness
179      * or not.
180      * @return true if upper from lower cases are processed differently.
181      */
182     public boolean isCaseSensitive()
183     {
184         return m__bCaseSensitive;
185     }
186 
187     /**
188      * Sets whether the compiler should care about new line delimiters
189      * or not.
190      * @param multiline false for parsing each line at a time.
191      */
192     public void setMultiline(boolean multiline)
193     {
194         m__bMultiline = multiline;
195     }
196 
197     /**
198      * Sets whether the compiler should care about new line delimiters
199      * or not.
200      * @return false if the engine parses each line one at a time.
201      */
202     public boolean isMultiline()
203     {
204         return m__bMultiline;
205     }
206 
207     /**
208      * Concrete version object updated everytime it's checked-in in a CVS
209      * repository.
210      */
211     public static final Version VERSION =
212         VersionFactory.createVersion("$Revision: 1.9 $");
213 
214     /**
215      * Retrieves the current version of this object.
216      * @return the version object with such information.
217      */
218     public Version getVersion()
219     {
220         return VERSION;
221     }
222 
223     /**
224      * Retrieves the current version of this class.
225      * @return the object with class version information.
226      */
227     public static Version getClassVersion()
228     {
229         return VERSION;
230     }
231 }