private RuleAttribute visitRuleAttribute( RuleAttribute attr ) { RuleAttribute clone = new RuleAttribute(); clone.setAttributeName( attr.getAttributeName() ); clone.setValue( attr.getValue() ); return clone; }
/** * Marshal model attributes * @param buf * @param model */ protected void marshalAttributes( final StringBuilder buf, final RuleModel model ) { boolean hasDialect = false; for ( int i = 0; i < model.attributes.length; i++ ) { RuleAttribute attr = model.attributes[ i ]; buf.append( "\t" ); buf.append( attr ); buf.append( "\n" ); if ( attr.getAttributeName().equals( "dialect" ) ) { constraintValueBuilder = DRLConstraintValueBuilder.getBuilder( attr.getValue() ); hasDialect = true; } } // Un comment below for mvel if ( !hasDialect ) { RuleAttribute attr = new RuleAttribute( "dialect", DEFAULT_DIALECT ); buf.append( "\t" ); buf.append( attr ); buf.append( "\n" ); } }
private TextBox textBoxEditor( final RuleAttribute at, final boolean isReadOnly ) { final TextBox box = new TextBox(); box.setEnabled( !isReadOnly ); box.setVisibleLength( ( at.getValue().length() < 3 ) ? 3 : at.getValue().length() ); box.setText( at.getValue() ); box.addChangeHandler( new ChangeHandler() { public void onChange( ChangeEvent event ) { at.setValue( box.getText() ); } } ); if ( at.getAttributeName().equals( DATE_EFFECTIVE_ATTR ) || at.getAttributeName().equals( DATE_EXPIRES_ATTR ) ) { if ( at.getValue() == null || "".equals( at.getValue() ) ) { box.setText( "" ); } box.setVisibleLength( 10 ); } box.addKeyUpHandler( new KeyUpHandler() { public void onKeyUp( KeyUpEvent event ) { int length = box.getText().length(); box.setVisibleLength( length > 0 ? length : 1 ); } } ); return box; }
private boolean parseAttributes( RuleModel m, Map<String, AttributeDescr> attributes ) { boolean isJavaDialect = false; for ( Map.Entry<String, AttributeDescr> entry : attributes.entrySet() ) { String name = entry.getKey(); String value = entry.getValue().getValue(); RuleAttribute ruleAttribute = new RuleAttribute( name, value ); m.addAttribute( ruleAttribute ); isJavaDialect |= name.equals( "dialect" ) && value.equals( "java" ); } return isJavaDialect; }
private Widget checkBoxEditor( final RuleAttribute at, final boolean isReadOnly ) { final CheckBox box = new CheckBox(); box.setEnabled( !isReadOnly ); if ( at.getValue() == null ) { box.setValue( true ); at.setValue( TRUE_VALUE ); } else { box.setValue( ( at.getValue().equals( TRUE_VALUE ) ) ); } box.addClickHandler( new ClickHandler() { public void onClick( ClickEvent event ) { at.setValue( ( box.getValue() ) ? TRUE_VALUE : FALSE_VALUE ); } } ); return box; }
private Widget getEditorWidget( final RuleAttribute at, final int idx, final boolean isReadOnly ) { Widget editor; if ( at.getAttributeName().equals( ENABLED_ATTR ) || at.getAttributeName().equals( AUTO_FOCUS_ATTR ) || at.getAttributeName().equals( LOCK_ON_ACTIVE_ATTR ) || at.getAttributeName().equals( NO_LOOP_ATTR ) ) { editor = checkBoxEditor( at, isReadOnly ); } else { editor = textBoxEditor( at, isReadOnly ); } DirtyableHorizontalPane horiz = new DirtyableHorizontalPane(); horiz.add( editor ); if ( !isReadOnly ) { horiz.add( getRemoveIcon( idx ) ); } return horiz; }
public void onChange( ChangeEvent event ) { at.setValue( box.getText() ); } } );
public void onChange( ChangeEvent event ) { String attr = list.getItemText( list.getSelectedIndex() ); if ( attr.equals( RuleAttributeWidget.LOCK_LHS ) || attr.equals( RuleAttributeWidget.LOCK_RHS ) ) { model.addMetadata( new RuleMetadata( attr, "true" ) ); } else { model.addAttribute( new RuleAttribute( attr, "" ) ); } refresh.execute(); hide(); } } );
rm.attributes.length ); assertEquals( "salience", rm.attributes[ 0 ].getAttributeName() ); assertEquals( "a", rm.attributes[ 0 ].getValue() ); rm.attributes.length ); assertEquals( "salience", rm.attributes[ 0 ].getAttributeName() ); assertEquals( "a", rm.attributes[ 0 ].getValue() ); assertEquals( "agenda-group", rm.attributes[ 1 ].getAttributeName() ); assertEquals( "b", rm.attributes[ 1 ].getValue() );
layout.addAttribute( at.getAttributeName(), getEditorWidget( at, i,
public void onClick( ClickEvent event ) { at.setValue( ( box.getValue() ) ? TRUE_VALUE : FALSE_VALUE ); } } );
@Test public void testAttr() { RuleModel m = new RuleModel(); m.attributes = new RuleAttribute[ 1 ]; m.attributes[ 0 ] = new RuleAttribute( "enabled", "true" ); final String drl = brlPersistence.marshal( m ); assertTrue( drl.indexOf( "enabled true" ) > 0 ); }
@Test public void testLockOnActive() { RuleModel m = new RuleModel(); m.addAttribute( new RuleAttribute( "lock-on-active", "true" ) ); m.addAttribute( new RuleAttribute( "auto-focus", "true" ) ); m.addAttribute( new RuleAttribute( "duration", "42" ) ); String s = BRDRLPersistence.getInstance().marshal( m ); assertTrue( s.indexOf( "lock-on-active true" ) > -1 ); assertTrue( s.indexOf( "auto-focus true" ) > -1 ); assertTrue( s.indexOf( "duration 42" ) > -1 ); checkMarshallUnmarshall( s, m ); }
@Test public void testDefaultMVEL() { RuleModel m = new RuleModel(); String s = BRDRLPersistence.getInstance().marshal( m ); assertTrue( s.indexOf( "mvel" ) > -1 ); m.addAttribute( new RuleAttribute( "dialect", "goober" ) ); s = BRDRLPersistence.getInstance().marshal( m ); assertFalse( s.indexOf( "mvel" ) > -1 ); assertTrue( s.indexOf( "goober" ) > -1 ); }
@Test public void testAttributes() { final RuleModel m = new RuleModel(); final RuleAttribute at = new RuleAttribute( "salience", "42" ); m.addAttribute( at ); assertEquals( 1, m.attributes.length ); assertEquals( at, m.attributes[0] ); final RuleAttribute at2 = new RuleAttribute( "agenda-group", "x" ); m.addAttribute( at2 ); assertEquals( 2, m.attributes.length ); assertEquals( at2, m.attributes[1] ); m.removeAttribute( 0 ); assertEquals( 1, m.attributes.length ); assertEquals( at2, m.attributes[0] ); } /*
@Test public void testBasics() { String expected = "rule \"my rule\"\n\tno-loop true\n\tdialect \"mvel\"\n\twhen\n\t\tPerson( )\n" + "\t\tAccident( )\n\tthen\n\t\tinsert( new Report() );\nend\n"; RuleModel m = new RuleModel(); m.addLhsItem( new FactPattern( "Person" ) ); m.addLhsItem( new FactPattern( "Accident" ) ); m.addAttribute( new RuleAttribute( "no-loop", "true" ) ); m.addRhsItem( new ActionInsertFact( "Report" ) ); m.name = "my rule"; checkMarshallUnmarshall( expected, m ); }
@Test public void testInsertLogical() { String expected = "rule \"my rule\"\n\tno-loop true\n\tdialect \"mvel\"\n\twhen\n\t\tPerson( )\n" + "\t\tAccident( )\n\tthen\n\t\tinsertLogical( new Report() );\nend\n"; final RuleModel m = new RuleModel(); m.addLhsItem( new FactPattern( "Person" ) ); m.addLhsItem( new FactPattern( "Accident" ) ); m.addAttribute( new RuleAttribute( "no-loop", "true" ) ); m.addRhsItem( new ActionInsertLogicalFact( "Report" ) ); m.name = "my rule"; checkMarshallUnmarshall( expected, m ); }
m.addAttribute( new RuleAttribute( "dialect", "mvel" ) );
m.addAttribute( new RuleAttribute( "dialect", "java" ) );
m.name = "Complex Rule"; m.addAttribute( new RuleAttribute( "no-loop", "true" ) ); m.addAttribute( new RuleAttribute( "salience", "-10" ) ); m.addAttribute( new RuleAttribute( "agenda-group", "aGroup" ) );