01: /*
02: * Bossa Workflow System
03: *
04: * $Id: ResourceHandlerTransaction.java,v 1.3 2003/12/01 20:10:08 gdvieira Exp $
05: *
06: * Copyright (C) 2003 OpenBR Sistemas S/C Ltda.
07: *
08: * This file is part of Bossa.
09: *
10: * Bossa is free software; you can redistribute it and/or modify it
11: * under the terms of version 2 of the GNU General Public License as
12: * published by the Free Software Foundation.
13: *
14: * This program is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: * General Public License for more details.
18: *
19: * You should have received a copy of the GNU General Public
20: * License along with this program; if not, write to the
21: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22: * Boston, MA 02111-1307, USA.
23: */
24:
25: package com.bigbross.bossa.resource;
26:
27: /**
28: * This class implements a generic operation of the <code>Resource</code>
29: * class. It will locate two resources wherever they may be in the system.
30: * <p>
31: *
32: * @author <a href="http://www.bigbross.com">BigBross Team</a>
33: */
34: abstract class ResourceHandlerTransaction extends ResourceTransaction {
35:
36: private String hostRegistryId;
37: private String hostId;
38: private String resourceRegistryId;
39: private String resourceId;
40:
41: /**
42: * Creates a new resource operation. <p>
43: *
44: * @param host the resource that will perform the operation.
45: * @param resource the resource that will be manipulated.
46: */
47: ResourceHandlerTransaction(Resource host, Resource resource) {
48: this .hostRegistryId = host.getResourceRegistry().getGlobalId();
49: this .hostId = host.getId();
50: this .resourceRegistryId = resource.getResourceRegistry()
51: .getGlobalId();
52: this .resourceId = resource.getId();
53: }
54:
55: /**
56: * @see ResourceTransaction#execute(ResourceManager)
57: */
58: protected Object execute(ResourceManager resourceManager) {
59: ResourceRegistry hostRegistry = resourceManager
60: .getRegistry(hostRegistryId);
61: Resource host = hostRegistry.getResource(hostId);
62: ResourceRegistry resourceRegistry = resourceManager
63: .getRegistry(resourceRegistryId);
64: Resource resource = resourceRegistry.getResource(resourceId);
65: return execute(host, resource);
66: }
67:
68: /**
69: * Executes a transaction using the two provided resources. <p>
70: *
71: * @param host the resource that will perform the operation.
72: * @param resource the resource that will be manipulated.
73: * @return the value returned by the transaction.
74: */
75: protected abstract Object execute(Resource host, Resource resource);
76: }
|