View Javadoc

1   /*
2    * $Id: AbstractScriptComponent.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.MuleManager;
14  import org.mule.umo.UMOEventContext;
15  import org.mule.umo.lifecycle.InitialisationException;
16  import org.mule.util.MuleLogger;
17  
18  import javax.script.Bindings;
19  
20  public class AbstractScriptComponent extends Scriptable
21  {
22      private Bindings bindings;
23  
24      public void initialise() throws InitialisationException
25      {
26          super.initialise();
27          bindings = getScriptEngine().createBindings();
28      }
29  
30      protected void populateBindings(Bindings namespace, UMOEventContext context)
31      {
32          namespace.put("eventContext", context);
33          namespace.put("managementContext", MuleManager.getInstance());
34          namespace.put("message", context.getMessage());
35          namespace.put("descriptor", context.getComponentDescriptor());
36          namespace.put("componentNamespace", this.bindings);
37          namespace.put("log", new MuleLogger(logger));
38      }
39  
40      public Bindings getBindings()
41      {
42          return bindings;
43      }
44  }
45  
46