001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2004 Danet GmbH (www.danet.de), GS-AN.
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: * The initial version of this code has been contributed by Init AG
021: * (http://www.init-ka.de).
022: *
023: * $Id: GetDependencyCopiedFrom.java,v 1.2 2006/09/29 12:32:07 drmlipp Exp $
024: *
025: * $Log: GetDependencyCopiedFrom.java,v $
026: * Revision 1.2 2006/09/29 12:32:07 drmlipp
027: * Consistently using WfMOpen as projct name now.
028: *
029: * Revision 1.1 2004/09/15 20:10:12 mlipp
030: * Started adding Scarab interface.
031: *
032: */
033: package de.danet.an.workflow.tools.scarab;
034:
035: import java.io.Serializable;
036:
037: import java.util.Map;
038: import java.util.Vector;
039:
040: import java.rmi.RemoteException;
041:
042: import de.danet.an.workflow.omgcore.ProcessData;
043:
044: import de.danet.an.workflow.api.Activity;
045: import de.danet.an.workflow.api.DefaultProcessData;
046: import de.danet.an.workflow.api.FormalParameter;
047:
048: import de.danet.an.workflow.spis.aii.ApplicationNotStoppedException;
049: import de.danet.an.workflow.spis.aii.CannotExecuteException;
050: import de.danet.an.workflow.spis.aii.ResultProvider;
051: import de.danet.an.workflow.spis.aii.ToolAgent;
052:
053: /**
054: * This class provides a tool that gets issue id(as a result), if
055: * issue has any dependency (duplicated or blocked issues). If issue
056: * has no dependency result returns null.
057: *
058: * @author lgrischancew@init-ka.de
059: * @author <a href="mailto:lipp@danet.de"></a>
060: * @created on 22.03.2004
061: * @version $Revision: 1.2 $
062: */
063: public class GetDependencyCopiedFrom implements ToolAgent,
064: ResultProvider, Serializable {
065:
066: private static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory
067: .getLog(GetDependencyCopiedFrom.class);
068:
069: private String serverUrl = "http://localhost:12345";
070:
071: /** The result container. */
072: private ThreadLocal result = new ThreadLocal();
073:
074: /**
075: * Set the server URL. Defaults to
076: * <code>http://localhost:12345</code>.
077: *
078: * @param serverUrl the server URL
079: */
080: public void setServerUrl(String serverUrl) {
081: this .serverUrl = serverUrl;
082: }
083:
084: public void invoke(Activity activity, FormalParameter[] formPars,
085: Map map) throws CannotExecuteException, RemoteException {
086:
087: try {
088: String issueId = (String) map.get(formPars[0].id());
089: String dependTypeName = (String) map.get(formPars[1].id());
090: String resId = null;
091: for (int i = 0; i < formPars.length; i++) {
092: if (formPars[i].mode() != FormalParameter.Mode.IN) {
093: resId = formPars[i].id();
094: continue;
095: }
096: }
097:
098: ProcessData data = new DefaultProcessData();
099: Vector w = (Vector) (XmlRpcCall.rpc(serverUrl,
100: "scm.getDependencyCopiedFrom", new Object[] {
101: issueId, dependTypeName }));
102: if (w.size() > 0) {
103: for (int i = 0; i < w.size(); i++) {
104: data.put(resId, w.elementAt(i));
105: }
106: } else {
107: data.put(resId, null);
108: }
109: result.set(data);
110: } finally {
111: if (logger.isDebugEnabled()) {
112: logger.debug("Finished invocation of "
113: + activity.uniqueKey());
114: }
115: }
116: }
117:
118: /**
119: * Return the result evaluated during {@link ToolAgent#invoke
120: * <code>invoke</code>}. The method will only be called once after
121: * each invoke, i.e. the attribute holding the result be be
122: * cleared in this method.
123: *
124: * @return the result data or <code>null</code> if the invocation
125: * does not return any data.
126: */
127: public Object result() {
128: Map res = (Map) result.get();
129: result.set(null);
130: return res;
131: }
132:
133: public void terminate(Activity activity)
134: throws ApplicationNotStoppedException {
135: throw new ApplicationNotStoppedException(
136: "Terminate not implemented");
137: }
138: }
|