01: package org.osbl.concern;
02:
03: import org.concern.library.generic.HibernateLoader;
04: import org.concern.LoaderException;
05: import org.conform.*;
06: import org.conform.format.*;
07:
08: import java.util.*;
09: import java.lang.reflect.Method;
10:
11: public class GenericLoader extends HibernateLoader {
12: protected BeanMetaProvider beanMetaProvider;
13: protected FormatFactory formatFactory;
14: protected ResourceProvider resourceProvider;
15:
16: public void setBeanMetaProvider(BeanMetaProvider beanMetaProvider) {
17: this .beanMetaProvider = beanMetaProvider;
18: }
19:
20: public void setFormatFactory(FormatFactory formatFactory) {
21: this .formatFactory = formatFactory;
22: }
23:
24: public void setResourceProvider(ResourceProvider resourceProvider) {
25: this .resourceProvider = resourceProvider;
26: }
27:
28: public Map<String, String> formatSubjectLines(Object subject)
29: throws LoaderException {
30: Map<String, String> subjectLines = new HashMap<String, String>();
31:
32: BeanMeta beanMeta = new VariationBeanMetaProvider(
33: beanMetaProvider).getBeanMeta(getEntityClass());
34: String patternKey = (String) beanMeta
35: .getAttribute(PropertyMeta.ATTRIBUTE_PATTERN_KEY);
36: Format subjectFormat = beanMeta.getFormat();
37: if (subjectFormat == null)
38: subjectFormat = new NoFormat();
39:
40: Locale backupLocale = formatFactory.getLocale();
41: try {
42: List<Locale> supportedLocales = resourceProvider
43: .getSupportedLocales();
44: for (Locale locale : supportedLocales) {
45: formatFactory.setLocale(locale);
46: if (patternKey != null)
47: subjectFormat.setPattern(resourceProvider
48: .getMessage(locale, patternKey));
49: String subjectLine = subjectFormat.format(subject);
50: subjectLines.put(locale.toString(), subjectLine);
51: }
52: } finally {
53: FormatFactory.getInstance().setLocale(backupLocale);
54: }
55:
56: return subjectLines;
57: }
58:
59: public String getOriginator(Object subject) throws LoaderException {
60: try {
61: Method getter = subject.getClass()
62: .getMethod("getCreatedBy");
63: return (String) getter.invoke(subject);
64: } catch (Exception e) {
65: throw new LoaderException(e);
66: }
67: }
68: }
|