KickJava   Java API By Example, From Geeks To Geeks.

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


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

40 public class ComponentServerListenerTransaction
41 extends ComponentServerListenerSimple
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   ComponentServerListenerTransaction()
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.ComponentServerListener
80   _new()
81   {
82     return new ComponentServerListenerTransaction();
83   }
84   
85   /**
86    * Provide the reference of the resource corresponding to the current transaction
87    *
88    * @return the current resource
89    */

90   protected ComponentServerResource
91   get_resource()
92   {
93     try {
94       org.omg.CORBA.Object JavaDoc obj = org.objectweb.openccm.corba.TheORB.getORB().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       ComponentServerResource resource = null;
100       
101       for ( int i=0; i<resources_.size(); i++ ) {
102         resource = ( ComponentServerResource ) resources_.elementAt( i );
103         
104         if ( coordinator.is_same_transaction(resource.coordinator()) )
105           return resource;
106       }
107       return new ComponentServerResourceImpl(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(ComponentServerResource resource)
124   {
125     resources_.addElement( resource );
126   }
127   
128   public void
129   remove_resource(ComponentServerResource resource)
130   {
131     resources_.removeElement( resource );
132   }
133   
134   // ==================================================================
135
//
136
// Methods for the ::plugins::deployment::ComponentServerListener interface.
137
//
138
// ==================================================================
139
//
140
// IDL:omg.org/plugins/deployment/ComponentServerListener/get_sub_listener:1.0
141
//
142
/**
143    * Provide the equivalent Container listener for the current listener
144    *
145    * @return the equivalent Container listener
146    */

147   public org.objectweb.openccm.Deployment.listener.ContainerListener
148   get_sub_listener()
149   {
150     return new ContainerListenerTransaction();
151   }
152   
153   // ==================================================================
154
//
155
// Methods for the ::plugins::deployment::ComponentServerEvents interface.
156
//
157
// ==================================================================
158
//
159
// IDL:omg.org/plugins/deployment/ComponentServerEvents/on_create:1.0
160
//
161
/**
162    * Event sent after the create function is called on ComponentServer object
163    *
164    * @param ref the object created
165    */

166   public void
167   on_create (org.omg.Components.Deployment.Container ref)
168   {
169     delegate_.on_create (ref);
170     ComponentServerResource resource = get_resource();
171     if (resource == null)
172       super.on_create(ref);
173     else
174       resource.on_create(ref);
175   }
176 }
177
178
179
180
181
182
183
Popular Tags