If you want to check that there is no other WireCandidate besides the one matched, you
could use "not":
| rule "Use WireCandidate"
| when
| $import : ImportPackage( exporter == null )
| $wc : WireCandidate( importPackage == $import )
| not( WireCandidate( this != $wc, importPackage == $import ) )
| then
| System.out.println("Use WireCandidate " + $wc.getImportPackage() +
" --> " + $wc.getExportPackage());
| modify ( $wc.getImportPackage() ) { setExporter( $wc.getExportPackage() ) };
| retract ( $wc );
| end
|
Now, if you want a more general way of counting instances, use the count() function on
accumulate:
| rule "Use WireCandidate"
| when
| $import : ImportPackage( exporter == null )
| $wc : WireCandidate( importPackage == $import )
| // checks if the is exactly 1 instance
| Number( intValue == 1 ) from accumulate(
| $c : WireCandidate( importPackage == $import ),
| count($c) )
| then
| System.out.println("Use WireCandidate " + $wc.getImportPackage() +
" --> " + $wc.getExportPackage());
| modify ( $wc.getImportPackage() ) { setExporter( $wc.getExportPackage() ) };
| retract ( $wc );
| end
|
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4264895#...
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&a...