01: /*
02: *
03: * Copyright 2007 Giordano Maestro (giordano.maestro@assetdata.it)
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
06: * use this file except in compliance with the License. You may obtain a copy of
07: * the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14: * License for the specific language governing permissions and limitations under
15: * the License.
16: */
17: package org.romaframework.aspect.reporting.jr.component;
18:
19: import java.util.Map;
20:
21: import net.sf.jasperreports.engine.JRException;
22: import net.sf.jasperreports.engine.JasperReport;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26: import org.romaframework.aspect.reporting.ReportingException;
27: import org.romaframework.aspect.reporting.jr.DesignJr;
28: import org.romaframework.aspect.reporting.jr.element.DesignElement;
29: import org.romaframework.aspect.reporting.jr.template.TemplateManager;
30: import org.romaframework.core.flow.ObjectContext;
31: import org.romaframework.core.schema.SchemaClassDefinition;
32: import org.romaframework.core.schema.SchemaFeatures;
33:
34: public abstract class BaseComponentJr implements DesignElement {
35:
36: protected Log log = LogFactory.getLog("JR.REPORTING");
37: protected DesignJr design;
38: protected String id;
39: protected int level;
40: protected BaseComponentJr parent = null;
41:
42: public BaseComponentJr(BaseComponentJr iParent,
43: SchemaFeatures iSchemaFeatures,
44: SchemaClassDefinition iRootDesignClass) {
45: super ();
46: if (iParent == null) {
47: level = 1;
48: } else {
49: level = iParent.level + 1;
50: }
51: id = generateID(iParent, iSchemaFeatures);
52: id = id.replaceAll("\\.", "");
53: design = new DesignJr(iRootDesignClass, id);
54: parent = iParent;
55: }
56:
57: public JasperReport getCompiledReport() throws JRException {
58: return design.getCompiledReport();
59: }
60:
61: protected abstract String generateID(BaseComponentJr iParent,
62: SchemaFeatures iSchemaFeatures);
63:
64: protected boolean isRegistered() {
65: return !(ObjectContext.getInstance().getComponent(
66: TemplateManager.class).getDesign(id) == null);
67: }
68:
69: public abstract void fillDesign(Object toRender,
70: Map<String, Object> parametersSource) throws JRException;
71:
72: public void saveTemplate() throws ReportingException {
73: design.saveTemplate();
74: }
75:
76: public abstract void generateDesign() throws JRException;
77:
78: public String getId() {
79: return id;
80: }
81:
82: public BaseComponentJr getParent() {
83: return parent;
84: }
85:
86: public int getLevel() {
87: return level;
88: }
89: }
|