0

在以下代码中:

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();
     }
   }
}

这是什么意思:get(field("java.net.URL", "authority"),instance)

请参考我的文档。

4

1 回答 1

1

field("java.net.URL", "authority")将从类java.net.URL中安全地检索名为authority的字段

get(field, instance)反射性地获取指定实例中给定字段的值。

BTraceUtils的Javadoc是一个很好的起点。

于 2013-10-17T18:13:17.380 回答