Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/sun/facelets/compiler/NamespaceHandler.java


1   /**
2    * Licensed under the Common Development and Distribution License,
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    * 
6    *   http://www.sun.com/cddl/
7    *   
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
11   * implied. See the License for the specific language governing
12   * permissions and limitations under the License.
13   */
14  
15  package com.sun.facelets.compiler;
16  
17  import java.io.IOException;
18  import java.lang.reflect.Method;
19  import java.util.Map;
20  
21  import javax.el.ELException;
22  import javax.el.FunctionMapper;
23  import javax.faces.FacesException;
24  import javax.faces.component.UIComponent;
25  
26  import com.sun.facelets.FaceletContext;
27  import com.sun.facelets.FaceletException;
28  import com.sun.facelets.FaceletHandler;
29  import com.sun.facelets.el.CompositeFunctionMapper;
30  import com.sun.facelets.tag.TagLibrary;
31  
32  final class NamespaceHandler extends FunctionMapper implements FaceletHandler {
33  
34      private final TagLibrary library;
35      private final Map ns;
36      private FaceletHandler next;
37      
38      public NamespaceHandler(FaceletHandler next, TagLibrary library, Map ns) {
39          this.library = library;
40          this.ns = ns;
41          this.next = next;
42      }
43  
44      public void apply(FaceletContext ctx, UIComponent parent)
45              throws IOException, FacesException, FaceletException, ELException {
46          FunctionMapper orig = ctx.getFunctionMapper();
47          ctx.setFunctionMapper(new CompositeFunctionMapper(this, orig));
48          try {
49              next.apply(ctx, parent);
50          } finally {
51              ctx.setFunctionMapper(orig);
52          }
53      }
54  
55      public Method resolveFunction(String prefix, String localName) {
56          String uri = (String) this.ns.get(prefix);
57          if (uri != null) {
58              return this.library.createFunction(uri, localName);
59          }
60          return null;
61      }
62  
63  }