/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2004 Danet GmbH (www.danet.de), GS-AN.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: BAForProcessInstantiation.java 2368 2007-05-03 21:58:25Z mlipp $
*
* $Log$
* Revision 1.2 2006/09/29 12:32:08 drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.1.1.1 2004/08/18 15:17:38 drmlipp
* Update to 1.2
*
* Revision 1.2 2004/05/09 18:42:59 lipp
* Finished process instantiation restructuring.
*
* Revision 1.1 2004/05/06 19:39:18 lipp
* Restructured block activity handling.
*
*/
package de.danet.an.workflow.domain;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.rmi.RemoteException;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import de.danet.an.util.sax.HandlerStack;
import de.danet.an.util.sax.StackedHandler;
import de.danet.an.workflow.internalapi.ExtActivityLocal;
import de.danet.an.workflow.localcoreapi.WfActivityLocal;
import de.danet.an.workflow.api.SAXEventBuffer;
import de.danet.an.workflow.api.Activity.JoinAndSplitMode;
/**
* This class provides a temporary representation of a block activity
* used during process instantiation.
*
* @author <a href="mailto:mnl@mnl.de">Michael N. Lipp</a>
* @version $Revision: 2368 $
*/
public class BAForProcessInstantiation extends BlockActivity {
private static final org.apache.commons.logging.Log logger
= org.apache.commons.logging.LogFactory.getLog
(BAForProcessInstantiation.class);
private String setId = null;
private Map allActs = null;
private Collection entryActs = null;
private Collection exitActs = null;
private Map actIds = new HashMap ();
/**
* Creates an instance of <code>BAForProcessInstantiation</code>
* with all attributes initialized to given values.
* @param proc the process this block activity is part of
* @param key the block activity key
* @param actSetDef the activity set definition
* @param packageId the package id of the process being
* instantiated
* @param actSetDefs activity set definition map
* @param blkActId the id of the block activity
* @param joinMode the join mode of the block activity
* @param splitMode the split mode of the activity
* @throws SAXException if an error occurs
*/
public BAForProcessInstantiation
(AbstractProcess proc, String key,
SAXEventBuffer actSetDef, String packageId,
Map actSetDefs, String blkActId,
JoinAndSplitMode joinMode, JoinAndSplitMode splitMode)
throws SAXException {
super (key);
allActs = new HashMap ();
HandlerStack hs = new HandlerStack
(new BlockActivityInitializer
(proc, actSetDefs, blkActId, joinMode, splitMode));
hs.setContextData ("packageId", packageId);
actSetDef.emit(hs.contentHandler());
}
/**
* Add an activity to this block activity's activities.
* @param actId the id of the activity in the process definition
* @param act the activity
*/
public void add (String actId, WfActivityLocal act) {
allActs.put (actId, act);
}
/**
* Return the id of the activity set this block activity was
* created from.
* @return set id
*/
public String setId () {
return setId;
}
/**
* Return the collection of entry activities of this block
* activity.
* @return the entry activities
*/
public Collection entryActivities () {
return entryActs;
}
/**
* Return the collection of exit activities of this block
* activity.
* @return the exit activities
*/
public Collection exitActivities () {
return exitActs;
}
/**
* Return the id from the acivity set definition of the given
* activity which must be contained in this block activity.
* @param key the activity's key
* @return the id
*/
public String getMemberId (String key) {
return (String)actIds.get (key);
}
/**
* Helper class for creating a block activity.
*/
public class BlockActivityInitializer extends StackedHandler {
private AbstractProcess process = null;
private Map actSetDefs = null;
private String blkActId = null;
private String blkActKey = null;
private JoinAndSplitMode joinMode = JoinAndSplitMode.AND;
private JoinAndSplitMode splitMode = JoinAndSplitMode.AND;
private Set localFromIds = new HashSet ();
private Set localToIds = new HashSet ();
private Map setActIdMap = new HashMap ();
private Map setTrefsMap = new HashMap ();
/**
* Create a new initializer with the given parameters.
* @param proc the process this activity belongs to
* @param actSets activity set definition map
* @param blkActId the id of the block activity
* @param jm the join mode of the block activity
* @param sm the split mode of the activity
*/
public BlockActivityInitializer
(AbstractProcess proc, Map actSets,
String blkActId, JoinAndSplitMode jm, JoinAndSplitMode sm) {
process = proc;
actSetDefs = actSets;
this.blkActId = blkActId;
joinMode = jm;
splitMode = sm;
blkActKey = key();
}
/**
* Receive notification of the beginning of an element.
*
* @param uri the Namespace URI, or the empty string if the
* element has no Namespace URI or if Namespace processing is not
* being performed.
* @param loc the local name (without prefix), or the empty string
* if Namespace processing is not being performed.
* @param raw the raw XML 1.0 name (with prefix), or the empty
* string if raw names are not available.
* @param a the attributes attached to the element. If there are
* no attributes, it shall be an empty Attributes object.
* @throws SAXException not thrown.
*/
public void startElement
(String uri, String loc, String raw, Attributes a)
throws SAXException {
if (loc.equals ("ActivitySet")) {
setId = a.getValue ("Id");
} else if (loc.equals ("Activity")) {
getStack().push
(process.activityInitializer
(setActIdMap, setTrefsMap, actSetDefs, blkActKey));
} else if (loc.equals ("Transition")) {
localFromIds.add (a.getValue ("From"));
localToIds.add (a.getValue ("To"));
getStack().push
(process.transitionInitializer
(setActIdMap, setTrefsMap, blkActId));
}
}
/**
* Receive notification of the end of an element.
*
* @param uri the Namespace URI, or the empty string if the
* element has no Namespace URI or if Namespace processing is not
* being performed.
* @param loc the local name (without prefix), or the empty string
* if Namespace processing is not being performed.
* @param raw the raw XML 1.0 name (with prefix), or the empty
* string if raw names are not available.
* @throws SAXException not thrown.
*/
public void endElement(String uri, String loc, String raw)
throws SAXException {
if (loc.equals ("ActivitySet")) {
entryActs = new ArrayList ();
exitActs = new ArrayList ();
actIds = new HashMap();
for (Iterator i = setActIdMap.entrySet().iterator ();
i.hasNext ();) {
Map.Entry entry = (Map.Entry)i.next ();
String actId = (String)entry.getKey ();
ExtActivityLocal act = (ExtActivityLocal)entry.getValue ();
if (! localToIds.contains (actId)) {
// is entry activity
act.setJoinMode (joinMode);
entryActs.add(act);
actIds.put(act.key(), actId);
}
if (! localFromIds.contains (actId)) {
// is exit activity
act.setSplitMode (splitMode);
exitActs.add(act);
actIds.put(act.key(), actId);
}
}
}
}
}
}