<commit_before>/*
 * PhoneGap is available under *either* the terms of the modified BSD license *or* the
 * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
 * 
 * Copyright (c) 2005-2010, Nitobi Software Inc.
 * Copyright (c) 2010, IBM Corporation
 */
package com.phonegap.api;

import java.io.IOException;
import java.util.Hashtable;

import net.rim.device.api.script.Scriptable;
import net.rim.device.api.script.ScriptableFunction;

import com.phonegap.PhoneGapExtension;
import com.phonegap.file.FileUtils;
import com.phonegap.util.Logger;

/**
 * PluginManager represents an object in the script engine. It can be accessed
 * from the script environment using <code>phonegap.PluginManager</code>.
 * 
 * PluginManager provides a function, <code>exec</code>, that can be invoked 
 * from the script environment: <code>phonegap.PluginManager.exec(...)</code>.  
 * Invoking this function causes the script engine to load the appropriate 
 * PhoneGap Plugin and perform the specified action.
 */
public final class PluginManager extends Scriptable {
	
    /**
     * Field used to invoke Plugin actions.
     */
    public static final String FIELD_EXEC = "exec";	
    
    /**
     * Field used to cleanup Plugins.
     */
    public static final String FIELD_DESTROY = "destroy";
    
    /**
     * Field used to register a Plugin.
     */
    public static final String FIELD_ADD_PLUGIN = "addPlugin";
    
    /**
     * Loads the appropriate PhoneGap Plugins and invokes their actions.
     */
    private final PluginManagerFunction pluginManagerFunction;
    
    /**
     * Maps available services to Java class names.
     */
    private Hashtable services = new Hashtable();

    /**
     * Constructor.  Adds available PhoneGap services.
     * @param ext   The PhoneGap JavaScript Extension
     */
    public PluginManager(PhoneGapExtension ext) {
        this.pluginManagerFunction = new PluginManagerFunction(ext, this);
        this.addService("Camera", "com.phonegap.camera.Camera");
        this.addService("Network Status", "com.phonegap.network.Network");
        this.addService("Notification", "com.phonegap.notification.Notification");
        this.addService("Accelerometer", "com.phonegap.accelerometer.Accelerometer");
        this.addService("Geolocation", "com.phonegap.geolocation.Geolocation");
        this.addService("File", "com.phonegap.file.FileManager");
        this.addService("FileTransfer", "com.phonegap.http.FileTransfer");
    }
	
    /**
     * The following fields are supported from the script environment:
     * 
     *  <code>phonegap.pluginManager.exec</code> - Loads the appropriate 
     *  Plugin and invokes the specified action.
     *  <commit_msg>Oops.  Need this for setting contact photos.<commit_after>/*
 * PhoneGap is available under *either* the terms of the modified BSD license *or* the
 * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
 * 
 * Copyright (c) 2005-2010, Nitobi Software Inc.
 * Copyright (c) 2010, IBM Corporation
 */
package com.phonegap.api;

import java.io.IOException;
import java.util.Hashtable;

import net.rim.device.api.script.Scriptable;
import net.rim.device.api.script.ScriptableFunction;

import com.phonegap.PhoneGapExtension;
import com.phonegap.file.FileUtils;
import com.phonegap.util.Logger;

/**
 * PluginManager represents an object in the script engine. It can be accessed
 * from the script environment using <code>phonegap.PluginManager</code>.
 * 
 * PluginManager provides a function, <code>exec</code>, that can be invoked 
 * from the script environment: <code>phonegap.PluginManager.exec(...)</code>.  
 * Invoking this function causes the script engine to load the appropriate 
 * PhoneGap Plugin and perform the specified action.
 */
public final class PluginManager extends Scriptable {
	
    /**
     * Field used to invoke Plugin actions.
     */
    public static final String FIELD_EXEC = "exec";	
    
    /**
     * Field used to cleanup Plugins.
     */
    public static final String FIELD_DESTROY = "destroy";
    
    /**
     * Field used to register a Plugin.
     */
    public static final String FIELD_ADD_PLUGIN = "addPlugin";
    
    /**
     * Loads the appropriate PhoneGap Plugins and invokes their actions.
     */
    private final PluginManagerFunction pluginManagerFunction;
    
    /**
     * Maps available services to Java class names.
     */
    private Hashtable services = new Hashtable();

    /**
     * Constructor.  Adds available PhoneGap services.
     * @param ext   The PhoneGap JavaScript Extension
     */
    public PluginManager(PhoneGapExtension ext) {
        this.pluginManagerFunction = new PluginManagerFunction(ext, this);
        this.addService("Camera", "com.phonegap.camera.Camera");
        this.addService("Network Status", "com.phonegap.network.Network");
        this.addService("Notification", "com.phonegap.notification.Notification");
        this.addService("Accelerometer", "com.phonegap.accelerometer.Accelerometer");
        this.addService("Geolocation", "com.phonegap.geolocation.Geolocation");
        this.addService("File", "com.phonegap.file.FileManager");
        this.addService("FileTransfer", "com.phonegap.http.FileTransfer");
        this.addService("Contact", "com.phonegap.pim.Contact");
    }
	
    /**
     * The following fields are supported from the script environment:
     * 
     *  <code>phonegap.pluginManager.exec</code> - Loads the appropriate 
     *  Plugin and invokes the specified action.
     *  
{'fraction_non_alphanumeric': 0.10399856553702708, 'fraction_numerical': 0.005737851891698046, 'mean_word_length': 3.284178187403994, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2763480', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1517, 'n_words': 444}