001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 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: * $Id: DefaultResource.java,v 1.5 2007/03/27 21:59:43 mlipp Exp $
021: *
022: * $Log: DefaultResource.java,v $
023: * Revision 1.5 2007/03/27 21:59:43 mlipp
024: * Fixed lots of checkstyle warnings.
025: *
026: * Revision 1.4 2007/02/27 14:34:08 drmlipp
027: * Some refactoring to reduce cyclic dependencies.
028: *
029: * Revision 1.3 2006/10/15 19:29:51 mlipp
030: * Merged changes from 1.4.x up to 1.4ea3pre1.
031: *
032: * Revision 1.2.2.1 2006/10/14 21:34:06 mlipp
033: * Simplified resource assignment service implementation.
034: *
035: * Revision 1.2 2006/10/03 17:04:02 mlipp
036: * Fixed visibility.
037: *
038: * Revision 1.1 2006/10/02 20:53:56 mlipp
039: * New resource base classes.
040: *
041: * Revision 1.2 2006/09/29 12:32:12 drmlipp
042: * Consistently using WfMOpen as projct name now.
043: *
044: * Revision 1.1.1.2 2004/08/18 15:17:38 drmlipp
045: * Update to 1.2
046: *
047: * Revision 1.11 2002/12/19 21:37:42 lipp
048: * Reorganized interfaces.
049: *
050: * Revision 1.10 2002/11/26 11:23:29 lipp
051: * Modified RemoteException comment.
052: *
053: * Revision 1.9 2002/04/03 12:53:05 lipp
054: * JavaDoc fixes.
055: *
056: * Revision 1.8 2002/01/15 13:42:21 lipp
057: * Added resourceByKey to ResourceAssignmentService and some missing
058: * NoSuchResourceExceptions in various methods.
059: *
060: * Revision 1.7 2001/12/20 22:27:34 lipp
061: * WfResource release semantics fixed.
062: *
063: * Revision 1.6 2001/12/19 09:05:15 lipp
064: * Made it serializable.
065: *
066: * Revision 1.5 2001/12/17 12:14:04 lipp
067: * Adapted to configurable ResourceManagement/AssignmentServices.
068: *
069: * Revision 1.4 2001/12/16 21:48:57 lipp
070: * addAssignment implemented.
071: *
072: * Revision 1.3 2001/12/11 12:55:36 robert
073: * fixed parameter error
074: *
075: * Revision 1.2 2001/12/11 12:47:37 lipp
076: * JavaDoc fixes.
077: *
078: * Revision 1.1 2001/12/09 14:03:08 lipp
079: * Improved design of workflow/resource management interface.
080: *
081: */
082: package de.danet.an.workflow.spis.rms;
083:
084: import java.io.Serializable;
085:
086: import java.util.Collection;
087:
088: import java.rmi.RemoteException;
089:
090: import de.danet.an.workflow.omgcore.InvalidResourceException;
091: import de.danet.an.workflow.omgcore.NotAssignedException;
092: import de.danet.an.workflow.omgcore.WfAssignment;
093: import de.danet.an.workflow.omgcore.WfResource;
094:
095: import de.danet.an.workflow.api.Activity;
096: import de.danet.an.workflow.api.NoSuchResourceException;
097:
098: import de.danet.an.workflow.spis.ras.ResourceAssignmentService;
099:
100: /**
101: * This class provides a default implementation of the {@link
102: * de.danet.an.workflow.omgcore.WfResource <code>WfResource</code>}'s methods
103: * {@link de.danet.an.workflow.omgcore.WfResource#workItems
104: * <code>workItems</code>},
105: * {@link de.danet.an.workflow.omgcore.WfResource#isMemberOfWorkItems
106: * <code>isMemberOfWorkItems</code>} and
107: * {@link de.danet.an.workflow.omgcore.WfResource#release <code>release</code>}.
108: * The implementation is based on the methods of a
109: * {@link ResourceAssignmentContext <code>ResourceAssignmentContext</code>}
110: * passed to the constructor.
111: */
112: public class DefaultResource implements WfResource, Serializable {
113:
114: /**
115: * The resource service factory used.
116: */
117: private ResourceAssignmentContext callbackHandler = null;
118:
119: private String resourceKey = null;
120:
121: private String resourceName = null;
122:
123: /**
124: * The constructor. It ensures that a valid factory exists.
125: *
126: * @param assignSvc
127: * the callback handler
128: * @param key
129: * the resource's key
130: * @param name
131: * the resource's name
132: */
133: public DefaultResource(ResourceAssignmentContext cbh, String key,
134: String name) {
135: callbackHandler = cbh;
136: resourceKey = key;
137: resourceName = name;
138: }
139:
140: /**
141: * Retrieve the key of a resource.
142: *
143: * @return key of resource
144: * @throws RemoteException
145: * problems accessing resource
146: */
147: public String resourceKey() throws RemoteException {
148: return resourceKey;
149: }
150:
151: /**
152: * Retrieve the name of a resource.
153: *
154: * @return name of resource
155: * @throws RemoteException
156: * problems accessing resource
157: */
158: public String resourceName() throws RemoteException {
159: return resourceName;
160: }
161:
162: /**
163: * This method returns the {@link WfAssignment <code>WfAssignments</code>}s
164: * associated with a resource.
165: *
166: * @return the associated {@link WfAssignment <code>WfAssignments</code>}s.
167: * @throws RemoteException
168: * if a system-level error occurs.
169: * @throws IllegalStateException
170: * if the resource has become invalid. This is actually a
171: * remapping of the <code>NoSuchResourceException</code>
172: * thrown by {@link ResourceAssignmentService#workItems
173: * <code>ResourceAssignmentService.workItems()</code>}. It
174: * must be remapped because this method's signature is specified
175: * by
176: * {@link WfResource#workItems <code>WfResource.workItems()</code>}.
177: */
178: public Collection workItems() throws RemoteException,
179: IllegalStateException {
180: try {
181: return callbackHandler.workItems(this );
182: } catch (NoSuchResourceException e) {
183: throw new IllegalStateException(e.getMessage());
184: }
185: }
186:
187: /**
188: * Checks if a given {@link WfAssignment <code>WfAssignment</code>} is
189: * associated with this resource.
190: *
191: * @param assignment
192: * the assignment in question.
193: * @return <code>true</code> if the association exists.
194: * @throws RemoteException
195: * if a system-level error occurs. This is actually a remapping
196: * of the <code>NoSuchResourceException</code> thrown by
197: * {@link ResourceAssignmentService#isMemberOfWorkItems
198: * <code>ResourceAssignmentService.isMemberOfWorkItems(...)</code>}.
199: * It must be remapped because this method's signature is
200: * specified by {@link WfResource#isMemberOfWorkItems
201: * <code>WfResource.isMemberOfWorkItems(...)</code>}.
202: * @throws IllegalStateException
203: * if the resource has become invalid.
204: */
205: public boolean isMemberOfWorkItems(WfAssignment assignment)
206: throws RemoteException, IllegalStateException {
207: try {
208: return callbackHandler
209: .isMemberOfWorkItems(this , assignment);
210: } catch (NoSuchResourceException e) {
211: throw new IllegalStateException(e.getMessage());
212: }
213: }
214:
215: /**
216: * Signals to the resource that it is no longer needed for a specific
217: * assignment. The default implementation calls
218: * <code>removeAssignment</code> on the activity.
219: *
220: * @param fromAssignment
221: * the specific assignment.
222: * @param releaseInfo
223: * specifies additional information on the reason for realizing
224: * the resource as input.
225: * @throws NotAssignedException
226: * if the resource is not associated with the given assignment.
227: * @throws RemoteException
228: * if a system-level error occurs.
229: */
230: public void release(WfAssignment fromAssignment, String releaseInfo)
231: throws RemoteException, NotAssignedException {
232: try {
233: ((Activity) fromAssignment.activity())
234: .removeAssignment(fromAssignment.assignee());
235: } catch (InvalidResourceException e) {
236: throw (NotAssignedException) (new NotAssignedException())
237: .initCause(e);
238: }
239: }
240:
241: /*
242: * (non-Javadoc)
243: *
244: * @see java.lang.Object#hashCode()
245: */
246: public int hashCode() {
247: final int PRIME = 31;
248: int result = 1;
249: result = PRIME * result
250: + ((resourceKey == null) ? 0 : resourceKey.hashCode());
251: return result;
252: }
253:
254: /*
255: * (non-Javadoc)
256: *
257: * @see java.lang.Object#equals(java.lang.Object)
258: */
259: public boolean equals(Object obj) {
260: if (this == obj) {
261: return true;
262: }
263: if (obj == null) {
264: return false;
265: }
266: if (getClass() != obj.getClass()) {
267: return false;
268: }
269: final DefaultResource other = (DefaultResource) obj;
270: if (resourceKey == null) {
271: if (other.resourceKey != null) {
272: return false;
273: }
274: } else if (!resourceKey.equals(other.resourceKey)) {
275: return false;
276: }
277: return true;
278: }
279:
280: }
|