1.1 --- a/boot/src/main/java/org/apidesign/html/boot/impl/JsClassLoader.java Tue Jun 25 21:09:48 2013 +0200
1.2 +++ b/boot/src/main/java/org/apidesign/html/boot/impl/JsClassLoader.java Wed Jun 26 08:43:32 2013 +0200
1.3 @@ -23,6 +23,7 @@
1.4 import org.apidesign.html.boot.spi.Fn;
1.5 import java.io.IOException;
1.6 import java.io.InputStream;
1.7 +import java.io.Reader;
1.8 import java.net.URL;
1.9 import java.util.ArrayList;
1.10 import java.util.Enumeration;
1.11 @@ -126,7 +127,7 @@
1.12 }
1.13
1.14 protected abstract Fn defineFn(String code, String... names);
1.15 -
1.16 + protected abstract void loadScript(Reader code) throws Exception;
1.17
1.18 private final class FindInClass extends ClassVisitor {
1.19 private String name;
1.20 @@ -141,7 +142,14 @@
1.21 this.name = name;
1.22 super.visit(version, access, name, signature, superName, interfaces);
1.23 }
1.24 -
1.25 +
1.26 + @Override
1.27 + public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
1.28 + if ("Lnet/java/html/js/JavaScriptResource;".equals(desc)) {
1.29 + return new LoadResource();
1.30 + }
1.31 + return super.visitAnnotation(desc, visible);
1.32 + }
1.33
1.34
1.35 @Override
1.36 @@ -403,6 +411,24 @@
1.37 }
1.38 }
1.39 }
1.40 +
1.41 + private final class LoadResource extends AnnotationVisitor {
1.42 + public LoadResource() {
1.43 + super(Opcodes.ASM4);
1.44 + }
1.45 +
1.46 + @Override
1.47 + public void visit(String attrName, Object value) {
1.48 + String relPath = (String) value;
1.49 + if (relPath.startsWith("/")) {
1.50 + FnUtils.loadScript(JsClassLoader.this, relPath);
1.51 + } else {
1.52 + int last = name.lastIndexOf('/');
1.53 + String fullPath = name.substring(0, last + 1) + relPath;
1.54 + FnUtils.loadScript(JsClassLoader.this, fullPath);
1.55 + }
1.56 + }
1.57 + }
1.58 }
1.59
1.60 private class ClassWriterEx extends ClassWriter {