Package org.ocpsoft.rewrite.config

Examples of org.ocpsoft.rewrite.config.Rule


   @Override
   public RuleBuilder getRuleBuilder()
   {
      if (configurationRuleBuilder == null) {
         configurationRuleBuilder = config.addRule(new Rule() {
            @Override
            public void perform(Rewrite event, EvaluationContext context)
            {}

            @Override
View Full Code Here


                  public void perform(Rewrite event, EvaluationContext context)
                  {}
               });

      Assert.assertEquals(1, config.getRules().size());
      Rule rule = config.getRules().get(0);
      Assert.assertTrue(rule instanceof Context);

      String location = (String) ((Context) rule).get(RuleMetadata.PROVIDER_LOCATION);
      Assert.assertEquals(
               "org.ocpsoft.rewrite.metadata.ConfigurationBuilderMetadataTest"
View Full Code Here

   public void testBuildConfigurationMetadataWrappedRule()
   {
      Configuration config = ConfigurationBuilder.begin().addRule(RuleBuilder.define());

      Assert.assertEquals(1, config.getRules().size());
      Rule rule = config.getRules().get(0);
      Assert.assertTrue(rule instanceof Context);

      String location = (String) ((Context) rule).get(RuleMetadata.PROVIDER_LOCATION);
      Assert.assertEquals(
               "org.ocpsoft.rewrite.metadata.ConfigurationBuilderMetadataTest"
View Full Code Here

         {
            if (log.isDebugEnabled())
               log.debug("Using cached ruleset for event [" + event + "] from provider [" + provider + "].");
            for (int j = 0; j < list.size(); j++)
            {
               Rule rule = list.get(j);
               event.getEvaluatedRules().add(rule);

               context.clear();
               DefaultParameterValueStore values = new DefaultParameterValueStore();
               context.put(ParameterValueStore.class, values);
               context.setState(RewriteState.EVALUATING);

               if (rule.evaluate(event, context))
               {
                  if (handleBindings(event, context, values))
                  {
                     context.setState(RewriteState.PERFORMING);
                     if (log.isDebugEnabled())
                        log.debug("Rule [" + rule + "] matched and will be performed.");

                     List<Operation> preOperations = context.getPreOperations();
                     for (int k = 0; k < preOperations.size(); k++)
                     {
                        preOperations.get(k).perform(event, context);
                     }

                     if (event.getFlow().is(ServletRewriteFlow.HANDLED))
                     {
                        return;
                     }

                     rule.perform(event, context);

                     if (event.getFlow().is(ServletRewriteFlow.HANDLED))
                     {
                        return;
                     }

                     List<Operation> postOperations = context.getPostOperations();
                     for (int k = 0; k < postOperations.size(); k++)
                     {
                        postOperations.get(k).perform(event, context);
                     }

                     if (event.getFlow().is(ServletRewriteFlow.HANDLED))
                     {
                        return;
                     }
                  }
               }
               else
               {
                  event.getEvaluatedRules().remove(rule);
                  break;
               }
            }
         }
      }

      /*
       * Highly optimized loop - for performance reasons. Think before you change this!
       */
      List<Rule> cacheable = new ArrayList<Rule>();
      for (int i = 0; i < rules.size(); i++)
      {
         Rule rule = rules.get(i);
         event.getEvaluatedRules().add(rule);

         context.clear();
         DefaultParameterValueStore values = new DefaultParameterValueStore();
         context.put(ParameterValueStore.class, values);

         context.setState(RewriteState.EVALUATING);
         if (rule.evaluate(event, context))
         {
            if (handleBindings(event, context, values))
            {
               context.setState(RewriteState.PERFORMING);
               if (log.isDebugEnabled())
                  log.debug("Rule [" + rule + "] matched and will be performed.");
               cacheable.add(rule);
               List<Operation> preOperations = context.getPreOperations();
               for (int k = 0; k < preOperations.size(); k++)
               {
                  preOperations.get(k).perform(event, context);
               }

               if (event.getFlow().is(ServletRewriteFlow.HANDLED))
               {
                  break;
               }

               rule.perform(event, context);

               if (event.getFlow().is(ServletRewriteFlow.HANDLED))
               {
                  break;
               }
View Full Code Here

         {
            if (log.isDebugEnabled())
               log.debug("Using cached ruleset for event [" + event + "] from provider [" + provider + "].");
            for (int j = list.size() - 1; j >= 0; j--)
            {
               Rule rule = list.get(j);
               event.getEvaluatedRules().add(rule);

               context.clear();
               DefaultParameterValueStore values = new DefaultParameterValueStore();
               context.put(ParameterValueStore.class, values);
               context.setState(RewriteState.EVALUATING);

               if (rule.evaluate(event, context))
               {
                  if (handleBindings(event, context, values))
                  {
                     context.setState(RewriteState.PERFORMING);
                     if (log.isDebugEnabled())
                        log.debug("Rule [" + rule + "] matched and will be performed.");

                     List<Operation> preOperations = context.getPreOperations();
                     for (int k = 0; k < preOperations.size(); k++)
                     {
                        preOperations.get(k).perform(event, context);
                     }

                     if (event.getFlow().is(ServletRewriteFlow.HANDLED))
                     {
                        return;
                     }

                     rule.perform(event, context);

                     if (event.getFlow().is(ServletRewriteFlow.HANDLED))
                     {
                        return;
                     }

                     List<Operation> postOperations = context.getPostOperations();
                     for (int k = 0; k < postOperations.size(); k++)
                     {
                        postOperations.get(k).perform(event, context);
                     }

                     if (event.getFlow().is(ServletRewriteFlow.HANDLED))
                     {
                        return;
                     }
                  }
               }
               else
               {
                  event.getEvaluatedRules().remove(rule);
                  break;
               }
            }
         }
      }

      /*
       * Highly optimized loop - for performance reasons. Think before you change this!
       */
      List<Rule> cacheable = new ArrayList<Rule>();
      for (int i = rules.size() - 1; i >= 0; i--)
      {
         Rule rule = rules.get(i);
         event.getEvaluatedRules().add(rule);

         context.clear();
         DefaultParameterValueStore values = new DefaultParameterValueStore();
         context.put(ParameterValueStore.class, values);

         context.setState(RewriteState.EVALUATING);
         if (rule.evaluate(event, context))
         {
            if (handleBindings(event, context, values))
            {
               context.setState(RewriteState.PERFORMING);
               if (log.isDebugEnabled())
                  log.debug("Rule [" + rule + "] matched and will be performed.");
               cacheable.add(rule);
               List<Operation> preOperations = context.getPreOperations();
               for (int k = 0; k < preOperations.size(); k++)
               {
                  preOperations.get(k).perform(event, context);
               }

               if (event.getFlow().is(ServletRewriteFlow.HANDLED))
               {
                  break;
               }

               rule.perform(event, context);

               if (event.getFlow().is(ServletRewriteFlow.HANDLED))
               {
                  break;
               }
View Full Code Here

TOP

Related Classes of org.ocpsoft.rewrite.config.Rule

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.