From: <jbo...@li...> - 2006-07-08 16:08:03
|
Author: mar...@jb... Date: 2006-07-08 12:07:57 -0400 (Sat, 08 Jul 2006) New Revision: 4953 Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java Log: JBRULES-363 Java 5 language support -Rejigged the default settings, so it works more like the compiler setting. Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java 2006-07-08 13:06:06 UTC (rev 4952) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java 2006-07-08 16:07:57 UTC (rev 4953) @@ -34,22 +34,22 @@ * system property "drools.compiler.lnglevel". Valid values are 1.4, 1.5 and 1.6. */ public class PackageBuilderConfiguration { - public static final int ECLIPSE = 0; - public static final int JANINO = 1; + public static final int ECLIPSE = 0; + public static final int JANINO = 1; - /** This will be only setup once. It tries to look for a system property */ - private static final int CONFIGURED_COMPILER = getDefaultCompiler(); - - private int compiler = PackageBuilderConfiguration.CONFIGURED_COMPILER; - - private ClassLoader classLoader; + public static final String[] LANGUAGE_LEVELS = new String[]{"1.4", "1.5", "1.6"}; + public static final String DEFAULT_LANGUAGE_LEVEL = "1.4"; - public static final String DEFAULT_LANGUAGE_LEVEL = "1.4"; + /** These will be only setup once. It tries to look for a system property */ + private static final int CONFIGURED_COMPILER = getDefaultCompiler(); + private static final String CONFIGURED_LANGUAGE_LEVEL = getDefaultLanguageLevel(); - public static final String[] LANGUAGE_LEVELS = new String[] {"1.4","1.5","1.6"}; - - private String languageLevel = null; + private int compiler = PackageBuilderConfiguration.CONFIGURED_COMPILER; + private ClassLoader classLoader; + + private String languageLevel = PackageBuilderConfiguration.CONFIGURED_LANGUAGE_LEVEL; + public PackageBuilderConfiguration() { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if ( classLoader == null ) { @@ -61,18 +61,18 @@ public int getCompiler() { return this.compiler; } - + public String getJavaLanguageLevel() { - if (languageLevel != null) - return languageLevel; - languageLevel = System.getProperty( "drools.compiler.lnglevel", DEFAULT_LANGUAGE_LEVEL ); - if (Arrays.binarySearch( LANGUAGE_LEVELS, languageLevel ) < 0) - throw new RuntimeDroolsException( "value '" + languageLevel + "' is not a valid language level" ); - return languageLevel; + if ( languageLevel != null ) return languageLevel; + languageLevel = System.getProperty( "drools.compiler.lnglevel", + DEFAULT_LANGUAGE_LEVEL ); + if ( Arrays.binarySearch( LANGUAGE_LEVELS, + languageLevel ) < 0 ) throw new RuntimeDroolsException( "value '" + languageLevel + "' is not a valid language level" ); + return languageLevel; } - + public void setJavaLanguageLevel(String level) { - languageLevel = level; + languageLevel = level; } /** @@ -111,7 +111,7 @@ static int getDefaultCompiler() { try { final String prop = System.getProperty( "drools.compiler", - "ECLIPSE" ); + "ECLIPSE" ); if ( prop.equals( "ECLIPSE".intern() ) ) { return PackageBuilderConfiguration.ECLIPSE; } else if ( prop.equals( "JANINO" ) ) { @@ -125,4 +125,25 @@ return PackageBuilderConfiguration.ECLIPSE; } } + + static String getDefaultLanguageLevel() { + try { + String languageLevel = System.getProperty( "drools.compiler.lnglevel", + DEFAULT_LANGUAGE_LEVEL ); + + if ( Arrays.binarySearch( LANGUAGE_LEVELS, + languageLevel ) < 0 ) { + throw new RuntimeDroolsException( "value '" + languageLevel + "' is not a valid language level" ); + } + + return languageLevel; + } catch ( Exception e) { + e.printStackTrace(); + return "1.4"; + } +// } catch ( final SecurityException e ) { +// System.err.println( "Drools config: unable to read the drools.compiler.lnglevel property. Using default." ); +// return "1.4"; +// } + } } \ No newline at end of file |