/** * Set the paths and the exported package names * * @param classes the classes to reference */ public void setPathsAndPackageNames(Class<?>... classes) { setPaths(classes); setPackageNames(classes); }
public MockClassLoaderPolicy run() { return new MockClassLoaderPolicy(name); } });
@Override protected MockClassLoaderPolicy determinePolicy() { MockClassLoadingMetaData metaData = getClassLoadingMetaData(); MockClassLoaderPolicy policy = MockClassLoaderHelper.createMockClassLoaderPolicy(getContextName()); policy.setPrefix(metaData.getPrefix()); policy.setPackageNames(getPackageNames()); policy.setPaths(metaData.getPaths()); policy.setIncluded(metaData.getIncludedClasses()); policy.setExcluded(metaData.getExcludedClasses()); policy.setImportAll(isImportAll()); policy.setShutdownPolicy(getShutdownPolicy()); policy.setDelegates(getDelegates()); return policy; }
/** * Initialize the classloader system * * @param clazz the original clazz * @param importAll whether to import all * @param packages the reference classes for the packages * @return the clazz loaded from the new classloading system */ public Class<?> initializeClassLoader(Class<?> clazz, boolean importAll, Class<?>... packages) { MockClassLoaderPolicy policy = new MockClassLoaderPolicy(); Set<Class<?>> classes = new HashSet<Class<?>>(); classes.add(clazz); classes.addAll(Arrays.asList(packages)); policy.setImportAll(importAll); policy.setPathsAndPackageNames(classes.toArray(new Class[classes.size()])); return initializeClassLoader(clazz, policy); }
/** * Create a classloader * * It exports everything * * @param name the name * @param importAll whether to import all * @param packages the packages * @return the classloader * @throws Exception for any error */ public ClassLoader createClassLoader(String name, boolean importAll, String... packages) throws Exception { MockClassLoaderPolicy policy = MockClassLoaderHelper.createMockClassLoaderPolicy(name); policy.setImportAll(importAll); policy.setPathsAndPackageNames(packages); return createClassLoader(policy); }
/** * Set the path to expose * * @param path the path */ public void setPath(String path) { setPaths(path); }
/** * Set the paths and the exported package names * * @param packages the packages */ public void setPathsAndPackageNames(String... packages) { if (packages == null) { paths = null; packageNames = null; return; } paths = new String[packages.length]; for (int i = 0; i < packages.length; ++i) paths[i] = packages[i].replace('.', '/'); setPackageNames(packages); }
@Override public ObjectName getObjectName() { try { Hashtable<String, String> properties = new Hashtable<String, String>(); properties.put("name", "'" + name + "'"); properties.put("domain", "\"" + getDomainName() + "\""); return ObjectName.getInstance("jboss.classloader", properties); } catch (MalformedObjectNameException e) { throw new Error("Error creating object name", e); } }
@Override protected ProtectionDomain getProtectionDomain(String className, String path) { final Class<?> clazz; try { clazz = getClass().getClassLoader().loadClass(className); } catch (ClassNotFoundException e) { throw new Error("Could not load class: " + className, e); } return AccessController.doPrivileged(new PrivilegedAction<ProtectionDomain>() { public ProtectionDomain run() { return clazz.getProtectionDomain(); } }, getAccessControlContext()); }
/** * Initialize the classloader system * * @param clazz the original clazz * @param importAll whether to import all * @param packages the reference classes for the packages * @return the clazz loaded from the new classloading system */ public Class<?> initializeClassLoader(Class<?> clazz, boolean importAll, Class<?>... packages) { MockClassLoaderPolicy policy = new MockClassLoaderPolicy(); Set<Class<?>> classes = new HashSet<Class<?>>(); classes.add(clazz); for (Class<?> c : packages) classes.add(c); policy.setImportAll(importAll); policy.setPathsAndPackageNames(classes.toArray(new Class[classes.size()])); return initializeClassLoader(clazz, policy); }
/** * Create a classloader * * It exports everything * * @param name the name * @param importAll whether to import all * @param packages the packages * @return the classloader * @throws Exception for any error */ public ClassLoader createClassLoader(String name, boolean importAll, String... packages) throws Exception { MockClassLoaderPolicy policy = MockClassLoaderHelper.createMockClassLoaderPolicy(name); policy.setImportAll(importAll); policy.setPathsAndPackageNames(packages); return createClassLoader(policy); }
/** * Set the path to expose * * @param path the path */ public void setPath(String path) { setPaths(path); }
/** * Set the paths and the exported package names * * @param packages the packages */ public void setPathsAndPackageNames(String... packages) { if (packages == null) { paths = null; packageNames = null; return; } paths = new String[packages.length]; for (int i = 0; i < packages.length; ++i) paths[i] = packages[i].replace('.', '/'); setPackageNames(packages); }
@Override public ObjectName getObjectName() { try { Hashtable<String, String> properties = new Hashtable<String, String>(); properties.put("name", "'" + name + "'"); properties.put("domain", "\"" + getDomainName() + "\""); return ObjectName.getInstance("jboss.classloader", properties); } catch (MalformedObjectNameException e) { throw new Error("Error creating object name", e); } }
@Override protected ProtectionDomain getProtectionDomain(String className, String path) { final Class<?> clazz; try { clazz = getClass().getClassLoader().loadClass(className); } catch (ClassNotFoundException e) { throw new Error("Could not load class: " + className, e); } return AccessController.doPrivileged(new PrivilegedAction<ProtectionDomain>() { public ProtectionDomain run() { return clazz.getProtectionDomain(); } }, getAccessControlContext()); }
/** * Initialize the classloader system * * @param clazz the original clazz * @param parentFilter the parent filter * @param importAll whether to import all * @param packages the reference classes for the packages * @return the clazz loaded from the new classloading system */ public Class<?> initializeClassLoader(Class<?> clazz, ClassFilter parentFilter, boolean importAll, Class<?>... packages) { MockClassLoaderPolicy policy = new MockClassLoaderPolicy(); Set<Class<?>> classes = new HashSet<Class<?>>(); classes.add(clazz); classes.addAll(Arrays.asList(packages)); policy.setImportAll(importAll); policy.setPathsAndPackageNames(classes.toArray(new Class[classes.size()])); return initializeClassLoader(clazz, parentFilter, policy); }
/** * Set the paths and the exported package names * * @param classes the classes to reference */ public void setPathsAndPackageNames(Class<?>... classes) { setPaths(classes); setPackageNames(classes); }
public MockClassLoaderPolicy run() { return new MockClassLoaderPolicy(name); } });
/** * Initialize the classloader system * * @param clazz the original clazz * @param parentFilter the parent filter * @param importAll whether to import all * @param packages the reference classes for the packages * @return the clazz loaded from the new classloading system */ public Class<?> initializeClassLoader(Class<?> clazz, ClassFilter parentFilter, boolean importAll, Class<?>... packages) { MockClassLoaderPolicy policy = new MockClassLoaderPolicy(); Set<Class<?>> classes = new HashSet<Class<?>>(); classes.add(clazz); for (Class<?> c : packages) classes.add(c); policy.setImportAll(importAll); policy.setPathsAndPackageNames(classes.toArray(new Class[classes.size()])); return initializeClassLoader(clazz, parentFilter, policy); }
public ClassLoader run() { MockClassLoaderPolicy policy = new MockClassLoaderPolicy(name); return system.registerClassLoaderPolicy(domainName, policy); } });