Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jacorb.notification.filter.bsh;
  
  /*
   *        JacORB - a free Java ORB
   *
   *   Copyright (C) 1997-2012 Gerald Brose / The JacORB Team.
   *
   *   This library is free software; you can redistribute it and/or
   *   modify it under the terms of the GNU Library General Public
  *   License as published by the Free Software Foundation; either
  *   version 2 of the License, or (at your option) any later version.
  *
  *   This library is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  *   Library General Public License for more details.
  *
  *   You should have received a copy of the GNU Library General Public
  *   License along with this library; if not, write to the Free
  *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 import java.util.Date;
 
 
 import bsh.EvalError;
This is an example of an custom Filter plugin. to make this grammar available to the FilterFactory you have to add an entry with the prefix jacorb.notification.filter.plugin to jacorb.properties. The entry must have the following form: jacorb.notification.filter.plugin.GRAMMAR_NAME=CLASSNAME
to make this grammar available one had to add the following entry to jacorb.properties: jacorb.notification.filter.plugin.BSH=org.jacorb.notification.filter.bsh.BSHFilter

Author(s):
Alphonse Bendt
 
 public class BSHFilter extends AbstractFilter
 {
     public static final String CONSTRAINT_GRAMMAR = "BSH";

    
as instances of this class will be created using picocontainer the class can specify its dependencies in the constructor. picocontainer will fill in the appropiate values (as long as they are registered).
 
     public BSHFilter(Configuration configEvaluationContextFactory evaluationContextFactory,
             MessageFactory messageFactoryPOA poathrows ConfigurationException
     {
         super(configevaluationContextFactorymessageFactorypoa);
     }
 
     public String constraint_grammar()
     {
         return ;
     }
 
     public FilterConstraint newFilterConstraint(ConstraintExp constraintExp)
     {
         return new BSHFilterConstraint(constraintExp);
     }
 
     private static class BSHFilterConstraint implements FilterConstraint
     {
         private final String constraint_;
 
         BSHFilterConstraint(ConstraintExp constraintExp)
         {
              = constraintExp.constraint_expr;
         }
 
         public EvaluationResult evaluate(EvaluationContext contextMessage message)
                 throws EvaluationException
         {
             try
             {
                 Interpreter _interpreter = new Interpreter();
 
                 // TODO import useful stuff
                 // predefine useful functions?
                 _interpreter.eval("import org.omg.CORBA.*;");
 
                 _interpreter.set("event"message.toAny());
                 _interpreter.set("date"new Date());
                _interpreter.set("constraint");
                Object _result = _interpreter.eval();
                if (_result == null)
                {
                    return .;
                }
                if (_result instanceof Boolean)
                {
                    if (_result.equals(.))
                    {
                        return .;
                    }
                    return .;
                }
                if (_result instanceof String)
                {
                    if ("".equals(_result))
                    {
                        return .;
                    }
                    return .;
                }
                return .;
            } catch (EvalError e)
            {
                throw new EvaluationException(e);
            }
        }
    }
New to GrepCode? Check out our FAQ X