1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.view.facelets;
20
21 import javax.el.ELException;
22 import javax.faces.FacesException;
23 import javax.faces.view.facelets.FaceletException;
24 import java.io.IOException;
25 import java.net.URL;
26
27 /**
28 * FaceletFactory for producing Facelets relative to the context of the underlying implementation.
29 *
30 * @author Jacob Hookom
31 * @version $Id: FaceletFactory.java 1187700 2011-10-22 12:19:37Z bommel $
32 */
33 public abstract class FaceletFactory
34 {
35
36 private static ThreadLocal<FaceletFactory> instance = new ThreadLocal<FaceletFactory>();
37
38 /**
39 * Return a Facelet instance as specified by the file at the passed URI.
40 *
41 * @param uri
42 * @return
43 * @throws IOException
44 * @throws FaceletException
45 * @throws FacesException
46 * @throws ELException
47 */
48 public abstract Facelet getFacelet(String uri) throws IOException;
49
50 /**
51 * Create a Facelet from the passed URL. This method checks if the cached Facelet needs to be refreshed before
52 * returning. If so, uses the passed URL to build a new instance;
53 *
54 * @param url
55 * source url
56 * @return Facelet instance
57 * @throws IOException
58 * @throws FaceletException
59 * @throws FacesException
60 * @throws ELException
61 */
62 public abstract Facelet getFacelet(URL url) throws IOException, FaceletException, FacesException, ELException;
63
64 /**
65 * Return a Facelet instance as specified by the file at the passed URI. The returned facelet is used
66 * to create view metadata in this form:
67 * <p>
68 * UIViewRoot(in facet javax_faces_metadata(one or many UIViewParameter instances))
69 * </p>
70 * <p>
71 * This method should be called from FaceletViewMetadata.createMetadataView(FacesContext context)
72 * </p>
73 *
74 * @since 2.0
75 * @param uri
76 * @return
77 * @throws IOException
78 */
79 public abstract Facelet getViewMetadataFacelet(String uri) throws IOException;
80
81 /**
82 * Create a Facelet used to create view metadata from the passed URL. This method checks if the
83 * cached Facelet needs to be refreshed before returning. If so, uses the passed URL to build a new instance;
84 *
85 * @since 2.0
86 * @param url source url
87 * @return Facelet instance
88 * @throws IOException
89 * @throws FaceletException
90 * @throws FacesException
91 * @throws ELException
92 */
93 public abstract Facelet getViewMetadataFacelet(URL url) throws IOException, FaceletException, FacesException, ELException;
94
95 /**
96 * Return a Facelet instance as specified by the file at the passed URI. The returned facelet is used
97 * to create composite component metadata.
98 * <p>
99 * This method should be called from vdl.getComponentMetadata(FacesContext context)
100 * </p>
101 *
102 * @since 2.0.1
103 * @param uri
104 * @return
105 * @throws IOException
106 */
107 public abstract Facelet getCompositeComponentMetadataFacelet(String uri) throws IOException;
108
109 /**
110 * Create a Facelet used to create composite component metadata from the passed URL. This method checks if the
111 * cached Facelet needs to be refreshed before returning. If so, uses the passed URL to build a new instance.
112 *
113 * @since 2.0.1
114 * @param url source url
115 * @return Facelet instance
116 * @throws IOException
117 * @throws FaceletException
118 * @throws FacesException
119 * @throws ELException
120 */
121 public abstract Facelet getCompositeComponentMetadataFacelet(URL url) throws IOException, FaceletException, FacesException, ELException;
122
123 /**
124 * Set the static instance
125 *
126 * @param factory
127 */
128 public static final void setInstance(FaceletFactory factory)
129 {
130 if (factory == null)
131 {
132 instance.remove();
133 }
134 else
135 {
136 instance.set(factory);
137 }
138 }
139
140 /**
141 * Get the static instance
142 *
143 * @return
144 */
145 public static final FaceletFactory getInstance()
146 {
147 return instance.get();
148 }
149 }