View Javadoc

1   /*
2    * $Id: StreamingScriptComponent.java 10430 2008-01-21 16:28:22Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.components.script.jsr223;
12  
13  import org.mule.impl.model.streaming.StreamingService;
14  import org.mule.umo.UMOEventContext;
15  
16  import java.io.InputStream;
17  import java.io.OutputStream;
18  
19  import javax.script.Bindings;
20  
21  /**
22   * A JSR 223 Script streaming component. Allows any JSR 223 compliant script engines
23   * such as JavaScript, Groovy or Rhino to be embedded as Mule components.
24   */
25  public class StreamingScriptComponent extends AbstractScriptComponent implements StreamingService
26  {
27  
28      public void call(InputStream in, OutputStream out, UMOEventContext eventContext) throws Exception
29      {
30          Bindings bindings = this.getBindings();
31          this.populateBindings(bindings, in, out, eventContext);
32          this.runScript(bindings);
33      }
34  
35      protected void populateBindings(Bindings namespace, InputStream in, OutputStream out,
36          UMOEventContext context)
37      {
38          super.populateBindings(namespace, context);
39          
40          namespace.put("inputStream", in);
41          namespace.put("outputStream", out);
42      }
43  
44  }