source: extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/transverse/util/spring/SpringUtils.java @ 9921

Last change on this file since 9921 was 9921, checked in by mlg, 13 years ago

Adds spring for the dependency injection
Deletion of jdom (not useful just for a class that manipulates a simple XML file)

File size: 2.5 KB
Line 
1package fr.mael.jiwigo.transverse.util.spring;
2
3import org.springframework.beans.factory.xml.XmlBeanFactory;
4import org.springframework.core.io.ClassPathResource;
5
6import fr.mael.jiwigo.service.CategoryService;
7import fr.mael.jiwigo.service.CommentService;
8import fr.mael.jiwigo.service.ImageService;
9import fr.mael.jiwigo.service.TagService;
10import fr.mael.jiwigo.transverse.session.SessionManager;
11
12public class SpringUtils {
13
14    /**
15     * Id of the image service bean
16     */
17    private static String IMAGE_SERVICE = "imageService";
18    /**
19     * Id of the tag service bean
20     */
21    private static String TAG_SERVICE = "tagService";
22    /**
23     * Id of the category service bean
24     */
25    private static String CATEGORY_SERVICE = "categoryService";
26    /**
27     * Id of the comment service bean
28     */
29    private static String COMMENT_SERVICE = "commentService";
30
31    private static String SESSION_MANAGER = "sessionManager";
32
33    /**
34     * bean factory
35     */
36    private static XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("application-context.xml"));
37
38    private SpringUtils() {
39    }
40
41    /**
42     * @return the image service
43     */
44    public static ImageService getImageService() {
45        return (ImageService) factory.getBean(IMAGE_SERVICE);
46    }
47
48    /**
49     * @return the tag service
50     */
51    public static TagService getTagService() {
52        return (TagService) factory.getBean(TAG_SERVICE);
53    }
54
55    /**
56     * @return the comment service
57     */
58    public static CommentService getCommentService() {
59        return (CommentService) factory.getBean(COMMENT_SERVICE);
60    }
61
62    /**
63     * @return the category service
64     */
65    public static CategoryService getCategoryService() {
66        return (CategoryService) factory.getBean(CATEGORY_SERVICE);
67    }
68
69    /**
70     * @return the session manager
71     */
72    public static SessionManager getSessionManager() {
73        return (SessionManager) factory.getBean(SESSION_MANAGER);
74    }
75
76    //    public static void main(String[] args) {
77    //  try {
78    //      SessionManager sessionManager = getSessionManager();
79    //      sessionManager.setLogin("mael");
80    //      sessionManager.setUrl("http://mael.piwigo.com/ws.php");
81    //      sessionManager.setPassword("motdepasse");
82    //  } catch (IOException e) {
83    //      // TODO Auto-generated catch block
84    //      e.printStackTrace();
85    //  } catch (ProxyAuthenticationException e) {
86    //      // TODO Auto-generated catch block
87    //      e.printStackTrace();
88    //  }
89    //    }
90
91}
Note: See TracBrowser for help on using the repository browser.