1:
31: package ;
32:
33: import ;
34:
35: import ;
36: import ;
37: import ;
38: import ;
39: import ;
40: import ;
41:
42:
47: public abstract class ElementReadHandler extends AbstractXmlReadHandler
48: {
49: private boolean virtual;
50: private boolean enabled;
51: private String style;
52: private ArrayList expressionHandlers;
53: private ArrayList styleExpressionHandlers;
54: private ArrayList attributeExpressionHandlers;
55: private ArrayList attributeHandlers;
56: private ArrayList stylePropertyHandlers;
57: private DisplayConditionReadHandler displayConditionReadHandler;
58:
59: protected ElementReadHandler()
60: {
61: expressionHandlers = new ArrayList();
62: styleExpressionHandlers = new ArrayList();
63: attributeExpressionHandlers = new ArrayList();
64: stylePropertyHandlers = new ArrayList();
65: attributeHandlers = new ArrayList();
66: }
67:
68: public boolean isEnabled()
69: {
70: return enabled;
71: }
72:
73: public String getStyle()
74: {
75: return style;
76: }
77:
78:
84: protected void startParsing(final Attributes attrs) throws SAXException
85: {
86: super.startParsing(attrs);
87: style = attrs.getValue(FlowReportFactoryModule.NAMESPACE, "style");
88: final String enabledValue = attrs.getValue(FlowReportFactoryModule.NAMESPACE, "enabled");
89: if (enabledValue != null)
90: {
91: enabled = "true".equals(enabledValue);
92: }
93: else
94: {
95: enabled = true;
96: }
97:
98: final String virtualValue = attrs.getValue(FlowReportFactoryModule.NAMESPACE, "virtual");
99: if (virtualValue != null)
100: {
101: virtual = "true".equals(virtualValue);
102: }
103: else
104: {
105: virtual = false;
106: }
107: }
108:
109:
118: protected XmlReadHandler getHandlerForChild(final String uri,
119: final String tagName,
120: final Attributes atts)
121: throws SAXException
122: {
123: if (FlowReportFactoryModule.NAMESPACE.equals(uri))
124: {
125: if ("expression".equals(tagName))
126: {
127: final ExpressionReadHandler erh = new ExpressionReadHandler();
128: expressionHandlers.add(erh);
129: return erh;
130: }
131: if ("style-expression".equals(tagName))
132: {
133: final StyleExpressionReadHandler erh = new StyleExpressionReadHandler();
134: styleExpressionHandlers.add(erh);
135: return erh;
136: }
137: if ("style-property".equals(tagName))
138: {
139: final PropertyReadHandler erh = new PropertyReadHandler();
140: stylePropertyHandlers.add(erh);
141: return erh;
142: }
143: if ("attribute-expression".equals(tagName))
144: {
145: final AttributeExpressionReadHandler erh = new AttributeExpressionReadHandler();
146: attributeExpressionHandlers.add(erh);
147: return erh;
148: }
149: if ("attribute".equals(tagName))
150: {
151: final AttributeReadHandler erh = new AttributeReadHandler();
152: attributeHandlers.add(erh);
153: return erh;
154: }
155: if ("display-condition".equals(tagName))
156: {
157: displayConditionReadHandler = new DisplayConditionReadHandler();
158: return displayConditionReadHandler;
159: }
160: }
161: return null;
162: }
163:
164: protected void configureElement(final Element e)
165: {
166: if (displayConditionReadHandler != null)
167: {
168: e.setDisplayCondition(displayConditionReadHandler.getExpression());
169: }
170: for (int i = 0; i < expressionHandlers.size(); i++)
171: {
172: final ExpressionReadHandler handler =
173: (ExpressionReadHandler) expressionHandlers.get(i);
174: e.addExpression(handler.getExpression());
175: }
176: for (int i = 0; i < styleExpressionHandlers.size(); i++)
177: {
178: final StyleExpressionReadHandler handler =
179: (StyleExpressionReadHandler) styleExpressionHandlers .get(i);
180: e.setStyleExpression(handler.getStyleKey(), handler.getExpression());
181: }
182: for (int i = 0; i < stylePropertyHandlers.size(); i++)
183: {
184:
185: final PropertyReadHandler handler =
186: (PropertyReadHandler) stylePropertyHandlers .get(i);
187: e.getStyle().setPropertyValueAsString(handler.getName(), handler.getResult());
188: }
189: for (int i = 0; i < attributeExpressionHandlers.size(); i++)
190: {
191: final AttributeExpressionReadHandler handler =
192: (AttributeExpressionReadHandler) attributeExpressionHandlers .get(
193: i);
194: e.setAttributeExpression(handler.getAttributeName(),
195: handler.getExpression());
196: }
197: for (int i = 0; i < attributeHandlers.size(); i++)
198: {
199: final AttributeReadHandler handler =
200: (AttributeReadHandler) attributeHandlers .get(i);
201: e.setAttribute(handler.getNamespace(), handler.getName(), handler.getObject());
202: }
203: e.setEnabled(enabled);
204: e.setVirtual(virtual);
205: if (style != null)
206: {
207: e.setAttribute(FlowReportFactoryModule.NAMESPACE,"style", style);
208: }
209: }
210:
211: protected abstract Element getElement();
212:
213:
220: public Object getObject() throws SAXException
221: {
222: return getElement();
223: }
224: }