Package javax.rules

Examples of javax.rules.StatelessRuleSession


        RuleExecutionSet ruleSet =
            ruleSetProvider.createRuleExecutionSet( ruleReader, null );
        ruleAdministrator.registerRuleExecutionSet(
            RULES_RESOURCE, ruleSet, null );

        StatelessRuleSession statelessRuleSession = ( StatelessRuleSession ) ruleRuntime.createRuleSession( RULES_RESOURCE,
                                                                                                            null,
                                                                                                            RuleRuntime.STATELESS_SESSION_TYPE );
        assertNotNull( "cannot obtain StatelessRuleSession",
                       statelessRuleSession );
View Full Code Here


   * @param input
   * @throws Exception
   */
  public void execute(RuleRuntime rt, String ruleset, Object[] input)
      throws Exception {
    StatelessRuleSession srs = (StatelessRuleSession) rt.createRuleSession(
        ruleset, null, RuleRuntime.STATELESS_SESSION_TYPE);
    List output = srs.executeRules(Arrays.asList(input));
    System.out.println(output);
  }
View Full Code Here

        {
            log( "Ruleset URI: " + it.next( ) );
        }
        log( "Runtime API - Stateless Execution" );
        // create a StatelessRuleSession
        StatelessRuleSession statelessRuleSession = ( StatelessRuleSession )
            ruleRuntime.createRuleSession(
                uri, new HashMap( ), RuleRuntime.STATELESS_SESSION_TYPE );
        log( "Got Stateful Rule Session " + uri );
        log( "Implementation: " + statelessRuleSession );
        // add the user's User-Agent string to the session and execute it
        List inputList = new LinkedList( );
        inputList.add( userAgent );
        log( "Adding browser User-Agent to session: " + userAgent );
        List resultList = statelessRuleSession.executeRules( inputList );
        log( "Called executeRules on Stateless Rule Session: "
            + statelessRuleSession );
        log( "Result of calling executeRules: " + resultList );
        // release the session
        statelessRuleSession.release( );
        log( "Released Stateless Rule Session." );
        log( "Runtime API - Stateful Execution" );
        // create a StatefulRuleSession
        StatefulRuleSession statefulRuleSession = ( StatefulRuleSession )
            ruleRuntime.createRuleSession(
View Full Code Here

    }
    catch (RuleExecutionSetNotFoundException ex) {
      // expected
    }

    StatelessRuleSession session = (StatelessRuleSession) source.createSession(BIND_URI, null, RuleRuntime.STATELESS_SESSION_TYPE);
    assertNotNull("Created session is null", session);
    session.release();
  }
View Full Code Here

    DefaultRuleSource source = new DefaultRuleSource();
    setProperties(source);
    source.afterPropertiesSet();

    // get the stateless session
    StatelessRuleSession session = (StatelessRuleSession) source.createSession(BIND_URI, null, RuleRuntime.STATELESS_SESSION_TYPE);

    // execute it
    List facts = new ArrayList();
    facts.add("Gecko");
    facts = session.executeRules(facts);

    assertTrue("Facts does not contain Gecko", facts.contains("Gecko"));
    assertTrue("Facts does not contain a:Gecko", facts.contains("a:Gecko"));

    session.release();
  }
View Full Code Here

     * @param properties The proeprties for the session
     * @param callback The executor callback
     * @return Value returned by the executor implementation
     */
  public Object executeStateless(final String uri, final Map properties, final StatelessRuleSessionCallback callback) {
    StatelessRuleSession session = (StatelessRuleSession) createRuleSession(uri, properties, RuleRuntime.STATELESS_SESSION_TYPE);
    try {
      return callback.execute(session);
    }
    catch (InvalidRuleSessionException ex) {
      throw new Jsr94InvalidRuleSessionException(ex);
View Full Code Here

    }
    catch (RuleExecutionSetNotFoundException ex) {
      // expected
    }

    StatelessRuleSession session = (StatelessRuleSession) source.createSession(BIND_URI, null, RuleRuntime.STATELESS_SESSION_TYPE);
    assertNotNull("Created session is null", session);
    session.release();
  }
