Search code examples
javabtrace

what's the mean of the code about btrace


In the following code:

import static com.sun.btrace.BTraceUtils.*;
import com.sun.btrace.annotations.*;
import org.jboss.deployment.DeploymentInfo; 

@BTrace public class Trace{
   @OnMethod(
      clazz="org.jboss.deployment.SARDeployer",
      method="parseDocument"
   )
   public static void traceExecute(DeploymentInfo di){
      printFields(di);
   }

   @OnMethod(
      clazz="java.net.URL",
      method="openConnection",
      location=@Location(Kind.RETURN)
   )
   public static void resolveEntity(@Self Object instance){
     String protocol = str(get(field("java.net.URL", "protocol"),instance));
     String file = str(get(field("java.net.URL", "file"),instance));
     if(startsWith(protocol,"http") && (endsWith(file,".xsd") || endsWith(file,".dtd"))){
        String authority = str(get(field("java.net.URL", "authority"),instance));
        String path = str(get(field("java.net.URL", "path"),instance));
        println("=====================================");
        print(protocol);
        print("://");
        print(authority);
        print(path);
        println(" not found!");
        println("who call:");
        jstack();
     }
   }
}

What does this mean: get(field("java.net.URL", "authority"),instance) ?

Please refer me to the documentation.


Solution

  • field("java.net.URL", "authority") will safely retrieve the field named authority from the class java.net.URL

    get(field, instance) reflectively obtains the value of the given field in specified instance.

    The Javadoc for BTraceUtils is a good starting point.