1 /*
2 * JaspertReports JSF Plugin Copyright (C) 2011 A. Alonso Dominguez
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or (at
7 * your option) any later version. This library is distributed in the hope
8 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 *
11 * See the GNU Lesser General Public License for more details. You should have
12 * received a copy of the GNU Lesser General Public License along with this
13 * library; if not, write to the Free Software Foundation, Inc., 59 Temple
14 * Place, Suite 330, Boston, MA 02111-1307 USA A.
15 *
16 * Alonso Dominguez
17 * alonsoft@users.sf.net
18 */
19 package net.sf.jasperreports.jsf.context;
20
21 import java.util.Collection;
22 import javax.faces.component.UIComponent;
23 import javax.faces.context.FacesContext;
24
25 import net.sf.jasperreports.jsf.component.UIReport;
26 import net.sf.jasperreports.jsf.convert.ReportConverter;
27 import net.sf.jasperreports.jsf.convert.SourceConverter;
28 import net.sf.jasperreports.jsf.engine.Exporter;
29 import net.sf.jasperreports.jsf.engine.Filler;
30 import net.sf.jasperreports.jsf.resource.Resource;
31 import net.sf.jasperreports.jsf.util.Services;
32
33 /**
34 * The specific plugin's faces' context.
35 *
36 * @author A. Alonso Dominguez
37 */
38 public abstract class JRFacesContext {
39
40 /** Singleton instance key. */
41 protected static final String INSTANCE_KEY =
42 JRFacesContext.class.getName();
43
44 /** Default instance. */
45 private static final JRFacesContext DEFAULT_JRFACES_CONTEXT =
46 new DefaultJRFacesContext();
47
48 /**
49 * Obtains a singleton context instance.
50 *
51 * @param context current faces' context.
52 * @return the singleton instance.
53 */
54 public static JRFacesContext getInstance(final FacesContext context) {
55 if (context == null) {
56 throw new NullPointerException();
57 }
58
59 JRFacesContext instance = (JRFacesContext) context.getExternalContext()
60 .getApplicationMap().get(INSTANCE_KEY);
61 if (instance == null) {
62 instance = Services.chain(JRFacesContext.class,
63 DEFAULT_JRFACES_CONTEXT);
64 context.getExternalContext().getApplicationMap()
65 .put(INSTANCE_KEY, instance);
66 }
67 return instance;
68 }
69
70 /**
71 * Collection of available source types.
72 *
73 * @return collection of available source types.
74 */
75 public abstract Collection<String> getAvailableSourceTypes();
76
77 /**
78 * Collection of availbale export formats.
79 *
80 * @return collection of available export formats.
81 */
82 public abstract Collection<String> getAvailableExportFormats();
83
84 public abstract Collection<ContentType> getSupportedContentTypes();
85
86 /**
87 * Obtains the external context helper instance.
88 *
89 * @param context current faces' context.
90 * @return the external context helper.
91 */
92 public abstract ExternalContextHelper getExternalContextHelper(
93 FacesContext context);
94
95 /**
96 * Instantiates a source converter appropiate for the given component.
97 *
98 * @param context current faces' context.
99 * @param component the component which is asking the source converter.
100 * @return a source converter instance.
101 */
102 public abstract SourceConverter createSourceConverter(
103 FacesContext context, UIComponent component);
104
105 public abstract ReportConverter createReportConverter(
106 FacesContext context, UIReport component);
107
108 /**
109 * Creates a new report instance.
110 *
111 * @param context current faces' context.
112 * @param component a report component.
113 * @param name resource name.
114 * @return a resource instance.
115 */
116 public abstract Resource createResource(FacesContext context,
117 UIComponent component, String name);
118
119 /**
120 * Obtains the report's filler instance.
121 *
122 * @param context current faces' context.
123 * @param component the report component.
124 * @return a filler instance.
125 */
126 public abstract Filler getFiller(
127 FacesContext context, UIReport component);
128
129 /**
130 * Obtains the report's exporter instance.
131 *
132 * @param context current faces' context.
133 * @param component the report component
134 * @return an exporter instance.
135 */
136 public abstract Exporter getExporter(
137 FacesContext context, UIReport component);
138
139 }