[rules-users] Best way to detect duplicate rule names?

Mark Proctor mproctor at codehaus.org
Tue Nov 20 16:10:44 EST 2007


At the moment no, we could expose a handler/even that allows the user to 
add additional behaviour. For now your best way of doing this is to 
augment the PackageBuilder with AOP.

Mark
Jared Davis wrote:
> Hi,
>
> What is the best way to detect duplicate rule names in drl files? In my
> application a duplicate rule name is an error.
>
> There are multiple drl files loaded into one package.  If the rule name is
> duplicated across the files only the last rule is used. This behavior is clearly
> documented.
>
>
> The code below silently eats duplicated rules.
>
>  Reader sourceDrl = new InputStreamReader(  new FileInputStream("r1.drl"));
>  Reader sourceDsl = new InputStreamReader(  new FileInputStream("r.dsl"));
>  Reader sourceDrlTwo = new InputStreamReader(  new FileInputStream("r2.drl"));
>  Reader sourceDslTwo = new InputStreamReader(  new FileInputStream("r.dsl"));
>       
>  PackageBuilder builder = new PackageBuilder();
>  builder.addPackageFromDrl( sourceDrl, sourceDsl );
>  builder.addPackageFromDrl( sourceDrlTwo, sourceDslTwo );
>  System.out.println(builder.hasErrors()); // returns false 
> // A duplicate rule is not an error
>  Package pkg = builder.getPackage();
>
>
> Is there a better alternative than loading each drl into a separate
> PackageBuilder to track the individual rule counts in each drl file?
>
> eg
>
>  PackageBuilder builder = new PackageBuilder();
>  builder.addPackageFromDrl( sourceDrl, sourceDsl );
>  int ruleCountOne = builder.getPackage().getRules().length;
>
>  PackageBuilder builderTwo = new PackageBuilder();
>  builderTwo.addPackageFromDrl( sourceDrlTwo, sourceDslTwo );
>  int ruleCountTwo = builderTwo.getPackage().getRules().length;
>
>  // now re-compile file (reset readers as well...)
>
>  builder.addPackageFromDrl( sourceDrlTwo, sourceDslTwo );
>  if (builder.getPackage().getRules().length != (ruleCountOne + ruleCountTwo)) {
>    System.out.println("A duplicate exists - No clue what the name is"); 
>    // grep -i rule *.drl | sort | uniq -c
>  }
>
> This does not detect a duplicate rule name in the same file - that would be even
> better.
>
> Regards,
>
> Jared Davis
>
>
>  
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>   




More information about the rules-users mailing list