1 package com.fc.taglibs.castor;
2
3 import java.io.*;
4 import java.util.ArrayList;
5 import java.util.Collection;
6 import java.util.Vector;
7 import javax.naming.*;
8 import javax.servlet.jsp.*;
9 import javax.servlet.jsp.tagext.*;
10
11
12
13
14 import javax.naming.InitialContext;
15 import org.exolab.castor.jdo.DataObjects;
16 import org.exolab.castor.jdo.Database;
17 import org.exolab.castor.jdo.PersistenceException;
18 import org.exolab.castor.jdo.TransactionNotInProgressException;
19 import org.exolab.castor.jdo.OQLQuery;
20
21
22 public class CastorOqlTag extends BodyTagSupport
23 {
24
25 /***
26 * The name of this tag
27 */
28 private static String _tagName = "CastorOqlTag";
29
30 /***
31 * The OQL string
32 */
33 private String query;
34
35
36 private Database db = null;
37 //private DataObjects jdo = null;
38 private OQLQuery oql = null;
39
40
41 /***
42 * Sets the Query
43 */
44 public void setQuery(String _query)
45 {
46 this.query = _query;
47 }
48
49 /***
50 * Return the Castor Database
51 */
52 public Database getDatabase()
53 {
54 return this.db;
55 }
56
57 /***
58 * Return the Castor OQL Query
59 */
60 public OQLQuery getOql()
61 {
62 return this.oql;
63 }
64
65 /***
66 * Do the start tag bit
67 */
68 public int doStartTag() throws JspException
69 {
70
71 try
72 {
73
74 /*
75 * Check to see if this tag is nested within a transactional tag
76 * Get the database. Exception if no Transaction parent tag found.
77 */
78 CastorTransactionInitiator t = (CastorTransactionInitiator)findAncestorWithClass(this, CastorTransactionInitiator.class);
79 if (t!=null)
80 {
81 db = t.getDatabase();
82 log ("Got transaction from parent tag", null);
83 }
84 else
85 {
86 //This code is for possible use of OQL tag standalone.
87 //jdo = (DataObjects)pageContext.getAttribute(this.name,PageContext.PAGE_SCOPE);
88 //this.db = jdo.getDatabase();
89 String msg = "Tag not nested within a CastorTransactionTag.";
90 log(msg,null);
91 throw new Exception(msg);
92 }
93 /*
94 * Create an OQL Query instance
95 */
96 log ("Getting OQLQuery from database", null);
97 oql = db.getOQLQuery(this.query);
98 }
99 catch(Exception e)
100 {
101 log(e.getMessage() , e);
102 throw new JspTagException(e.getMessage());
103 }
104
105 return EVAL_BODY_INCLUDE;
106 }
107
108
109 public int doEndTag() throws JspException
110 {
111 return EVAL_PAGE;
112 }
113
114
115 private void log(String msg,Exception e)
116 {
117 if (e!=null)
118 {
119 System.err.println(_tagName + ": " + msg);
120 e.printStackTrace();
121 }
122 else
123 {
124 System.out.println(_tagName + ": " + msg);
125 }
126 }
127
128 }
This page was automatically generated by Maven