View Javadoc

1   /**
2    *
3    *  Licensed to the Apache Software Foundation (ASF) under one or more
4    *  contributor license agreements.  See the NOTICE file distributed with
5    *  this work for additional information regarding copyright ownership.
6    *  The ASF licenses this file to You under the Apache License, Version 2.0
7    *  (the "License"); you may not use this file except in compliance with
8    *  the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  package org.apache.geronimo.connector.deployment.jsr88;
19  
20  import javax.enterprise.deploy.model.DDBean;
21  import org.apache.geronimo.deployment.plugin.XmlBeanSupport;
22  import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType;
23  import org.apache.xmlbeans.SchemaTypeLoader;
24  
25  /**
26   * Represents connectiondefinition-instance/connectionmanager in the Geronimo
27   * Connector deployment plan.
28   *
29   * @version $Rev: 470597 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $
30   */
31  public class ConnectionManager extends XmlBeanSupport {
32      private DDBean outboundRA;
33      private SinglePool singlePool;
34      private PartitionedPool partitionedPool;
35  
36      public ConnectionManager() {
37          super(null);
38      }
39  
40      public ConnectionManager(DDBean outboundRA, GerConnectionmanagerType manager) {
41          super(null);
42          configure(outboundRA, manager);
43      }
44  
45      void configure(DDBean outboundRA, GerConnectionmanagerType manager) {
46          this.outboundRA = outboundRA;
47          setXmlObject(manager);
48          if(!manager.isSetNoTransaction() && !manager.isSetLocalTransaction() &&
49                  !manager.isSetXaTransaction()) {
50              String[] test = outboundRA.getText("transaction-support");
51              if(test.length > 0) {
52                  String tx = test[0];
53                  if(tx.equalsIgnoreCase("NoTransaction")) {
54                      manager.addNewNoTransaction();
55                  } else if(tx.equalsIgnoreCase("LocalTransaction")) {
56                      manager.addNewLocalTransaction();
57                  } else if(tx.equalsIgnoreCase("XATransaction")) {
58                      manager.addNewXaTransaction();
59                      manager.getXaTransaction().addNewTransactionCaching();
60                  }
61              }
62          }
63          if(manager.isSetSinglePool()) {
64              singlePool = new SinglePool(manager.getSinglePool());
65          } else if(manager.isSetPartitionedPool()) {
66              partitionedPool = new PartitionedPool(manager.getPartitionedPool());
67          } else if(!manager.isSetNoPool()) {
68              singlePool = new SinglePool(manager.addNewSinglePool());
69          }
70      }
71  
72      protected GerConnectionmanagerType getManager() {
73          return (GerConnectionmanagerType) getXmlObject();
74      }
75  
76      // ----------------------- JavaBean Properties for connection-manager ----------------------
77  
78      public boolean isContainerManagedSecurity() {
79          return getManager().isSetContainerManagedSecurity();
80      }
81  
82      public void setContainerManagedSecurity(boolean set) {
83          if(set) {
84              if(!isContainerManagedSecurity()) {
85                  getManager().addNewContainerManagedSecurity();
86                  pcs.firePropertyChange("containerManagedSecurity", !set, set);
87              }
88          } else {
89              if(isContainerManagedSecurity()) {
90                  getManager().unsetContainerManagedSecurity();
91                  pcs.firePropertyChange("containerManagedSecurity", !set, set);
92              }
93          }
94      }
95  
96      public boolean isTransactionNone() {
97          return getManager().isSetNoTransaction();
98      }
99  
100     public void setTransactionNone(boolean set) {
101         if(set) {
102             if(!isTransactionNone()) {
103                 getManager().addNewNoTransaction();
104                 pcs.firePropertyChange("transactionNone", !set, set);
105             }
106             if(isTransactionLocal()) setTransactionLocal(false);
107             if(isTransactionXA()) setTransactionXA(false);
108             if(isTransactionLog()) setTransactionLog(false);
109         } else {
110             if(isTransactionNone()) {
111                 getManager().unsetNoTransaction();
112                 pcs.firePropertyChange("transactionNone", !set, set);
113             }
114         }
115     }
116 
117     public boolean isTransactionLocal() {
118         return getManager().isSetLocalTransaction();
119     }
120 
121     public void setTransactionLocal(boolean set) {
122         if(set) {
123             if(!isTransactionLocal()) {
124                 getManager().addNewLocalTransaction();
125                 pcs.firePropertyChange("transactionLocal", !set, set);
126             }
127             if(isTransactionNone()) setTransactionNone(false);
128             if(isTransactionXA()) setTransactionXA(false);
129             if(isTransactionLog()) setTransactionLog(false);
130         } else {
131             if(isTransactionLocal()) {
132                 getManager().unsetLocalTransaction();
133                 pcs.firePropertyChange("transactionLocal", !set, set);
134             }
135         }
136     }
137 
138     public boolean isTransactionLog() {
139         return getManager().isSetTransactionLog();
140     }
141 
142     public void setTransactionLog(boolean set) {
143         if(set) {
144             if(!isTransactionLog()) {
145                 getManager().addNewTransactionLog();
146                 pcs.firePropertyChange("transactionLog", !set, set);
147             }
148             if(isTransactionNone()) setTransactionNone(false);
149             if(isTransactionXA()) setTransactionXA(false);
150             if(isTransactionLocal()) setTransactionLocal(false);
151         } else {
152             if(isTransactionLog()) {
153                 getManager().unsetTransactionLog();
154                 pcs.firePropertyChange("transactionLog", !set, set);
155             }
156         }
157     }
158 
159     public boolean isTransactionXA() {
160         return getManager().isSetXaTransaction();
161     }
162 
163     public void setTransactionXA(boolean set) {
164         if(set) {
165             if(!isTransactionXA()) {
166                 getManager().addNewXaTransaction();
167                 pcs.firePropertyChange("transactionXA", !set, set);
168             }
169             if(isTransactionNone()) setTransactionNone(false);
170             if(isTransactionLog()) setTransactionLog(false);
171             if(isTransactionLocal()) setTransactionLocal(false);
172         } else {
173             if(isTransactionXA()) {
174                 boolean oldTX = isTransactionXACachingTransaction();
175                 boolean oldThread = isTransactionXACachingThread();
176                 getManager().unsetXaTransaction();
177                 pcs.firePropertyChange("transactionXA", !set, set);
178                 if(oldTX) {
179                     pcs.firePropertyChange("transactionXACachingTransaction", true, false);
180                 }
181                 if(oldThread) {
182                     pcs.firePropertyChange("transactionXACachingThread", true, false);
183                 }
184             }
185         }
186     }
187 
188     public boolean isTransactionXACachingTransaction() {
189         return isTransactionXA() && getManager().getXaTransaction().isSetTransactionCaching();
190     }
191 
192     public void setTransactionXACachingTransaction(boolean set) {
193         if(set) {
194             setTransactionXA(true);
195             if(!getManager().getXaTransaction().isSetTransactionCaching()) {
196                 getManager().getXaTransaction().addNewTransactionCaching();
197                 pcs.firePropertyChange("transactionXACachingTransaction", !set, set);
198             }
199         } else {
200             if(isTransactionXA() && getManager().getXaTransaction().isSetTransactionCaching()) {
201                 getManager().getXaTransaction().unsetTransactionCaching();
202                 pcs.firePropertyChange("transactionXACachingTransaction", !set, set);
203             }
204         }
205     }
206 
207     public boolean isTransactionXACachingThread() {
208         return isTransactionXA() && getManager().getXaTransaction().isSetThreadCaching();
209     }
210 
211     public void setTransactionXACachingThread(boolean set) {
212         if(set) {
213             setTransactionXA(true);
214             if(!getManager().getXaTransaction().isSetThreadCaching()) {
215                 getManager().getXaTransaction().addNewThreadCaching();
216                 pcs.firePropertyChange("transactionXACachingThread", !set, set);
217             }
218         } else {
219             if(isTransactionXA() && getManager().getXaTransaction().isSetThreadCaching()) {
220                 getManager().getXaTransaction().unsetThreadCaching();
221                 pcs.firePropertyChange("transactionXACachingThread", !set, set);
222             }
223         }
224     }
225 
226     public boolean isPoolNone() {
227         return getManager().isSetNoPool();
228     }
229 
230     public void setPoolNone(boolean set) {
231         if(set) {
232             if(!getManager().isSetNoPool()) {
233                 getManager().addNewNoPool();
234                 pcs.firePropertyChange("poolNone", !set, set);
235             }
236             if(getPoolSingle() != null) setPoolSingle(null);
237             if(getPoolPartitioned() != null) setPoolPartitioned(null);
238         } else {
239             if(getManager().isSetNoPool()) {
240                 getManager().unsetNoPool();
241                 pcs.firePropertyChange("poolNone", !set, set);
242             }
243             if(getPoolSingle() == null && getPoolPartitioned() == null) {
244                 setPoolSingle(new SinglePool());
245             }
246         }
247     }
248 
249     public SinglePool getPoolSingle() {
250         return singlePool;
251     }
252 
253     public void setPoolSingle(SinglePool pool) {
254         SinglePool old = getPoolSingle();
255         if(pool != null) {
256             singlePool = pool;
257             if(!getManager().isSetSinglePool()) {
258                 getManager().addNewSinglePool();
259             }
260             singlePool.configure(getManager().getSinglePool());
261             pcs.firePropertyChange("poolSingle", old, pool);
262             if(isPoolNone()) setPoolNone(false);
263             if(getPoolPartitioned() != null) setPoolPartitioned(null);
264         } else {
265             if(getManager().isSetSinglePool()) {
266                 getManager().unsetSinglePool();
267                 pcs.firePropertyChange("poolSingle", old, pool);
268             }
269         }
270     }
271 
272     public PartitionedPool getPoolPartitioned() {
273         return partitionedPool;
274     }
275 
276     public void setPoolPartitioned(PartitionedPool pool) {
277         PartitionedPool old = getPoolPartitioned();
278         if(pool != null) {
279             partitionedPool = pool;
280             if(!getManager().isSetPartitionedPool()) {
281                 getManager().addNewPartitionedPool();
282             }
283             partitionedPool.configure(getManager().getPartitionedPool());
284             pcs.firePropertyChange("poolPartitioned", old, pool);
285             if(isPoolNone()) setPoolNone(false);
286             if(getPoolSingle() != null) setPoolSingle(null);
287         } else {
288             if(getManager().isSetPartitionedPool()) {
289                 getManager().unsetPartitionedPool();
290                 pcs.firePropertyChange("poolPartitioned", old, pool);
291             }
292         }
293     }
294 
295     // ----------------------- End of JavaBean Properties ----------------------
296 
297     protected SchemaTypeLoader getSchemaTypeLoader() {
298         return Connector15DCBRoot.SCHEMA_TYPE_LOADER;
299     }
300 }