KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > workflow > WorkflowModule


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.module.workflow;
14
15 import info.magnolia.cms.beans.config.ContentRepository;
16 import info.magnolia.cms.core.Content;
17 import info.magnolia.cms.module.RegisterException;
18 import info.magnolia.cms.util.ContentUtil;
19 import info.magnolia.cms.util.FactoryUtil;
20 import info.magnolia.module.admininterface.AbstractAdminModule;
21 import info.magnolia.module.workflow.flows.FlowDefinitionManager;
22 import info.magnolia.module.workflow.jcr.JCRPersistedEngine;
23
24 import javax.jcr.RepositoryException;
25
26 import openwfe.org.ServiceException;
27 import openwfe.org.engine.impl.expool.SimpleExpressionPool;
28
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33 /**
34  * Module "workflow" entry class.
35  * @author Sameer Charles
36  * @author Fabrizio Giustina
37  * @author Nicolas Modrzyk
38  * @version 3.0
39  */

40 public class WorkflowModule extends AbstractAdminModule {
41
42     /**
43      *
44      */

45     public static final String JavaDoc COMMANDS_CATALOG_PATH = "/modules/workflow/config/commands";
46
47     public static final String JavaDoc CACHE_URL_DEFINITION = "/modules/workflow/config/cache";
48
49     /**
50      * Logger.
51      */

52     private static Logger log = LoggerFactory.getLogger(WorkflowModule.class);
53
54     /**
55      * The current used engine
56      */

57     private static JCRPersistedEngine wfEngine;
58     private static String JavaDoc cacheURL;
59
60     /**
61      * @see info.magnolia.module.admininterface.AbstractAdminModule#onRegister(int)
62      */

63     protected void onRegister(int registerState) throws RegisterException {
64         Content menu = ContentUtil.getContent(ContentRepository.CONFIG, "/modules/adminInterface/config/menu");
65         try {
66             menu.orderBefore("inbox", "security");
67             menu.save();
68         }
69         catch (RepositoryException e) {
70             log.warn("can't move menupoint", e);
71         }
72     }
73
74     /**
75      * register commands and start OWFE engine
76      */

77     protected void onInit() {
78         registerCacheUrl();
79         startEngine();
80     }
81
82     public static String JavaDoc getCacheURL() {
83         return cacheURL;
84     }
85
86     private void registerCacheUrl() {
87         Content node = ContentUtil.getContent(ContentRepository.CONFIG, CACHE_URL_DEFINITION);
88         try {
89             if(node!=null && node.hasNodeData("serverURL")) {
90                 String JavaDoc serverURL = node.getNodeData("serverURL").getString();
91                 if(serverURL !=null) {
92                     cacheURL = serverURL;
93                     log.info("Cache server base url for flows is set to:"+cacheURL);
94                 }
95             }
96         } catch (Exception JavaDoc e) {
97
98         }
99     }
100
101     /**
102      *
103      */

104     private void startEngine() {
105         try {
106             log.info("Starting openwfe engine");
107             wfEngine = new JCRPersistedEngine();
108             wfEngine.registerParticipant(new MgnlParticipant("user-.*"));
109             wfEngine.registerParticipant(new MgnlParticipant("group-.*"));
110             wfEngine.registerParticipant(new MgnlParticipant("role-.*"));
111             wfEngine.registerParticipant(new MgnlParticipant("command-.*"));
112         }
113         catch (Exception JavaDoc e) {
114             log.error("An exception arised when creating the workflow engine", e);
115         }
116     }
117
118     public void destroy() {
119         JCRPersistedEngine engine = getEngine();
120         if (engine != null && engine.isRunning()) {
121             log.info("Stopping workflow engine..");
122             try {
123                 // before try to stop purge and scheduling tasks
124
((SimpleExpressionPool) engine.getExpressionPool()).stop();
125                 engine.stop();
126             }
127             catch (ServiceException se) {
128                 log.error("Failed to stop Open WFE engine");
129                 log.error(se.getMessage(), se);
130             }
131         }
132     }
133
134     /**
135      * return the global work flow engine
136      */

137     static public JCRPersistedEngine getEngine() {
138         return wfEngine;
139     }
140     
141     public static FlowDefinitionManager getFlowDefinitionManager(){
142         return (FlowDefinitionManager) FactoryUtil.getSingleton(FlowDefinitionManager.class);
143     }
144
145 }
Popular Tags