/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.dynamo.iface;

import com.silverwrist.dynamo.event.ScriptEngineStartListener;
import com.silverwrist.dynamo.except.ConfigException;

/**
 * An initialization service exposed by the scripting engine controller which allows components and modules
 * to configure it.  Items set up by this interface will apply to all newly-started scripting engines.
 *
 * @author Eric J. Bowersox &lt;erbo@silcom.com&gt;
 * @version X
 */
public interface ScriptEngineConfig
{
  /**
   * Adds a new "declared object" to the scripting engine.  Such "declared objects" are typically exposed
   * as "global variables" in any scripts run by the scripting engine.  This is a handy way, for instance,
   * to implement native-code libraries usable by scripts.
   *
   * @param name Name of the object to be declared.  This will be the name of the variable exposed to scripts.
   * @param obj The object instance to be exposed to scripts.
   * @param klass Class the object is to be exposed as.  This is used by scripting engines to infer type
   *              and property/method information for the object.
   * @return An instance of {@link com.silverwrist.dynamo.iface.ComponentShutdown ComponentShutdown} which
   *         will "undeclare" the object when its
   *         {@link com.silverwrist.dynamo.iface.ComponentShutdown#shutdown() shutdown()} method is called.
   * @exception com.silverwrist.dynamo.except.ConfigException If the object cannot be declared (its name is
   *            reserved, for instance, or an object of that name has already been declared.
   */
  public ComponentShutdown addDeclaredObject(String name, Object obj, Class klass) throws ConfigException;

  /**
   * Adds a new "hook" to the script engine startup process in the form of an event listener.  The
   * {@link com.silverwrist.dynamo.event.ScriptEngineStartListener#scriptEngineStarting(com.silverwrist.dynamo.event.ScriptEngineStartEvent) scriptEngineStarting()}
   * method of the given object will be called when an instance of a script enine starts up.
   *
   * @param listener The event listener to register for handling startup events.
   * @return An instance of {@link com.silverwrist.dynamo.iface.ComponentShutdown ComponentShutdown} which will
   *         unregister the given event listener when its
   *         {@link com.silverwrist.dynamo.iface.ComponentShutdown#shutdown() shutdown()} method is called.
   */
  public ComponentShutdown addStartListener(ScriptEngineStartListener listener);

} // end interface ScriptEngineConfig
