FileDocCategorySizeDatePackage
CHManagerImpl.javaAPI DocphoneME MR2 API (J2ME)9727Wed May 02 18:00:44 BST 2007com.sun.midp.content

CHManagerImpl

public class CHManagerImpl extends com.sun.midp.content.CHManager implements com.sun.midp.main.MIDletProxyListListener
Handle all of the details of installing ContentHandlers. Called at by the installer at the appropriate times to {@link #preInstall parse and verify the JAD/Manifest attributes} and {@link #install remove old content handlers and register new ones}. If the installation fails the old handlers are {@link #restore restored}. When a suite is to be removed the content handlers are {@link #uninstall uninstalled}.

Two versions of this file exist; one which is no-op used when MIDP stack is not built with CHAPI and the real implementation when MIDP stack is BUILT with CHAPI.

Fields Summary
private RegistryInstaller
regInstaller
Installed handlers accumulator.
private javax.microedition.content.Invocation
installInvoc
The Invocation in progress for an install.
javax.microedition.content.ContentHandlerServer
handler
The ContentHandler for the Installer.
Constructors Summary
public CHManagerImpl()
Creates a new instance of CHManagerImpl. Always initialize the Access to the Registry as if the GraphicalInstaller is running.

    
Methods Summary
public java.lang.StringgetInstallURL(javax.microedition.midlet.MIDlet midlet)
Get a URL to install from the Invocation mechanism, if one has been queued.

param
midlet to check for an invocation
return
the URL to install; null if none available.
see
com.sun.midp.content.CHManagerImpl

	try {
	    handler = Registry.getServer(midlet.getClass().getName());
	} catch (ContentHandlerException che) {
            return null;
        }

        installInvoc = handler.getRequest(false);
        if (installInvoc != null) {
            String url = installInvoc.getURL();
            if (url != null && url.length() > 0) {
                return url;
            }
        }
	return null;
    
public voidinitCleanupMonitor(com.sun.midp.main.MIDletProxyList midletProxyList)
Setup to monitor for MIDlets starting and exiting and check for incompletely handled Invocation requests. Cleanup only occurs within the AMS Isolate. This method is only called from MIDletSuiteLoader in the AMS Isolate.

param
midletProxyList reference to the MIDlet proxy list

        midletProxyList.addListener(this);
    
public voidinstall()
Install the content handlers found and verified by preinstall. Register any content handlers parsed from the JAD/Manifest attributes.

        if (regInstaller != null) {
            regInstaller.install();
            regInstaller = null; // Let GC take it.
        }
    
public voidinstallDone(boolean success)
Complete the installation of the URL provided by {@link #getInstallURL} with the success/failure status provided.

param
success true if the install was a success
see
com.sun.midp.content.CHManagerImpl

        if (installInvoc != null) {
	    handler.finish(installInvoc,
			   success ? Invocation.OK : Invocation.CANCELLED);
            installInvoc = null;
            regInstaller = null; // Double-clean.
        }
    
public voidmidletAdded(com.sun.midp.main.MIDletProxy midlet)
The ContentHandler monitor ignores MIDlet added callbacks. The necessary initialization is done in the Isolate and MIDletState that instantiates the MIDlet. Called when a MIDlet is added to the list and only in the AMS Isolate.

param
midlet The proxy of the MIDlet being added

    
public voidmidletInit(int suiteId, java.lang.String classname)
Notification that a MIDlet is about to be created. Set the cleanup flag on all invocations for the MIDlet.

param
suiteId the storage name of the MIDlet suite
param
classname the midlet classname

	InvocationStore.setCleanup(suiteId, classname, true);
    
public voidmidletRemoved(com.sun.midp.main.MIDletProxy midlet)
The ContentHandler monitor uses the MIDlet removed callback to cleanup any Invocations in an incorrect state. Called (in the AMS Isolate) when a MIDlet is removed from the list.

param
midlet The proxy of the removed MIDlet

	AppProxy.getCurrent().logInfo("midletRemoved: " +
				      midlet.getClassName());

	// Cleanup unprocessed Invocations
	RegistryImpl.cleanup(midlet.getSuiteId(), midlet.getClassName());

	// Check for and execute a pending MIDlet suite
	InvocationImpl.invokeNext();
    
public voidmidletStartError(int externalAppId, int suiteId, java.lang.String className, int errorCode, java.lang.String errorDetails)
Called when error occurred while starting a MIDlet object.

param
externalAppId ID assigned by the external application manager
param
suiteId Suite ID of the MIDlet
param
className Class name of the MIDlet
param
errorCode start error code
param
errorDetails start error details

    
public voidmidletUpdated(com.sun.midp.main.MIDletProxy midlet, int fieldId)
The ContentHandler monitor ignores MIDlet update callbacks. Called when the state of a MIDlet in the list is updated.

param
midlet The proxy of the MIDlet that was updated
param
fieldId code for which field of the proxy was updated

    
public voidpreInstall(com.sun.midp.installer.Installer installer, com.sun.midp.installer.InstallState state, com.sun.midp.midlet.MIDletSuite msuite, java.lang.String authority)
Parse the ContentHandler attributes and check for errors.
  • Parse attributes into set of ContentHandlers.
  • If none, return
  • Check for permission to install handlers
  • Check each for simple invalid arguments
  • Check each for MIDlet is registered
  • Check each for conflicts with other application registrations
  • Find any current registrations
  • Merge current dynamic current registrations into set of new
  • Check and resolve any conflicts between static and curr dynamic
  • Retain current set and new set for registration step.

param
installer the installer with access to the JAR, etc.
param
state the InstallState with the attributes and other context
param
msuite access to information about the suite
param
authority the authority, if any, that authorized the trust level
exception
InvalidJadException if there is no classname field, or if there are more than five comma separated fields on the line.

	try {
	    AppBundleProxy bundle =
		new AppBundleProxy(installer, state, msuite, authority);
            regInstaller = new RegistryInstaller();
            regInstaller.preInstall(bundle);
	} catch (IllegalArgumentException ill) {
	    throw new InvalidJadException(
			  InvalidJadException.INVALID_CONTENT_HANDLER,
			  ill.getMessage());
	} catch (ContentHandlerException che) {
	    if (che.getErrorCode() == ContentHandlerException.AMBIGUOUS) {
		throw new InvalidJadException(
			      InvalidJadException.CONTENT_HANDLER_CONFLICT,
			      che.getMessage());
	    } else {
		throw new InvalidJadException(
			      InvalidJadException.INVALID_CONTENT_HANDLER,
			      che.getMessage());
	    }
	} catch (ClassNotFoundException cnfe) {
	    throw new InvalidJadException(InvalidJadException.CORRUPT_JAR,
					  cnfe.getMessage());
	}
    
public voidrestore()
The content handler registrations are restored to the previous state.

    
public voiduninstall(int suiteId)
Uninstall the Content handler specific information for the specified suiteId.

param
suiteId the suiteId

        RegistryInstaller.uninstallAll(suiteId, false);