jakarta-oro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject cvs commit: jakarta-oro/src/java/org/apache/oro/text PatternMatchingEngineFactory.java
Date Tue, 15 Jun 2004 20:22:29 GMT
dfs         2004/06/15 13:22:29

  Modified:    src/java/org/apache/oro/text
                        PatternMatchingEngineFactory.java
  Log:
  Made all of the default engines be initialized by checking for
  existence of classes with Class.forName().
  
  Revision  Changes    Path
  1.4       +38 -19    jakarta-oro/src/java/org/apache/oro/text/PatternMatchingEngineFactory.java
  
  Index: PatternMatchingEngineFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-oro/src/java/org/apache/oro/text/PatternMatchingEngineFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PatternMatchingEngineFactory.java	15 Jun 2004 02:55:42 -0000	1.3
  +++ PatternMatchingEngineFactory.java	15 Jun 2004 20:22:29 -0000	1.4
  @@ -38,30 +38,49 @@
     public static final String POSIX_KEY   = "org.apache.regexp";
     public static final String DEFAULT_KEY = PERL5_KEY;
   
  +  private static final int __KEY    = 0;
  +  private static final int __CLASS  = 1;
  +  private static final int __ENGINE = 2;
  +
  +  private static final String[] __DEFAULT_ENGINES[] = {
  +    { PERL5_KEY, "org.apache.oro.text.regex.Perl5Matcher",
  +      "org.apache.oro.text.regex.Perl5Engine" },
  +    { AWK_KEY, "org.apache.oro.text.awk.AwkMatcher",
  +      "org.apache.oro.text.awk.AwkEngine" },
  +    // Yes, we really do want to check for Perl5Matcher because it's
  +    // required by GlobEngine.
  +    { GLOB_KEY, "org.apache.oro.text.Perl5Matcher",
  +      "org.apache.oro.text.GlobEngine" },
  +    { JAVA_KEY, "java.util.regex.Pattern",
  +      "org.apache.oro.text.java.JavaEngine" }
  +  };
  +
     private HashMap __factories;
   
     public PatternMatchingEngineFactory() {
       __factories = new HashMap();
   
  -    put(PERL5_KEY, new Perl5Engine());
  -    put(AWK_KEY,   new AwkEngine());
  -    put(GLOB_KEY,  new GlobEngine());
  -
  -    try {
  -      Class.forName("java.util.regex.Pattern");
  -      put(JAVA_KEY,
  -          (PatternMatchingEngine)
  -          Class.forName("org.apache.oro.text.java.JavaEngine").newInstance());
  -    } catch(ClassNotFoundException cnfe) {
  -      // Don't do anything.  java.util.regex package doesn't exist.
  -    } catch(InstantiationException ie) {
  -      // This will never happen.  Could use an assertion but that locks us
  -      // into J2SE 1.4.
  -    } catch(IllegalAccessException iae) {
  -      // This will never happen.  Could use an assertion but that locks us
  -      // into J2SE 1.4.
  +    for(int i = 0; i < __DEFAULT_ENGINES.length; ++i) {
  +      try {
  +        Class.forName(__DEFAULT_ENGINES[i][__CLASS]);
  +        Class.forName(__DEFAULT_ENGINES[i][__ENGINE]);
  +        put(__DEFAULT_ENGINES[i][__KEY],
  +            (PatternMatchingEngine)
  +            Class.forName(__DEFAULT_ENGINES[i][__ENGINE]).newInstance());
  +      } catch(ClassNotFoundException cnfe) {
  +        // Don't do anything.  Package doesn't exist.
  +      } catch(InstantiationException ie) {
  +        // This will never happen.  Could use an assertion but that locks us
  +        // into J2SE 1.4.  We print the stack trace in case a developer made
  +        // a mistake in one of the class names.
  +        ie.printStackTrace();
  +      } catch(IllegalAccessException iae) {
  +        // This will never happen.  Could use an assertion but that locks us
  +        // into J2SE 1.4.  Again, we print a stack trace in case of developer
  +        // error.
  +        iae.printStackTrace();
  +      }
       }
  -
     }
   
     public PatternMatchingEngine get(String key) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: oro-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: oro-dev-help@jakarta.apache.org


Mime
View raw message