FileDocCategorySizeDatePackage
PackageManager.javaAPI DocJMF 2.1.1e7606Mon May 12 12:20:38 BST 2003javax.media

PackageManager

public class PackageManager extends Object
A PackageManager maintains a persistent store of package-prefix lists. A package prefix specifies the prefix for a complete class name. A factory uses a package-prefix list to find a class that might belong to any of the packages that are referenced in the prefix list.

The Manager uses package-prefix lists to find protocol handlers and content handlers for time-based media.

The current version of a package-prefix list is obtained with the get<package-prefix>List method. This method returns the prefix list in use; any changes to the list take effect immediately. Unless it is made persistent with commit<package-prefix>List, a package-prefix list is only valid while the Manager is referenced. The commit<package-prefix>List method ensures that any changes made to a package-prefix list are still visible the next time that the Manager is referenced.

see
Manager
version
1.6, 02/08/21.

Fields Summary
private static PackageManager
pm
private static Method
mGetProtocolPrefixList
private static Method
mSetProtocolPrefixList
private static Method
mCommitProtocolPrefixList
private static Method
mGetContentPrefixList
private static Method
mSetContentPrefixList
private static Method
mCommitContentPrefixList
private static final Class[]
sigNone
private static final Class[]
sigVector
private static Vector
protoPrefixList
The package prefix used when searching for protocol handlers.
private static Vector
contentPrefixList
The package prefix used when searching for content handlers.
Constructors Summary
Methods Summary
public static voidcommitContentPrefixList()
Make changes to the content prefix-list persistent.

This method throws a SecurityException if the calling thread does not have access to system properties.

	if (pm != null && mCommitContentPrefixList != null) {
	    runMethod(mCommitContentPrefixList, null);
	}
    
public static voidcommitProtocolPrefixList()
Make changes to the protocol package-prefix list persistent.

This method throws a SecurityException if the calling thread does not have access to system properties.

	if (pm != null && mCommitProtocolPrefixList != null) {
	    runMethod(mCommitProtocolPrefixList, null);
	}
    
public static java.util.VectorgetContentPrefixList()
Get the current value of the content package-prefix list. Any changes made to this list take effect immediately.

return
The content package-prefix list.

	// Default value
	contentPrefixList = new Vector();
	contentPrefixList.addElement("javax");
	contentPrefixList.addElement("com.sun");
    
	if (pm != null && mGetContentPrefixList != null) {
	    return (Vector) runMethod(mGetContentPrefixList, null);
	} else
	    return contentPrefixList;
    
static java.lang.reflect.MethodgetDeclaredMethod(java.lang.Class c, java.lang.String name, java.lang.Class[] params)
netscape browser throws SecurityException when you call Class.getDeclaredMethod or Class.getDeclaredMethods There is a privilege called UniversalMemberAccess which should allow this call. But Netscape has disabled this privilege; they mention this in in their security faq. So, we call getMethod and using getDeclaringClass method, check to see if it the subclass overrided it or not. Note: this code is used in all cases, not just netscape

	
	Method m = c.getMethod(name, params);
	if (m.getDeclaringClass() == c) {
	    return m;
	} else {
	    return null;
	}
    
public static java.util.VectorgetProtocolPrefixList()
Get the current value of the protocol package-prefix list.

return
The protocol package-prefix list.

	if (pm != null && mGetProtocolPrefixList != null) {
	    return (Vector) runMethod(mGetProtocolPrefixList, null);
	} else
	    return protoPrefixList;
    
private static java.lang.ObjectrunMethod(java.lang.reflect.Method m, java.lang.Object[] params)


     
	// Default value
	protoPrefixList = new Vector();
	protoPrefixList.addElement("javax");
	protoPrefixList.addElement("com.sun");

	try {
	    Class pmClass = Class.forName("javax.media.pm.PackageManager");
	    if (pmClass != null) {
		Object tryPM = pmClass.newInstance();
		if (tryPM instanceof PackageManager) {
		    pm = (PackageManager) tryPM;

		    mGetProtocolPrefixList =
			getDeclaredMethod(pmClass, "getProtocolPrefixList",
						  sigNone);
		    mSetProtocolPrefixList =
			getDeclaredMethod(pmClass, "setProtocolPrefixList",
						  sigVector);
		    mCommitProtocolPrefixList =
			getDeclaredMethod(pmClass, "commitProtocolPrefixList",
						  sigNone);
		    mGetContentPrefixList =
			getDeclaredMethod(pmClass, "getContentPrefixList",
						  sigNone);
		    mSetContentPrefixList =
			getDeclaredMethod(pmClass, "setContentPrefixList",
						  sigVector);
		    mCommitContentPrefixList =
			getDeclaredMethod(pmClass, "commitContentPrefixList",
						  sigNone);
		}
	    }
	} catch (ClassNotFoundException cnfe) {
	    System.err.println(cnfe);
	} catch (InstantiationException ie) {
	    System.err.println(ie);
	} catch (IllegalAccessException iae) {
	    System.err.println(iae);
	} catch (SecurityException se) {
	    System.out.println("PackageManager: SecurityException: " + se);
	    System.err.println(se);
	} catch (NoSuchMethodException nsme) {
	}
    
	try {
	    return m.invoke(null, params);
	} catch (IllegalAccessException iae) {
	} catch (IllegalArgumentException iare) {
	} catch (InvocationTargetException ite) {
	}
	return null;
    
public static voidsetContentPrefixList(java.util.Vector list)
Set the current value of the content package-prefix list. This is required for changes to take effect.

param
list The content package-prefix list to set.

	if (pm != null && mSetContentPrefixList != null) {
	    Object [] params = new Object[1];
	    params[0] = list.clone();
	    runMethod(mSetContentPrefixList, params);
	    contentPrefixList = getContentPrefixList();
	} else
	    contentPrefixList = (Vector)list.clone();
    
public static voidsetProtocolPrefixList(java.util.Vector list)
Set the protocol package-prefix list. This is required for changes to take effect.

param
list The new package-prefix list to use.

	if (pm != null && mSetProtocolPrefixList != null) {
	    Object [] params = new Object[1];
	    params[0] = list.clone();
	    runMethod(mSetProtocolPrefixList, params);
	    protoPrefixList = getProtocolPrefixList();
	} else
	    protoPrefixList = (Vector)list.clone();