public boolean removeResourceStore(final ResourceStore pStore) { final int n = stores.length; int i = 0; // FIXME: this should be improved with a Map // find the pStore and index position with var i while ((i < n) && (stores[i] != pStore)) { i++; } // pStore was not found if (i == n) { return false; } // if stores length > 1 then array copy old values, else create new empty store final ResourceStore[] newStores = new ResourceStore[n - 1]; if (i > 0) { System.arraycopy(stores, 0, newStores, 0, i); } if (i < n - 1) { System.arraycopy(stores, i + 1, newStores, i, (n - i - 1)); } stores = newStores; delegate = new ResourceStoreClassLoader(parent, stores); return true; }
public boolean addResourceStore(final ResourceStore pStore) { try { final int n = stores.length; final ResourceStore[] newStores = new ResourceStore[n + 1]; System.arraycopy(stores, 0, newStores, 1, n); newStores[0] = pStore; stores = newStores; delegate = new ResourceStoreClassLoader(parent, stores); return true; } catch (final RuntimeException e) { LOG.error("Could not add resource store", e); } return false; }
public void reload() { if (LOG.isTraceEnabled()) LOG.trace("Reloading class loader"); delegate = new ResourceStoreClassLoader(parent, stores); }
public ReloadingClassLoader(final ClassLoader pParent) { super(pParent); parent = pParent; URL parentRoot = pParent.getResource(""); FileManager fileManager = ActionContext.getContext().getInstance(FileManagerFactory.class).getFileManager(); URL root = fileManager.normalizeToFileProtocol(parentRoot); root = ObjectUtils.defaultIfNull(root, parentRoot); try { if (root != null) { stores = new ResourceStore[]{new FileResourceStore(new File(root.toURI()))}; } else { throw new XWorkException("Unable to start the reloadable class loader, consider setting 'struts.convention.classes.reload' to false"); } } catch (URISyntaxException e) { throw new XWorkException("Unable to start the reloadable class loader, consider setting 'struts.convention.classes.reload' to false", e); } catch (RuntimeException e) { // see WW-3121 // TODO: Fix this for a reloading mechanism to be marked as stable if (root != null) LOG.error("Exception while trying to build the ResourceStore for URL [#0]", e, root.toString()); else LOG.error("Exception while trying to get root resource from class loader", e); LOG.error("Consider setting struts.convention.classes.reload=false"); throw e; } delegate = new ResourceStoreClassLoader(parent, stores); }