Package javax.rules

Examples of javax.rules.RuleRuntime


      System.out.println( "Bound RuleExecutionSet to URI: " + uri);

      // Get a RuleRuntime and invoke the rule engine.
      System.out.println( "\nRuntime API\n" );

      RuleRuntime ruleRuntime = serviceProvider.getRuleRuntime();
      System.out.println( "Acquired RuleRuntime: " + ruleRuntime );

      // create a StatefulRuleSession
      statefulRuleSession =
              (StatefulRuleSession) ruleRuntime.createRuleSession( uri,
              new HashMap(),
              RuleRuntime.STATEFUL_SESSION_TYPE );

      System.out.println( "Got Stateful Rule Session: " + statefulRuleSession );
View Full Code Here


            System.out.println( "Bound RuleExecutionSet to URI: " + uri);

            // Get a RuleRuntime and invoke the rule engine.
            System.out.println( "\nRuntime API\n" );

            RuleRuntime ruleRuntime = serviceProvider.getRuleRuntime();
            System.out.println( "Acquired RuleRuntime: " + ruleRuntime );

            // create a StatelessRuleSession
            StatelessRuleSession statelessRuleSession =
                    (StatelessRuleSession) ruleRuntime.createRuleSession(uri,
                    new HashMap(), RuleRuntime.STATELESS_SESSION_TYPE);

            System.out.println( "Got Stateless Rule Session: " +
                                                    statelessRuleSession );

            // call executeRules with some input objects

            // Create a Customer as specified by the TCK documentation.
            Customer inputCustomer = new Customer();
            inputCustomer.setCreditLimit(5000);

            // Create an Invoice as specified by the TCK documentation.
            Invoice inputInvoice = new Invoice();
            inputInvoice.setAmount(2000);

            // Create a input list.
            List input = new ArrayList();
            input.add(inputCustomer);
            input.add(inputInvoice);

            // Print the input.
            System.out.println("Calling rule session with the following data");
            System.out.println("Customer credit limit input: " +
                                               inputCustomer.getCreditLimit());
            System.out.println("Invoice:\n" +
                                               " amount: " + inputInvoice.getAmount() +
                                               " status: " + inputInvoice.getStatus());

            // Execute the rules without a filter.
            List results = statelessRuleSession.executeRules(input);

            System.out.println( "Called executeRules on Stateless Rule Session: " + statelessRuleSession );

            System.out.println( "Result of calling executeRules: " +
                                                    results.size() + " results." );

            // Loop over the results.
            Iterator itr = results.iterator();
            while(itr.hasNext()) {
                    Object obj = itr.next();
                    if (obj instanceof Customer)
                            System.out.println("Customer credit limit result: " +
                                                               ((Customer) obj).getCreditLimit());
                    if (obj instanceof Invoice)
                            System.out.println("Invoice:\n" +
                                                               " amount: " + ((Invoice) obj).getAmount() +
                                                               " status: " + ((Invoice) obj).getStatus());
            }

            // Release the session.
            statelessRuleSession.release();
            System.out.println( "Released Stateless Rule Session." );
            System.out.println();

            // create a StatefulRuleSession
            StatefulRuleSession statefulRuleSession =
                    (StatefulRuleSession) ruleRuntime.createRuleSession( uri,
                    new HashMap(),
                    RuleRuntime.STATEFUL_SESSION_TYPE );

            System.out.println( "Got Stateful Rule Session: " + statefulRuleSession );
            // Add another Invoice.
View Full Code Here

      System.out.println( "Bound RuleExecutionSet to URI: " + uri);

      // Get a RuleRuntime and invoke the rule engine.
      System.out.println( "\nRuntime API\n" );

      RuleRuntime ruleRuntime = serviceProvider.getRuleRuntime();
      System.out.println( "Acquired RuleRuntime: " + ruleRuntime );

      // create a StatefulRuleSession
      StatefulRuleSession statefulRuleSession =
              (StatefulRuleSession) ruleRuntime.createRuleSession( uri,
              new HashMap(),
              RuleRuntime.STATEFUL_SESSION_TYPE );

      System.out.println( "Got Stateful Rule Session: " + statefulRuleSession );
View Full Code Here

      System.out.println( "Bound RuleExecutionSet to URI: " + uri);

      // Get a RuleRuntime and invoke the rule engine.
      System.out.println( "\nRuntime API\n" );

      RuleRuntime ruleRuntime = serviceProvider.getRuleRuntime();
      System.out.println( "Acquired RuleRuntime: " + ruleRuntime );

      // create a StatefulRuleSession
      statefulRuleSession =
              (StatefulRuleSession) ruleRuntime.createRuleSession( uri,
              new HashMap(),
              RuleRuntime.STATEFUL_SESSION_TYPE );

      System.out.println( "Got Stateful Rule Session: " + statefulRuleSession );
View Full Code Here

      System.out.println( "Bound RuleExecutionSet to URI: " + uri);

      // Get a RuleRuntime and invoke the rule engine.
      System.out.println( "\nRuntime API\n" );

      RuleRuntime ruleRuntime = serviceProvider.getRuleRuntime();
      System.out.println( "Acquired RuleRuntime: " + ruleRuntime );

      // create a StatefulRuleSession
      StatefulRuleSession statefulRuleSession =
              (StatefulRuleSession) ruleRuntime.createRuleSession( uri,
              new HashMap(),
              RuleRuntime.STATEFUL_SESSION_TYPE );

      System.out.println( "Got Stateful Rule Session: " + statefulRuleSession );
