Java Generics error when implementing Hibernate message interpolator
Posted
by
Jayaprakash
on Stack Overflow
See other posts from Stack Overflow
or by Jayaprakash
Published on 2010-12-28T13:31:51Z
Indexed on
2010/12/28
13:53 UTC
Read the original article
Hit count: 185
Framework: Spring, Hibernate. O/S: Windows
I am trying to implement hibernate's Custom message interpolator following the direction of this Link.
When implementing the below class, it gives an error "Cannot make a static reference to the non-static type Locale".
public class ClientLocaleThreadLocal<Locale> {
private static ThreadLocal tLocal = new ThreadLocal();
public static void set(Locale locale) {
tLocal.set(locale);
}
public static Locale get() {
return tLocal.get();
}
public static void remove() {
tLocal.remove();
}
}
As I do not know generics enough, not sure how is being used by TimeFilter class below and the purpose of definition in the above class.
public class TimerFilter implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException {
try {
ClientLocaleThreadLocal.set(req.getLocale());
filterChain.doFilter(req, res);
}finally {
ClientLocaleThreadLocal.remove();
}
}
public void init(FilterConfig arg0) throws ServletException {
}
}
Will doing the following be okay?
Change static method/field in ClientLocaleThreadLocal to non-static method/fields
In TimeFilter, set locale by instantiating new object as below. new ClientLocaleThreadLocal().set(req.getLocale())
Thanks for your help in advance
© Stack Overflow or respective owner