Package groovy.lang

Examples of groovy.lang.Binding


        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        final Console console = new Console(Console.class.getClassLoader());
        console.setBeforeExecution(new Closure(null) {
          public void doCall() {
            console.setShell(new GroovyShell(Console.class.getClassLoader(), new Binding()) {
              public Object run(String scriptText, String fileName, String[] args) throws org.codehaus.groovy.control.CompilationFailedException {
                return super.run(IMPORTS + scriptText, fileName, args);
              };
            });
          }
View Full Code Here


    protected boolean handleBody(HttpRequest request, HttpResponse response) throws IOException {
        if( request.getUrl().endsWith(".groovy") ) {
            if( log.isLoggable( Level.INFO ) ) {
                log.log( Level.INFO, "Executing script: " + request.getUrl() );
            }
            Binding binding = createScriptContext(request, response);

            try {
                GroovyShell shell = new GroovyShell( binding );
                File groovyScript = Http.translatePath( groovyDir, request.getUrl() );
                if( groovyScript.exists() ) {
View Full Code Here

        return false;
    }

    private Binding createScriptContext(HttpRequest request, HttpResponse response) {
        // Set up the script context
        Binding binding = new Binding();
        binding.setVariable("request", request);
        binding.setVariable("response", response);
        return binding;
    }
View Full Code Here

  private static final Logger logger = Logger.getLogger(ScriptInGroovy.class);

  public ScriptInGroovy(final String filename) {
    super(filename);
    groovyScript = filename;
    groovyBinding = new Binding();
    groovyBinding.setVariable("game", this);
    groovyBinding.setVariable("logger", logger);
    groovyBinding.setVariable("storage", new HashMap<Object, Object>());

    groovyBinding.setVariable("rules", SingletonRepository.getRuleProcessor());
View Full Code Here

    final int autoclose = MathHelper.parseInt(attributes.get("autoclose"));
   
    ChatCondition condition = null;
    final String condString = attributes.get("condition");
    if (condString != null) {
      final GroovyShell interp = new GroovyShell(new Binding());
      String code = "import games.stendhal.server.entity.npc.condition.*;\r\n"
        + condString;
      try {
        condition = (ChatCondition) interp.evaluate(code);
      } catch (CompilationFailedException e) {
View Full Code Here

  protected ChatCondition getCondition(final ConfigurableFactoryContext ctx) {
    String value = ctx.getString("condition", null);
    if (value == null) {
      return null;
    }
    Binding groovyBinding = new Binding();
    final GroovyShell interp = new GroovyShell(groovyBinding);
    try {
      String code = "import games.stendhal.server.entity.npc.condition.*;\r\n"
        + value;
      return (ChatCondition) interp.evaluate(code);
View Full Code Here

  protected ChatAction getAction(final ConfigurableFactoryContext ctx) {
    String value = ctx.getString("action", null);
    if (value == null) {
      return null;
    }
    Binding groovyBinding = new Binding();
    final GroovyShell interp = new GroovyShell(groovyBinding);
    try {
      String code = "import games.stendhal.server.entity.npc.action.*;\r\n"
        + value;
      return (ChatAction) interp.evaluate(code);
View Full Code Here

    private void runScript(Script script, ContentHandler handler)
    {
        HiveMindBuilder builder = new HiveMindBuilder(handler);

        Binding processorBinding = new Binding();
        processorBinding.setVariable("processor", builder);

        script.setBinding(processorBinding);

        script.run();
    }
View Full Code Here

        assertEquals(7, result);
    }
   
    @Test
    public void testLatLng() {
        Binding binding = new Binding();
        binding.setVariable("street", "1600 Pennsylvania Avenue");
        binding.setVariable("city", "Washington");
        binding.setVariable("state", "DC");
        GroovyShell shell = new GroovyShell(binding);
        try {
            shell.evaluate(new File("src/geocodeV3.groovy"));
            assertEquals(38.898,
                Double.parseDouble((String) binding.getVariable("lat")),0.01);
            assertEquals(-77.037,
                Double.parseDouble((String) binding.getVariable("lng")),0.01);
        } catch (CompilationFailedException | IOException e) {
            e.printStackTrace();
        }
    }
View Full Code Here

        }
    }
   
    @Test
    public void testLatLngWithModifiedBinding() {
        Binding binding = new Binding();

        // The White House, Washington, DC
        binding.setVariable("street", "1600 Pennsylvania Avenue");
        binding.setVariable("city", "Washington");
        binding.setVariable("state", "DC");
        GroovyShell shell = new GroovyShell(binding);
        try {
            shell.evaluate(new File("src/geocodeV3.groovy"));
            assertEquals(38.898,
                Double.parseDouble((String) binding.getVariable("lat")),0.01);
            assertEquals(-77.037,
                Double.parseDouble((String) binding.getVariable("lng")),0.01);

            // Greenwich Observatory, Greenwich, England
            binding.setVariable("street", "Blackheath Avenue");
            binding.setVariable("city","Greenwich");
            binding.setVariable("state","UK");
            shell.evaluate(new File("src/geocodeV3.groovy"));
            assertEquals(51.476,
                    Double.parseDouble((String) binding.getVariable("lat")),0.01);
                assertEquals(0.001,
                    Double.parseDouble((String) binding.getVariable("lng")),0.01);
               
        } catch (CompilationFailedException | IOException e) {
            e.printStackTrace();
        }
    }
View Full Code Here

TOP

Related Classes of groovy.lang.Binding

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.