KickJava   Java API By Example, From Geeks To Geeks.

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


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.ContainerListenerSimple;
30
31 /**
32  * Transaction implementation for the
33  * ::plugins::deployment::ContainerListener interface.
34  *
35  * @author <a HREF="mailto:Romain.Rouvoy@lifl.fr">Romain Rouvoy</a>
36  *
37  * @version 0.3
38  */

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

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

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

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

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

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

148   public void
149   on_create (org.omg.Components.CCMHome ref)
150   {
151     delegate_.on_create (ref);
152     ContainerResource 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
// Methods for the ::plugins::deployment::ContainerListener interface.
163
//
164
// ==================================================================
165
//
166
// IDL:omg.org/plugins/deployment/ContainerListener/get_sub_listener:1.0
167
//
168
/**
169    * Provide the equivalent CCMHome listener for the current listener
170    *
171    * @return the equivalent CCMHome listener
172    */

173   public org.objectweb.openccm.Deployment.listener.CCMHomeListener
174   get_sub_listener()
175   {
176     return new CCMHomeListenerTransaction();
177   }
178 }
179
180
181
Popular Tags