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 java.io.IOException;
22  import java.net.URL;
23  import javax.faces.view.facelets.FaceletCache;
24  import javax.faces.view.facelets.FaceletContext;
25  
26  /**
27   * Extended FaceletCache contract that supports additional Myfaces specific concepts
28   * that are necessary to implement.
29   *
30   * @author Leonardo Uribe
31   * @since 2.1.12
32   */
33  public abstract class AbstractFaceletCache<V> extends FaceletCache<V>
34  {
35      private FaceletCache.MemberFactory<V> _compositeComponentMetadataFaceletFactory;
36  
37      /**
38       * Retrieve a Facelet instance from the cache given the passed url, but taking into
39       * account the facelet context too, so the cache can implement special rules 
40       * according to the context for recompile the facelet if necessary.
41       * 
42       * @param ctx
43       * @param url
44       * @return
45       * @throws IOException 
46       */
47      public V getFacelet(FaceletContext ctx, URL url) throws IOException
48      {
49          return getFacelet(url);
50      }
51      
52      /**
53       * Retrieve or create a Facelet instance used to create composite component 
54       * metadata from the cache.
55       * 
56       * @param url
57       * @return
58       * @throws IOException 
59       */
60      public abstract V getCompositeComponentMetadataFacelet(URL url) throws IOException;
61  
62      /**
63       * Check if the composite component metadata facelet associated with the url is
64       * cached or not.
65       * 
66       * @param url
67       * @return 
68       */
69      public abstract boolean isCompositeComponentMetadataFaceletCached(URL url);
70      
71      /**
72       * Set the factories used for create Facelet instances.
73       * 
74       * @param faceletFactory
75       * @param viewMetadataFaceletFactory
76       * @param compositeComponentMetadataFaceletFactory 
77       */
78      protected void setMemberFactories(FaceletCache.MemberFactory<V> faceletFactory,
79                                        FaceletCache.MemberFactory<V> viewMetadataFaceletFactory,
80                                        FaceletCache.MemberFactory<V> compositeComponentMetadataFaceletFactory)
81      {
82          if  (compositeComponentMetadataFaceletFactory == null)
83          {
84              throw new NullPointerException("viewMetadataFaceletFactory is null");
85          }
86          _compositeComponentMetadataFaceletFactory = compositeComponentMetadataFaceletFactory;
87          setMemberFactories(faceletFactory, viewMetadataFaceletFactory);
88      }
89      
90      /**
91       * 
92       * @return 
93       */
94      protected FaceletCache.MemberFactory<V> getCompositeComponentMetadataMemberFactory()
95      {
96          return _compositeComponentMetadataFaceletFactory;
97      }    
98  }