View Full Code Here

        properties.clear();
        final List list = new ArrayList();
        properties.put( "list",
                        list );
       
        RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime();
        StatefulRuleSession session = (StatefulRuleSession) ruleRuntime.createRuleSession( "IntegrationExampleTest.xls",
                                                                                           properties,
                                                                                           RuleRuntime.STATEFUL_SESSION_TYPE );

        //ASSERT AND FIRE
        session.addObject( new Cheese( "stilton",
View Full Code Here

     */
    public void testRuleRuntime() throws Exception {
        Class.forName("org.drools.jsr94.rules.RuleServiceProviderImpl");
        RuleServiceProvider ruleServiceProvider = RuleServiceProviderManager.getRuleServiceProvider("http://drools.org/");
       
        final RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime();
        assertNotNull( "cannot obtain RuleRuntime",
                       ruleRuntime );
        assertTrue( "not a class instance",
                    ruleRuntime == ruleServiceProvider.getRuleRuntime() );
    }
View Full Code Here

    /**
     * Test createRuleSession.
     */
    public void testCreateRuleStatelessRuleSession() throws Exception {
        final RuleRuntime ruleRuntime = this.ruleServiceProvider.getRuleRuntime();
        assertNotNull( "cannot obtain RuleRuntime",
                       ruleRuntime );

        // expect RuleExecutionSetNotFoundException
        try {
            ruleRuntime.createRuleSession( "someUri",
                                           null,
                                           RuleRuntime.STATELESS_SESSION_TYPE );
            fail( "RuleExecutionSetNotFoundException expected" );
        } catch ( final RuleExecutionSetNotFoundException ex ) {
            // ignore exception
        }

        // read rules and register with administrator
        final Reader ruleReader = new InputStreamReader( RuleRuntimeTest.class.getResourceAsStream( this.RULES_RESOURCE ) );
        final RuleExecutionSet ruleSet = this.ruleSetProvider.createRuleExecutionSet( ruleReader,
                                                                                      null );
        this.ruleAdministrator.registerRuleExecutionSet( this.RULES_RESOURCE,
                                                         ruleSet,
                                                         null );

        final StatelessRuleSession statelessRuleSession = (StatelessRuleSession) ruleRuntime.createRuleSession( this.RULES_RESOURCE,
                                                                                                                null,
                                                                                                                RuleRuntime.STATELESS_SESSION_TYPE );
        assertNotNull( "cannot obtain StatelessRuleSession",
                       statelessRuleSession );

View Full Code Here

    /**
     * Test createRuleSession.
     */
    public void testCreateRuleStatefulRuleSession() throws Exception {
        final RuleRuntime ruleRuntime = this.ruleServiceProvider.getRuleRuntime();
        assertNotNull( "cannot obtain RuleRuntime",
                       ruleRuntime );

        // expect RuleExecutionSetNotFoundException
        try {
            ruleRuntime.createRuleSession( "someUri",
                                           null,
                                           RuleRuntime.STATEFUL_SESSION_TYPE );
            fail( "RuleExecutionSetNotFoundException expected" );
        } catch ( final RuleExecutionSetNotFoundException ex ) {
            // ignore exception
        }

        // read rules and register with administrator
        final Reader ruleReader = new InputStreamReader( RuleRuntimeTest.class.getResourceAsStream( this.RULES_RESOURCE ) );
        final RuleExecutionSet ruleSet = this.ruleSetProvider.createRuleExecutionSet( ruleReader,
                                                                                      null );
        this.ruleAdministrator.registerRuleExecutionSet( this.RULES_RESOURCE,
                                                         ruleSet,
                                                         null );

        final StatefulRuleSession statefulRuleSession = (StatefulRuleSession) ruleRuntime.createRuleSession( this.RULES_RESOURCE,
                                                                                                             null,
                                                                                                             RuleRuntime.STATEFUL_SESSION_TYPE );
        assertNotNull( "cannot obtain StatefulRuleSession",
                       statefulRuleSession );

View Full Code Here

    /**
     * Test getRegistrations.
     */
    public void testGetRegistrations() throws Exception {
        final RuleRuntime ruleRuntime = this.ruleServiceProvider.getRuleRuntime();
        assertNotNull( "cannot obtain RuleRuntime",
                       ruleRuntime );

        // read rules and register with administrator
        final Reader ruleReader = new InputStreamReader( RuleRuntimeTest.class.getResourceAsStream( this.RULES_RESOURCE ) );
        final RuleExecutionSet ruleSet = this.ruleSetProvider.createRuleExecutionSet( ruleReader,
                                                                                      null );
        this.ruleAdministrator.registerRuleExecutionSet( this.RULES_RESOURCE,
                                                         ruleSet,
                                                         null );

        final List list = ruleRuntime.getRegistrations();
        assertTrue( "no registrations found",
                    list.size() > 0 );

        this.ruleAdministrator.deregisterRuleExecutionSet( this.RULES_RESOURCE,
                                                           null );
View Full Code Here

TOP

Related Classes of javax.rules.RuleRuntime

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.