FileDocCategorySizeDatePackage
TCPStandaloneContext.javaAPI DocExample6532Tue May 29 16:57:10 BST 2007com.sun.xml.ws.transport.tcp.server

TCPStandaloneContext

public final class TCPStandaloneContext extends Object implements TCPContext
author
Alexey Stashok

Fields Summary
private final ClassLoader
classloader
private final Map
attributes
Constructors Summary
public TCPStandaloneContext(ClassLoader classloader)

    
        
        this.classloader = classloader;
    
Methods Summary
private voidgatherResourcesWithFileMode(java.lang.String path, java.net.URI resourceURI, java.util.Set resources)

        final File file = new File(resourceURI);
        final String[] list = file.list(new FilenameFilter() {
            public boolean accept(File file, String name) {
                return name.charAt(0) != '.";
            }
        });
        
        for(String filename : list) {
            resources.add(path + filename);
        }
    
private voidgatherResourcesWithJarMode(java.lang.String path, java.net.URI resourceURI, java.util.Set resources)

        final String resourceURIAsString = resourceURI.toASCIIString();
        final int pathDelim = resourceURIAsString.indexOf('!");
        final String zipFile = resourceURIAsString.substring("jar:file:/".length(), (pathDelim != -1) ? pathDelim : resourceURIAsString.length());
        ZipFile file = null;
        
        try {
            file = new ZipFile(zipFile);
            
            String pathToCompare = path;
            if (pathToCompare.charAt(0) == '/") {
                pathToCompare = pathToCompare.substring(1, pathToCompare.length());
            }
            if (!pathToCompare.endsWith("/")) {
                pathToCompare = pathToCompare + "/";
            }
            
            for(final Enumeration<? extends ZipEntry> e = file.entries(); e.hasMoreElements(); ) {
                final ZipEntry entry = e.nextElement();
                if (entry.getName().startsWith(pathToCompare) && !entry.getName().equals(pathToCompare)) {
                    resources.add("/" + entry.getName());
                }
            }
        } catch(IOException e) {
        } finally {
            if (file != null) {
                try {
                    file.close();
                } catch (IOException ex) {
                }
            }
        }
    
public java.lang.ObjectgetAttribute(java.lang.String name)

        return attributes.get(name);
    
public java.net.URLgetResource(java.lang.String resource)

        if (resource.charAt(0) == '/") {
            resource = resource.substring(1, resource.length());
        }
        
        return classloader.getResource(resource);
    
public java.io.InputStreamgetResourceAsStream(java.lang.String resource)

        return classloader.getResourceAsStream(resource);
    
public java.util.SetgetResourcePaths(java.lang.String path)

        try {
            return populateResourcePaths(path);
        } catch (Exception ex) {
        }
        
        return Collections.emptySet();
    
private java.util.EnumerationgetResources(java.lang.String resource)

        if (resource.charAt(0) == '/") {
            resource = resource.substring(1, resource.length());
        }
        
        return classloader.getResources(resource);
    
private java.util.SetpopulateResourcePaths(java.lang.String path)

        final Set<String> resources = new HashSet<String>();
        
        for(final Enumeration<URL> initResources = getResources(path); initResources.hasMoreElements(); ) {
            final URI resourceURI = initResources.nextElement().toURI();
            if (resourceURI.getScheme().equals("file")) {
                gatherResourcesWithFileMode(path, resourceURI, resources);
            } else if (resourceURI.getScheme().equals("jar")) {
                gatherResourcesWithJarMode(path, resourceURI, resources);
            }
        }
        
        return resources;
    
public voidsetAttribute(java.lang.String name, java.lang.Object value)

        attributes.put(name, value);