<commit_before>package org.osgi.impl.bundle.midletcontainer;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.*;
import org.osgi.service.log.LogService;

import javax.microedition.midlet.MIDlet;
import org.osgi.framework.*;
import org.osgi.service.application.*;

public final class MidletDescriptor extends ApplicationDescriptor implements ServiceListener {
	private Properties					props;
	private Hashtable			  		names;
	private Hashtable			  		icons;
	private BundleContext				bc;
	private String				  		startClass;
	private String				  		pid;
	private Bundle				  		bundle;
	private String				  		defaultLanguage;
	private boolean				  		locked;
	private boolean             registeredLaunchable;
	private MidletContainer			midletContainer;
	private static int			    instanceCounter;
	private ServiceRegistration serviceReg;

	public MidletDescriptor(BundleContext bc, Properties props, Map names, Map icons,
			String defaultLang, String startClass, Bundle bundle,
			MidletContainer midletContainer) throws Exception {
		
		super( (String)props.get(Constants.SERVICE_PID) );

		this.bc = bc;
		this.midletContainer = midletContainer;
		this.props = new Properties();
		this.props.putAll(props);
		this.names = new Hashtable(names);
		this.icons = new Hashtable(icons);
		this.startClass = startClass;
		this.bundle = bundle;
		this.serviceReg = null;
		if (names.size() == 0 || icons.size() == 0
				|| !props.containsKey("application.bundle.id")
				|| !props.containsKey(Constants.SERVICE_PID)
				|| !props.containsKey(ApplicationDescriptor.APPLICATION_VERSION)
				|| !props.containsKey(ApplicationDescriptor.APPLICATION_LOCATION ))
			throw new Exception("Invalid MEG container input!");
		if (!names.containsKey(defaultLang)) {
			throw new Exception("Invalid default language!");
		}
		else {
			defaultLanguage = defaultLang;
			pid = props.getProperty(Constants.SERVICE_PID);
			return;
		}
	}

	Bundle getBundle() {
		return bundle;
	}

	public String getPID() {
		return pid;
	}

	public Map getPropertiesSpecific(String locale) {
		checkBundle();
		Hashtable properties = new Hashtable();
		if( locale == null )
			locale = "";
		String localizedName = (String) names.get(locale);
		if (localizedName == null) {
			if ((localizedName = (String) names.get(defaultLanguage)) == null) {
				Enumeration enum = names.keys();
				String firstKey = (String) enum.nextElement();
				localizedName = (String) names.get(firstKey);
				locale = firstKey;
			}
			else {
				localizedName = (String) names.get(defaultLanguage);
			}
			locale = defaultLanguage;
		}
		properties.put(ApplicationDescriptor.APPLICATION_NAME, localizedName);
		properties.put(ApplicationDescriptor.APPLICATION_ICON, icons.get(locale));
		properties.put("application.bundle.id", props
				.getProperty("application.bundle.id"));
		properties.put(ApplicationDescriptor.APPLICATION_VERSION, props
				.getProperty(ApplicationDescriptor.APPLICATION_VERSION));
		properties.put(ApplicationDescriptor.APPLICATION_LOCATION, props
				.getProperty(ApplicationDescriptor.APPLICATION_LOCATION));
		properties.put(ApplicationDescriptor.APPLICATION_VENDOR, props
				.getProperty(ApplicationDescriptor.APPLICATION_VENDOR));
		String visible = props.getProperty(ApplicationDescriptor.APPLICATION_VISIBLE);
		if (visible != null && visible.equalsIgnoreCase("false"))
			properties.put(ApplicationDescriptor.APPLICATION_VISIBLE, new Boolean( false ) );
		else
			properties.put(ApplicationDescriptor.APPLICATION_VISIBLE, new Boolean( true ) );
		boolean launchable = false;
		try {
			launchable = isLaunchable();
		}
		catch (Exception e) {
			Activator.log( LogService.LOG_ERROR ,"Exception occurred at searching the Midlet container reference!",e);
		}
		properties.put(ApplicationDescriptor.APPLICATION_LOCKED, new Boolean(locked));
		properties.put(ApplicationDescriptor.APPLICATION_LAUNCHABLE, new Boolean(launchable));
		properties.put(ApplicationDescriptor.APPLICATION_CONTAINER, "MIDlet");
		properties.put(Constants.SERVICE_PID, new String(pid));
		
		return properties;
	}

	public ApplicationHandle launchSpecific(Map args) throws Exception {
		checkBundle();
		String instID = createNewInstanceID(bc, pid);
		MIDlet midlet = createMidletInstance( instID );
		if (midlet == null)
			throw new Exception("Cannot create meglet instance!");
		else {
			MidletHandle midHnd = new MidletHandle(bc, instID, this, 
					                                   midletContainer, midlet, startClass );
      midHnd.startHandle(args);
			return midHnd;
		}
	}

