5 // Created by Andreas Monitzer on 2006-07-31.
6 // Copyright 2006 Andreas Monitzer. All rights reserved.
9 #import "AIJavaController.h"
10 #import <JavaVM/NSJavaVirtualMachine.h>
12 @interface JavaVector : NSObject {
16 - (NSString*)toString;
20 @protocol JavaCocoaAdapter
21 - (JavaClassLoader*)classLoader:(JavaVector*)jars :(JavaClassLoader*)parent;
24 @implementation AIJavaController
27 * @brief Controller loaded
29 - (void)controllerDidLoad
34 * @brief Controller will close
36 - (void)controllerWillClose
40 - (JavaClassLoader *)classLoaderWithJARs:(NSArray *)jars
42 return [self classLoaderWithJARs:jars parentClassLoader:nil];
48 * @result a JavaClassLoader which loads classes from the indicated jars
50 - (JavaClassLoader*)classLoaderWithJARs:(NSArray*)jars parentClassLoader:(JavaClassLoader*)parent
53 vm = [[NSJavaVirtualMachine alloc] initWithClassPath:[NSJavaVirtualMachine defaultClassPath]];
54 //Dynamically load class file
55 JavaCocoaAdapter = [vm defineClass:[NSData dataWithContentsOfFile:[[NSBundle bundleForClass:[self class]] pathForResource:@"JavaCocoaAdapter" ofType:@"class"]] withName:@"net/adium/JavaCocoaAdapter"];
56 NSLog(@"JavaCocoaAdapter = %@", JavaCocoaAdapter);
59 //Convert NSArray to java.util.Vector
60 JavaVector *vec = [[vm findClass:@"java.util.Vector"] newWithSignature:@"(I)",[jars count]];
62 NSEnumerator *enumerator = [jars objectEnumerator];
64 while ((path = [enumerator nextObject])) {
68 JavaClassLoader *result = [JavaCocoaAdapter classLoader:vec :parent];