net.sf.ehcache.management.scanner.TerracottaPrivateClassScanner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of management-ehcache-impl Show documentation
Show all versions of management-ehcache-impl Show documentation
A product library implementing the ehcache management resource service interfaces and integrating with ehcache to construct the relevant management resource entities.
The newest version!
package net.sf.ehcache.management.scanner;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import com.sun.jersey.core.spi.scanning.ScannerException;
import com.sun.jersey.core.spi.scanning.ScannerListener;
import com.sun.jersey.core.spi.scanning.uri.BundleSchemeScanner;
import com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner;
import com.sun.jersey.core.spi.scanning.uri.JarZipSchemeScanner;
import com.sun.jersey.core.spi.scanning.uri.UriSchemeScanner;
import com.sun.jersey.core.spi.scanning.uri.VfsSchemeScanner;
public class TerracottaPrivateClassScanner implements UriSchemeScanner {
private static final String PRIVATE_CLASS_SUFFIX = ".class_terracotta";
private Map scanners = new HashMap();
public TerracottaPrivateClassScanner() {
inspect(new JarZipSchemeScanner());
inspect(new FileSchemeScanner());
inspect(new VfsSchemeScanner());
inspect(new BundleSchemeScanner());
}
private void inspect(UriSchemeScanner scanner) {
for (String scheme : scanner.getSchemes()) {
scanners.put(scheme, scanner);
}
}
@Override
public Set getSchemes() {
return scanners.keySet();
}
@Override
public void scan(URI u, ScannerListener sl) throws ScannerException {
UriSchemeScanner scanner = scanners.get(u.getScheme());
if (scanner == null) {
throw new AssertionError();
}
scanner.scan(u, new ClazzScannerListener(sl));
}
private static class ClazzScannerListener implements ScannerListener {
private final ScannerListener sl;
ClazzScannerListener(ScannerListener sl) {
this.sl = sl;
}
public boolean onAccept(String name) {
if (name.endsWith(PRIVATE_CLASS_SUFFIX)) {
name = name.substring(0, name.lastIndexOf(PRIVATE_CLASS_SUFFIX)).concat(".class");
}
return sl.onAccept(name);
}
public void onProcess(String name, InputStream in) throws IOException {
sl.onProcess(name, in);
}
}
}