001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2006 Danet GmbH (www.danet.de), BU BTS.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: StateMapper.java,v 1.5 2007/01/31 22:55:36 mlipp Exp $
021: *
022: * $Log: StateMapper.java,v $
023: * Revision 1.5 2007/01/31 22:55:36 mlipp
024: * Some more refactoring and fixes of problems introduced by refactoring.
025: *
026: * Revision 1.4 2007/01/31 12:24:07 drmlipp
027: * Design revisited.
028: *
029: * Revision 1.3 2007/01/30 21:06:40 mlipp
030: * Fixed handling of not explicitly initialized substates.
031: *
032: * Revision 1.2 2007/01/30 11:56:14 drmlipp
033: * Merged Wf-XML branch.
034: *
035: * Revision 1.1.2.3 2007/01/11 10:23:52 schnelle
036: * Creation of StateChanged notifications.
037: *
038: * Revision 1.1.2.2 2006/12/20 14:37:59 schnelle
039: * Implemented Factory GetDefinition.
040: *
041: * Revision 1.1.2.1 2006/12/20 13:32:25 schnelle
042: * Basic implementato of GetProperties for Instance and Activity.
043: *
044: */
045: package de.danet.an.workflow.clients.wfxml;
046:
047: import java.util.ArrayList;
048: import java.util.Collections;
049: import java.util.Comparator;
050: import java.util.Iterator;
051: import java.util.List;
052: import java.util.Map;
053:
054: import de.danet.an.workflow.omgcore.InvalidStateException;
055:
056: /**
057: * This class provides a mapping facility of ASAP state definitions to OMG
058: * state definitions and vice versa.
059: *
060: * @author Dirk Schnelle
061: */
062: class StateMapper {
063: /** Mapping of ASAP states to OMG states. */
064: private static final Map omgStates;
065:
066: /** Mapping of OMG states to ASAP states. */
067: private static final Map asapStates;
068: private static final List asapStatesList;
069:
070: static {
071: omgStates = new java.util.HashMap();
072:
073: omgStates
074: .put("open.notrunning", "open.not_running.not_started");
075: omgStates.put("open.notrunning.suspended",
076: "open.not_running.suspended");
077: omgStates.put("open.running", "open.running");
078: omgStates.put("open.running.debug.completing",
079: "open.running.debug.completing");
080: omgStates.put("closed.completed", "closed.completed");
081: omgStates.put("closed.abnormalCompleted", "closed.aborted");
082: omgStates.put("closed.abnormalCompleted.terminated",
083: "closed.terminated");
084: omgStates.put("closed.abnormalCompleted.aborted",
085: "closed.aborted");
086:
087: asapStates = new java.util.HashMap();
088:
089: asapStates.put("open", "open");
090: asapStates.put("open.not_running", "open.notrunning");
091: asapStates.put("open.not_running.not_started",
092: "open.notrunning");
093: asapStates.put("open.not_running.suspended",
094: "open.notrunning.suspended");
095: asapStates.put("open.running", "open.running");
096: asapStates.put("open.running.running", "open.running");
097: asapStates.put("open.running.debug.completing",
098: "open.running.debug.completing");
099: asapStates.put("closed", "closed");
100: asapStates.put("closed.completed", "closed.completed");
101: asapStates.put("closed.completed.normal", "closed.completed");
102: asapStates.put("closed.terminated",
103: "closed.abnormalCompleted.terminated");
104: asapStates.put("closed.aborted",
105: "closed.abnormalCompleted.aborted");
106:
107: asapStatesList = new ArrayList(asapStates.keySet());
108: Collections.sort(asapStatesList, new Comparator() {
109: public int compare(Object o1, Object o2) {
110: return ((String) o2).length() - ((String) o1).length();
111: }
112: });
113: }
114:
115: /**
116: * Retrieves the name of the ASAP state for the given OMG state.
117: * @param omgState name of the OMG state.
118: * @return name of the correspondent ASAP state.
119: * @throws InvalidStateException
120: */
121: static String omg2asapState(String omgState) {
122:
123: String res = (String) asapStates.get(omgState);
124: if (res != null) {
125: return res;
126: }
127: for (Iterator i = asapStatesList.iterator(); i.hasNext();) {
128: String parentState = (String) i.next();
129: if (omgState.startsWith(parentState)) {
130: res = (String) asapStates.get(parentState);
131: break;
132: }
133: }
134: asapStates.put(omgState, res);
135: return res;
136: }
137:
138: /**
139: * Retrieves the name of the OMG state for the given ASAP state.
140: * @param asapState name of the ASAP state.
141: * @return name of the correspondent OMG state.
142: * @throws InvalidStateException
143: */
144: static String asap2omgState(String asapState)
145: throws InvalidStateException {
146: String omgState = (String) omgStates.get(asapState);
147: if (omgState == null) {
148: throw new InvalidStateException("unkonwn state: '"
149: + asapState + "'");
150: }
151: return omgState;
152: }
153: }
|