1:
31: package ;
32:
33: import ;
34:
35: import ;
36: import ;
37: import ;
38: import ;
39: import ;
40: import ;
41: import ;
42: import ;
43: import ;
44:
45:
50: public abstract class AbstractElementReadHandler
51: extends AbstractXmlReadHandler implements NodeReadHandler
52: {
53: private boolean virtual;
54: private boolean enabled;
55: private String style;
56: private ArrayList expressionHandlers;
57: private ArrayList styleExpressionHandlers;
58: private ArrayList attributeExpressionHandlers;
59: private ArrayList attributeHandlers;
60: private ArrayList stylePropertyHandlers;
61: private DisplayConditionReadHandler displayConditionReadHandler;
62:
63: protected AbstractElementReadHandler()
64: {
65: expressionHandlers = new ArrayList();
66: styleExpressionHandlers = new ArrayList();
67: attributeExpressionHandlers = new ArrayList();
68: stylePropertyHandlers = new ArrayList();
69: attributeHandlers = new ArrayList();
70: }
71:
72: public boolean isEnabled()
73: {
74: return enabled;
75: }
76:
77: public String getStyle()
78: {
79: return style;
80: }
81:
82:
88: public void init(final RootXmlReadHandler rootHandler,
89: final String uri,
90: final String tagName)
91: {
92: super.init(rootHandler, uri, tagName);
93:
94: final Element element = getElement();
95: element.setNamespace(uri);
96: element.setType(tagName);
97: }
98:
99:
105: protected void startParsing(final Attributes attrs) throws SAXException
106: {
107: super.startParsing(attrs);
108: style = attrs.getValue(FlowReportFactoryModule.NAMESPACE, "style");
109: final String enabledValue = attrs.getValue(FlowReportFactoryModule.NAMESPACE, "enabled");
110: if (enabledValue != null)
111: {
112: enabled = "true".equals(enabledValue);
113: }
114: else
115: {
116: enabled = true;
117: }
118:
119: final String virtualValue = attrs.getValue(FlowReportFactoryModule.NAMESPACE, "virtual");
120: if (virtualValue != null)
121: {
122: virtual = "true".equals(virtualValue);
123: }
124: else
125: {
126: virtual = false;
127: }
128: }
129:
130:
139: protected XmlReadHandler getHandlerForChild(final String uri,
140: final String tagName,
141: final Attributes atts)
142: throws SAXException
143: {
144: if (FlowReportFactoryModule.NAMESPACE.equals(uri))
145: {
146: if ("expression".equals(tagName))
147: {
148: final ExpressionReadHandler erh = new ExpressionReadHandler();
149: expressionHandlers.add(erh);
150: return erh;
151: }
152: if ("style-expression".equals(tagName))
153: {
154: final StyleExpressionReadHandler erh = new StyleExpressionReadHandler();
155: styleExpressionHandlers.add(erh);
156: return erh;
157: }
158: if ("style-property".equals(tagName))
159: {
160: final PropertyReadHandler erh = new PropertyReadHandler();
161: stylePropertyHandlers.add(erh);
162: return erh;
163: }
164: if ("attribute-expression".equals(tagName))
165: {
166: final AttributeExpressionReadHandler erh = new AttributeExpressionReadHandler();
167: attributeExpressionHandlers.add(erh);
168: return erh;
169: }
170: if ("attribute".equals(tagName))
171: {
172: final AttributeReadHandler erh = new AttributeReadHandler();
173: attributeHandlers.add(erh);
174: return erh;
175: }
176: if ("display-condition".equals(tagName))
177: {
178: displayConditionReadHandler = new DisplayConditionReadHandler();
179: return displayConditionReadHandler;
180: }
181: }
182: return null;
183: }
184:
185: protected void configureElement(final Element e)
186: {
187: if (displayConditionReadHandler != null)
188: {
189: e.setDisplayCondition(displayConditionReadHandler.getExpression());
190: }
191: for (int i = 0; i < expressionHandlers.size(); i++)
192: {
193: final ExpressionReadHandler handler =
194: (ExpressionReadHandler) expressionHandlers.get(i);
195: e.addExpression(handler.getExpression());
196: }
197: for (int i = 0; i < styleExpressionHandlers.size(); i++)
198: {
199: final StyleExpressionReadHandler handler =
200: (StyleExpressionReadHandler) styleExpressionHandlers .get(i);
201: e.setStyleExpression(handler.getStyleKey(), handler.getExpression());
202: }
203: for (int i = 0; i < stylePropertyHandlers.size(); i++)
204: {
205:
206: final PropertyReadHandler handler =
207: (PropertyReadHandler) stylePropertyHandlers .get(i);
208: e.getStyle().setPropertyValueAsString(handler.getName(), handler.getResult());
209: }
210: for (int i = 0; i < attributeExpressionHandlers.size(); i++)
211: {
212: final AttributeExpressionReadHandler handler =
213: (AttributeExpressionReadHandler) attributeExpressionHandlers .get(
214: i);
215: e.setAttributeExpression(handler.getAttributeName(),
216: handler.getExpression());
217: }
218: for (int i = 0; i < attributeHandlers.size(); i++)
219: {
220: final AttributeReadHandler handler =
221: (AttributeReadHandler) attributeHandlers .get(i);
222: e.setAttribute(handler.getNamespace(), handler.getName(), handler.getObject());
223: }
224: e.setEnabled(enabled);
225: e.setVirtual(virtual);
226: if (style != null)
227: {
228: e.setAttribute(FlowReportFactoryModule.NAMESPACE,"style", style);
229: }
230: }
231:
232: protected abstract Element getElement();
233:
234: public final Node getNode()
235: {
236: return getElement();
237: }
238:
239:
246: public Object getObject() throws SAXException
247: {
248: return getElement();
249: }
250: }