Source code: com/aendvari/tethys/tag/inset/InsetBaseTag.java
1 /*
2 * InsetBaseTag.java
3 *
4 * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5 *
6 * See the file LICENSE for terms of use.
7 *
8 */
9
10 package com.aendvari.tethys.tag.inset;
11
12 import java.lang.reflect.Method;
13
14 import java.io.IOException;
15
16 import javax.servlet.http.*;
17 import javax.servlet.jsp.*;
18 import javax.servlet.jsp.tagext.*;
19
20 import com.aendvari.common.model.*;
21
22 import com.aendvari.tethys.context.*;
23
24 import com.aendvari.tethys.tag.*;
25 import com.aendvari.tethys.tag.context.*;
26
27
28 /**
29 * <p>Base class for inset tags.</p>
30 *
31 * @author Scott Milne
32 *
33 */
34
35 public abstract class InsetBaseTag extends ContextTag implements InsetAncestorTag
36 {
37 /* Variables */
38
39 /** Contains the context for the inset tag. */
40 protected Context insetContext;
41
42 /** The method to retrieve the context object from this tag. */
43 protected static Method insetContextMethod;
44
45
46 /* Constructor */
47
48 public InsetBaseTag()
49 {
50 super();
51
52 // retrieve context method
53 if (insetContextMethod == null)
54 {
55 try
56 {
57 insetContextMethod = InsetAncestorTag.class.getMethod("getInsetContext", null);
58 }
59 catch (NoSuchMethodException exception)
60 {
61 // should not happen
62 }
63 }
64 }
65
66 public Context getInsetContext() { return insetContext; }
67
68 /**
69 * Establishes the {@link Context} of this tag.
70 * The internal 'responseContext' is set to {@link Context} object associated with
71 * the current <code>modelContext</code>.
72 *
73 * @exception JspTagException The context could not be established.
74 *
75 */
76
77 protected void establishInsetContext()
78 throws JspTagException
79 {
80 // get the inset map
81 ContextMap contextMap = InsetTagData.getData(
82 pageContext, getDataScope()).getInsetMap();
83
84 // get the context
85 insetContext = determineContext(
86 contextMap, InsetAncestorTag.class, insetContextMethod);
87 }
88
89 /**
90 * Returns the parent {@link Context} for this tag.
91 *
92 * @return A {@link Context} instance representing the parent context,
93 * null if none found.
94 *
95 * @exception JspTagException If the context cannot be determined.
96 *
97 */
98
99 public Context getParentInsetContext()
100 throws JspTagException
101 {
102 // get the inset map
103 ContextMap contextMap = InsetTagData.getData(
104 pageContext, getDataScope()).getInsetMap();
105
106 // determine parent context
107 Context context = getParentContext(
108 contextMap, this, InsetAncestorTag.class, insetContextMethod);
109
110 return context;
111 }
112
113 /**
114 * Release all allocated resources.
115 *
116 */
117
118 public void release()
119 {
120 super.release();
121
122 insetContext = null;
123 }
124 }
125