|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| WerkflowHelper.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* WerkflowHelper.java
|
|
| 3 |
* Copyright 2002-2004 Bill2, Inc.
|
|
| 4 |
*
|
|
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 6 |
* you may not use this file except in compliance with the License.
|
|
| 7 |
* You may obtain a copy of the License at
|
|
| 8 |
*
|
|
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 10 |
*
|
|
| 11 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 14 |
* See the License for the specific language governing permissions and
|
|
| 15 |
* limitations under the License.
|
|
| 16 |
*/
|
|
| 17 |
package org.dentaku.foundation.workflow;
|
|
| 18 |
|
|
| 19 |
import org.codehaus.werkflow.SimpleAttributes;
|
|
| 20 |
import org.codehaus.werkflow.Wfms;
|
|
| 21 |
import org.codehaus.werkflow.definition.ProcessDefinition;
|
|
| 22 |
import org.codehaus.werkflow.engine.WorkflowEngine;
|
|
| 23 |
import org.codehaus.werkflow.personality.Personality;
|
|
| 24 |
import org.codehaus.werkflow.personality.basic.BasicPersonality;
|
|
| 25 |
import org.codehaus.werkflow.service.SimpleWfmsServices;
|
|
| 26 |
import org.codehaus.werkflow.service.messaging.simple.SimpleMessagingManager;
|
|
| 27 |
import org.codehaus.werkflow.service.persistence.fleeting.FleetingPersistenceManager;
|
|
| 28 |
import org.dentaku.foundation.event.WerkflowEvent;
|
|
| 29 |
|
|
| 30 |
import java.net.URL;
|
|
| 31 |
import java.util.HashMap;
|
|
| 32 |
|
|
| 33 |
public class WerkflowHelper { |
|
| 34 |
private static WerkflowHelper instance = new WerkflowHelper(); |
|
| 35 |
|
|
| 36 | 0 |
public static WerkflowHelper getInstance() { |
| 37 | 0 |
return instance;
|
| 38 |
} |
|
| 39 |
|
|
| 40 | 0 |
private WerkflowHelper() {
|
| 41 |
} |
|
| 42 |
private Wfms wfms;
|
|
| 43 |
private HashMap workflows = new HashMap(); |
|
| 44 |
|
|
| 45 | 0 |
public Wfms getWfms()
|
| 46 |
{
|
|
| 47 | 0 |
if ( this.wfms == null ) |
| 48 |
{
|
|
| 49 | 0 |
SimpleWfmsServices services = new SimpleWfmsServices();
|
| 50 |
|
|
| 51 | 0 |
services.setMessagingManager( new SimpleMessagingManager() );
|
| 52 | 0 |
services.setPersistenceManager( new FleetingPersistenceManager() );
|
| 53 |
|
|
| 54 | 0 |
this.wfms = new WorkflowEngine( services ); |
| 55 |
} |
|
| 56 |
|
|
| 57 | 0 |
return this.wfms; |
| 58 |
} |
|
| 59 |
|
|
| 60 | 0 |
public void deploy(URL url) |
| 61 |
throws Exception
|
|
| 62 |
{
|
|
| 63 | 0 |
if (workflows.get(url) == null) { |
| 64 | 0 |
Personality personality = BasicPersonality.getInstance(); |
| 65 |
|
|
| 66 | 0 |
ProcessDefinition[] processDefs = personality.load( url ); |
| 67 |
|
|
| 68 | 0 |
for ( int i = 0 ; i < processDefs.length ; ++i ) |
| 69 |
{
|
|
| 70 | 0 |
getWfms().getAdmin().deployProcess( processDefs[i] ); |
| 71 |
} |
|
| 72 |
|
|
| 73 | 0 |
workflows.put(url, null);
|
| 74 |
} |
|
| 75 |
} |
|
| 76 |
|
|
| 77 | 0 |
public void dispatch(WerkflowEvent event) throws Exception { |
| 78 | 0 |
deploy(event.getWorkflowURL()); |
| 79 | 0 |
SimpleAttributes attrs = new SimpleAttributes();
|
| 80 |
|
|
| 81 | 0 |
attrs.setAttribute( "event", event );
|
| 82 | 0 |
getWfms().getRuntime().callProcess("", "EventDispatch", attrs); |
| 83 |
} |
|
| 84 |
} |
|
| 85 |
|
|
||||||||||