Package org.drools.base

Examples of org.drools.base.ClassObjectFilter


               while (e.hasMoreElements())
               {
                  Principal role = (Principal) e.nextElement();
  
                  boolean found = false;
                  Iterator<Role> iter = getSecurityContext().iterateObjects(new ClassObjectFilter(Role.class));
                  while (iter.hasNext())
                  {
                     Role r = iter.next();
                     if (r.getName().equals(role.getName()))
                     {
                        found = true;
                        break;
                     }
                  }
                 
                  if (!found)
                  {
                     getSecurityContext().insert(new Role(role.getName()));
                  }
                 
               }
            }
         }   
        
         Iterator<Role> iter = getSecurityContext().iterateObjects(new ClassObjectFilter(Role.class));
         while (iter.hasNext())
         {
            Role r = iter.next();
            if (!identity.hasRole(r.getName()))
            {
View Full Code Here


        workingMemory.insert( new Cheese( "stilton",
                                          10 ) );

        workingMemory.fireAllRules();

        Iterator events = workingMemory.iterateObjects( new ClassObjectFilter( PersonInterface.class ) );

        assertTrue( events.hasNext() );
        assertEquals( 1,
                      results.size() );
        assertEquals( results.get( 0 ),
View Full Code Here

               while (e.hasMoreElements())
               {
                  Principal role = (Principal) e.nextElement();
  
                  boolean found = false;
                  Iterator<Role> iter = getSecurityContext().iterateObjects(new ClassObjectFilter(Role.class));
                  while (iter.hasNext())
                  {
                     Role r = iter.next();
                     if (r.getName().equals(role.getName()))
                     {
                        found = true;
                        break;
                     }
                  }
                 
                  if (!found)
                  {
                     getSecurityContext().insert(new Role(role.getName()));
                  }
                 
               }
            }
         }   
        
         Iterator<Role> iter = getSecurityContext().iterateObjects(new ClassObjectFilter(Role.class));
         while (iter.hasNext())
         {
            Role r = iter.next();
            if (!identity.hasRole(r.getName()))
            {
View Full Code Here

   @Override
   public boolean hasRole(String role)
   {
      if (securityContext != null)
      {
         Iterator<Role> iter = securityContext.iterateObjects(new ClassObjectFilter(Role.class));
        
         while (iter.hasNext())
         {
            Role r = iter.next();
            if (r.getName().equals(role)) return true;
View Full Code Here

   {
      StatefulSession securityContext = getSecurityContext();
     
      if (securityContext != null)
      {
         Iterator<Role> iter = securityContext.iterateObjects(new ClassObjectFilter(Role.class));
         while (iter.hasNext())
         {
            getSecurityContext().retract(securityContext.getFactHandle(iter.next()));
         }
      }
View Full Code Here

   {
      StatefulSession securityContext = getSecurityContext();     
     
      if (securityContext != null)
      {
         Iterator<Role> iter = securityContext.iterateObjects(new ClassObjectFilter(Role.class));
         while (iter.hasNext())
         {
            Role r = iter.next();
            if (r.getName().equals(role))
            {
View Full Code Here

                                           1 );
        List list;

        final FactHandle h1 = workingMemory.insert( cheese1 );
        workingMemory.fireAllRules();
        list = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( cheese1.getType().getClass() ) ) );
        assertEquals( 1,
                      list.size() );
        // probably dangerous, as contains works with equals, not identity
        assertEquals( cheese1.getType(),
                      list.get( 0 ) );
        // FactHandle ht = workingMemory.getFactHandle(c1.getType());

        final FactHandle h2 = workingMemory.insert( cheese2 );
        workingMemory.fireAllRules();
        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( cheese1.getType().getClass() ) ) );
        assertEquals( 1,
                      list.size() );
        assertEquals( cheese1.getType(),
                      list.get( 0 ) );
       
        assertEquals( 3, IteratorToList.convert( workingMemory.iterateObjects() ).size() );

        workingMemory.retract( h1 );
        workingMemory.fireAllRules();
        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( cheese1.getType().getClass() ) ) );
        assertEquals( "cheese-type " + cheese1.getType() + " was retracted, but should not. Backed by cheese2 => type.",
                      1,
                      list.size() );
        assertEquals( "cheese-type " + cheese1.getType() + " was retracted, but should not. Backed by cheese2 => type.",
                      cheese1.getType(),
                      list.get( 0 ) );

        workingMemory.retract( h2 );
        workingMemory.fireAllRules();
        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( cheese1.getType().getClass() ) ) );
        assertEquals( "cheese-type " + cheese1.getType() + " was not retracted, but should have. Neither  cheese1 => type nor cheese2 => type is true.",
                      0,
                      list.size() );
    }
View Full Code Here

        workingMemory.setGlobal( "b",
                                 b );

        FactHandle h1 = workingMemory.insert( a );
        workingMemory.fireAllRules();
        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( a.getClass() ) ) );
        assertEquals( 2,
                      list.size() );
        assertTrue( list.contains( a ) );
        assertTrue( list.contains( b ) );

        workingMemory.retract( h1 );
        workingMemory.fireAllRules();
        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( a.getClass() ) ) );
        assertEquals( "b was retracted, but it should not have. Is backed by b => b being true.",
                      1,
                      list.size() );
        assertEquals( "b was retracted, but it should not have. Is backed by b => b being true.",
                      b,
                      list.get( 0 ) );

        h1 = workingMemory.getFactHandle( b );
        workingMemory.retract( h1 );
        workingMemory.fireAllRules();
        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( a.getClass() ) ) );
        assertEquals( 0,
                      list.size() );
    }
View Full Code Here

                                 a );
        workingMemory.setGlobal( "l",
                                 l );

        workingMemory.fireAllRules();
        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( a.getClass() ) ) );
        assertEquals( "a still asserted.",
                      0,
                      list.size() );
        assertEquals( "Rule has not fired (looped) expected number of times",
                      10,
View Full Code Here

                                 a );
        workingMemory.setGlobal( "l",
                                 l );

        workingMemory.fireAllRules();
        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( a.getClass() ) ) );
        assertEquals( "a still in WM",
                      0,
                      list.size() );
        assertEquals( "Rule should not loop",
                      1,
View Full Code Here

TOP

Related Classes of org.drools.base.ClassObjectFilter

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.