%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.ojb.BrokerTag |
|
|
1 | /* |
|
2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
15 | */ |
|
16 | package org.apache.commons.jelly.tags.ojb; |
|
17 | ||
18 | import org.apache.commons.jelly.JellyTagException; |
|
19 | import org.apache.commons.jelly.TagSupport; |
|
20 | import org.apache.commons.jelly.XMLOutput; |
|
21 | import org.apache.ojb.broker.PersistenceBroker; |
|
22 | import org.apache.ojb.broker.PersistenceBrokerFactory; |
|
23 | ||
24 | /** |
|
25 | * <p>Tag handler for <Driver> in JSTL, used to create |
|
26 | * a simple DataSource for prototyping.</p> |
|
27 | * |
|
28 | * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> |
|
29 | * @version $Revision: 1.4 $ |
|
30 | */ |
|
31 | public class BrokerTag extends TagSupport { |
|
32 | ||
33 | /** The variable name to export. */ |
|
34 | private String var; |
|
35 | ||
36 | /** The persistence broker instance */ |
|
37 | private PersistenceBroker broker; |
|
38 | ||
39 | 0 | public BrokerTag() { |
40 | 0 | } |
41 | ||
42 | ||
43 | // Tag interface |
|
44 | //------------------------------------------------------------------------- |
|
45 | public void doTag(XMLOutput output) throws JellyTagException { |
|
46 | 0 | if ( var == null ) { |
47 | 0 | var = "org.apache.commons.jelly.ojb.Broker"; |
48 | } |
|
49 | 0 | if ( broker != null ) { |
50 | 0 | context.setVariable(var, broker); |
51 | 0 | invokeBody(output); |
52 | } |
|
53 | else { |
|
54 | 0 | broker = PersistenceBrokerFactory.defaultPersistenceBroker(); |
55 | 0 | context.setVariable(var, broker); |
56 | ||
57 | try { |
|
58 | 0 | invokeBody(output); |
59 | 0 | } |
60 | finally { |
|
61 | 0 | broker.close(); |
62 | 0 | broker = null; |
63 | 0 | context.removeVariable(var); |
64 | } |
|
65 | } |
|
66 | 0 | } |
67 | ||
68 | // Properties |
|
69 | //------------------------------------------------------------------------- |
|
70 | /** Sets the variable name to define for this expression |
|
71 | */ |
|
72 | public void setVar(String var) { |
|
73 | 0 | this.var = class="keyword">var; |
74 | 0 | } |
75 | ||
76 | /** @return the persistence broker instance */ |
|
77 | public PersistenceBroker getBroker() { |
|
78 | 0 | return broker; |
79 | } |
|
80 | ||
81 | /** Sets the persistence broker instance */ |
|
82 | public void setBroker(PersistenceBroker broker) { |
|
83 | 0 | this.broker = broker; |
84 | 0 | } |
85 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |