FileDocCategorySizeDatePackage
Log.javaAPI DocJMF 2.1.1e6495Mon May 12 12:20:50 BST 2003com.sun.media

Log

public class Log extends Object
A public static class to generate and write to jmf.log.

Fields Summary
public static boolean
isEnabled
private static DataOutputStream
log
private static String
fileName
private static int
indent
private static com.sun.media.JMFSecurity
jmfSecurity
private static Method[]
m
private static Class[]
cl
private static Object[]
args
private static boolean
ieSec
private static String
permission
private static int
permissionid
static boolean
errorWarned
Constructors Summary
Methods Summary
public static synchronized voidcomment(java.lang.Object str)

	if (isEnabled) {

	    if (jmfSecurity != null && !requestPerm())
		return;

	    try {
		log.writeBytes("## " + str + "\n");
	    } catch (IOException e) {}
	}
    
public static synchronized voiddecrIndent()

	indent--;
    
public static synchronized voiddumpStack(java.lang.Throwable e)

	if (isEnabled) {

	    if (jmfSecurity != null && !requestPerm())
		return;

	    e.printStackTrace(new PrintWriter(log, true));
	    write("");
	} else
	    e.printStackTrace();
    
public static synchronized voiderror(java.lang.Object str)


          
	if (isEnabled) {

	    if (jmfSecurity != null && !requestPerm())
		return;

	    if (!errorWarned) {
		System.err.println("An error has occurred.  Check jmf.log for details.");
		errorWarned = true;
	    }

	    try {
		log.writeBytes("XX " + str + "\n");
	    } catch (IOException e) {}
	} else {
	    System.err.println(str);
	}
    
public static intgetIndent()

	return indent;
    
public static synchronized voidincrIndent()

	indent++;
    
public static synchronized voidprofile(java.lang.Object str)

	if (isEnabled) {

	    if (jmfSecurity != null && !requestPerm())
		return;

	    try {
		log.writeBytes("$$ " + str + "\n");
	    } catch (IOException e) {}
	}
    
private static synchronized booleanrequestPerm()



     

      // This is to guard against the log file being opened twice at
      // the same time.
      synchronized (fileName) {

       // Check so we won't run this twice.
       if (isEnabled && log == null) {

	Object llog = com.sun.media.util.Registry.get("allowLogging");

	// Check the registry file to see if logging is turned on.
	if (llog != null && llog instanceof Boolean) {
	    if (! ((Boolean)llog).booleanValue())
		isEnabled = false;
	}

	// Check security to open the file.
	if (isEnabled) {
	    try {
		jmfSecurity = JMFSecurityManager.getJMFSecurity();
		if (jmfSecurity == null) {
		    // allow log writing for applications.
		} else if (jmfSecurity.getName().startsWith("jmf-security")) {
		    permission = "write file";
		    permissionid = JMFSecurity.WRITE_FILE;
		    jmfSecurity.requestPermission(m, cl, args, JMFSecurity.WRITE_FILE);
		    m[0].invoke(cl[0], args[0]);
		    
		    permission = "delete file";
		    permissionid = JMFSecurity.DELETE_FILE;
		    jmfSecurity.requestPermission(m, cl, args, JMFSecurity.DELETE_FILE);
		    m[0].invoke(cl[0], args[0]);
		    permission = "read system property";
		    permissionid = JMFSecurity.READ_PROPERTY;
		    jmfSecurity.requestPermission(m, cl, args, JMFSecurity.READ_PROPERTY);
		    m[0].invoke(cl[0], args[0]);
		} else if (jmfSecurity.getName().startsWith("internet")) {
		    PolicyEngine.checkPermission(PermissionID.FILEIO);
		    PolicyEngine.assertPermission(PermissionID.FILEIO);
		    ieSec = true;
		}
	    } catch (Exception e) { 
		isEnabled = false;
	    }
	}

	if (isEnabled) {
            isEnabled = false;
	    try {
		String dir;
		Object ldir = com.sun.media.util.Registry.get("secure.logDir");
		if (ldir != null && ldir instanceof String && !("".equals(ldir)))
		    dir = (String)ldir;
		else
		    dir = (String)System.getProperty("user.dir");

		String file = dir + File.separator + fileName;
		log = new DataOutputStream(new FileOutputStream(file));
		if (log != null) {
		    System.err.println("Open log file: " + file);
		    isEnabled = true;
		    writeHeader();
		}
	    } catch (Exception e) {
		System.err.println("Failed to open log file.");
	    }
	}

       } // Don't need to run this twise.
      }  // synchronized (fileName)
    
	try {
	    if (!ieSec) {
		permission = "write file";
		permissionid = JMFSecurity.WRITE_FILE;
		jmfSecurity.requestPermission(m, cl, args, JMFSecurity.WRITE_FILE);
		m[0].invoke(cl[0], args[0]);
	    } else {
		PolicyEngine.checkPermission(PermissionID.FILEIO);
		PolicyEngine.assertPermission(PermissionID.FILEIO);
	    }
	} catch (Exception e) { 
	    return false;
	}
	return true;
    
public static synchronized voidsetIndent(int i)

	indent = i;
    
public static synchronized voidwarning(java.lang.Object str)

	if (isEnabled) {

	    if (jmfSecurity != null && !requestPerm())
		return;

	    try {
		log.writeBytes("!! " + str + "\n");
	    } catch (IOException e) {}
	}
    
public static synchronized voidwrite(java.lang.Object str)

	if (isEnabled) {

	    if (jmfSecurity != null && !requestPerm())
		return;

	    try {
		for (int i = indent; i > 0; i--)
		    log.writeBytes("    ");
		log.writeBytes(str + "\n");
	    } catch (IOException e) {}
	}
    
private static synchronized voidwriteHeader()


	if (jmfSecurity != null && !requestPerm())
	    return;

	write("#\n# JMF " + BasicPlayer.VERSION + "\n#\n");

	String os = null, osver = null, osarch = null;
	String java = null, jver = null;
	try {
	    os = System.getProperty("os.name");	
	    osarch = System.getProperty("os.arch");	
	    osver = System.getProperty("os.version");	
	    java = System.getProperty("java.vendor");
	    jver = System.getProperty("java.version");	
	} catch (Throwable e) {
	    // Can't get the info.  No big deal.
	    return;
	}

	if (os != null)
	    comment("Platform: " + os + ", " + osarch + ", " + osver);
	if (java != null)
	    comment("Java VM: " + java + ", " + jver);
	write("");