KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > plugins > transaction > deployment > CCMHomeListenerTransaction


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Romain Rouvoy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.plugins.transaction.deployment;
28
29 import org.objectweb.openccm.Deployment.listener.simple.CCMHomeListenerSimple;
30
31
32 /**
33  * Transaction implementation for the
34  * ::Deployment::listener::CCMHomeListener interface.
35  *
36  * @author <a HREF="mailto:Romain.Rouvoy@lifl.fr">Romain Rouvoy</a>
37  *
38  * @version 0.3
39  */

40 public class CCMHomeListenerTransaction
41 extends CCMHomeListenerSimple
42 {
43   // ==================================================================
44
//
45
// Internal state.
46
//
47
// ==================================================================
48
/**
49    * List of resources non committed
50    */

51   protected org.objectweb.ccm.util.Vector resources_;
52   
53   // ==================================================================
54
//
55
// Constructor.
56
//
57
// ==================================================================
58
/**
59    * Constructor with parameter
60    *
61    * @param source the event source
62    */

63   public
64   CCMHomeListenerTransaction()
65   {
66     resources_ = new org.objectweb.ccm.util.Vector () ;
67   }
68   
69   // ==================================================================
70
//
71
// Internal methods.
72
//
73
// ==================================================================
74
/**
75    * Provide a new instance of the class
76    *
77    * @return new instance
78    */

79   protected org.objectweb.openccm.Deployment.listener.CCMHomeListener
80   _new()
81   {
82     return new CCMHomeListenerTransaction();
83   }
84   
85   /**
86    * Provide the reference of the resource corresponding to the current transaction
87    *
88    * @return the current resource
89    */

90   protected CCMHomeResource
91   get_resource()
92   {
93     try {
94       org.omg.CORBA.Object JavaDoc obj = org.objectweb.openccm.corba.TheORB.getORB()
95         .resolve_initial_references("TransactionCurrent");
96       org.omg.CosTransactions.Current current = org.omg.CosTransactions.CurrentHelper.narrow( obj );
97       org.omg.CosTransactions.Control control = current.get_control();
98       if (control == null) return null ;
99       org.omg.CosTransactions.Coordinator coordinator = control.get_coordinator();
100       CCMHomeResource resource = null;
101       
102       for ( int i=0 ; i<resources_.size() ; i++ ) {
103         resource = (CCMHomeResource) resources_.elementAt( i );
104         
105         if (coordinator.is_same_transaction(resource.coordinator()))
106           return resource;
107       }
108       return new CCMHomeResourceImpl(this,
109                                      source_,
110                                      coordinator,
111                                      TheTransactionManager.get_instance().getCurrent());
112     } catch ( Exception JavaDoc ex ) {
113       return null ;
114     }
115   }
116   
117   // ==================================================================
118
//
119
// Public methods.
120
//
121
// ==================================================================
122

123   public void
124   add_resource(CCMHomeResource resource)
125   {
126     resources_.addElement( resource );
127   }
128   
129   public void
130   remove_resource(CCMHomeResource resource)
131   {
132     resources_.removeElement( resource );
133   }
134   
135   // ==================================================================
136
//
137
// Methods for the ::Deployment::listener::CCMHomeEvents interface.
138
//
139
// ==================================================================
140
//
141
// IDL:omg.org/Deployment/listener/CCMHomeEvents/on_create:1.0
142
//
143
/**
144    * Event sent after the create function is called on CCMHome object
145    *
146    * @param ref the object created
147    */

148   public void
149   on_create (org.omg.Components.CCMObject ref)
150   {
151     delegate_.on_create (ref);
152     CCMHomeResource resource = get_resource();
153     if (resource == null)
154       super.on_create(ref);
155     else
156       resource.on_create(ref);
157   }
158 }
159
160
161
162
163
164
Popular Tags