01: /*
02: * This file is part of the WfMOpen project.
03: * Copyright (C) 2001-2006 Danet GmbH (www.danet.de), BU BTS.
04: * All rights reserved.
05: *
06: * This program is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU General Public License as published by
08: * the Free Software Foundation; either version 2 of the License, or
09: * (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * $Id: DefaultUserResource.java,v 1.2 2006/10/15 19:29:51 mlipp Exp $
21: *
22: * $Log: DefaultUserResource.java,v $
23: * Revision 1.2 2006/10/15 19:29:51 mlipp
24: * Merged changes from 1.4.x up to 1.4ea3pre1.
25: *
26: * Revision 1.1.2.1 2006/10/14 21:34:05 mlipp
27: * Simplified resource assignment service implementation.
28: *
29: * Revision 1.1 2006/10/02 20:53:56 mlipp
30: * New resource base classes.
31: *
32: */
33: package de.danet.an.workflow.spis.rms;
34:
35: import java.io.Serializable;
36: import java.rmi.RemoteException;
37:
38: import de.danet.an.workflow.api.UserResource;
39: import de.danet.an.workflow.spis.ras.ResourceAssignmentService;
40:
41: /**
42: * This class provides a <code>UserResource</code> implementation based
43: * on the <code>BasicResource</code>. The class ensures that the resource
44: * key can be distinguished as a user resource's key.
45: *
46: * @author Michael Lipp
47: */
48: public class DefaultUserResource extends DefaultResource implements
49: UserResource, Serializable {
50:
51: /**
52: * Create a new instance with all attributes initialized
53: * to defaults or the given values.
54: *
55: * @param cbh
56: * @param id
57: * @param name
58: */
59: public DefaultUserResource(ResourceAssignmentContext cbh,
60: String id, String name) {
61: super (cbh, "U:" + id, name);
62: }
63:
64: /**
65: * Check if the given key is a user resource's key.
66: */
67: public static boolean isValidKey(String key) {
68: return key.startsWith("U:");
69: }
70:
71: /**
72: * Return the id part of a key.
73: */
74: public static String getId(String key) {
75: if (!isValidKey(key)) {
76: throw new IllegalArgumentException(key);
77: }
78: return key.substring(2);
79: }
80:
81: /**
82: * Return the id passed to the constructor.
83: */
84: public String getId() {
85: try {
86: return resourceKey().substring(2);
87: } catch (RemoteException e) {
88: // cannot really happen, considering the base class.
89: throw new IllegalStateException();
90: }
91: }
92: }
|