	public void lockSpecific() {
		checkBundle();
		locked = true;
		if( serviceReg != null ) {
			Dictionary properties = new Hashtable( getProperties(Locale.getDefault().getLanguage()));<commit_msg>CHANGED: service properties are added to getServiceSpecific, according to the new API<commit_after>package org.osgi.impl.bundle.midletcontainer;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.*;
import org.osgi.service.log.LogService;

import javax.microedition.midlet.MIDlet;
import org.osgi.framework.*;
import org.osgi.service.application.*;

public final class MidletDescriptor extends ApplicationDescriptor implements ServiceListener {
	private Properties					props;
	private Hashtable			  		names;
	private Hashtable			  		icons;
	private BundleContext				bc;
	private String				  		startClass;
	private String				  		pid;
	private Bundle				  		bundle;
	private String				  		defaultLanguage;
	private boolean				  		locked;
	private boolean             registeredLaunchable;
	private MidletContainer			midletContainer;
	private static int			    instanceCounter;
	private ServiceRegistration serviceReg;

	public MidletDescriptor(BundleContext bc, Properties props, Map names, Map icons,
			String defaultLang, String startClass, Bundle bundle,
			MidletContainer midletContainer) throws Exception {
		
		super( (String)props.get(Constants.SERVICE_PID) );

		this.bc = bc;
		this.midletContainer = midletContainer;
		this.props = new Properties();
		this.props.putAll(props);
		this.names = new Hashtable(names);
		this.icons = new Hashtable(icons);
		this.startClass = startClass;
		this.bundle = bundle;
		this.serviceReg = null;
		if (names.size() == 0 || icons.size() == 0
				|| !props.containsKey("application.bundle.id")
				|| !props.containsKey(Constants.SERVICE_PID)
				|| !props.containsKey(ApplicationDescriptor.APPLICATION_VERSION)
				|| !props.containsKey(ApplicationDescriptor.APPLICATION_LOCATION ))
			throw new Exception("Invalid MEG container input!");
		if (!names.containsKey(defaultLang)) {
			throw new Exception("Invalid default language!");
		}
		else {
			defaultLanguage = defaultLang;
			pid = props.getProperty(Constants.SERVICE_PID);
			return;
		}
	}

	Bundle getBundle() {
		return bundle;
	}

	public String getPID() {
		return pid;
	}

	public Map getPropertiesSpecific(String locale) {
		checkBundle();
		Hashtable properties = new Hashtable();
		if( locale == null )
			locale = "";
		String localizedName = (String) names.get(locale);
		if (localizedName == null) {
			if ((localizedName = (String) names.get(defaultLanguage)) == null) {
				Enumeration enum = names.keys();
				String firstKey = (String) enum.nextElement();
				localizedName = (String) names.get(firstKey);
				locale = firstKey;
			}
			else {
				localizedName = (String) names.get(defaultLanguage);
			}
			locale = defaultLanguage;
		}
		properties.put(ApplicationDescriptor.APPLICATION_NAME, localizedName);
		properties.put(ApplicationDescriptor.APPLICATION_ICON, icons.get(locale));
		properties.put("application.bundle.id", props
				.getProperty("application.bundle.id"));
		properties.put(ApplicationDescriptor.APPLICATION_VERSION, props
				.getProperty(ApplicationDescriptor.APPLICATION_VERSION));
		properties.put(ApplicationDescriptor.APPLICATION_LOCATION, props
				.getProperty(ApplicationDescriptor.APPLICATION_LOCATION));
		properties.put(ApplicationDescriptor.APPLICATION_VENDOR, props
				.getProperty(ApplicationDescriptor.APPLICATION_VENDOR));
		String visible = props.getProperty(ApplicationDescriptor.APPLICATION_VISIBLE);
		if (visible != null && visible.equalsIgnoreCase("false"))
			properties.put(ApplicationDescriptor.APPLICATION_VISIBLE, new Boolean( false ) );
		else
			properties.put(ApplicationDescriptor.APPLICATION_VISIBLE, new Boolean( true ) );
		boolean launchable = false;
		try {
			launchable = isLaunchable();
		}
		catch (Exception e) {
			Activator.log( LogService.LOG_ERROR ,"Exception occurred at searching the Midlet container reference!",e);
		}
		properties.put(ApplicationDescriptor.APPLICATION_LOCKED, new Boolean(locked));
		properties.put(ApplicationDescriptor.APPLICATION_LAUNCHABLE, new Boolean(launchable));
		properties.put(ApplicationDescriptor.APPLICATION_CONTAINER, "MIDlet");
		properties.put(Constants.SERVICE_PID, new String(pid));
		
		if( serviceReg != null ) {
			ServiceReference ref = serviceReg.getReference();
			String keys[] = ref.getPropertyKeys();
			for( int q=0; q != keys.length; q++ )
				properties.put( keys[ q ], ref.getProperty( keys[ q ] ) );
		}
		
		return properties;
	}

	public ApplicationHandle launchSpecific(Map args) throws Exception {
		checkBundle();
		String instID = createNewInstanceID(bc, pid);
		MIDlet midlet = createMidletInstance( instID );
		if (midlet == null)
			throw new Exception("Cannot create meglet instance!");
		else {
			MidletHandle midHnd = new MidletHandle(bc, instID, this, 
					                                   midletContainer, midlet, startClass );
      midHnd.startHandle(args);
			return midHnd;
		}
	}

	public void lockSpecific() {
		checkBundle();
		locked = true;
		if( serviceReg != null ) {
			Dictionary properties = new Hashtable( getProperties(Locale.getDefault().getLanguage()));
{'fraction_non_alphanumeric': 0.10284701014678357, 'fraction_numerical': 0.0004925623091321052, 'mean_word_length': 4.571899012074644, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1896464', 'n_tokens_mistral': 3281, 'n_tokens_neox': 2851, 'n_words': 647}