View Full Code Here

    public void testExecuteRulesGlobals() throws Exception {
        final java.util.Map map = new HashMap();
        java.util.Vector v = new java.util.Vector();
        map.put( "vector",
                 v );
        final StatelessRuleSession statelessSession = this.sessionBuilder.getStatelessRuleSession( this.bindUri_globals,
                                                                                                   map );

        final List inObjects = new ArrayList();

        final Person bob = new Person( "bob" );
        inObjects.add( bob );

        final Person jeannie = new Person( "jeannie" );
        jeannie.addSister( "rebecca" );
        inObjects.add( jeannie );

        final Person rebecca = new Person( "rebecca" );
        rebecca.addSister( "jeannie" );
        inObjects.add( rebecca );

        // execute the rules
        final List outList = statelessSession.executeRules( inObjects );

        assertEquals( "incorrect size",
                      5,
                      outList.size() );

        assertContains( outList,
                        bob );

        assertContains( outList,
                        rebecca );

        assertContains( outList,
                        jeannie );

        assertContains( outList,
                        "rebecca and jeannie are sisters" );

        assertContains( outList,
                        "jeannie and rebecca are sisters" );

        v = (java.util.Vector) map.get( "vector" );

        assertNotNull( "Global Vector null",
                       v );

        assertContains( v,
                        "rebecca and jeannie are sisters" );

        assertContains( v,
                        "jeannie and rebecca are sisters" );

        assertEquals( "Vector v incorrect size",
                      2,
                      v.size() );

        statelessSession.release();
    }
View Full Code Here

    /**
     * Test executeRules with normal drl.
     */
    @Test
    public void testExecuteRules() throws Exception {
        final StatelessRuleSession statelessSession = this.sessionBuilder.getStatelessRuleSession( this.bindUri );

        final List inObjects = new ArrayList();

        final Person bob = new Person( "bob" );
        inObjects.add( bob );

        final Person jeannie = new Person( "jeannie" );
        jeannie.addSister( "rebecca" );
        inObjects.add( jeannie );

        final Person rebecca = new Person( "rebecca" );
        rebecca.addSister( "jeannie" );
        inObjects.add( rebecca );

        // execute the rules
        final List outList = statelessSession.executeRules( inObjects );

        assertEquals( "incorrect size",
                      5,
                      outList.size() );

        assertContains( outList,
                        bob );

        assertContains( outList,
                        rebecca );

        assertContains( outList,
                        jeannie );

        assertContains( outList,
                        "rebecca and jeannie are sisters" );

        assertContains( outList,
                        "jeannie and rebecca are sisters" );

        statelessSession.release();
    }
View Full Code Here

    /**
     * Test executeRules with normal drl.
     */
    @Test
    public void testExecuteRulesWithXml() throws Exception {
        final StatelessRuleSession statelessSession = this.sessionBuilder.getStatelessRuleSession( this.bindUri_xml );

        final List inObjects = new ArrayList();

        final Person bob = new Person( "bob" );
        inObjects.add( bob );

        final Person jeannie = new Person( "jeannie" );
        jeannie.addSister( "rebecca" );
        inObjects.add( jeannie );

        final Person rebecca = new Person( "rebecca" );
        rebecca.addSister( "jeannie" );
        inObjects.add( rebecca );

        //execute the rules
        final List outList = statelessSession.executeRules( inObjects );

        assertEquals( "incorrect size",
                      5,
                      outList.size() );

        assertContains( outList,
                        bob );

        assertContains( outList,
                        rebecca );

        assertContains( outList,
                        jeannie );

        assertContains( outList,
                        "rebecca and jeannie are sisters" );

        assertContains( outList,
                        "jeannie and rebecca are sisters" );

        statelessSession.release();
    }
View Full Code Here

TOP

Related Classes of javax.rules.StatelessRuleSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.