1 19 20 package org.netbeans.modules.j2ee.metadata; 21 22 import java.lang.reflect.Field ; 23 import org.netbeans.api.java.classpath.ClassPath; 24 import org.netbeans.spi.java.classpath.ClassPathFactory; 25 import org.netbeans.spi.java.classpath.ClassPathImplementation; 26 27 31 public final class ClassPathSupport { 32 33 private ClassPathSupport() { 34 } 35 36 public static ClassPath createWeakProxyClassPath(ClassPath[] delegates) { 37 if (delegates == null) { 38 throw new NullPointerException ("The delegates parameter cannot be null"); 39 } 40 ClassPathImplementation[] impls = new ClassPathImplementation[delegates.length]; 41 for (int i = 0; i < delegates.length; i++) { 42 impls[i] = getClassPathImpl(delegates[i]); 43 } 44 return ClassPathFactory.createClassPath(new WeakProxyClassPathImplementation(impls)); 45 } 46 47 private static ClassPathImplementation getClassPathImpl(ClassPath classPath) { 48 try { 49 Field field = classPath.getClass().getDeclaredField("impl"); field.setAccessible(true); 51 return (ClassPathImplementation)field.get(classPath); 52 } catch (SecurityException ex) { 53 throw wrapException(ex); 54 } catch (IllegalArgumentException ex) { 55 throw wrapException(ex); 56 } catch (IllegalAccessException ex) { 57 throw wrapException(ex); 58 } catch (NoSuchFieldException ex) { 59 throw wrapException(ex); 60 } 61 } 62 63 private static Error wrapException(Throwable t) { 64 Error e = new AssertionError (t.getMessage()); 65 e.initCause(t); 66 return e; 67 } 68 } 69 | Popular Tags |