Source code: com/aendvari/tethys/tag/message/MessageBodyTag.java
1 /*
2 * MessageBodyTag.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.message;
11
12 import java.lang.reflect.Method;
13
14 import javax.servlet.jsp.*;
15 import javax.servlet.jsp.tagext.*;
16
17 import com.aendvari.common.model.*;
18
19 import com.aendvari.tethys.context.*;
20 import com.aendvari.tethys.context.message.*;
21
22 import com.aendvari.tethys.tag.*;
23
24
25 /**
26 * <p>A base class for all message tags requiring context.</p>
27 *
28 * @author Scott Milne
29 *
30 */
31
32 public abstract class MessageBodyTag extends com.aendvari.tethys.tag.context.ContextTag implements MessageAncestorTag
33 {
34 /* Variables. */
35
36
37 /** Contains the path of the context. */
38 protected String path;
39
40 /** The {@link Context} object for this tag. */
41 protected MessageContext messageContext;
42
43 /** The method to retrieve the context object from this tag. */
44 protected static Method messageContextMethod;
45
46
47 /* Constructors. */
48
49 public MessageBodyTag()
50 {
51 super();
52
53 // retrieve context method
54 if (messageContextMethod == null)
55 {
56 try
57 {
58 messageContextMethod = MessageAncestorTag.class.getMethod("getMessageContext", null);
59 }
60 catch (NoSuchMethodException exception)
61 {
62 // should not happen
63 }
64 }
65
66 path = null;
67 messageContext = null;
68 }
69
70 /* Attributes */
71
72
73 public String getPath() { return path;}
74 public void setPath(String path) { this.path = path; }
75
76 public MessageContext getMessageContext() { return messageContext; }
77
78 /**
79 * Release all allocated resources.
80 *
81 */
82
83 public void release()
84 {
85 super.release();
86
87 path = null;
88 messageContext = null;
89 }
90
91 /**
92 * Establishes the {@link Context} of this tag.
93 * The internal 'messageContext' is set to {@link Context} object associated with
94 * the <code>context</code> string.
95 *
96 * @exception JspTagException The context could not be established.
97 *
98 */
99
100 protected void establishMessageContext()
101 throws JspTagException
102 {
103 // get the context map
104 ContextMap contextMap = MessageTagData.getData(
105 pageContext, getDataScope()).getMessageContextMap();
106
107 // determine the context for this tag
108 messageContext = (MessageContext)determineContext(
109 contextMap, MessageAncestorTag.class, messageContextMethod);
110 }
111
112 /**
113 * Returns the parent {@link Context} for this tag.
114 *
115 * @return The {@link MessageContext} instance representing the parent context,
116 * null if none found.
117 *
118 * @exception JspTagException If the context cannot be determined.
119 *
120 */
121
122 public MessageContext getParentMessageContext()
123 throws JspTagException
124 {
125 // get the context map
126 ContextMap contextMap = MessageTagData.getData(
127 pageContext, getDataScope()).getMessageContextMap();
128
129 // determine parent context
130 Context context = getParentContext(
131 contextMap, this, MessageAncestorTag.class, messageContextMethod);
132
133 return (MessageContext)context;
134 }
135 }
136