View Javadoc

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 1194849 2011-10-29 09:28:45Z struberg $
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)
94              throws IOException, FaceletException, FacesException, ELException;
95  
96      /**
97       * Return a Facelet instance as specified by the file at the passed URI. The returned facelet is used
98       * to create composite component metadata.
99       * <p>
100      * This method should be called from vdl.getComponentMetadata(FacesContext context)  
101      * </p>
102      * 
103      * @since 2.0.1
104      * @param uri
105      * @return
106      * @throws IOException
107      */
108     public abstract Facelet getCompositeComponentMetadataFacelet(String uri) throws IOException;
109     
110     /**
111      * Create a Facelet used to create composite component metadata from the passed URL. This method checks if the 
112      * cached Facelet needs to be refreshed before returning. If so, uses the passed URL to build a new instance.
113      * 
114      * @since 2.0.1
115      * @param url source url
116      * @return Facelet instance
117      * @throws IOException
118      * @throws FaceletException
119      * @throws FacesException
120      * @throws ELException
121      */
122     public abstract Facelet getCompositeComponentMetadataFacelet(URL url)
123             throws IOException, FaceletException, FacesException, ELException;
124     
125     /**
126      * Set the static instance
127      * 
128      * @param factory
129      */
130     public static final void setInstance(FaceletFactory factory)
131     {
132         if (factory == null)
133         {
134             instance.remove();
135         }
136         else
137         {
138             instance.set(factory);
139         }
140     }
141 
142     /**
143      * Get the static instance
144      * 
145      * @return
146      */
147     public static final FaceletFactory getInstance()
148     {
149         return instance.get();
150     }
151 }