Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * To change this template, choose Tools | Templates
  * and open the template in the editor.
  */
 
 package com.sun.jersey.server.impl.application;
 

Author(s):
paulsandoz
public class CloseableServiceFactory implements
    private static final Logger LOGGER = Logger.getLogger(CloseableServiceFactory.class.getName());
    private final HttpContext context;
    public CloseableServiceFactory(@Context HttpContext context) {
        this. = context;
    }
    // InjectableProvider
    public ComponentScope getScope() {
        return .;
    }
    public Injectable getInjectable(ComponentContext icContext aType c) {
        if (c != CloseableService.class)
           return null;
        return this;
    }
    // Injectable
    public CloseableService getValue() {
        return this;
    }
    // CloseableService
    
    public void add(Closeable c) {
        Set<Closeables = (Set<Closeable>).getProperties().
                get(CloseableServiceFactory.class.getName());
        if (s == null) {
            s = new HashSet<Closeable>();
            .getProperties().put(CloseableServiceFactory.class.getName(), s);
        }
        s.add(c);
    }
    public void close(HttpContext context) {
        Set<Closeables = (Set<Closeable>)context.getProperties().
                get(CloseableServiceFactory.class.getName());
        if (s != null) {
            for (Closeable c : s) {
                try {
                    c.close();
                } catch (Exception ex) {
                    .log(."Unable to close"ex);
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X