KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > ConnectorDescriptorInfo


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.connectors;
25
26 import com.sun.enterprise.deployment.EnvironmentProperty;
27 import java.io.Serializable JavaDoc;
28 import java.util.Set JavaDoc;
29 import java.util.Vector JavaDoc;
30 import java.util.HashSet JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.logging.Logger JavaDoc;
33 import com.sun.logging.LogDomains;
34 import com.sun.enterprise.connectors.util.ConnectionPoolReconfigHelper.ReconfigAction;
35
36 /**
37  * This class abstract the ra.xml values pertaining to the connection
38  * management. It contains various config properties of MCF, Resource adapter,
39  * Connection and also their respective classes and interfaces.
40  * @author Srikanth P
41  */

42
43 public class ConnectorDescriptorInfo implements Serializable JavaDoc {
44     
45     protected String JavaDoc rarName_;
46     protected String JavaDoc resourceAdapterClass_;
47     protected String JavaDoc connectionDefinitionName_;
48     protected String JavaDoc managedConnectionFactoryClass_;
49     protected String JavaDoc connectionFactoryClass_;
50     protected String JavaDoc connectionFactoryInterface_;
51     protected String JavaDoc connectionClass_;
52     protected String JavaDoc connectionInterface_;
53     protected Set JavaDoc mcfConfigProperties_;
54     protected Set JavaDoc resourceAdapterConfigProperties_;
55
56     private static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
57
58     /** Default constructor
59      *
60      */

61
62     public ConnectorDescriptorInfo() {
63
64         mcfConfigProperties_ = new HashSet JavaDoc();
65         resourceAdapterConfigProperties_ = new HashSet JavaDoc();
66     }
67
68     /**
69      * Clone method
70      * @return ConnectorDescriptorInfo instance
71      */

72
73     public ConnectorDescriptorInfo doClone() {
74
75         ConnectorDescriptorInfo cdi = new ConnectorDescriptorInfo();
76         cdi.setMCFConfigProperties(mcfConfigProperties_);
77         cdi.setResourceAdapterConfigProperties(
78                        resourceAdapterConfigProperties_);
79         cdi.setRarName(rarName_);
80         cdi.setResourceAdapterClassName(resourceAdapterClass_);
81         cdi.setConnectionDefinitionName(connectionDefinitionName_);
82         cdi.setManagedConnectionFactoryClass(managedConnectionFactoryClass_);
83         cdi.setConnectionFactoryClass(connectionFactoryClass_);
84         cdi.setConnectionFactoryInterface(connectionFactoryInterface_);
85         cdi.setConnectionClass(connectionClass_);
86         cdi.setConnectionInterface(connectionInterface_);
87         return cdi;
88     }
89     
90     /**
91      * Constructor
92      * @param mcfConfigProperties Array of MCF config properties
93      * @resourceAdapterConfigProperties Array of Resource adapter config props
94      */

95
96     public ConnectorDescriptorInfo(
97                         EnvironmentProperty[] mcfConfigProperties,
98                         EnvironmentProperty[] resourceAdapterConfigProperties)
99     {
100         mcfConfigProperties_ = new HashSet JavaDoc();
101         resourceAdapterConfigProperties_ = new HashSet JavaDoc();
102         if(mcfConfigProperties != null) {
103             for(int i=0; i<mcfConfigProperties.length; ++i) {
104                 mcfConfigProperties_.add(mcfConfigProperties[i]);
105             }
106         }
107         if(resourceAdapterConfigProperties != null) {
108             for(int i=0; i<mcfConfigProperties.length; ++i) {
109                 resourceAdapterConfigProperties_.add(mcfConfigProperties[i]);
110             }
111         }
112     }
113
114     /** Adds an MCF config property to the existing array/Set of MCF config
115      * properties.
116      * @configProperty Config property to be added.
117      */

118
119     public void addMCFConfigProperty(EnvironmentProperty configProperty) {
120         if(configProperty != null) {
121             mcfConfigProperties_.add(configProperty);
122         }
123     }
124
125     /** Removes an config property from the existing array/Set of MCF config
126      * properties
127      * @param configProperty Config property to be removed.
128      */

129
130     public void removeMCFConfigProperty(EnvironmentProperty configProperty) {
131         if(configProperty != null) {
132             mcfConfigProperties_.remove(configProperty);
133         }
134     }
135
136     /**
137      * Setter method for MCFConfigProperties property.
138      * @param configProperties Set MCF config properties
139      */

140
141     public void setMCFConfigProperties(Set JavaDoc configProperties) {
142         mcfConfigProperties_ = configProperties;
143     }
144
145     /**
146      * Setter method for MCFConfigProperties property.
147      * @param configProperties Array of MCF config properties
148      */

149
150     public void setMCFConfigProperties(EnvironmentProperty[] configProperties) {
151         if(configProperties != null) {
152             for(int i=0; i<configProperties.length; ++i) {
153                 mcfConfigProperties_.add(configProperties[i]);
154             }
155         }
156     }
157
158     /**
159      * Getter method for MCFConfigProperties property
160      * @return Set of managed connection factory config properties
161      */

162
163     public Set JavaDoc getMCFConfigProperties() {
164         return mcfConfigProperties_;
165     }
166
167     /** Adds a Resource Adapter config property to the existing array/Set
168      * of Resource Adapter config properties.
169      * @configProperty Config property to be added.
170      */

171
172     public void addResourceAdapterConfigProperty(
173                         EnvironmentProperty configProperty)
174     {
175         if(configProperty != null) {
176             resourceAdapterConfigProperties_.add(configProperty);
177         }
178     }
179
180     /** Removes a Resource Adapter config property to the existing array/Set
181      * of Resource Adapter config properties.
182      * @configProperty Config property to be removed.
183      */

184
185     public void removeResourceAdapterConfigProperty(
186                         EnvironmentProperty configProperty)
187     {
188         if(configProperty != null) {
189             resourceAdapterConfigProperties_.remove(configProperty);
190         }
191     }
192
193     /**
194      * Setter method for ResourceAdapterConfigProperties property.
195      * @param configProperties Set ResourceAdapter config properties
196      */

197
198     public void setResourceAdapterConfigProperties(Set JavaDoc configProperties) {
199         resourceAdapterConfigProperties_ = configProperties;
200     }
201
202     /**
203      * Setter method for ResourceAdapterConfigProperties property.
204      * @param configProperties Array ResourceAdapter config properties
205      */

206
207     public void setResourceAdapterConfigProperties(
208                          EnvironmentProperty[] configProperties)
209     {
210         if(configProperties != null) {
211             for(int i=0; i<configProperties.length; ++i) {
212                 resourceAdapterConfigProperties_.add(configProperties[i]);
213             }
214         }
215     }
216
217     /**
218      * Getter method for ResourceAdapterConfigProperties property
219      * @return Set of resource adapter config properties
220      */

221
222     public Set JavaDoc getResourceAdapterConfigProperties() {
223         return resourceAdapterConfigProperties_;
224     }
225
226     /**
227      * Getter method for RarName property
228      * @return rarName
229      */

230
231     public String JavaDoc getRarName() {
232         return rarName_;
233     }
234
235     /** Setter method for RarName property
236      * @param rarName rar name
237      */

238     
239     public void setRarName(String JavaDoc rarName) {
240         rarName_ = rarName;
241     }
242
243     /**
244      * Getter method for ResourceAdapterClassName property
245      * @return Resource adapter class name
246      */

247
248     public String JavaDoc getResourceAdapterClassName() {
249         return resourceAdapterClass_;
250     }
251
252     /** Setter method for ResourceAdapterClassName property
253      * @param resourceAdapterClass Resource adapter class name
254      */

255   
256     public void setResourceAdapterClassName(String JavaDoc resourceAdapterClass) {
257         resourceAdapterClass_ = resourceAdapterClass;
258     }
259
260     /**
261      * Getter method for ConnectionDefinitionName property
262      * @return connection definition name
263      */

264
265     public String JavaDoc getConnectionDefinitionName() {
266         return connectionDefinitionName_;
267     }
268
269     /** Setter method for ConnectionDefinitionName property
270      * @param connectionDefinitionName connection definition name
271      */

272     
273     public void setConnectionDefinitionName(String JavaDoc connectionDefinitionName) {
274         connectionDefinitionName_ = connectionDefinitionName;
275     }
276
277     /**
278      * Getter method for ManagedConnectionFactoryClass property
279      * @return managed connection factory class
280      */

281
282     public String JavaDoc getManagedConnectionFactoryClass() {
283         return managedConnectionFactoryClass_;
284     }
285
286     /** Setter method for ManagedConnectionFactoryClass property
287      * @param managedConnectionFactoryClass managed connection factory class
288      */

289     
290     public void setManagedConnectionFactoryClass(
291                       String JavaDoc managedConnectionFactoryClass)
292     {
293         managedConnectionFactoryClass_ = managedConnectionFactoryClass;
294     }
295
296     /**
297      * Getter method for ConnectionFactoryClass property
298      * @return connection factory class
299      */

300
301     public String JavaDoc getConnectionFactoryClass() {
302         return connectionFactoryClass_;
303     }
304
305     /** Setter method for ConnectionFactoryClass property
306      * @param connectionFactoryClass connection factory class
307      */

308
309     public void setConnectionFactoryClass(String JavaDoc connectionFactoryClass) {
310         connectionFactoryClass_ = connectionFactoryClass;
311     }
312
313     /**
314      * Getter method for ConnectionFactoryInterface property
315      * @return connection factory interface class
316      */

317
318     public String JavaDoc getConnectionFactoryInterface() {
319         return connectionFactoryInterface_;
320     }
321
322     /** Setter method for ConnectionFactoryInterface property
323      * @param connectionFactoryInterface connection factory interface class
324      */

325
326     public void setConnectionFactoryInterface(
327                        String JavaDoc connectionFactoryInterface)
328     {
329         connectionFactoryInterface_ = connectionFactoryInterface;
330     }
331
332     /**
333      * Getter method for ConnectionClass property
334      * @return connection class
335      */

336
337     public String JavaDoc getConnectionClass() {
338         return connectionClass_;
339     }
340
341     /** Setter method for ConnectionClass property
342      * @param connectionClass connection Class
343      */

344
345     public void setConnectionClass(String JavaDoc connectionClass) {
346         connectionClass_ = connectionClass;
347     }
348
349     /**
350      * Getter method for ConnectionInterface property
351      * @return connectionInterface class
352      */

353
354     public String JavaDoc getConnectionInterface() {
355         return connectionInterface_;
356     }
357
358     /** Setter method for ConnectionInterface property
359      * @param connectionInterface connection interface class
360      */

361
362     public void setConnectionInterface(String JavaDoc connectionInterface) {
363         connectionInterface_ = connectionInterface;
364     }
365         
366     /**
367      * Compare the MCF Config properties in this object with the
368      * passed ones
369      *
370      * @param cdi - The ConnDescInfo object whose MCF config props are to
371      * to be comapred against our props
372      * @return true - if the config properties are the same
373      * false otherwise
374      */

375
376     public ReconfigAction compareMCFConfigProperties( ConnectorDescriptorInfo cdi) {
377         return compareMCFConfigProperties( cdi, new HashSet JavaDoc() );
378     }
379
380     /**
381      * Compare the MCF Config properties in this object with the
382      * passed ones. The properties in the Set of excluded properties
383      * are not compared against
384      *
385      * @param cdi - The ConnDescInfo object whose MCF config props are to
386      * to be comapred against our props
387      * @return true - if the config properties are the same
388      * false otherwise
389      */

390
391     public ReconfigAction compareMCFConfigProperties(
392             ConnectorDescriptorInfo cdi, Set JavaDoc excluded )
393     {
394         Set JavaDoc mcfConfigProps = cdi.getMCFConfigProperties();
395
396         if (mcfConfigProps.size() != mcfConfigProperties_.size() ) {
397             //return false;
398
//Cannot determine anything due to size disparity - assume restart
399
return ReconfigAction.RECREATE_POOL;
400         }
401     
402         boolean same = false;
403         Iterator JavaDoc iter = mcfConfigProps.iterator();
404     
405         while( iter.hasNext() ) {
406             EnvironmentProperty prop = (EnvironmentProperty)iter.next();
407             //see if this property is in our list of excludes
408
if (excluded.contains( prop.getName()) ) {
409                 //_logger.finest("mcfProp ignored : " + prop.getName() );
410
continue;
411             }
412         
413             Iterator JavaDoc iter2 = mcfConfigProperties_.iterator();
414             while( iter2.hasNext() ) {
415                 if(isEnvPropEqual(prop,(EnvironmentProperty)iter2.next())){
416                     //we have a match
417
same = true;
418                     //_logger.finest("mcfprop matched : " + prop.getName());
419
break;
420                 }
421             }
422             if (! same ) {
423                 //_logger.finest("mcfprop not matched : " + prop.getName() );
424
//return false;
425
return ReconfigAction.RECREATE_POOL;
426             }
427             same = false;
428         }
429
430         return ReconfigAction.NO_OP;
431     }
432
433     /**
434     * The EnvironmentProperty::equals method only checks for name equality
435     * So we need to write a custom equals
436     */

437
438     private boolean isEnvPropEqual( EnvironmentProperty e1,
439             EnvironmentProperty e2 )
440     {
441         if (e1 != null && e2 != null &&
442         e1.getName() != null && e2.getName() != null &&
443         e1.getName().equals( e2.getName())) {
444             if (e1.getValue() != null && e2.getValue() != null &&
445                        e1.getValue().equals( e2.getValue() ) ) {
446                 return true;
447             }
448         }
449         /*
450         _logger.finest("isEnvPropEqual:: " + e1.getName()+"+"+e1.getValue()+
451         " -- "+e2.getName() + "+"+e2.getValue());
452     */

453              
454         return false;
455     }
456 }
457
Popular Tags