KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > resource > ResourceSpec


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 package com.sun.enterprise.resource;
24
25 import java.io.Serializable JavaDoc;
26 import com.sun.enterprise.connectors.PoolMetaData;
27 import com.sun.enterprise.connectors.ConnectorConstants;
28
29 /**
30  * ResourceSpec is used as a key to locate the correct resource pool
31  */

32
33 public class ResourceSpec implements Serializable JavaDoc {
34     private String JavaDoc resourceId;
35     private int resourceIdType;
36     private boolean pmResource;
37     private boolean nonTxResource;
38     private boolean lazyEnlistable_;
39     private boolean lazyAssociatable_;
40     private Object JavaDoc connectionToAssoc_;
41     private boolean isXA_;
42     
43     private String JavaDoc connectionPoolName;
44     
45     static public final int JDBC_URL = 0;
46     static public final int JNDI_NAME = 1;
47     static public final int JMS = 2;
48
49     public ResourceSpec(String JavaDoc resourceId,
50         int resourceIdType) {
51         if (resourceId == null) throw new NullPointerException JavaDoc();
52         this.resourceId = resourceId;
53         this.resourceIdType = resourceIdType;
54         if (resourceId.endsWith(ConnectorConstants.PM_JNDI_SUFFIX) ) {
55             pmResource = true;
56         }
57     if (resourceId.endsWith(ConnectorConstants.NON_TX_JNDI_SUFFIX) ) {
58         nonTxResource = true;
59     }
60     }
61
62     public ResourceSpec( String JavaDoc resourceId, int resourceIdType,
63         PoolMetaData pmd ) {
64         this( resourceId, resourceIdType );
65         
66         if (pmd != null ) {
67             if ( pmd.isPM() ) {
68                 pmResource = true;
69             }
70             if( pmd.isNonTx() ) {
71                 nonTxResource = true;
72             }
73
74             if( pmd.isLazyEnlistable() && !nonTxResource && !pmResource ) {
75                 lazyEnlistable_ = true;
76             }
77
78             if ( pmd.isLazyAssociatable() && !nonTxResource && !pmResource) {
79                 lazyAssociatable_ = true;
80                 //The rationale behind doing this is that in the PoolManagerImpl
81
//when we return from getResource called by associateConnections,
82
//enlistment should happen immediately since we are associating on
83
//first use anyway,
84
lazyEnlistable_ = false;
85             }
86         
87         }
88
89     }
90     
91     public String JavaDoc getConnectionPoolName() {
92         return connectionPoolName;
93     }
94     
95     
96     public void setConnectionPoolName(String JavaDoc name) {
97         connectionPoolName = name;
98     }
99     
100     
101     /* The logic is *
102      * If the connectionpool exist then equality check is against *
103      * connectionPoolName *
104      * *
105      * If connection is null then equality check is made against *
106      * resourceId and resourceType *
107      */

108
109     public boolean equals(Object JavaDoc other) {
110         if (other == null) return false;
111         if (other instanceof ResourceSpec) {
112             ResourceSpec obj = (ResourceSpec) other;
113             if(connectionPoolName == null) {
114                 return (resourceId.equals(obj.resourceId) &&
115                 resourceIdType == obj.resourceIdType);
116             } else {
117                 return (connectionPoolName.equals(obj.connectionPoolName));
118
119             }
120         } else {
121             return false;
122         }
123     }
124
125     /* If the connectionpool exist then hashcode of connectionPoolName *
126      * is returned. *
127      * *
128      * If connectionpool is null return the hashcode of *
129      * resourceId + resourceIdType *
130      */

131     
132     public int hashCode() {
133         if(connectionPoolName == null) {
134             return resourceId.hashCode() + resourceIdType;
135         } else {
136             return connectionPoolName.hashCode();
137         }
138     }
139     
140     public String JavaDoc getResourceId() {
141         return resourceId;
142     }
143     
144     public boolean isPM() {
145         return pmResource;
146     }
147
148     /**
149      * Returns the status of the noTxResource flag
150      *
151      * returns true if this resource is a noTx resource
152      */

153    
154     public boolean isNonTx() {
155         return nonTxResource;
156     }
157
158     public boolean isXA() {
159         return isXA_;
160     }
161
162     public void markAsXA() {
163         isXA_ = true;
164     }
165     
166     public boolean isLazyEnlistable() {
167         return lazyEnlistable_;
168     }
169
170
171     public void setLazyEnlistable( boolean lazyEnlist ) {
172         lazyEnlistable_ = lazyEnlist;
173     }
174
175     public boolean isLazyAssociatable() {
176         return lazyAssociatable_;
177     }
178
179
180     public void setLazyAssociatable( boolean lazyAssoc ) {
181         lazyAssociatable_ = lazyAssoc;
182     }
183     
184     public void setConnectionToAssociate( Object JavaDoc conn ) {
185         connectionToAssoc_ = conn;
186     }
187     
188     public Object JavaDoc getConnectionToAssociate() {
189         return connectionToAssoc_;
190     }
191     
192     public String JavaDoc toString() {
193         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("ResourceSpec :- ");
194         sb.append("\nconnectionPoolName : " + connectionPoolName );
195         sb.append("\nisXA_ : " + isXA_ );
196         sb.append("\nresoureId : " + resourceId );
197         sb.append("\nresoureIdType : " + resourceIdType );
198         sb.append("\npmResource : " + pmResource );
199         sb.append("\nnonTxResource : " + nonTxResource );
200         sb.append("\nlazyEnlistable : " + lazyEnlistable_ );
201         sb.append("\nlazyAssociatable : " + lazyAssociatable_ );
202
203         return sb.toString();
204     }
205
206 }
207
Popular Tags