49 return c;
50 }
51 if (!name.startsWith(PREFIX)) {
52 return super.loadClass(name, resolve);
53 }
54 if (name.length() != templateClassName.length()) {
55 throw new ClassNotFoundException("Only can load classes with name.length() = " + getNameLength() + " got: '" + name + "' length: " + name.length());
56 }
57 byte[] bytecode = getPatchedByteCode(name);
58 c = defineClass(name, bytecode, 0, bytecode.length);
59 if (resolve) {
60 resolveClass(c);
61 }
62 return c;
63 }
64
65 /**
66 * Create generating class loader that will use class file for given class
67 * from classpath as template.
68 */
69 public GeneratingClassLoader(String templateClassName) {
70 this.templateClassName = templateClassName;
71 classPath = System.getProperty("java.class.path").split(File.pathSeparator);
72 try {
73 templateClassNameBytes = templateClassName.getBytes(encoding);
74 } catch (UnsupportedEncodingException e) {
75 throw new RuntimeException(e);
76 }
77 }
78
79 /**
80 * Create generating class loader that will use class file for
81 * nsk.share.classload.TemplateClass as template.
82 */
83 public GeneratingClassLoader() {
84 this(TemplateClass.class.getName());
85 }
86
87 public int getNameLength() {
88 return templateClassName.length();
|
49 return c;
50 }
51 if (!name.startsWith(PREFIX)) {
52 return super.loadClass(name, resolve);
53 }
54 if (name.length() != templateClassName.length()) {
55 throw new ClassNotFoundException("Only can load classes with name.length() = " + getNameLength() + " got: '" + name + "' length: " + name.length());
56 }
57 byte[] bytecode = getPatchedByteCode(name);
58 c = defineClass(name, bytecode, 0, bytecode.length);
59 if (resolve) {
60 resolveClass(c);
61 }
62 return c;
63 }
64
65 /**
66 * Create generating class loader that will use class file for given class
67 * from classpath as template.
68 */
69 @SuppressWarnings("initialization")
70 public GeneratingClassLoader(String templateClassName) {
71 this.templateClassName = templateClassName;
72 classPath = System.getProperty("java.class.path").split(File.pathSeparator);
73 try {
74 templateClassNameBytes = templateClassName.getBytes(encoding);
75 } catch (UnsupportedEncodingException e) {
76 throw new RuntimeException(e);
77 }
78 }
79
80 /**
81 * Create generating class loader that will use class file for
82 * nsk.share.classload.TemplateClass as template.
83 */
84 public GeneratingClassLoader() {
85 this(TemplateClass.class.getName());
86 }
87
88 public int getNameLength() {
89 return templateClassName.length();
|