001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.geronimo.connector.deployment.jsr88;
018    
019    import javax.enterprise.deploy.model.DDBean;
020    import org.apache.geronimo.deployment.plugin.XmlBeanSupport;
021    import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType;
022    import org.apache.xmlbeans.SchemaTypeLoader;
023    
024    /**
025     * Represents connectiondefinition-instance/connectionmanager in the Geronimo
026     * Connector deployment plan.
027     *
028     * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
029     */
030    public class ConnectionManager extends XmlBeanSupport {
031        private DDBean outboundRA;
032        private SinglePool singlePool;
033        private PartitionedPool partitionedPool;
034    
035        public ConnectionManager() {
036            super(null);
037        }
038    
039        public ConnectionManager(DDBean outboundRA, GerConnectionmanagerType manager) {
040            super(null);
041            configure(outboundRA, manager);
042        }
043    
044        void configure(DDBean outboundRA, GerConnectionmanagerType manager) {
045            this.outboundRA = outboundRA;
046            setXmlObject(manager);
047            if(!manager.isSetNoTransaction() && !manager.isSetLocalTransaction() &&
048                    !manager.isSetXaTransaction()) {
049                String[] test = outboundRA.getText("transaction-support");
050                if(test.length > 0) {
051                    String tx = test[0];
052                    if(tx.equalsIgnoreCase("NoTransaction")) {
053                        manager.addNewNoTransaction();
054                    } else if(tx.equalsIgnoreCase("LocalTransaction")) {
055                        manager.addNewLocalTransaction();
056                    } else if(tx.equalsIgnoreCase("XATransaction")) {
057                        manager.addNewXaTransaction();
058                        manager.getXaTransaction().addNewTransactionCaching();
059                    }
060                }
061            }
062            if(manager.isSetSinglePool()) {
063                singlePool = new SinglePool(manager.getSinglePool());
064            } else if(manager.isSetPartitionedPool()) {
065                partitionedPool = new PartitionedPool(manager.getPartitionedPool());
066            } else if(!manager.isSetNoPool()) {
067                singlePool = new SinglePool(manager.addNewSinglePool());
068            }
069        }
070    
071        protected GerConnectionmanagerType getManager() {
072            return (GerConnectionmanagerType) getXmlObject();
073        }
074    
075        // ----------------------- JavaBean Properties for connection-manager ----------------------
076    
077        public boolean isContainerManagedSecurity() {
078            return getManager().isSetContainerManagedSecurity();
079        }
080    
081        public void setContainerManagedSecurity(boolean set) {
082            if(set) {
083                if(!isContainerManagedSecurity()) {
084                    getManager().addNewContainerManagedSecurity();
085                    pcs.firePropertyChange("containerManagedSecurity", !set, set);
086                }
087            } else {
088                if(isContainerManagedSecurity()) {
089                    getManager().unsetContainerManagedSecurity();
090                    pcs.firePropertyChange("containerManagedSecurity", !set, set);
091                }
092            }
093        }
094    
095        public boolean isTransactionNone() {
096            return getManager().isSetNoTransaction();
097        }
098    
099        public void setTransactionNone(boolean set) {
100            if(set) {
101                if(!isTransactionNone()) {
102                    getManager().addNewNoTransaction();
103                    pcs.firePropertyChange("transactionNone", !set, set);
104                }
105                if(isTransactionLocal()) setTransactionLocal(false);
106                if(isTransactionXA()) setTransactionXA(false);
107                if(isTransactionLog()) setTransactionLog(false);
108            } else {
109                if(isTransactionNone()) {
110                    getManager().unsetNoTransaction();
111                    pcs.firePropertyChange("transactionNone", !set, set);
112                }
113            }
114        }
115    
116        public boolean isTransactionLocal() {
117            return getManager().isSetLocalTransaction();
118        }
119    
120        public void setTransactionLocal(boolean set) {
121            if(set) {
122                if(!isTransactionLocal()) {
123                    getManager().addNewLocalTransaction();
124                    pcs.firePropertyChange("transactionLocal", !set, set);
125                }
126                if(isTransactionNone()) setTransactionNone(false);
127                if(isTransactionXA()) setTransactionXA(false);
128                if(isTransactionLog()) setTransactionLog(false);
129            } else {
130                if(isTransactionLocal()) {
131                    getManager().unsetLocalTransaction();
132                    pcs.firePropertyChange("transactionLocal", !set, set);
133                }
134            }
135        }
136    
137        public boolean isTransactionLog() {
138            return getManager().isSetTransactionLog();
139        }
140    
141        public void setTransactionLog(boolean set) {
142            if(set) {
143                if(!isTransactionLog()) {
144                    getManager().addNewTransactionLog();
145                    pcs.firePropertyChange("transactionLog", !set, set);
146                }
147                if(isTransactionNone()) setTransactionNone(false);
148                if(isTransactionXA()) setTransactionXA(false);
149                if(isTransactionLocal()) setTransactionLocal(false);
150            } else {
151                if(isTransactionLog()) {
152                    getManager().unsetTransactionLog();
153                    pcs.firePropertyChange("transactionLog", !set, set);
154                }
155            }
156        }
157    
158        public boolean isTransactionXA() {
159            return getManager().isSetXaTransaction();
160        }
161    
162        public void setTransactionXA(boolean set) {
163            if(set) {
164                if(!isTransactionXA()) {
165                    getManager().addNewXaTransaction();
166                    pcs.firePropertyChange("transactionXA", !set, set);
167                }
168                if(isTransactionNone()) setTransactionNone(false);
169                if(isTransactionLog()) setTransactionLog(false);
170                if(isTransactionLocal()) setTransactionLocal(false);
171            } else {
172                if(isTransactionXA()) {
173                    boolean oldTX = isTransactionXACachingTransaction();
174                    boolean oldThread = isTransactionXACachingThread();
175                    getManager().unsetXaTransaction();
176                    pcs.firePropertyChange("transactionXA", !set, set);
177                    if(oldTX) {
178                        pcs.firePropertyChange("transactionXACachingTransaction", true, false);
179                    }
180                    if(oldThread) {
181                        pcs.firePropertyChange("transactionXACachingThread", true, false);
182                    }
183                }
184            }
185        }
186    
187        public boolean isTransactionXACachingTransaction() {
188            return isTransactionXA() && getManager().getXaTransaction().isSetTransactionCaching();
189        }
190    
191        public void setTransactionXACachingTransaction(boolean set) {
192            if(set) {
193                setTransactionXA(true);
194                if(!getManager().getXaTransaction().isSetTransactionCaching()) {
195                    getManager().getXaTransaction().addNewTransactionCaching();
196                    pcs.firePropertyChange("transactionXACachingTransaction", !set, set);
197                }
198            } else {
199                if(isTransactionXA() && getManager().getXaTransaction().isSetTransactionCaching()) {
200                    getManager().getXaTransaction().unsetTransactionCaching();
201                    pcs.firePropertyChange("transactionXACachingTransaction", !set, set);
202                }
203            }
204        }
205    
206        public boolean isTransactionXACachingThread() {
207            return isTransactionXA() && getManager().getXaTransaction().isSetThreadCaching();
208        }
209    
210        public void setTransactionXACachingThread(boolean set) {
211            if(set) {
212                setTransactionXA(true);
213                if(!getManager().getXaTransaction().isSetThreadCaching()) {
214                    getManager().getXaTransaction().addNewThreadCaching();
215                    pcs.firePropertyChange("transactionXACachingThread", !set, set);
216                }
217            } else {
218                if(isTransactionXA() && getManager().getXaTransaction().isSetThreadCaching()) {
219                    getManager().getXaTransaction().unsetThreadCaching();
220                    pcs.firePropertyChange("transactionXACachingThread", !set, set);
221                }
222            }
223        }
224    
225        public boolean isPoolNone() {
226            return getManager().isSetNoPool();
227        }
228    
229        public void setPoolNone(boolean set) {
230            if(set) {
231                if(!getManager().isSetNoPool()) {
232                    getManager().addNewNoPool();
233                    pcs.firePropertyChange("poolNone", !set, set);
234                }
235                if(getPoolSingle() != null) setPoolSingle(null);
236                if(getPoolPartitioned() != null) setPoolPartitioned(null);
237            } else {
238                if(getManager().isSetNoPool()) {
239                    getManager().unsetNoPool();
240                    pcs.firePropertyChange("poolNone", !set, set);
241                }
242                if(getPoolSingle() == null && getPoolPartitioned() == null) {
243                    setPoolSingle(new SinglePool());
244                }
245            }
246        }
247    
248        public SinglePool getPoolSingle() {
249            return singlePool;
250        }
251    
252        public void setPoolSingle(SinglePool pool) {
253            SinglePool old = getPoolSingle();
254            if(pool != null) {
255                singlePool = pool;
256                if(!getManager().isSetSinglePool()) {
257                    getManager().addNewSinglePool();
258                }
259                singlePool.configure(getManager().getSinglePool());
260                pcs.firePropertyChange("poolSingle", old, pool);
261                if(isPoolNone()) setPoolNone(false);
262                if(getPoolPartitioned() != null) setPoolPartitioned(null);
263            } else {
264                if(getManager().isSetSinglePool()) {
265                    getManager().unsetSinglePool();
266                    pcs.firePropertyChange("poolSingle", old, pool);
267                }
268            }
269        }
270    
271        public PartitionedPool getPoolPartitioned() {
272            return partitionedPool;
273        }
274    
275        public void setPoolPartitioned(PartitionedPool pool) {
276            PartitionedPool old = getPoolPartitioned();
277            if(pool != null) {
278                partitionedPool = pool;
279                if(!getManager().isSetPartitionedPool()) {
280                    getManager().addNewPartitionedPool();
281                }
282                partitionedPool.configure(getManager().getPartitionedPool());
283                pcs.firePropertyChange("poolPartitioned", old, pool);
284                if(isPoolNone()) setPoolNone(false);
285                if(getPoolSingle() != null) setPoolSingle(null);
286            } else {
287                if(getManager().isSetPartitionedPool()) {
288                    getManager().unsetPartitionedPool();
289                    pcs.firePropertyChange("poolPartitioned", old, pool);
290                }
291            }
292        }
293    
294        // ----------------------- End of JavaBean Properties ----------------------
295    
296        protected SchemaTypeLoader getSchemaTypeLoader() {
297            return Connector15DCBRoot.SCHEMA_TYPE_LOADER;
298        }
299    }